Assignment 5
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, rev, show, exit.
The command show displays the name and the score of the top five players in the descending order of scores.
The command exit terminates the system.
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 any of the top five socres, then it should be added to the list and the lowest score discarded. Otherwise, the list should remain unchanged.
The command rev reverses the order of the top five scores except the Anonymous ones.
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, rev, show, exit):
add 50 Potter
add 20 Ron
add 45 Granger
show
The top five scores are:
1. Potter, Score: 50
2. Granger, Score: 45
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. Granger, Score: 45
3. Malfoy, Score: 30
4. Ron, Score: 20
5. Anonymous, Score: 0
rev
show
The top five scores are:
1. Ron, Score: 50
2. Malfoy, Score: 45
3. Granger, Score: 30
4. Potter, 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 behave as in the above example.
You only need to add your code to the function definitions of add_item() and reverse_items()
Do not modify initialize_system() and display_items() unless you know what you are doing.
Input-output samples:
Suggestion:
Using member function at() instead of brackets [] for accessing vector elements, because at() will catch the error when your vector subscripts are out of range.