72.5k views
5 votes
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).

Ex:Enter player 1's jersey number: 84Enter player 1's rating: 7Enter player 2's jersey number: 23Enter player 2's rating: 4Enter player 3's jersey number: 4Enter player 3's rating: 5Enter player 4's jersey number: 30Enter player 4's rating: 2Enter player 5's jersey number: 66Enter player 5's rating: 9ROSTERPlayer 1 -- Jersey number: 84, Rating: 7Player 2 -- Jersey number: 23, Rating: 4...

1 Answer

7 votes

Answer:

#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 << "Enter player " << i

<< "'s jersey number: ";

cin >> temp;

jerseyNumber.push_back(temp);

cout << "Enter player " << i

<< "'s rating: ";

cin >> temp;

rating.push_back(temp);

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 << "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 >> temp;

jerseyNumber.push_back(temp);

cout << "Enter the player's rating: ";

cin >> temp;

rating.push_back(temp);

break;

case 'd':

case 'D':

cout << "Enter a jersey number: ";

cin >> temp;

int i;

for (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 << "\\ABOVE " << 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;

}

}

}

Step-by-step explanation:

User GShenanigan
by
4.6k points