Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need some help with a C++ program that can calculate and report a Soccer Leagu

ID: 671510 • Letter: I

Question

I need some help with a C++ program that can calculate and report a Soccer League Results Table. The program is to have two inputs files, File_a will feature the 20 teams names in alphabetical order and File_b will report a number of game results of the form - TeamA 1 Team B 0, TeamC 3 TeamD 4, meaning TeamA scored 1 goal and TeamB 0 goals etc. For each game the following results will occur; Win(3pts), Draw(1pt), Loss(0pts).

The Program is to have the following steps:

1. Read File_a and store the team names in an appropriate structure. It may be assumed that this file contains no errors. The file may then be closed after the team names have been stored.

2. Read File_b (the results file) one dataset at a time, stopping at EOF. This file may contain errors in the team name being misspelt or the number of goals scored may be negative. If either case occurs, print the dataset containing the error and then ignore the dataset, not updating either team.

3. For each game it is required to record the result (win, loss, draw) for each team, and then update the recorded data for each team. This will involve searching for the teams name and recording the respective result for each team.

4. Produce an output table that has the 20 teams listed in alphabetical order that shows clearly: Games played, Points, Goals For, Goals Against and Goal Differential for eac team. Note output is to be of the form such that the names are to be right-justified.

5. Produce a 2nd output table that sorts and ranks the teams in decreasing order based upon performance (competition points). Where two teams are on the same points sort by Goal Differential, then Goals For. The second table is to report the same data as the first table, simply put in a different sorting.

It is to be noted that the program is to make use of user-defined structure types of the form (structname_t) and then have a single array of these objects. Also designed functions should be incorporated wherever fitting.

File_a will be of the form: Arsenal AstonVilla Bournemouth Chelsea CrystalPalace Everton Leicester Liverpool ManCity ManUtd Newcastle Norwich Southampton Stoke Sunderland Swansea Tottenham Watford WestBrom WestHam

An example of File_b is:

Chelsea 3 Leicester 0

Newcastle 2 WestHam 2

Bournemouth 0 Tottemham 1

Wigan 0 AstonVilla 0

WestBrom 4 Sunderland

ManUtd -4 ManCity 3

Thanks :)

Explanation / Answer

public partial class frmLeague : Form

{

