Question

In: Computer Science

This program will store roster and rating information for a basketball team. Coaches rate players during...

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:

 

(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:

 

(3) Implement the "Output roster" menu option.

Ex:

 

(4) Implement the "Add player" menu option. If the user chooses this option and the roster is full, print the following error message:

 

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:

 

(5) Implement the "Delete player" menu option. If the user chooses the option when the roster is empty, immediately print the message:

 

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:

 

If the given jersey number is not found, inform the user:

 

(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:

 

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:

 

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:

 

and sorts the roster by jersey number. Do not add this option to the MENU message. And remember to move the player rating accordingly!

I need help with my HW its in C++. it also asking for an input. thank you!!

Solutions

Expert Solution

// C++ program to maintain a roster of basketball players

#include <iostream>

#include <iomanip>

#define MAX_PLAYERS 10 //maximum number of player in the roster

using namespace std;

// function declaration

void sort(int player_jersey[], int player_rating[], int num_players);

int main() {

       // roster of players jersey and rating

       int player_jersey[MAX_PLAYERS];

       int player_rating[MAX_PLAYERS];

       char choice;

       int num_players = 0;

       bool found;

       int jersey, rating;

       // loop to input details for 5 players

       cout<<"Enter details of 5 players : "<<endl;

       for(num_players=0;num_players<5;num_players++)

       {

             cout<<"Enter jersey number(0-99) and player's rating (1-9) separated by a space : ";

             cin>>player_jersey[num_players]>>player_rating[num_players];

       }

       // loop that continues until the user exits

       do

       {

             // display the menu

             cout<<"\nMenu"<<endl;

             cout<<"1. Output roster "<<endl;

             cout<<"2. Add Player"<<endl;

             cout<<"3. Delete Player"<<endl;

             cout<<"4. Update Player Rating"<<endl;

             cout<<"5. Output players above a rating"<<endl;

             cout<<"6. Exit"<<endl;

             cout<<"Enter your choice (1-6): ";

             cin>>choice;

             switch(choice)

             {

                    case '1': // output the roster

                           if(num_players == 0)

                                 cout<<"Empty Roster"<<endl;

                           else

                           {

                                  cout<<left<<setw(15)<<"Jersey"<<left<<setw(10)<<"Rating"<<endl;

                                 for(int i=0;i<num_players;i++)

                                        cout<<left<<setw(15)<<player_jersey[i]<<left<<setw(10)<<player_rating[i]<<endl;

                                 cout<<endl;

                           }

                           break;

                    case '2': // add a player

                           if(num_players == MAX_PLAYERS)

                                 cout<<"Roster full, cannot add more players"<<endl;

                           else

                           {

                                 cout<<"Enter new player's jersey number and rating (separated by a space) : ";

                                 cin>>jersey>>rating;

                                 player_jersey[num_players] = jersey;

                                 player_rating[num_players] = rating;

                                 num_players++;

                           }

                           break;

                    case '3': // delete a player

                           if(num_players == 0)

                                 cout<<"Empty Roster, cannot delete a player"<<endl;

                           else

                           {

                                 cout<<"Enter the player's jersey number : ";

                                 cin>>jersey;

                                 found = false;

                                 for(int i=0;i<num_players;i++)

                                 {

                                        if(player_jersey[i] == jersey)

                                        {

                                               for(int j=i;j<num_players-1;j++)

                                               {

                                                     player_jersey[j] = player_jersey[j+1];

                                                     player_rating[j] = player_rating[j+1];

                                               }

                                               found = true;

                                               num_players--;

                                               break;

                                        }

                                 }

                                 if(!found)

                                        cout<<"Player with jersey number : "<<jersey<<" not present in the roster"<<endl;

                           }

                           break;

                    case '4': // update the player rating

                           cout<<"Enter player's jersey number : ";

                           cin>>jersey;

                           cout<<"Enter new rating for the player : ";

                           cin>>rating;

                           for(int i=0;i<num_players;i++)

                           {

                                 if(player_jersey[i] == jersey)

                                 {

                                        player_rating[i] =rating;

                                        break;

                                 }

                           }

                           break;

                    case '5': // output players above a rating

                           cout<<"Enter the rating : ";

                           cin>>rating;

                           for(int i=0;i<num_players;i++)

                           {

                                 if(player_rating[i] > rating)

                                        cout<<"Jersey : "<<player_jersey[i]<<" Rating : "<<player_rating[i]<<endl;

                           }

                           cout<<endl;

                           break;

                    case '6': // quit

                           break;

                    case 's': // secret option to sort players based on jersey numbers

                           sort(player_jersey,player_rating,num_players);

                           break;

                    default:

                           cout<<"Invalid choice"<<endl;

             }

       }while(choice != '6');

       return 0;

}

// function to sort the players based on jersey numbers

void sort(int player_jersey[], int player_rating[], int num_players)

{

       int min;

       for(int i=0;i<num_players-1;i++)

       {

             min = i;

             for(int j=i+1;j<num_players;j++)

             {

                    if(player_jersey[j] < player_jersey[min])

                           min = j;

             }

             if(min != i)

             {

                    int temp = player_jersey[i];

                    player_jersey[i] = player_jersey[min];

                    player_jersey[min] = temp;

                    temp = player_rating[i];

                    player_rating[i] = player_rating[min];

                    player_rating[min] = temp;

             }

       }

}

//end of program

Output:


Related Solutions

This program will store roster and rating information for a soccer team. Coaches rate players during...
This program will store roster and rating information for a soccer team. Coaches rate players during tryouts to ensure a balanced team. (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). (3 pts) Ex: Enter player 1's jersey number: 84 Enter player 1's...
C++ this program will store roster and rating information for a soccer team. Coaches rate players...
C++ this program will store roster and rating information for a soccer team. Coaches rate players during tryouts to ensure a balanced team. (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 vector and the ratings in another int vector. Output these vectors (i.e., output the roster). Ex: Enter player 1's jersey number: 84 Enter player 1's rating:...
C code please This program will store roster and rating information for a soccer team. Coaches...
C code please This program will store roster and rating information for a soccer team. Coaches rate players during tryouts to ensure a balanced team. (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). (3 pts) Ex: Enter player 1's jersey number: 84...
Program: Soccer team roster This program will store roster and rating information for a soccer team....
Program: Soccer team roster This program will store roster and rating information for a soccer team. Coaches rate players during tryouts to ensure a balanced team. (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). (3 pts) Ex: Enter player 1's jersey number:...
Soccer team roster (Dictionaries) This program will store roster and rating information for a soccer team.
Soccer team roster (Dictionaries) This program will store roster and rating information for a soccer team. Coaches rate players during tryouts to ensure a balanced team. (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 and the ratings in a dictionary. Output the dictionary's elements with the jersey numbers in ascending order (i.e., output the roster from smallest to largest jersey...
C++ 18.27 LAB*: Program: Soccer team roster (Vectors) This program will store roster and rating information...
C++ 18.27 LAB*: Program: Soccer team roster (Vectors) This program will store roster and rating information for a soccer team. Coaches rate players during tryouts to ensure a balanced team. (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 vector and the ratings in another int vector. Output these vectors (i.e., output the roster). (3 pts) Ex: Enter...
Please write in C. This program will store roster and rating information for a soccer team....
Please write in C. This program will store roster and rating information for a soccer team. Coaches rate players during tryouts to ensure a balanced team. (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). (3 pts) ex Enter player 1's jersey number:...
Write a program in C++ to keep statistics for a basketball team consisting of 10 players...
Write a program in C++ to keep statistics for a basketball team consisting of 10 players using parallel arrays. The stats for each player should include the total points, shots attempted, shots made, free throw attempts, free throws made, rebounds, assists, and turnovers. Use functions to perform the following: Calculate the shooting percentage Calculate free throw percentage Print the player's names, shooting percentage, free throw percentage, rebounds, assists, and turnovers. After each player, use "endl" to skip to a new...
Soma recorded in the table the height of each player on the basketball team Basketball Players’...
Soma recorded in the table the height of each player on the basketball team Basketball Players’ Heights (in inches) 66 66 68 57 64 65 67 67 64 65 Construct a normal probability distribution curve for this population! Indicate the number for the mean, 1SD, 2SD and 3SD (both sides of the mea) (1+ 6*0.5=4p)
Consider a Little League team that has 15 players on its roster. (a) How many ways...
Consider a Little League team that has 15 players on its roster. (a) How many ways are there to select 9 players for the starting lineup? ways (b) How many ways are there to select 9 players for the starting lineup and a batting order for the 9 starters? ways (c) Suppose 7 of the 15 players are left-handed. How many ways are there to select 3 left-handed outfielders and have all 6 other positions occupied by right-handed players? ways
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT