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, del, 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 is assumed to be within the range of 1 and 99. If the entered score is greater than any of the top five socres, it will be added to the list, and the lowest score will be removed. If not, the list remains unchanged.
The del command enables the user to input a score. The record on the leaderboard matching this score will be removed, and a new entry for "Anonymous" with a score of 0 will be added at the end. If multiple records share the same score, the earliest one entered will be deleted.
If the entered score does not match any record on the leaderboard, no changes will be made.
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, del, show, exit):
add 94 Aubrey
add 62 Isabella
add 62 Hazel
add 44 Lily
add 92 Elizabeth
show
The top five scores are:
1. Aubrey, Score: 94
2. Elizabeth, Score: 92
3. Isabella, Score: 62
4. Hazel, Score: 62
5. Lily, Score: 44
del 62
show
The top five scores are:
1. Aubrey, Score: 94
2. Elizabeth, Score: 92
3. Hazel, Score: 62
4. Lily, Score: 44
5. Anonymous, Score: 0
del 63
show
The top five scores are:
1. Aubrey, Score: 94
2. Elizabeth, Score: 92
3. Hazel, Score: 62
4. Lily, Score: 44
5. Anonymous, Score: 0
exit
In the above example, when add 62 Hazel is executed, the leaderboard already includes Isabella with the same score of 62. Hazel should be placed below Elizabeth because Hazel's score is not higher than Elizabeth's.
Your solution should be based on the code template.
Your program must conform the following requirements:
The output of your program should match the example provided exactly.
Add your code only within the function definitions of add_item() and delete_item()
Do not modify initialize_system(), display_items(), and interactive_test().
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.