Question: Write a class that maintains the top ten scores for a game application, implementing the add and remove methods of Section 3.1.1, but using a
Write a class that maintains the top ten scores for a game application, implementing the add and remove methods of Section 3.1.1, but using a singly linked list instead of an array. (Hint: You should keep track of the number of game entries explicitly.)
add and remove methods of Section 3.1.1 But please use but using a singly linked list instead of an array.
public void add(GameEntry e) { int newScore = e.getScore( ); // is the new entry e really a high score? if (numEntries board[numEntries1].getScore( )) { if (numEntries 0 && board[j1].getScore( )
public GameEntry remove(int i) throws IndexOutOfBoundsException { if (i = numEntries) throw new IndexOutOfBoundsException("Invalid index: " + i); GameEntry temp = board[i]; // save the object to be removed for (int j = i; j



PS: CAN YOU PLEASE DO THESE FUNCTIONS IN SINGLY LINKED LISTS ONLY IN THE MOST BASIC WAY. CAN YOU ALSO PLEASE EXAPLIN IN THE MOST BASIC WAY WHAT THEY DO STEP BY STEP. ONLY HAVE TO DO ADD AND REMOVE FUNCTION IN SINGLY LIST. NOTHING ELSE.
1. GameEntry class Member variables: - string: name - int: score Member functions: - GameEntry(const string\& n=" ", int s=0 ) - GameEntry() - string getName() const; - int getScore(); Access type - member variables: private - member functions: public 2. GENode class Member variables: - GameEntry elem; //data - GENode *next; //pointer to the next node Member functions: - No member functions Access type - Private 3. Scores class Member variables: Since in this case we are going to use singly linked list, the member variables are not the same as the implementation in the book. And will depend on the implementation that you are going to define. One option can be as below: - int maxEntries; // maximum number of entries - int numEntries; // actual number of entries - GENode* head; // head of the singly linked list - GENode* tail; //end of the singly linked list Member functions: - Scores(int maxEnt = 10); - SScores() - void add(const GameEntry\& e) - GameEntry remove(int i) throw(IndexOutOfBounds) - void printAll(); //prints all the game entries in the list Access type Member functions: public Member variables: private Answer questions below before implementing: Why member functions are public? Why data members are private? 4. It is up to you 5. Main Write the main function in a separate file. Test Scores operations in the main function Include necessary files in main.cpp file Inside the main function: Create an object of type Scores, with maxEntries = 5; Add 4 GameEntry items with diff score min 5. Print all. Add 3 other GameEntry with scores between the first 4. Print all. Remove the first GmeEntry. Print All
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