   public frmLeague()

{

InitializeComponent();

}

int[] Scores = new int[8]{0,0,0,0,0,0,0,0};

string[] Teams = new string[8] { "The Flying Handbag", "South Shore Labour Club", "Kirkham Liberal Club", "Rossall Tavern", "Blackpool Deaf Society", "The Dinmore Hotel", "The Gardeners Arms", "Bispham Conservative Club" };

private void btnShow_Click(object sender, EventArgs e)

{

TextReader Reader = new StreamReader("results.txt");

string OutPut;

while (Reader.Peek()>8)

{

OutPut = Reader.ReadLine();

string[] Split = OutPut.Split(new Char[] { ',' });

for (int count = 0; count < 8; count++)

{

if (Split[0] == Teams[count])

{

Scores[count] = Scores[count] + Convert.ToInt32(Split[1]);

}

lblLeagueTable.Text = (Convert.ToString(Split[0]) + (Convert.ToString(Split[1])));  

}

Reader.Close();

}

void GenerateGroups()

{

    for(int i = 0; i < 8; i++)

    {

        Border brd = new Border();

        brd.CornerRadius = new CornerRadius(5);

        brd.Margin = new Thickness(2);

        brd.SetValue(Grid.ColumnProperty, i % 4);

        brd.SetValue(Grid.RowProperty, i / 4);

        LinearGradientBrush lgb = new LinearGradientBrush();

        lgb.StartPoint = new Point(0, 0);

        lgb.EndPoint = new Point(1, 1);

        lgb.GradientStops = new GradientStopCollection();

        lgb.GradientStops.Add(new GradientStop()

          { Offset = 0.0, Color = Color.FromArgb(255, 0, 0, 0)});

        lgb.GradientStops.Add(new GradientStop()

          { Offset = 0.5, Color = Color.FromArgb(255, 30, 30, 30)});

        lgb.GradientStops.Add(new GradientStop()

          { Offset = 1.0, Color = Color.FromArgb(255, 40, 40, 40)});

        brd.Background = lgb;

        lgbEven.StartPoint = new Point(0, 0);

        lgbEven.EndPoint = new Point(1, 1);

        lgbEven.GradientStops = new GradientStopCollection();

        lgbEven.GradientStops.Add(new GradientStop()

              { Offset = 0.0, Color = Color.FromArgb(255, 0, 0, 0) });

        lgbEven.GradientStops.Add(new GradientStop()

              { Offset = 0.5, Color = Color.FromArgb(255, 30, 30, 30) });

        lgbEven.GradientStops.Add(new GradientStop()

              { Offset = 1.0, Color = Color.FromArgb(255, 80, 80, 80) });

        Grid grdGroup = new Grid();

        grdGroup.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(28) });

        grdGroup.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });

        grdGroup.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });

        grdGroup.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(18) });

        grdGroup.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(18) });

        grdGroup.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(18) });

        grdGroup.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(18) });

        TextBlock txtGroupID = new TextBlock()

        {

            Text = ((char)(i + 65)).ToString(),

            Foreground = new SolidColorBrush(Colors.White),

            FontSize = 18,

            FontWeight = FontWeights.Bold

        };

        txtGroupID.SetValue(Grid.ColumnProperty, 0);

        txtGroupID.SetValue(Grid.RowProperty, 0);

        txtGroupID.SetValue(Grid.RowSpanProperty, 4);

        txtGroupID.SetValue(VerticalAlignmentProperty, VerticalAlignment.Center);

        txtGroupID.SetValue(HorizontalAlignmentProperty, HorizontalAlignment.Center);

        grdGroup.Children.Add(txtGroupID);

        for (int j = 0; j < 4; j++)

        {

            Grid grdTeam = new Grid();

            grdTeam.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });

            grdTeam.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });

            grdTeam.RowDefinitions.Add(new RowDefinition() { Height = new GridLength(25) });

            grdTeam.SetValue(Grid.ColumnProperty, 1);

            grdTeam.SetValue(Grid.ColumnSpanProperty, 2);

            grdTeam.SetValue(Grid.RowProperty, j);

            grdTeam.HorizontalAlignment = HorizontalAlignment.Stretch;

            grdTeam.VerticalAlignment = VerticalAlignment.Center;

            grdTeam.Width = 120;

            Team team =

              GameHelper.Instance.TeamsDictionary[GameHelper.Instance.TeamCodes[i * 4 + j]];

            Image img = new Image()

            {

                Source = new BitmapImage(new Uri(string.Format(

                         @"http://www.fifa.com/imgml/flags/reflected/m/{0}.png",

                         team.TeamID.ToLower()), UriKind.Absolute)),

               

                Width = 28.5,

                Height = 25.0,

                VerticalAlignment = VerticalAlignment.Center

            };

            img.SetValue(Grid.ColumnProperty, 0);

            img.SetValue(Grid.RowProperty, j);

            img.VerticalAlignment = VerticalAlignment.Top;

            img.HorizontalAlignment = HorizontalAlignment.Stretch;

            img.Clip = new RectangleGeometry() { Rect =

                       new Rect(new Point(0, 0), new Point(28.5, 14)) };

            img.Tag = team.TeamID;

            TranslateTransform tf = new TranslateTransform()

            {

                 X = 0,

                 Y = 6

            };

            img.RenderTransform = tf;

            TextBlock txt = new TextBlock()

            {

                Text = team.TeamName,

                Foreground = new SolidColorBrush(Colors.White)

            };

            txt.SetValue(Grid.ColumnProperty, 1);

            txt.SetValue(Grid.RowProperty, j);

            txt.VerticalAlignment = VerticalAlignment.Center;

            txt.HorizontalAlignment = HorizontalAlignment.Stretch;

            txt.Tag = team.TeamID;

            grdTeam.Tag = team.TeamID;

            grdTeam.Children.Add(img);

            grdTeam.Children.Add(txt);

            grdTeam.MouseEnter += new MouseEventHandler(team_MouseEnter);

            grdTeam.MouseLeave += new MouseEventHandler(team_MouseLeave);

            grdTeam.MouseLeftButtonUp +=

                    new MouseButtonEventHandler(team_MouseLeftButtonUp);

            grdGroup.Children.Add(grdTeam);

        }

        brd.Child = grdGroup;

        grdGroupsContainer.Children.Add(brd);

    }

}