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.
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);