Answer:
Question Options :
(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).
(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)
(3) Implement the “Output roster” menu option. (1 pt)
(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 arrays. (1 pt)
(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)
(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)
(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)
/******************************************************************************
This program will store roster and rating information for a soccer team.
*******************************************************************************/
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector< int> jerseyNumber;
vector< int> rating;
int temp;
for (int i = 1; i <= 5; i++) {
cout << "\nEnter player " << i << "'s jersey number: ";
cin >> temp;
if ((temp >= 0) && (temp <= 99)){
jerseyNumber.push_back(temp);}
cout << "Enter player " << i << "'s rating: ";
cin >> temp;
if ((temp >= 0) && (temp <= 9)){
rating.push_back(temp);}
cout << endl;
} cout << endl;
cout << "ROSTER" << endl;
for (int i = 0; i < 5; i++)
cout << "Player " << i + 1 << " -- " << "Jersey number: " << jerseyNumber.at(i) << ", Rating: " << rating.at(i) << endl;
char option;
while (true) {
cout << endl;
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: " << endl;
cin >> option;
switch (option) {
case 'a':
case 'A':
cout << "Enter another player's jersey number: " << endl;
cin >> temp;
if ((temp >= 0) && (temp <= 99)){
jerseyNumber.push_back(temp);}
cout << "Enter another player's rating: " << endl;
cin >> temp;
if ((temp >= 0) && (temp <= 9)){
rating.push_back(temp);}
break;
case 'd':
case 'D':
cout << "Enter a jersey number: ";
cin >> temp;
for (int i = 0; i < jerseyNumber.size(); i++) {
if (jerseyNumber.at(i) == temp) {
jerseyNumber.erase(jerseyNumber.begin() + i);
rating.erase(rating.begin() + i);
break; }
} break;
case 'u':
case 'U':
cout << "Enter a jersey number: ";
cin >> temp;
for (int i = 0; i < jerseyNumber.size(); i++) {
if (jerseyNumber.at(i) == temp) {
cout << "Enter a new rating " << "for player: ";
cin >> temp;
rating.at(i) = temp;
break; }
} break;
case 'r':
case 'R':
cout << "Enter a rating: ";
cin >> temp;
cout << "\nABOVE " << temp << endl;
for (int i = 0; i < jerseyNumber.size(); i++)
if (rating.at(i) > temp)
cout << "Player " << i + 1 << " -- " << "Jersey number: " << jerseyNumber.at(i)
<< ", Rating: " << rating.at(i) << endl;
break;
case 'o':
case 'O':
cout << "ROSTER" << endl;
for (int i = 0; i < jerseyNumber.size(); i++)
cout << "Player " << i + 1 << " -- " << "Jersey number: " << jerseyNumber.at(i)
<< ", Rating: " << rating.at(i) << endl;
break;
case 'q':
return 0;
default: cout << "Invalid menu option." << " Try again." << endl;
}
}
}
Explanation: