Problem description

Your program must have void functions as follows:

void readData: Include parameters for an input file stream, array of player names, array of batting averages for each player, array of player home run totals, array of player strike out totals, array of player walk totals, and total number of players. The function will read all values from the input data file and store the values in the appropriate arrays.

void processData: Include parameters for an array of batting averages for each player, array of player home run totals, array of player strike out totals, array of player walk totals, total number of players, and array of team statistics. This function will calculate the team batting average (the average batting average across all players in the array), the total number of home runs across all players, the total number of strike outs across all players, and the total number of walks across all players, and it must store these calculated statistics in a separate array for future output.

void writeData: Include parameters for an output file stream, team name, year, an array of team statistics (calculated above), and the total number of statistics to write to the file. This function must append a single line to the output file in the following format:

team-name, year, team-batting-average, team-home runs, team-strikeouts, team-walks

You may assume a maximum number of 20 players in a given input file. Use named constants for maximum number of players and the maximum stats (4).

The program accepts file names as command line arguments.

If the input data file foes not exist, issue an error message and terminate the program.

Input data file example:

First line: team name
Second line: year
Third line: Number of players
Fourth line to the last line: player name, batting average, homerun total, strikeout total, walkout total

more Dodgers2017.txt

Dodgers
2017
9
Jones .265 29 115 39
Machado .294 37 120 48
Schoop .267 25 137 21
Davis .221 38 219 88
Trumbo .256 47 170 51
Mancini .357 3 4 0
Smith .249 16 89 48
Joseph .174 0 28 7
Tejada .167 0 13 7

more Dodgers2018.txt

Dodgers
2018
9
Jones .272 19 81 18
Machado .243 18 80 40
Schoop .305 24 90 24
Davis .226 17 115 38
Trumbo .238 17 102 36
Mancini .299 17 84 20
Smith .264 11 58 25
Joseph .298 5 43 8
Tejada .227 0 14 7

Sample run:

./a.out
Error: Specify the file names as a command line argument.
For example: ./a.out file1.txt file2.txt

./a.out Dodgers2017.txt
Error: Specify the file names as a command line argument.
For example: ./a.out file1.txt file2.txt

./a.out Dodgers2017.txt dodgers.txt
more dodgers.txt
Dodgers 2017 0.250 195 895 309
more dodgers.txt
Dodgers 2018 0.264 128 667 216

NOTES: In order to append to a file, open the file with the append mode "a". For example, outfile.open(outfilename.c_str(), ios_base::app);

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.