Question

In: Computer Science

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 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. For this step, the other options do nothing. (2 pts)

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. (1 pt)

Ex:

ROSTER
Player 1 -- Jersey number: 84, Rating: 7
Player 2 -- Jersey number: 23, Rating: 4
...

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

Enter a new player's jersey number:
49
Enter the player's rating:
8

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

Enter a jersey number:
4

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

Enter a jersey number:
23
Enter a new rating for player:
6

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

Enter a rating:
5

ABOVE 5
Player 1 -- Jersey number: 84, Rating: 7
...

Solutions

Expert Solution

C++ code:

#include <iostream>
#include <vector>

using namespace std;

int main() {
    // Vectors
    vector<int> jerseys;
    vector<int> ratings;

    int jerseyNumber, rating;
    char option;

    // Input 5 pairs of jersey numbers and ratings
    for (int i = 0; i < 5; i++) {
        cout << "Enter player " << i + 1 << "'s jersey number:\n";
        cin >> jerseyNumber;
        // Validate user input
        while (jerseyNumber < 0 || jerseyNumber > 99) {
            cout << "Enter player " << i + 1 << "'s jersey number (0 - 99):\n";
            cin >> jerseyNumber;
        }
        // Add jersey number to the vector
        jerseys.push_back(jerseyNumber);

        cout << "Enter player " << i + 1 << "'s rating:" << endl;
        cin >> rating;
        // Validate user input
        while (rating < 1 || rating > 9) {
            cout << "Enter player " << i + 1 << "'s rating (1 - 9):\n";
            cin >> rating;
        }
        // Add rating to the vector
        ratings.push_back(rating);
        cout << "\n";
    }

    // Output the roster
    cout << "ROSTER\n";
    for (int i = 0; i < jerseys.size(); i++) {
        cout << "Player " << i + 1 << " -- Jersey Number: " << jerseys[i] << ", Rating: " << ratings[i] << "\n";
    }
    cout << "\n";

    do {
        // Menu of options
        cout << "MENU\n";
        cout << "a - Add player\n";
        cout << "d - Remove player\n";
        cout << "u - Update player rating\n";
        cout << "r - Output players above a rating\n";
        cout << "o - Output roster\n";
        cout << "q - Quit\n\n";

        cout << "Choose an option:\n";
        cin >> option;
        cout << "\n";

        switch (option) {
            // "Output roster" menu option
            case 'o':
                cout << "ROSTER\n";
                for (int i = 0; i < jerseys.size(); i++) {
                    cout << "Player " << i + 1 << " -- Jersey Number: " << jerseys[i] << ", Rating: " << ratings[i] << "\n";
                }
                break;

            // "Add player" menu option
            case 'a':
                cout << "Enter a new player's jersey number:\n";
                cin >> jerseyNumber;
                // Validate user input
                while (jerseyNumber < 0 || jerseyNumber > 99) {
                    cout << "Enter a new player's jersey number (0 - 99):\n";
                    cin >> jerseyNumber;
                }
                // Add jersey number to the vector
                jerseys.push_back(jerseyNumber);

                cout << "Enter the player's rating:" << endl;
                cin >> rating;
                // Validate user input
                while (rating < 1 || rating > 9) {
                    cout << "Enter the player's rating (1 - 9):\n";
                    cin >> rating;
                }
                // Add rating to the vector
                ratings.push_back(rating);
                break;

            // "Delete player" menu option
            case 'd':
                cout << "Enter a jersey number:\n";
                cin >> jerseyNumber;
                for (int i = 0; i < jerseys.size(); i++) {
                    if (jerseys[i] == jerseyNumber) {
                        jerseys.erase(jerseys.begin() + i);
                        ratings.erase(ratings.begin() + i);
                        break;
                    }
                }
                break;

            // "Update player rating" menu option
            case 'u':
                cout << "Enter a jersey number:\n";
                cin >> jerseyNumber;
                cout << "Enter a new rating for player:\n";
                cin >> rating;
                // Validate user input
                while (rating < 1 || rating > 9) {
                    cout << "Enter a new rating for player (1 - 9):\n";
                    cin >> rating;
                }

                for (int i = 0; i < jerseys.size(); i++) {
                    if (jerseys[i] == jerseyNumber) {
                        ratings[i] = rating;
                    }
                }
                break;

            // "Output players above a rating" menu option
            case 'r':
                cout << "Enter a rating:\n";
                cin >> rating;
                cout << "ABOVE " << rating << "\n";
                for (int i = 0, count = 0; i < ratings.size(); i++) {
                    if (ratings[i] > rating) {
                        count++;
                        cout << "Player " << count << " -- Jersey Number: " << jerseys[i] << ", Rating: " << ratings[i] << "\n";
                    }
                }
                break;

            case 'q':
                break;

            default:
                cout << "Invalid option. Try again.\n";
        }
        cout << "\n";
    } while (option != 'q');

    return 0;
}

Sample output:

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
Player 3 -- Jersey Number: 4, Rating: 5
Player 4 -- Jersey Number: 30, Rating: 2
Player 5 -- Jersey Number: 66, Rating: 9

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

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 a new player's jersey number:
49
Enter the player's rating:
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
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

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

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:
23
Enter a new rating for player:
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:
o
ROSTER
Player 1 -- Jersey Number: 84, Rating: 7
Player 2 -- Jersey Number: 23, Rating: 6
Player 3 -- Jersey Number: 30, Rating: 2
Player 4 -- Jersey Number: 66, Rating: 9
Player 5 -- Jersey Number: 49, Rating: 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:
r
Enter a rating:
5
ABOVE 5
Player 1 -- Jersey Number: 84, Rating: 7
Player 2 -- Jersey Number: 23, Rating: 6
Player 3 -- Jersey Number: 66, Rating: 9
Player 4 -- Jersey Number: 49, Rating: 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:
q

Kindly rate the answer and for any help just drop a comment


Related Solutions

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...
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:...
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...
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:...
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...
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...
C++ Vectors. Create a program do the following in the program: 1. declare an vector without...
C++ Vectors. Create a program do the following in the program: 1. declare an vector without specifying the size 2. use push_back to add random integers between 100 and 999 to the vector 3. write a function that returns the smallest, largest, and average of the numbers in the vector display the smallest, largest, and average of the numbers in the vector
You MUST use VECTORS in this lab. Do NOT use ARRAYS. Write code in C++ with...
You MUST use VECTORS in this lab. Do NOT use ARRAYS. Write code in C++ with //comments . Please include a screen shot of the output Part 4: Calorie Counting Specifications: Write a program that allows the user to enter the number of calories consumed per day. Store these calories in an integer vector. The user should be prompted to enter the calories over the course of one week (7 days). Your program should display the total calories consumed over...
You MUST use VECTORS in this lab. Do NOT use ARRAYS. Write code in C++ with...
You MUST use VECTORS in this lab. Do NOT use ARRAYS. Write code in C++ with //comments . Please include a screen shot of the output Part 1: Largest and Smallest Vector Values Specifications: Write a program that generates 10 random integers between 50 and 100 (inclusive) and puts them into a vector. The program should display the largest and smallest values stored in the vector. Create 3 functions in addition to your main function. One function should generate the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT