Question

In: Computer Science

Write a C++ program to help the Administration of a football league to manipulate the list...

Write a C++ program to help the Administration of a football league to manipulate the list of players registered in different teams. There are 26 teams participating in the league, each is denoted by a letter in the range A to Z. Each team can have 11 players at most. The information of all teams' players are stored in a text file named 'players.dat'. Each line from the input file contains the details of one player; where the player's details include his first-name and family- name, the age (in years), and the team's letter (from the range A-Z). --see the sample input below

The intended program will perform the following tasks:

 Continuously displaying a menu for the user until the user selects 'X' (or 'x') to exit the program. The menu provides 4 options: Add Player (A or a), Team Inquiry (I or i), Print Statistics (P or p), and Exit (X or x).

 When the 'Add Player' operation is selected, the main function will ask the user to provide all the information of the new player, then it calls a user-defined function named addPlayer(...) to add the player to the file. Before the record is added to the file, two things must be checked:

o The provided team-letter must be in the range A-Z. This must be validated via another user- defined function named teamCodeIsValid(...); and a suitable error message should be displayed by the function addPlayer(...) if the letter is invalid.

o The number of the players in the specified team must be less than 11 before adding the new player. This must be counted and returned via another user-define function named countPlayers(...); and a suitable error message should be displayed if the team is already full.

 When the 'Team Inquiry' operation is selected, the main function should ask the user to provide the letter of the desired team, then it calls a user-defined function (named displayTeam(...)) to display the details and the number of all players in the team. If the specified team has no players at all, then the function displayTeam(...) should display a suitable notification to the user.

 When the 'Print Statistics' operation is selected, the main function will call a user-defined function named printStat(...) to display a statistical report which shows the number of players in each team (see sample output). HINT: CONSIDER USING THE FUNCTION countPlayers(...).

Solutions

Expert Solution

please refer below code

#include<iostream>
#include<fstream>
#include<string>

using namespace std;

//Checkin number of players in team if 11 return false else true
bool countPlayers(int *team_count,char ch)
{
if(team_count[ch - 'A'] < 11)
return true;

return false;

}
//checking valid team code
bool teamCodeIsValid(char ch)
{
return ch >= 'A' && ch <= 'Z';
}
//adding player in the file
void addPlayer(string name, string surname, int age, char team_name, ofstream &outfile, int *team_count)
{
if (!teamCodeIsValid(team_name))
{
cout<<"\nInvalid team Name"<<endl;
}
else if(!countPlayers(team_count,team_name))
{
cout<<"\nteam is full"<<endl;
}
else
{
outfile << name <<" "<< surname <<" "<< age << " " <<team_name<<endl;
team_count[team_name - 'A']++;
}

}
//displaying the team stats
void displayTeam(char *file_name,char team_name, int team_count)
{
string name,surname;
int age;
char tn,ch;
std::ifstream infile;
infile.open(file_name);
if(team_count == 0)
{
cout<<"No players at all in the team"<<endl;
return;
}
//reading output file created
while(infile >> name >> surname >> age >> tn)
{
if(tn - team_name == 0)
cout<<name<<" "<<surname<<" "<<age<<" "<<team_name<<endl;
}
cout<<"Total Number of players = "<<team_count<<endl;

}
//printing stats
void printStat(int *team_count)
{
char ch = 'A';
cout<<"Team Name\tNumber of Players"<<endl;

for(int i = 0; i < 26; i++)
{
cout<<ch<<"\t\t"<<team_count[i]<<endl;
ch++;
}

}
int main()
{
char option,team_name;
string name,surname;
int age;
std::ofstream outfile;
int team_count[26] = {0};
char file_name[20] = "players.dat";
outfile.open(file_name);
while(1)
{
cout<<"\nMenu : "<<endl;
cout<<"Add Player [A or a]\nTeam Inquiry [I or i]\nPrint Statistic [P or p]\nExit [X or x]"<<endl<<endl;
cin>>option;

if(option == 'A' || option == 'a')
{
cout<<"Enter Name of the player : ";
cin>>name;
cout<<"\nEnter Family name of the player : ";
cin>>surname;

cout<<"\nEnter age of the Player : ";
cin>>age;

cout<<"\nEnter team name : ";
cin>>team_name;

addPlayer(name,surname,age,team_name,outfile,team_count);

}
else if(option == 'I' || option == 'i')
{
cout<<"\nEnter the team name for Inquiry : ";
cin>>team_name;

displayTeam(file_name,team_name,team_count[team_name-'A']);
}
else if(option == 'P' || option == 'p')
{
cout<<"\nBelow are the statistics of team"<<endl;
printStat(team_count);
}
else
{
cout<<"\nExiting....."<<endl;
break;
}
}
return 0;
}

please refer below output


Menu :
Add Player [A or a]
Team Inquiry [I or i]
Print Statistic [P or p]
Exit [X or x]

A
Enter Name of the player : Shane

Enter Family name of the player : Warne

Enter age of the Player : 25

Enter team name : A

Menu :
Add Player [A or a]
Team Inquiry [I or i]
Print Statistic [P or p]
Exit [X or x]

A
Enter Name of the player : Ricky

Enter Family name of the player : Ponting

Enter age of the Player : 32

Enter team name : B

Menu :
Add Player [A or a]
Team Inquiry [I or i]
Print Statistic [P or p]
Exit [X or x]

A
Enter Name of the player : Chris

Enter Family name of the player : Martin

Enter age of the Player : 31

Enter team name : B

Menu :
Add Player [A or a]
Team Inquiry [I or i]
Print Statistic [P or p]
Exit [X or x]

