Home / Expert Answers / Computer Science / i-am-stuck-please-answer-in-c-question-the-local-baseball-team-is-computerizing-its-records-you-pa462

(Solved): I am stuck, please answer in C++.QUESTION:The local baseball team is computerizing its records. You ...



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)

  1. A Statistic File –

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.

  1. In the main function, you will call a function GetPlayer to read from Roster file and store the player names and id into the array and return the year for the season.

int GetPlayer (PlayerInfo [ ] );

(Be careful! The players’ identification numbers are 1 through 20, but C++ array index starts at 0).

  1. Call a PrintRoster function to send the roster for the team with player ID in order to an output file
  2. Call a SortPlayer function to sort them by last name. (i.e. Use Bubble Sort)

NOTE: The index of the array is no longer the player’s ID.

  1. Then call a GetStatistics function to read the statistics file, updating each player’s statistics of hits, walks and outs.

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.

  1. A function to calculate each player’s batting average and on base average and store them.

(remember to do casting in order to retain the factional part)

batting average = (hits) / (hits + outs)

on base average = (hits + walks) / (total at bats)

  1. A function to Send the players’ statistic to the output file including their Batting Average, On Base Average, in DL list, the best hitter, the worst hitter, the best base runner and the worst base runner. (Note: A player is in the DL if he didn’t play at all in the entire season.)

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.



We have an Answer from Expert

View Expert Answer

Expert Answer



Here's a C++ implementation of the program with comments explaining each section of the code:
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe