Question

Football Game Scores Write a C++ program that stores the following data about a football game...

Football Game Scores

Write a C++ 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). A sample file is on the next page.

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

//games.txt

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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please let me know if you need more information:-

-----------------------------------------------------------------------

#include <iostream>
# include <fstream>
#include <iomanip>
#include <stdlib.h>
using namespace std;
struct games_record {
   string visit_team;
   int home_score;
   int visit_score;
};
void printMenu() {
   cout << "1. print information of all games" << endl;
   cout << "2. print information for a specific game" << endl;
   cout << "3. print information of all games" << endl;
   cout << "4. print information of all games" << endl;
}
int main() {
   int i = 0, totalValues = 0;

   string team_name; //added Newly
   ifstream inFile;
   string tmp = "";
   inFile.open("games.txt");
   inFile >> totalValues;
   getline(inFile, tmp);
   cout << "total value : " << totalValues << endl;
   games_record* records = new games_record[totalValues];
   while (inFile.eof() == NULL) {
       getline(inFile, records[i].visit_team);
       cout << records[i].visit_team << endl;
       inFile >> records[i].home_score >> records[i].visit_score;
       cout << records[i].home_score << endl;
       cout << records[i].visit_score << endl;
       getline(inFile, tmp); //skip line
       i++;
   }
   int choice = 0;
   int avg__home_Score = 0;
   int avg__visit_Score = 0;
   printMenu();
   cin >> choice;
   while (true) {
       switch (choice) {
       case 1:
           cout << '_' << setw(18) << "__________________" << '_' << setw(10)
                   << "___________" << '_' << setw(10) << "__________" << '_'
                   << endl;
           cout << '|' << setw(18) << "VISIT_TEAM" << '|' << setw(10)
                   << "HIGH_SCORE" << '|' << setw(10) << "VISIT_SCORE" << '|'
                   << endl;
           cout << '_' << setw(18) << "__________________" << '_' << setw(10)
                   << "___________" << '_' << setw(10) << "__________" << '_'
                   << endl;
           for (int i = 0; i < totalValues; i++)
               cout << '|' << setw(18) << records[i].visit_team << '|'
                       << setw(10) << records[i].home_score << '|' << setw(10)
                       << records[i].visit_score << '|' << endl;
           cout << '_' << setw(18) << "__________________" << '_' << setw(10)
                   << "___________" << '_' << setw(10) << "__________" << '_'
                   << endl;
           break;
       case 2:
       // char team_name[250];
           cout << "Enter the Team Name" << endl;

            cin.get();
           getline (cin,team_name);
           for (int i = 0; i < totalValues; i++) {
               if (records[i].visit_team == team_name) {
                   cout << '|' << setw(18) << records[i].visit_team << '|'
                           << setw(10) << records[i].home_score << '|'
                           << setw(10) << records[i].visit_score << '|'
                           << endl;
               }
           }
           break;
       case 3:
           for (int i = 0; i < totalValues; i++)
               avg__home_Score += records[i].home_score;
           cout << "Average home_score: " << (avg__home_Score / totalValues)
                   << endl;
           break;
       case 4:
           for (int i = 0; i < totalValues; i++)
               avg__visit_Score += records[i].visit_score;
           cout << "Average visit_score: " << (avg__visit_Score / totalValues)
                   << endl;
           break;
       default:
           cout << "Please enter valid input" << endl;
           break;
       }
       printMenu();
       cin >> choice;
   }
   return 0;
}

Please find below sample output:-

total value 5 SD Mines 21 17 Northern State 10 BYU 10 21 Creighton 14 Sam Houston State 14 24 1. print information of all gam4 Average visit_score: 14 1. print information of all games 2. print information for a specific game 3. print Average home_sc

1. print information of all games 2. print information for a specific game 3. print Average home_score of all games 4. print

---------------------------------------------------------

Thanks

