Question
I need to update this C++ code according to these instructions. Here is my code: #include #include #include #include using namespace std ; struct player
I need to update this C++ code according to these instructions.
Here is my code:
#include
using namespace std ;
struct player { string name ; int jersynumber ; string position ; int score ; } ;
// this is comparator to sort players by high to low score bool scoreComparator(player a, player b){ return a.score > b.score ; } // this is comparator to sort by names bool nameComparator(player a, player b){ return a.name
// sorting the players based on the scores using scoreComparator void sortByScoresHighToLow(player playerList[], int n){ sort(playerList, playerList+n, scoreComparator); } //searching players with playername as key void searchByPlayerName(player playerList[], int n, string playerName){ for (int i = 0; i
// sorting the players based on the names using nameComparator void sortByName(player playerList[], int n){ sort(playerList, playerList+n, nameComparator); } // sorting the players based on the Jersy number using jersyComaparator void sortByJersy(player playerList[], int n){ sort(playerList, playerList+n, jersyComaparator); } // sorting the players based on the positions using positionComparator void sortByPosition(player playerList[], int n){ sort(playerList, playerList+n, positionComparator); }
void printToScreen(player playerList[], int n){ player p ; // printing all values to screen for (int i = 0; i
int loadFile(char filename[], player plist[]){ ifstream fin ;
fin.open(filename); // loading file object int index = 0 ; while(!fin.eof()){ // reading from file fin >> plist[index].name >> plist[index].jersynumber >> plist[index].position >> plist[index].score ; index++; } fin.close(); // returning number of players read return index ;
}
void printToFile(char filename[], player plist[], int n){ player p ; ofstream fout ; // loading output file object fout.open(filename); // writing every player into a file for (int i = 0; i
}
// you can change this depending on the contents of the files const int SIZE=25;
int main(int argc, char const *argv[]) { player plist[SIZE] ; int option ; char filename[1000] ; cout > filename ; int n = loadFile(filename, plist); string tp ; int pt ; do{ //Main Menu cout> option ; switch(option){ case 0 : cout> tp ; searchByPlayerName(plist, n, tp); break ; case 3 : cout > pt ; searchByJersy(plist, n, pt); break ; case 4 : cout > tp ; searchByPosition(plist, n, tp); break ; case 5 : sortByName(plist, n); printToScreen(plist, n); break ; case 6 : sortByJersy(plist, n); printToScreen(plist, n); break ; case 7 : sortByPosition(plist, n); printToScreen(plist, n); break ; case 8 : cout > filename ; printToFile(filename, plist, n); break ; case 9 : cout
}while(option != 9) ;
return 0; }
/*file to read from>scores.txt:
Drake 9 LeftWideReceiver 13 Clemont 11 LeftTackle 1 Sean 7 LeftGuard 1 Noah 5 Center 7 Sam 10 RightGuard 1 Will 8 RightTackle 1 Josh 3 TightEnd 6 Matt 4 Quarterback 21 Rob 6 FullBack 6 Timmy 2 HalfBack 6 Eddy 1 RightWideReceiver 13 Alfred 12 Substitution 0 Freddy 16 Substituion 1 Billy 23 Substituiton 3 Tommy 20 Substitution 1 */
Create a text based menu to perform the following functions: -Enter "0" Display team name. Enter "1" Sort players from highest score to lowest score. Enter "2" Search by player name or by jersey number or by position Selecting this option should let the user choose between three search options. Enter "3" Sort by player name or by jersey number or by position Selecting this option should let the user choose between three sort options. -Enter "4" Write to file. -Enter "5" to ExitStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started