I am stuck, please answer in C++.
QUESTION:
The local baseball team is computerizing its records. You were asked to write a program that computes batting averages and other statistics.
There are 20 players on the team, identified by the numbers 1 through 20.
You will have two input files:
You need to test run your program using those 2 files
(1) A Roster File –
A file contains 21 lines, first line is an integer indicating the season. The rest is in the format “last name first name” (separated by a space) for each player, as follows:
2019
Smith Sam
Jones Bob
Miller Miles (20 names for 20 players)
and etc….. (The players ’s ID are numbered 1-20 in the order listed in this file.)
Notice this file contains no player numbers, just their names)
A separate file contains the game-by game statistics for the players as a “player ID number, hits, walks, outs”
3 4 3 0
9 7 3 0
11 4 2 2
9 1 1 1
3 5 2 8
and etc…….
Here is an example:
20 2 1 1
The example above indicates that during a particular game in the season, player number 20 was at bat four times and made 2 hits, 1 walk, and 1 out.
For each player, there are several lines in the file. (a player can play more than one game in a season)
The file is organized by the batting line-ups (it is not sorted by player number).
Each player’s batting average is computed by adding the player’s total number of hits dividing by the total number of times at bat. A walk does not count as either a hit or a time at bat when the batting average is being calculated.
When your statistics file contains no data, print message to output file saying, “the 2019 baseball season was cancelled” and end the execution.
Create an array of PlayerInfo struct to hold the players’ data. The array is local to main function and passes to other functions as argument.
struct PlayerInfo { int PlayerID;
string LastName; struct declared in global area (above main & function prototype
string FirstName;
int Hits, Walks, Outs;
double Batting, OnBase; };
PlayerInfo Player[20];
array declared inside main function and pass it to sub functions.
Requirements:
Don’t use the followings in your program at all: no vectors, no stacks, no multi-dimensional arrays, no parallel arrays.
No global variable allowed. Global area can only have function prototypes and named constants and struct declaration.
(your program must follow this logic)
Functions must be called in this order inside main function.
int GetPlayer (PlayerInfo [ ] );
(Be careful! The players’ identification numbers are 1 through 20, but C++ array index starts at 0).
NOTE: The index of the array is no longer the player’s ID.
Hints – you need to keep the player identification numbers with the player names and the data in the struct. When you
read a player’s game line, look up the player in the array of structs before you adding up the hits, walks and outs.
(remember to do casting in order to retain the factional part)
batting average = (hits) / (hits + outs)
on base average = (hits + walks) / (total at bats)
Sample of an output file:
Baseball Season 2019
--------------------------------
Smith Sam Player 1
Jones Bob Player 2
Miller Miles Player 3
and etc……
Rutter Jack Player 20
The alphabetical list of players with each player’s statistics (partial list)
Player Number Hits Walks Outs Batting Average On Base Average In Disable List
-------------------------------------------------------------------------------------------------------------------------------------------------------
Apbee Cory 5 xx xx xx 0.xx 0.xx
Buzz Bee 8 xx xx xx 0.xx 0.xx
Carter John 4 Yes
Crane David 19 xx xx xx 0.xx 0.xx
and etc……
Give the name(s) and batting average of the best hitter (i.e. highest batting average).
Give the name(s) and on-base average of the best base runner
Give the name(s) and batting average of the worst hitter
Give the name(s) and on-base average of the worst base runner
If there is a tie for best or worst, Print all the players’ names.
Just An Example: (might not be true for your input file)
The best hitter with batting average of 0.68: Jones
The worst hitter with batting average of 0.04: Miller, Smith File 1 data
2019
Smith Sam
Jones Bob
Miller Miles
Carter John
Apbee Cory
Jackson James
Zutter Tommy
Buzz Bee
Duncan Michael
Tso Terry
Lenn Lance
Johnson Albert
Knight Owl
Neon Bret
Ora Adam
Elfin Victor
Hoo Frank
Greene Martin
Crane David
Rutter Jack
file 2 data
15 3 2 1
10 2 1 1
9 5 2 1
3 2 2 1
19 1 2 3
20 1 1 1
5 3 1 3
1 2 2 3
11 0 2 2
12 6 3 2
8 3 0 0
7 1 2 3
19 2 2 1
6 5 2 0
5 1 1 1
15 2 5 3
11 1 1 3
14 4 2 3
9 0 1 2
5 1 1 1
Brand new code please. Comments on code would be really helpful.