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