This program will store roster and player information for a baseball team. An input file will contain the following:
· the player name
· the player number,
· the number of hits,
· the number of outs,
· and the number of times at bat
The program is to compute and display each player's statistics including walks and batting average.
(1) (5 pts)Implement a menu of options in the main() function for a user to modify and display the roster. Each option is represented by a single character. The program initially outputs the menu, and will output the menu again after a user chooses an option and views the results. The program ends when the user chooses the option to Quit. For this step, the other options do nothing it is just to build the menu. If the user chooses an invalid option, display the message: "ERROR -- Invalid option" .
XXXXXXXXXXpts) Use the structure data type defined in the template to store information for a single player. Write a function,
void readFile( PlayerInfo players[ ], int& playerCount )
that will prompt the user for a file name and read from the file into the a
ay of PlayerInfo structures. Use a separate variable, playerCount, to keep track of how many players are actually stored in the a
ay. The a
ay may not be full at all times.
**WARNING!!! ** For some reason, ZyBooks getline() function is not removing the endline character from the end of the name when reading from the file. Once you read the player's name from the file, you will need to remove this last character.
Research the ignore() function to move beyond the return key at the end of the player's stat numbers before reading the the name of the next player from the file. file.ignore(80, '\n').
The maximum number of players per team will be 15. The program should write an e
or message to the screen, "***Too many players in file." If the input file exceeds 15 players. The program should then continue by processing the first 15 players read. A players name cannot exceed 25 characters.
Output the contents of the a
ay (i.e., output all the player information) by writing a displayTeam( ) function using parameters called from main( ). Use column headers and formatted output to present the data as a table of information. For this step, initialize walks and batting averages to zero.
(2) (5 pts) Implement a function calcBatAvg() using parameters to calculate player walks and batting average with parameters. The number of walks is calculated by (number of times at bat - [number of hits + number of outs]), and the batting average is calculated by (number of hits / [number of times at bat - number of walks]). Batting average should be displayed using 3 decimal places.
(3) (5 pt) Implement the "Display players above batting average" menu option, by writing a displayBatAvg( ) function. Prompt the user for a batting average. Display only players who meet or exceed this batting average.
5) (10 pt) Implement the "Add player" menu option. Prompt the user for a new player's jersey number and rating. If there is room in the a
ay (check playerCount), add the new information otherwise output the e
or message: "Too many players, player cannot be added." Once the player is added, increment the '''playerCount''' and call the calcBatAvg() function to calculate walks and batting average. (10 pt)
using namespace std;
const int MAX = 15;
maximum number of players on team
structure PlayerInfo - data for one playe
int numWalks = 0;
TODO: Write functions here
ay to hold PlayerInfo
int playerCount = 0;
how many players in a
read player info from file
display menu, loop until user wants to quit