Add a comment
Know the answer?
Add Answer to:
Football Game Scores Write a C++ program that stores the following data about a football game...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I am getting an error that the variable num was not declared in the scope on...

    I am getting an error that the variable num was not declared in the scope on the line of code that has; while(num != 5). Do you know how to fixe this error? #include <iostream> #include <iomanip> #include <string> #include<fstream> #include <cstring> using namespace std; //Declare the structure struct Games { string visit_team; int home_score; int visit_score; }; // Function prototypes int readData(Games *&stats); int menu(); void pickGame(Games *&stats, int size); void inputValid (Games *&stats, int size); void homeTotal(Games *&stats,...

  • Write a program in C++ Lightening Lanes Case Study Problem Statement On Tuesday afternoons, Lightening Lanes...

    Write a program in C++ Lightening Lanes Case Study Problem Statement On Tuesday afternoons, Lightening Lanes Bowling Alley runs a special class to teach children to bowl. Each lane has an instructor who works with a team of four student bowlers and instructs them as they bowl three lines (games). The management of Lightening Lanes has asked you to develop a program that will report each student’s 3-game average score and compare it to the average score they bowled the...

  • (C++) Write a program that declares a struct to store the data of a football player...

    (C++) Write a program that declares a struct to store the data of a football player (player’s name, player’s position, number of touchdowns, number of catches, number of passing yards, number of receiving yards, and the number of rushing yards). Declare an array of 10 components to store the data of 10 football players. Your program must contain a function to input data and a function to output data. Add functions to search the array to find the index of...

  • Write a program (C++) that shows Game sales. The program should use a structure to store...

    Write a program (C++) that shows Game sales. The program should use a structure to store the following data about the Game sale: Game company Type of Game (Action, Adventure, Sports etc.) Year of Sale Sale Price The program should use an array of at least 3 structures (3 variables of the same structure). It should let the user enter data into the array, change the contents of any element and display the data stored in the array. The program...

  • Write a Python program that stores the data for each player on the team, and it...

    Write a Python program that stores the data for each player on the team, and it also lets the manager set a starting lineup for each game. Questions: - Handle the exception that occurs if the program can’t find the data file. - Handle the exceptions that occur if the user enters a string where an integer is expected. - Handle the exception that occurs if the user enters zero for the number of at bats. - Thoroughly test the...

  • Write a complete C++ program that reads students names and their test scores from an input...

    Write a complete C++ program that reads students names and their test scores from an input text file. The program should output each student’s name followed by the test scores and the relevant grade in an output text file. It should also find and display on screen the highest/lowest test score and the name of the students having the highest/lowest test score, average and variance of all test scores. Student data obtained from the input text file should be stored...

  • c++ A menu-driven program gives the user the option to find statistics about different baseball players....

    c++ A menu-driven program gives the user the option to find statistics about different baseball players. The program reads from a file and stores the data for ten baseball players, including player’s team, name of player, number of homeruns, batting average, and runs batted in. (You can make up your data, or get it online, for example: http://espn.go.com/mlb/statistics ) Write a program that declares a struct to store the data for a player. Declare an array of 10 components to...

  • Lightening Lanes Case Study Problem Statements On Tuesday afternoons, Lightening Lanes Bowling Alley runs a special...

    Lightening Lanes Case Study Problem Statements On Tuesday afternoons, Lightening Lanes Bowling Alley runs a special class to teach children to bowl. Each lane has an instructor who works with a team of four student bowlers and instructs them as they bowl three lines (games). The management of Lightening Lanes has asked you to develop a program that will report each student’s 3-game average score and compare it to the average score they bowled the previous week. In this way,...

  • Pls help me with this Node Js homework. First implement this ejs file. Check out the...

    Pls help me with this Node Js homework. First implement this ejs file. Check out the TODO section and implement it. Given: ejs file: <% include ../partials/header %> <% include ../partials/menu %>    <div class="container">        <br>        <div class="jumbotron">        <h1 class="display-4">Fall 2018 Stats</h1>        <p class="lead">Detailed information on how the Buffs are doing in the 2018 Football Season!</p>        </div>               <table class="table table-bordered" id="stats_table">            <tr>   ...

  • C Program: Write a program that will read names, ids, dept names, and cgpа of some...

    C Program: Write a program that will read names, ids, dept names, and cgpа of some students from a file and will show the results. Consider that the name of the file is 'input.csv'. It is just a text file where each line holds information of one student. Example format of two lines in the file is as follows: David Smith, 21, Computer Science, 3.98 Jone Smith, 11, Finance, 3.45 Read all information from the file, and print them on...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT