Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

struct Player {
    string firstName;
    string lastName;
    int jerseyNumber;
    int rating;
};

// Prompt menu options to user
void displayMenu() {
    cout << "MENU\n";
    cout << "a - Add player\n";
    cout << "d - Remove player\n";
    cout << "u - Update player rating\n";
    cout << "o - Output roster\n";
    cout << "q - Quit\n";
    cout << "\nChoose an option: \n";
  
}

 

// Add new player to the roster
void addPlayer(vector<Player>& roster) {
    Player newPlayer;
    cout << "\nEnter the new player's data\n";
    cout << "first name:\n";
    cin >> newPlayer.firstName;
    cout << "last name:\n";
    cin >> newPlayer.lastName;
    cout << "jersey number:\n";
    cin >> newPlayer.jerseyNumber;
    cout << "rating:\n\n";
    cin >> newPlayer.rating;
    roster.push_back(newPlayer);
}

// Remove a player from the roster based on their jersey number
void removePlayer(vector<Player>& roster) {
    int jerseyNumber;
    cout << "\nEnter a jersey number: ";
    cin >> jerseyNumber;

    auto iter = find_if(roster.begin(), roster.end(), [jerseyNumber](const Player& p) { return p.jerseyNumber == jerseyNumber; });

    if (iter == roster.end()) {
        cout << "Player not found.\n";
    }
    else {
        roster.erase(iter);
        cout << "Player removed from roster.\n";
    }
}

// Update a player's rating based on their jersey number
void updatePlayerRating(vector<Player>& roster) {
    int jerseyNumber;
    cout << "\nEnter a jersey number: "<<endl;
    cin >> jerseyNumber;

    auto iter = find_if(roster.begin(), roster.end(), [jerseyNumber](const Player& p) { return p.jerseyNumber == jerseyNumber; });

    if (iter == roster.end()) {
        cout << "Player not found.\n";
    }
    else {
        int newRating;
        cout << "Enter a new rating for player: ";
        cin >> newRating;
        iter->rating = newRating;
        cout << "Player rating updated.\n";
    }
}

// Output the roster
void outputRoster(const vector<Player>& roster) {
    cout << "\nROSTER\n";
    for (size_t i = 0; i < roster.size(); i++) {
        cout << "Player " << i + 1 << " -- " << roster[i].firstName << " " << roster[i].lastName << ", jersey number " << roster[i].jerseyNumber << ", rating " << roster[i].rating << endl;
    }
    cout << endl;
}

int main() {
    vector<Player> roster;
    char option;

    do {
        displayMenu();
        cin >> option;

        switch (option) {
        case 'a':
            addPlayer(roster);
            break;
        case 'd':
            removePlayer(roster);
            break;
        case 'u':
            updatePlayerRating(roster);
            break;
        case 'o':
            outputRoster(roster);
            break;
        case 'q':
            break;
        default:
            cout << "Invalid option. Please try again.\n";
        }

    } while (option != 'q');

    return 0;
}

 

SO I need to put a blank space under the second Choose an option(the last line)  

This page willer andrating information for a soportes Coaches to players during you to ensure a balanced team
Your program will bemandien, matiple function app. The coach can do multiple operations during a single men of the app
Fachported by a single chater and a separate function. The new appass again after any of the options
For this party the quit aption. So your program will start caste an empty vectos object for the rester, display the menu, and
- A player
dove plager
u-update player rating
-Duteroster
chase an aptin
numbers and rating to Dort wory about wor checking Append the new p
Enter the now player's data
first
jersey number:
rating:
Nowinpleet the "Durgus noster en option togeth
ROSTER
Player 1--Tas charles, jersey numbers, rating 7
Player 2--Laure Focsát, jersey number 23, rating4
in the player rating menuption in a new function Pront the userfor a players jersey sunber Propagain for
newing for the player, and then change that players ding. The app gives no status message. You cause the display option
the change was used (8 p)
Batera jersey number:
21
ter a new rating for player:
the The app gives
use toucan use the display roster option to see if th
This is that made the a) and pop back) vedtar dasmanber factions to have every vector ters after the
dan pastice, and then get rid of the
Ester jersey number:
expand button
Transcribed Image Text:This page willer andrating information for a soportes Coaches to players during you to ensure a balanced team Your program will bemandien, matiple function app. The coach can do multiple operations during a single men of the app Fachported by a single chater and a separate function. The new appass again after any of the options For this party the quit aption. So your program will start caste an empty vectos object for the rester, display the menu, and - A player dove plager u-update player rating -Duteroster chase an aptin numbers and rating to Dort wory about wor checking Append the new p Enter the now player's data first jersey number: rating: Nowinpleet the "Durgus noster en option togeth ROSTER Player 1--Tas charles, jersey numbers, rating 7 Player 2--Laure Focsát, jersey number 23, rating4 in the player rating menuption in a new function Pront the userfor a players jersey sunber Propagain for newing for the player, and then change that players ding. The app gives no status message. You cause the display option the change was used (8 p) Batera jersey number: 21 ter a new rating for player: the The app gives use toucan use the display roster option to see if th This is that made the a) and pop back) vedtar dasmanber factions to have every vector ters after the dan pastice, and then get rid of the Ester jersey number:
Output is nearly correct, but whitespace differs. See highlights below. Special character legend
Input
Your output
Expected output
MENU
a Add player
d - Remove player
u - Update player rating
o- Output roster
q - Quit
Choose an option:
MENU
a - Add player
d Remove player
u - Update player rating
o Output roster
q - Quit
Choose an option:
t
expand button
Transcribed Image Text:Output is nearly correct, but whitespace differs. See highlights below. Special character legend Input Your output Expected output MENU a Add player d - Remove player u - Update player rating o- Output roster q - Quit Choose an option: MENU a - Add player d Remove player u - Update player rating o Output roster q - Quit Choose an option: t
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education