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
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:-
---------------------------------------------------------
Thanks
Football Game Scores Write a C++ program that stores the following data about a football game...
(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 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...
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...
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. 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...
Write a C++ menu driven Payroll program. Must be user friendly. Menu 1. Check data file 2. Read Data file 3. Process payroll for one employee 4. Process payroll for all employees 5. Print out to a text or an HTML file 6. Exit You must use the following Payroll classes, structures, pointers, arrays, enum, vector, recursive, advance file I/O, STL, iterators and containers. The program to process an input file below to calculate tax of 28% and output it...
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 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> ...
For this assignment, you are to write a program that does the following: (C++) • read exam scores from a file name data.txt into an array, and • after reading all the scores, output the following to the monitor: the average score and the total number of scores. In addition, the program must use the following functions: //precondition: fileName is name of the file to open, inFile is the input file 2 of 2 //postcondition: inFile is opened. If inFile...
please write in C++ Write a program that uses a structure to store the following inventory data in a file: The data can be either read from a text file or the keyboard Item name (string) Quantity on hand(int) Wholesale cost(double) Retail Cost(double) The program should have a menu that allows the user to perform the following tasks: Add new records to the file Display any record in the file User will provide the name of the item or the...