You will develop a C++ program to store and manage information about baseball players. The program will read the following information for each player in the data file: player’s name (string) team identifier (string) games played (integer) at bats (integer) runs scored (integer) hits (integer) doubles (integer) triples (integer) homeruns (integer)
You will develop a C++
player’s name (string)
team identifier (string)
games played (integer)
at bats (integer)
runs scored (integer)
hits (integer)
doubles (integer)
triples (integer)
homeruns (integer)
Separate parallel
For each player, your program will compute the batting average and the slugging percentage. Those computed values will be stored in separate corresponding parallel arrays. The following formulas will be used for those computations:
singles = hits - (doubles + triples + homeruns)
total bases = singles + 2*doubles + 3*triples + 4*homeruns
batting average = (hits) / (at bats)
slugging percentage = (total bases) / (at bats)
A player with zero at bats is defined to have a batting average and slugging percentage of zero.
Note that only name, team identifier, batting average and the slugging percentage are stored and retained in the vectors and arrays.
- The program will recognize the following commands:
QUIT
INPUT filename
TEAM identifier
REPORT n BATTING
REPORT n SLUGGING
The program will recognize commands entered with any mix of upper and lowercase letters.
The program will be operated interactively: it will prompt the user and accept commands from the keyboard and continue until QUIT is entered.
If the user enters an invalid command, the program will display an appropriate message and prompt the user to enter another command.
- The “QUIT” command will halt execution.
- The "INPUT" command will be followed by a string representing the name of an input file. The program will discard the current data set stored in memory, and then process the input file as the source for a new data set (open the file, read the file and for each line store the data in the appropriate vectors or arrays.
If the user enters an invalid file name, the program will display an appropriate message and prompt the user to enter another file name. The program will halt after the user enters an invalid file name three consecutive times.
- The "TEAM" command will be followed by a string representing a team identifier. The program will display all information about all players on that team, in alphabetical order.
The information will be displayed in tabular form. The fields will be identified using column headers, and the fields will be aligned beneath the headers.
If the user enters an invalid team identifier, the program will display an appropriate message and prompt the user to enter another command; the program will not display an empty table.
- The "REPORT" command will be followed by an integer number and a string (one of "HITS", "BATTING" or "SLUGGING").
If the user enters an invalid command, the program will display an appropriate message and prompt the user to enter another command; the program will not display an empty report.
For each report, the program will display all information about the top "n" players in a given category:
BATTING -- batting average
SLUGGING -- slugging percentage
The reports will be sorted from highest to lowest value in the category.
The information will be displayed in tabular form. The fields will be identified using column headers, and the fields will be aligned beneath the headers. All real values will be displayed with three digits of precision following the decimal point.
- The program will display appropriate messages to inform the user about any unusual circumstances.
- The program will consist of at least four meaningful functions. Communication between functions will occur via parameters and return values; you may not use any global variables.

Trending now
This is a popular solution!
Step by step
Solved in 2 steps









