C++ Im getting errors and dont know how to fix it. .................................................... //roster.h #ifndef ROSTER_H #define ROSTER_H #include <vector> int searchPlayer(vector<int> jerseyNum, int jNum); void displayMenu(); void addPlayer(vector<int> &jerseyNum,vector<int> &rating); void deletePlayer(vector<int> &jerseyNum,vector<int> &rating); void displayAboveRating(vector<int> jerseyNum,vector<int> rating); void updatePlayer(vector<int> &jerseyNum,vector<int> &rating); void display(vector<int> jerseyNum,vector<int> rating); #endif ============================== // Roster.cpp #include <iostream> #include <vector> using namespace std; #include "Roster.h" int searchPlayer(vector<int> jerseyNum, int jNum) { for (unsigned int i = 0; i < jerseyNum.size(); i++) { if (jerseyNum[i] == jNum) return i; } return -1; } void displayMenu() { cout << "\nMENU" << endl; cout << "a - Add Player" << endl; cout << "d - Delete 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; cout << "Enter Choice :"; } void addPlayer(vector<int> &jerseyNum,vector<int> &rating) { int jnum,rate; cout << "Enter a new Player's jersey number :"; cin >> jnum; cout << "Enter the player's rating :"; cin >> rate; jerseyNum.push_back(jnum); rating.push_back(rate); } void deletePlayer(vector<int> &jerseyNum,vector<int> &rating) { int jnum; cout << "Enter a Player's jersey number :"; cin >> jnum; int index = searchPlayer(jerseyNum, jnum); if (index == -1) { cout << "** Player not found **" << endl; } else { jerseyNum.erase(jerseyNum.begin() + index); rating.erase(rating.begin() + index); } } void displayAboveRating(vector<int> jerseyNum,vector<int> rating) { int rate; cout << "Enter a rating :"; cin >> rate; cout << "ABOVE " << rate << endl; for (unsigned int i = 0; i < jerseyNum.size(); i++) { if (rating[i] > rate) { cout << "Player" << (i + 1) << " -- Jersey Number:" << jerseyNum[i] << ", Rating:" << rating[i] << endl; } } } void updatePlayer(vector<int> &jerseyNum,vector<int> &rating) { int jnum,rate; cout << "Enter a Player's jersey number :"; cin >> jnum; int index = searchPlayer(jerseyNum, jnum); if (index == -1) { cout << "** Player not found **" << endl; } else { cout << "Enter the player's rating :" << endl; cin >> rate; rating[index] = rate; } } void display(vector<int> jerseyNum,vector<int> rating) { cout << "ROSTER" << endl; for (unsigned int i = 0; i <jerseyNum.size(); i++) { cout << "Player" << (i + 1) << " -- Jersey Number:" << jerseyNum[i] << ", Rating:" << rating[i] << endl; } } ====================================== // main.cpp #include <iostream> #include <vector> using namespace std; #include "Roster.h" int main() { int jnum,rate; char choice; vector<int> jerseyNum; vector<int> rating; for(int i=0;i<5;i++) { cout<<"Enter player "<<(i+1)<<"'s jersey number: "; cin>>jnum; jerseyNum.push_back(jnum); cout<<"Enter player "<<(i+1)<<"'s rating: "; cin>>rate; rating.push_back(rate); } while(true) { displayMenu(); cin>>choice; // Based on the user choice the corresponding case will executed switch (choice) { case 'a': { addPlayer(jerseyNum,rating); } continue; case 'd': { deletePlayer(jerseyNum,rating); continue; } case 'u': { updatePlayer(jerseyNum,rating); continue; } case 'r': { displayAboveRating(jerseyNum,rating); continue; } case 'o': { display(jerseyNum,rating); continue; } case 'q': { cout << "** PROGRAM EXIT**" << endl; break; } default: { cout << "Invalid Choice" << endl; continue; } } break; } return 0; }
C++
Im getting errors and dont know how to fix it.
....................................................
//roster.h
#ifndef ROSTER_H
#define ROSTER_H
#include <
int searchPlayer(vector<int> jerseyNum, int jNum);
void displayMenu();
void addPlayer(vector<int> &jerseyNum,vector<int> &rating);
void deletePlayer(vector<int> &jerseyNum,vector<int> &rating);
void displayAboveRating(vector<int> jerseyNum,vector<int> rating);
void updatePlayer(vector<int> &jerseyNum,vector<int> &rating);
void display(vector<int> jerseyNum,vector<int> rating);
#endif
==============================
// Roster.cpp
#include <iostream>
#include <vector>
using namespace std;
#include "Roster.h"
int searchPlayer(vector<int> jerseyNum, int jNum)
{
for (unsigned int i = 0; i < jerseyNum.size(); i++)
{
if (jerseyNum[i] == jNum)
return i;
}
return -1;
}
void displayMenu()
{
cout << "\nMENU" << endl;
cout << "a - Add Player" << endl;
cout << "d - Delete 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;
cout << "Enter Choice :";
}
void addPlayer(vector<int> &jerseyNum,vector<int> &rating)
{
int jnum,rate;
cout << "Enter a new Player's jersey number :";
cin >> jnum;
cout << "Enter the player's rating :";
cin >> rate;
jerseyNum.push_back(jnum);
rating.push_back(rate);
}
void deletePlayer(vector<int> &jerseyNum,vector<int> &rating)
{
int jnum;
cout << "Enter a Player's jersey number :";
cin >> jnum;
int index = searchPlayer(jerseyNum, jnum);
if (index == -1)
{
cout << "** Player not found **" << endl;
}
else
{
jerseyNum.erase(jerseyNum.begin() + index);
rating.erase(rating.begin() + index);
}
}
void displayAboveRating(vector<int> jerseyNum,vector<int> rating)
{
int rate;
cout << "Enter a rating :";
cin >> rate;
cout << "ABOVE " << rate << endl;
for (unsigned int i = 0; i < jerseyNum.size(); i++)
{
if (rating[i] > rate)
{
cout << "Player" << (i + 1) << " -- Jersey Number:" << jerseyNum[i]
<< ", Rating:" << rating[i] << endl;
}
}
}
void updatePlayer(vector<int> &jerseyNum,vector<int> &rating)
{
int jnum,rate;
cout << "Enter a Player's jersey number :";
cin >> jnum;
int index = searchPlayer(jerseyNum, jnum);
if (index == -1)
{
cout << "** Player not found **" << endl;
}
else
{
cout << "Enter the player's rating :" << endl;
cin >> rate;
rating[index] = rate;
}
}
void display(vector<int> jerseyNum,vector<int> rating)
{
cout << "ROSTER" << endl;
for (unsigned int i = 0; i <jerseyNum.size(); i++)
{
cout << "Player" << (i + 1) << " -- Jersey Number:" << jerseyNum[i]
<< ", Rating:" << rating[i] << endl;
}
}
======================================
// main.cpp
#include <iostream>
#include <vector>
using namespace std;
#include "Roster.h"
int main()
{
int jnum,rate;
char choice;
vector<int> jerseyNum;
vector<int> rating;
for(int i=0;i<5;i++)
{
cout<<"Enter player "<<(i+1)<<"'s jersey number: ";
cin>>jnum;
jerseyNum.push_back(jnum);
cout<<"Enter player "<<(i+1)<<"'s rating: ";
cin>>rate;
rating.push_back(rate);
}
while(true)
{
displayMenu();
cin>>choice;
// Based on the user choice the corresponding case will executed
switch (choice)
{
case 'a':
{
addPlayer(jerseyNum,rating);
}
continue;
case 'd':
{
deletePlayer(jerseyNum,rating);
continue;
}
case 'u':
{
updatePlayer(jerseyNum,rating);
continue;
}
case 'r':
{
displayAboveRating(jerseyNum,rating);
continue;
}
case 'o':
{
display(jerseyNum,rating);
continue;
}
case 'q':
{
cout << "** PROGRAM EXIT**" << endl;
break;
}
default:
{
cout << "Invalid Choice" << endl;
continue;
}
}
break;
}
return 0;
}
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 1 images