Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

This program will store roster and player information for a baseball team. An input file will contain the following: · the player name · the player number, · the number of hits, · the number of outs,...

1 answer below »
This program will store roster and player information for a baseball team. An input file will contain the following:
· the player name
· the player number,
· the number of hits,
· the number of outs,
· and the number of times at bat
The program is to compute and display each player's statistics including walks and batting average.
(1) (5 pts)Implement a menu of options in the main() function for a user to modify and display the roster. Each option is represented by a single character. The program initially outputs the menu, and will output the menu again after a user chooses an option and views the results. The program ends when the user chooses the option to Quit. For this step, the other options do nothing it is just to build the menu. If the user chooses an invalid option, display the message: "ERROR -- Invalid option" .
XXXXXXXXXXpts) Use the structure data type defined in the template to store information for a single player. Write a function,
void readFile( PlayerInfo players[ ], int& playerCount )
that will prompt the user for a file name and read from the file into the a
ay of PlayerInfo structures. Use a separate variable, playerCount, to keep track of how many players are actually stored in the a
ay. The a
ay may not be full at all times.
**WARNING!!! ** For some reason, ZyBooks getline() function is not removing the endline character from the end of the name when reading from the file. Once you read the player's name from the file, you will need to remove this last character.
Research the ignore() function to move beyond the return key at the end of the player's stat numbers before reading the the name of the next player from the file. file.ignore(80, '\n').
The maximum number of players per team will be 15. The program should write an e
or message to the screen, "***Too many players in file." If the input file exceeds 15 players. The program should then continue by processing the first 15 players read. A players name cannot exceed 25 characters.
Output the contents of the a
ay (i.e., output all the player information) by writing a displayTeam( ) function using parameters called from main( ). Use column headers and formatted output to present the data as a table of information. For this step, initialize walks and batting averages to zero.
(2) (5 pts) Implement a function calcBatAvg() using parameters to calculate player walks and batting average with parameters. The number of walks is calculated by (number of times at bat - [number of hits + number of outs]), and the batting average is calculated by (number of hits / [number of times at bat - number of walks]). Batting average should be displayed using 3 decimal places.
(3) (5 pt) Implement the "Display players above batting average" menu option, by writing a displayBatAvg( ) function. Prompt the user for a batting average. Display only players who meet or exceed this batting average.
5) (10 pt) Implement the "Add player" menu option. Prompt the user for a new player's jersey number and rating. If there is room in the a
ay (check playerCount), add the new information otherwise output the e
or message: "Too many players, player cannot be added." Once the player is added, increment the '''playerCount''' and call the calcBatAvg() function to calculate walks and batting average. (10 pt)
#include #include #include #include #include #include using namespace std;
global constant
const int MAX = 15;     
maximum number of players on team
structure PlayerInfo - data for one playe
struct PlayerInfo
{
    string name;
    int playerNumber;
    int numHits;
    int numOuts;
    int timesAtBat;
    int numWalks = 0;
    double batAvg=0;
};
TODO: Write functions here
int main()
{
    PlayerInfo players[25];            
a
ay to hold PlayerInfo
    int playerCount = 0;            
how many players in a
ay

read player info from file



display menu, loop until user wants to quit
}
Answered Same Day Jul 15, 2021

Solution

Aditya answered on Jul 16 2021
136 Votes
#include #include #include #include #include #include #include #include using namespace std;
global constant
const int MAX = 15;     
maximum number of players on team
structure PlayerInfo - data for one playe
struct PlayerInfo
{
    string name;
    int playerNumber;
    int numHits;
    int numOuts;
    int timesAtBat;
    int numWalks = 0;
    double batAvg=0;
};
TODO: Write functions here
vecto
string> split(string str, string token){
vecto
string
esult;
while(str.size()){
int index = str.find(token);
if(index!=string::npos){
result.push_back(str.substr(0,index));
str = str.substr(index+token.size());
if(str.size()==0)result.push_back(str);
}else{
result.push_back(str);
str = "";
}
}
return result;
}
void calcBatAvg(PlayerInfo temp[],int &playercount)
{
for(int i=0;i {
temp[i].numWalks=temp[i].timesAtBat-(temp[i].numHits+temp[i].numOuts);
temp[i].batAvg= temp[i].numHits/(double)(temp[i].timesAtBat+temp[i].numWalks);
}
}
void readFile( PlayerInfo players[ ], int&playerCount )
{
fstream f;
string fname;
cout
"\n1. baseball1.txt";
cout
"\n2. baseball2.txt";
cout
"\n\nChoose FileName : ";
int choice;
cin
choice;
switch(choice)
{
case 1:
f.open("baseball1.txt",ios::in);
if (f.is_open())
{
string tp;
while(getline(f, tp))
{
if(playerCount<15)
{
players[playerCount].name = tp;
getline(f, tp);
vecto
string> tokens = split(tp," ");
players[playerCount].playerNumber =...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here