C Programming Write a program that stores the following data

C++ Programming

Write a program that stores the following data about a football game in a structure:

Field Name

Description

visit_team

string (name of visiting team)

home_score

Int

visit_score

Int

The program should read the number of games from a data file named “games.txt”, dynamically allocate an array of structures for the games using one structure for each game, and then read the information for each game from the same file (visiting team, home score, visiting team’s score)

Use a menu-driven interface to allow the user to:

Print the information for all games, in table form.

Print the information for a specific game, given the visiting team’s name.

Print the average points per game scored by the home team during the season.

Print the average points per game scored against the home team during the season.

Use an enumerated data type for the menu item selection

Your program should be modular with separate functions for input and each part of the processing. Your output should be well-organized, neat, and easy to read.

A sample file is shown below:

5
SD Mines
21 17
Northern State
10 3
BYU
10 21
Creighton
14 7
Sam Houston State
14 24

Field Name

Description

visit_team

string (name of visiting team)

home_score

Int

visit_score

Int

Solution

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
const int SIZE = 50;
int TotalPoints(int *, int);
struct Player
{ //Add players details
char name[SIZE];
int playNum;
int Points;
};
int main()
{
const int NUM_PLAYERS = 12; //Number of Players
   // Dynamically allocate the memory needed.
Player *players = new Player[NUM_PLAYERS]; //Array of structures
int index;                           //Loop
   int total=0;
// Get Player data & the score(home & visit)
cout << \"\ You will need the following information.\ \";
   cout << \"Pertaining to your Players.\ \";
cout << \"The Player\'s Details\ \";
   cout << \"Score.\ \ \ \";


for (index = 0; index < NUM_PLAYERS; index++) //Use switch case for menu type selection
{
//Modify according to players details
cout << \"Please enter the Player\'s Name: \";
       cin.getline( players[index].name, 50 );
cout << \"Please enter the Player\'s Number: \";
( cin >> players[index].playNum ).get();
       //To test my values for zero, negative
       while (players[index].playNum <=0)
       {
           cout << \"Zero or negative numbers not allowed\ \";
           cout << \"Please enter the Player\'s Number: \";
           (cin >> players[index].playNum).get();
       }
//adding home & visit scores
cout << \"Please enter the Points Scored by the Player: \";
( cin >> players[index].Points ).get();
       //To test my values for zero, negative.
       while (players[index].Points < 0)
       {
           cout << \"Zero or negative numbers not allowed\ \";
           cout << \"Please enter the Points Scored by the Player: \";
           (cin >> players[index].Points).get();
       }
       cout << endl << endl;
}
   //Display the players data
   cout << \"Here is the players data:\ \ \";
   cout << \" Name Number Score   \ \";
   cout << \"--------------------------------\ \";
   for (index = 0; index < NUM_PLAYERS; index++)
   {
       cout << setw(8) << players[index].name;
       cout << setw(8) << players[index].playNum;
       cout << setw(8) << players[index].Points << endl;
   }
   //Calculate the average
   for (index = 0; index < NUM_PLAYERS; index++)
   {
//formula for average
       }
   //Display the total(average) for both
   cout << \"\ \ The total of points scored by the team are: \";
   cout << total << endl;
     
   // Delete the memory.
   delete [] players;
return 0;
}

C++ Programming Write a program that stores the following data about a football game in a structure: Field Name Description visit_team string (name of visiting
C++ Programming Write a program that stores the following data about a football game in a structure: Field Name Description visit_team string (name of visiting
C++ Programming Write a program that stores the following data about a football game in a structure: Field Name Description visit_team string (name of visiting

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site