Assignment 5: Leaderboard
Write a system that tracks the top five scores for a game. The system has a list of five items, and each item has a name and the corresponding score. Initially, the list consists of five items with the name Anonymous and the score of 0. The system supports four commands: add, mod, show, exit.
The command show displays the name and the score of the top five players in the descending order of scores.
The command add takes a score and a name from the user. The score entered by the user is assumed to be between 1 and 99. If the score is greater than or equal to any of the top five scores, then it should be added to the list, and the lowest score is discarded. Otherwise, the list should remain unchanged.
If the entered score of name1 is the same as some score of name2 in the leaderboard, then the entered score should be added to the leaderboard, and name1 should be higher than name2.
The command mod takes a score and an item number from the user. The item number is assumed to be between 1 and 5. This score is assigned to the item specified by the item number. The sequence of items needs to be properly adjusted accroding to the scores.
If the modified score of name1 is the same as some score of name2 in the leadboard, then name1 should be higher than name2.
This system does not record items that are not in the leaderboard. For example, suppose an item has been entered, and this item is not added to the leaderboard. Then, this item is discarded and will not be used in the future.
A complete example is given below (illustration).
Enter commands (add, mod, show, exit):
add 50 Potter
add 20 Ron
add 20 Granger
show
The top five scores are:
1. Potter, Score: 50
2. Granger, Score: 20
3. Ron, Score: 20
4. Anonymous, Score: 0
5. Anonymous, Score: 0
add 30 Malfoy
show
The top five scores are:
1. Potter, Score: 50
2. Malfoy, Score: 30
3. Granger, Score: 20
4. Ron, Score: 20
5. Anonymous, Score: 0
mod 60 3
show
The top five scores are:
1. Granger, Score: 60
2. Potter, Score: 50
3. Malfoy, Score: 30
4. Ron, Score: 20
5. Anonymous, Score: 0
mod 50 3
show
The top five scores are:
1. Granger, Score: 60
2. Malfoy, Score: 50
3. Potter, Score: 50
4. Ron, Score: 20
5. Anonymous, Score: 0
exit
Your solution should be based on the code template.
Your program must conform the following requirements:
The outputs of your program should be exactly the same as those in the above example.
You only need to add your code to the function definitions of add_item() and modify_item()
Do not modify initialize_system() and display_items()
Do not modify main() unless you know what you are doing.
Input-output samples:
Suggestion:
Use the functions defined in the vector library to finish this assignment, e.g. insert(), pop_back(), erase(), push_back()
Use scores.at(i) instead of scores[i]
Test all the input-output samples before sending your solution.