In: Computer Science
C++ PLEASE
IMPORTANT:
This program will store roster and rating information for a basketball team. Coaches rate players during tryouts to ensure a balanced team. A roster can include at most 10 players.
(1) Prompt the user to input five pairs of numbers: A player's
jersey number (0 - 99) and the player's rating (1 - 9). Store the
jersey numbers in one int array and the ratings in another int
array. Output these arrays (i.e., output the roster).
Ex:
Enter player 1's jersey number: 84 Enter player 1's rating: 7 Enter player 2's jersey number: 23 Enter player 2's rating: 4 Enter player 3's jersey number: 4 Enter player 3's rating: 5 Enter player 4's jersey number: 30 Enter player 4's rating: 2 Enter player 5's jersey number: 66 Enter player 5's rating: 9 ROSTER Player 1 -- Jersey number: 84, Rating: 7 Player 2 -- Jersey number: 23, Rating: 4 ...
(2) Implement a menu of options for a user to modify the roster.
Each option is represented by a single character. The program
initially outputs the menu, and outputs the menu after a user
chooses an option. The program ends when the user chooses the
option to Quit.
Ex:
MENU a - Add player d - Remove player u - Update player rating r - Output players above a rating o - Output roster q - Quit Choose an option:
(3) Implement the "Output roster" menu option.
Ex:
ROSTER Player 1 -- Jersey number: 84, Rating: 7 Player 2 -- Jersey number: 23, Rating: 4 ...
(4) Implement the "Add player" menu option. If the user chooses this option and the roster is full, print the following error message:
Impossible to add new player: roster is full.
If the roster is not full, prompt the user for a new player's
jersey number and rating, and append the values to the two
arrays.
Ex:
Enter a new player's jersey number: 49 Enter the player's rating: 8
(5) Implement the "Delete player" menu option. If the user chooses the option when the roster is empty, immediately print the message:
Can not delete from empty roster.
If the roster is not empty, prompt the user for a player's
jersey number. Remove the player from the roster (delete the jersey
number and rating), paying attention not to leave unused spaces in
the two arrays.
Ex:
Enter a jersey number: 4
If the given jersey number is not found, inform the user:
Error! Player not found.
(6) Implement the "Update player rating" menu option. Prompt the
user for a player's jersey number. Prompt again for a new rating
for the player, and then look up and change that player's
rating.
Ex:
Enter a jersey number: 23 Enter a new rating for player: 6
In this case, if the given jersey number is not found, no further action is taken (note that the format of the program requires both input either way).
(7) Implement the "Output players above a rating" menu option.
Prompt the user for a rating. Print the jersey number and rating
for all players with ratings above the entered value.
Ex:
Enter a rating: 5 ABOVE 5 Player 1 -- Jersey number: 84, Rating: 7 ...
If no players are found above a given rating, the program will simply produce an empty list.
BONUS
For an extra 10 points, implement a secret option s that prints the message:
Executing secret option!
and sorts the roster by jersey number. Do not add this option to the MENU message. And remember to move the player rating accordingly!
#include <iostream>
using namespace std;
int main(void)
{
int jerseyNum[10]; // two arrays for jersey number and rating of players
int rating[10];
int i,j,jersey,rate,size = 5;
char option;
cout<<"Enter five pairs of numbers: A player's jersey number (0 -99) and the player's rating (1 - 9)";
for(i=0;i<5;i++) //enter data for 5 players
{
cout<<"\nEnter player " <<i+1<< " 's jersey number:";
cin>>jerseyNum[i];
cout<<"\nEnter player "<<i+1<<" 's rating:";
cin>>rating[i];
}
cout<<"\nMENU";
cout<<"\na - Add player";
cout<<"\nd - Delete player";
cout<<"\nu - Update player rating";
cout<<"\nr - Output players above a rating";
cout<<"\no - Output roster";
cout<<"\nq - Quit";
cout<<"\n\n\nChoose an option:";
cin>>option;
do
{
switch(option)
{
case 'a': cout<<"\nEnter another player 's jersey number:";
cin>>jerseyNum[size];
cout<<"\nEnter another player 's rating:";
cin>>rating[size];
size++;
break;
case 'd': cout<<"\nEnter a jersey number : ";
cin>>jersey;
for(i=0;i<size;i++)
{
if(jerseyNum[i] == jersey)
{
for(j=i;j<size;j++)
{
jerseyNum[j] = jerseyNum[j+1];
rating[j] = rating[j+1];
}
}
}
size--;
break;
case 'u': cout<<"\nEnter a jersey number:";
cin>>jersey;
for(i=0;i<size;i++)
{
if(jerseyNum[i] == jersey) //update rating of player
{
cout<<"\nEnter a new rating for player:"<< i+1;
cin>>rating[i];
}
}
break;
case 'r': cout<<"\nEnter a rating:";
cin>>rate;
cout<<"\nABOVE "<<rate;
for(i=0;i<size;i++)
{
if(rating[i] > rate) //find all playershaving rating more than input value
{
cout<<"\nPlayer "<<(i+1)<<" -- Jersey number: "<<jerseyNum[i]<<" Rating:"<<rating[i];
}
}
break;
case 'o': cout<<"\nROSTER"; //display data for all players
for(i=0;i<size;i++)
{
cout<<"\nPlayer "<<(i+1)<<" -- Jersey number: "<<jerseyNum[i]<<" Rating:"<<rating[i];
}
break;
case 'q': exit(0); //exit
default: cout<<"\nInvalid option";
break;
}
cout<<"\nChoose an option:";
cin>>option;
}while(option != 'q');
return 0;
}
Output:
Enter five pairs of numbers: A player's jersey number (0 -99) and the player's rating (1 - 9) Enter player 1 's jersey number:84 Enter player 1 's rating:7 Enter player 2 's jersey number:23 Enter player 2 's rating:4 Enter player 3 's jersey number:4 Enter player 3 's rating:5 Enter player 4 's jersey number:30 Enter player 4 's rating:2 Enter player 5 's jersey number:66 Enter player 5 's rating:9 MENU a - Add player d - Delete player u - Update player rating r - Output players above a rating o - Output roster q - Quit Choose an option:o ROSTER Player 1 -- Jersey number: 84 Rating:7 Player 2 -- Jersey number: 23 Rating:4 Player 3 -- Jersey number: 4 Rating:5 Player 4 -- Jersey number: 30 Rating:2 Player 5 -- Jersey number: 66 Rating:9 Choose an option:a Enter another player 's jersey number:49 Enter another player 's rating:8 Choose an option:o ROSTER Player 1 -- Jersey number: 84 Rating:7 Player 2 -- Jersey number: 23 Rating:4 Player 3 -- Jersey number: 4 Rating:5 Player 4 -- Jersey number: 30 Rating:2 Player 5 -- Jersey number: 66 Rating:9 Player 6 -- Jersey number: 49 Rating:8 Choose an option:d Enter a jersey number : 4 Choose an option:o ROSTER Player 1 -- Jersey number: 84 Rating:7 Player 2 -- Jersey number: 23 Rating:4 Player 3 -- Jersey number: 30 Rating:2 Player 4 -- Jersey number: 66 Rating:9 Player 5 -- Jersey number: 49 Rating:8 Choose an option:u Enter a jersey number:23 Enter a new rating for player:6 Choose an option:r Enter a rating:5 ABOVE 5 Player 1 -- Jersey number: 84 Rating:7 Player 2 -- Jersey number: 23 Rating:6 Player 4 -- Jersey number: 66 Rating:9 Player 5 -- Jersey number: 49 Rating:8 Choose an option:q
Do ask if any doubt. Please upvote.