This program will store roster and rating information for a soccer team. Coaches
ID: 3591111 • Letter: T
Question
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 array(i.e., output the roster). (3 pts)
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. For this step, the other options do nothing. (2 pt)
Ex:
(3) Implement the "Output roster" menu option. (1 pt)
Ex:
(4) Implement the "Add player" menu option. Prompt the user for a new player's jersey number and rating. Append the values to the two vectors. (1 pt)
Ex:
(5) Implement the "Delete player" menu option. Prompt the user for a player's jersey number. Remove the player from the roster (delete the jersey number and rating). (2 pts)
Ex:
(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 change that player's rating. (1 pt)
Ex:
(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. (2 pts)
Ex:
#include <iostream>
#include <vector>
using namespace std;
int main(){
int jerseyNumber[5];
int rating[5];
int temp;
int counter = 1;
int i = 0;
while(counter <= 5){
cout<<"Enter player "<< counter <<"'s jersey number: "<<endl;
cin>>jerseyNumber[i];
cout<<"Enter player "<< counter <<"'s rating: "<<endl;
cin>>rating[i];
counter++;
i++;
}
cout<<"ROSTER"<<endl;
for (int i = 0; i < 5; i++){
cout<<"Player "<<i+1<<" -- "<<"Jersey number: "<<jerseyNumber[i]<<", Rating: "<<rating[i]<<endl<<endl;
char option;
cout<<"MENU"<<endl;
cout<<"a - Add player"<<endl;
cout<<"d - Remove player"<<endl;
cout<<"u - Update player rating"<<endl;
cout<<"r - Output players above a rating"<<endl;
cout<<"o - Output roster"<<endl;
cout<<"q - Quit"<<endl<<endl;
cout<<"Choose an option: ";
cin>>option;
switch(option){
case 'a':
case 'A':
cout<<"Enter a new player's jersey number: ";
cin>>jerseyNumber[i];
cout<<jerseyNumber[i]<<endl;
cout<<"Enter the player's rating: ";
cin>>rating[i];
cout<<rating[i]<<endl;
break;
case 'd':
case 'D':
// cout<<"Enter a jersey number: ";
//cin>>temp;
//int i;
//for(i = 0; i < 5; i++)
//{
//if(jerseyNumber[i] == temp)
{
//delete[] jerseyNumber([i]+1);
//delete[] rating([i]+1);
//break;
//}
}
break;
HOW CAN I FIX THE REST OF MY CODE FOR C++ (USING ARRAYS NOT VECTORS)
Explanation / Answer
#include<iostream>
using namespace std;
main()
{
// DECLARING variables
int count,i,j,g[100],r[100],rem,mod,abov;
char choice;
// taking user input for first 5 playres
for(count=0;count<5;count++)
{
cout << endl << "Enter player" << count+1 <<"'s jersey number: ";
cin >> g[count];
cout << "Enter player" << count+1 <<"'s rating: ";
cin >> r[count];
}
while(1)
{
// taking user input of choice
cout<<endl<<"MENU"<<endl;
cout<<"a - Add player"<<endl;
cout<<"d - Remove player"<<endl;
cout<<"u - Update player rating"<<endl;
cout<<"r - Output players above a rating"<<endl;
cout<<"o - Output roster"<<endl;
cout<<"q - Quit"<<endl<<endl;
cout<<"Choose an option: ";
cin >> choice;
// for Quit
if(choice == 'q')
{
break;
}
// r - Output players above a rating
else if(choice == 'r')
{
cout << "Enter a rating: ";
cin >> abov;
for(i=0,j=0;i<count;i++)
{
if(r[i] > abov)
{
cout << "Player " << j+1 << " -- Jersey number: " << g[i] << ", Rating: " << r[i] <<endl;
j++;
}
}
}
// u - Update player rating
else if(choice == 'u')
{
cout << "Enter a jersey number: ";
cin >> mod;
for(i=0;g[i]!=mod;i++);
cout << "Enter a new rating for player: ";
cin >> r[i];
}
// d - Delete player
else if(choice == 'd')
{
cout << "Enter a jersey number: ";
cin >> rem;
for(i=0;g[i]!=rem;i++);
g[i] = 0;
r[i] = 0;
}
//a - Add player
else if(choice == 'a')
{
cout << "Enter player" << count+1 <<"'s jersey number: ";
cin >> g[count];
cout << "Enter player" << count+1 <<"'s rating: ";
cin >> r[count];
count++;
}
// o - Output roster
else if(choice == 'o')
{
for(i=0,j=0;i<count;i++)
{
if(g[i]!=0)
{
cout << "Player " << j+1 << " -- Jersey number: " << g[i] << ", Rating: " << r[i] <<endl;
j++;
}
}
}
}
}
/* SAMPLE Output
Enter player1's jersey number: 10
Enter player1's rating: 9
Enter player2's jersey number: 9
Enter player2's rating: 8
Enter player3's jersey number: 8
Enter player3's rating: 7
Enter player4's jersey number: 7
Enter player4's rating: 6
Enter player5's jersey number: 6
Enter player5's rating: 5
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: a
Enter player6's jersey number: 5
Enter player6's rating: 4
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: d
Enter a jersey number: 8
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: o
Player 1 -- Jersey number: 10, Rating: 9
Player 2 -- Jersey number: 9, Rating: 8
Player 3 -- Jersey number: 7, Rating: 6
Player 4 -- Jersey number: 6, Rating: 5
Player 5 -- Jersey number: 5, Rating: 4
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: u
Enter a jersey number: 6
Enter a new rating for player: 2
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: o
Player 1 -- Jersey number: 10, Rating: 9
Player 2 -- Jersey number: 9, Rating: 8
Player 3 -- Jersey number: 7, Rating: 6
Player 4 -- Jersey number: 6, Rating: 2
Player 5 -- Jersey number: 5, Rating: 4
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: r
Enter a rating: 4
Player 1 -- Jersey number: 10, Rating: 9
Player 2 -- Jersey number: 9, Rating: 8
Player 3 -- Jersey number: 7, Rating: 6
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: q
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.