I

Enter the team name for Inquiry : B
Ricky Ponting 32 B
Chris Martin 31 B
Total Number of players = 2

Menu :
Add Player [A or a]
Team Inquiry [I or i]
Print Statistic [P or p]
Exit [X or x]

P

Below are the statistics of team
Team Name Number of Players
A 1
B 2
C 0
D 0
E 0
F 0
G 0
H 0
I 0
J 0
K 0
L 0
M 0
N 0
O 0
P 0
Q 0
R 0
S 0
T 0
U 0
V 0
W 0
X 0
Y 0
Z 0

Menu :
Add Player [A or a]
Team Inquiry [I or i]
Print Statistic [P or p]
Exit [X or x]

X

Exiting.....

Process returned 0 (0x0) execution time : 67.546 s
Press any key to continue.


Related Solutions

String Manipulator Write a program to manipulate strings. (Visual Studio C++) In this program take a...
String Manipulator Write a program to manipulate strings. (Visual Studio C++) In this program take a whole paragraph with punctuations (up to 500 letters) either input from user, initialize or read from file and provide following functionalities within a class: a)   Declare class Paragraph_Analysis b)   Member Function: SearchWord (to search for a particular word) c)   Member Function: SearchLetter (to search for a particular letter) d)   Member Function: WordCount (to count total words) e)   Member Function: LetterCount (ONLY to count all...
C program help 1. Write a program to compute the Mileage given by a vehicle. Mileage...
C program help 1. Write a program to compute the Mileage given by a vehicle. Mileage = (new_odometer – old_odometer)/(gallons_gas) // illustrating how ‘for’ loop works. 2. How to initialize an array of size 5 using an initializer list and to compute it’s sum How to initialize an array of size 5 with even numbers starting from 2 using ‘for’ loop and to compute it’s sum 3. Program to compute the car insurance premium for a person based on their...
Exercise 2: Write a program in Java to manipulate a Double Linked List: 1. Create Double...
Exercise 2: Write a program in Java to manipulate a Double Linked List: 1. Create Double Linked List 2. Display the list 3. Count the number of nodes 4. Insert a new node at the beginning of a Double Linked List. 5. Insert a new node at the end of a DoubleLinked List 6. Insert a new node after the value 5 of Double Linked List 7. Delete the node with value 6. 8. Search an existing element in a...
Exercise 3: Stack Write a program in Java to manipulate a Stack List: 1. Create Stack...
Exercise 3: Stack Write a program in Java to manipulate a Stack List: 1. Create Stack List 2. Display the list 3. Create the function isEmply 4. Count the number of nodes 5. Insert a new node in the Stack List. 6. Delete the node in the Stack List. 7. Call all methods above in main method with the following data: Test Data : Input the number of nodes : 4 Input data for node 1 : 5 Input data...
Exercise 1: Write a program in Java to manipulate a Singly Linked List: 1. Create Singly...
Exercise 1: Write a program in Java to manipulate a Singly Linked List: 1. Create Singly Linked List 2. Display the list 3. Count the number of nodes 4. Insert a new node at the beginning of a Singly Linked List. 5. Insert a new node at the end of a Singly Linked List 6. Insert a new node after the value 5 of Singly Linked List 7. Delete the node with value 6. 8. Search an existing element in...
Write a program (C++) which allows a League of Legends player to both store and output...
Write a program (C++) which allows a League of Legends player to both store and output statistics on their games played. When the program starts it allows the user to enter new entries. The entries contain the following information: Champion Name Kills Assists Deaths Win? Each entry is appended to a file called games.txt. When the user is done entering data the statistics from the games in the file are to be displayed. The average kills, assists, and deaths are...
A statistical program is recommended. The National Football League (NFL) records a variety of performance data...
A statistical program is recommended. The National Football League (NFL) records a variety of performance data for individuals and teams. To investigate the importance of passing on the percentage of games won by a team, the following data show the conference (Conf), average number of passing yards per attempt (Yds/Att), the number of interceptions thrown per attempt (Int/Att), and the percentage of games won (Win%) for a random sample of 16 NFL teams for one full season. Team Conf Yds/Att...
DATAfile: NFLPassing A statistical program is recommended. The National Football League (NFL) records a variety of...
DATAfile: NFLPassing A statistical program is recommended. The National Football League (NFL) records a variety of performance data for individuals and teams. To investigate the importance of passing on the percentage of games won by a team, the following data show the conference (Conf), average number of passing yards per attempt (Yds/Att), the number of interceptions thrown per attempt (Int/Att), and the percentage of games won (Win%) for a random sample of 16 NFL teams for one full season. Team...
A statistical program is recommended. The National Football League (NFL) records a variety of performance data...
A statistical program is recommended. The National Football League (NFL) records a variety of performance data for individuals and teams. To investigate the importance of passing on the percentage of games won by a team, the following data show the conference (Conf), average number of passing yards per attempt (Yds/Att), the number of interceptions thrown per attempt (Int/Att), and the percentage of games won (Win%) for a random sample of 16 NFL teams for one full season. Team Conf Yds/Att...
A statistical program is recommended. The National Football League (NFL) records a variety of performance data...
A statistical program is recommended. The National Football League (NFL) records a variety of performance data for individuals and teams. To investigate the importance of passing on the percentage of games won by a team, the following data show the conference (Conf), average number of passing yards per attempt (Yds/Att), the number of interceptions thrown per attempt (Int/Att), and the percentage of games won (Win%) for a random sample of 16 NFL teams for one full season. Team Conf Yds/Att...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT