Answered step by step
Verified Expert Solution
Question
1 Approved Answer
For this assignment, implement a high score system using a sorted list data structure to sort scores from highest to lowest. Your program should print
For this assignment, implement a high score system using a sorted list data structure to
sort scores from highest to lowest. Your program should print out a list of scores, ask the
user for a new score, insert the new score in the correct position, print out the new score
list, and let the user keep entering scores and displaying the sorted list until the user quits.
If you wish, you can seed the high score list with a few dummy scores, ala vintage arcade
games, or just start with an empty sorted list.
Unlike vintage arcade games, we are just storing the scores and not associated names or
initials of who got the score.
I have placed an incomplete sorted list implementation called SortedListHasA on a shared
folder for you to use for this assignment:
It uses the containment "has A scheme discussed in the book and in class; namely, it has
a basic linked list as part of its private member data, and then adds some methods in order
to implement the sorted list operations.
Familiarize yourself with the code. The compilation instructions to get running on hills
are similar to the instructions for the earlier LinkedList assignment, except you need to
work with the codebase for SortedListHasA.zip instead of LinkedList.zip.
Pay particular attention to the member function getPostion in SortedListHasA.cpp which
is wrong. As implemented, this function always returns As a result, many of the tests
called from main fail and an exception is thrown.
For this assignment, you'll need to do the following:
In SortedListHasA.cpp implement getPosition so that it works correctly. It should
return either the position of the given entry, if it occurs in the sorted list, or the position
where the entry would occur, but as a negative integer. Once you have this working, you
can verify that it works by checking that the tests pass.
Once you're confident it works, comment out the calls to various tests from main and instead implement the high score system described above. if the user enter a negative score, the program should end.
Here is the SortedListHasA.cpp
#include "SortedListHasA.h Header file
#include "LinkedList.h
#include
#include
template
SortedListHasA::SortedListHasA
listPtr new LinkedList;
end default constructor
template
SortedListHasA::SortedListHasAconst SortedListHasA& sList
First, create our own list
listPtr new LinkedList;
Then add items to it using public methods
forint position ; position sList.getLength; position
listPtrinsertposition sList.getEntryposition;
end for
end copy constructor
template
SortedListHasA::~SortedListHasA
clear;
end destructor
template
void SortedListHasA::insertSortedconst ItemType& newEntry
int newPosition fabsgetPositionnewEntry;
listPtrinsertnewPosition newEntry;
end insertSorted
template
bool SortedListHasA::removeSortedconst ItemType& anEntry
bool ableToRemove false;
if isEmpty
int position getPositionanEntry;
ableToRemove position ;
if ableToRemove
ableToRemove listPtrremoveposition;
end if
end if
return ableToRemove;
end removeSorted
template
int SortedListHasA::getPositionconst ItemType& anEntry const
this version of getPosition always returns Fix it so that it implements
getPosition correctly. It should return either the position of the given
entry, if it occurs in the sorted list, or the position where the entry
would occur, but as a negative integer.
int position ;
return position;
end getPosition
List operations:
template
bool SortedListHasA::removeint position
return listPtrremoveposition;
end remove
template
void SortedListHasA::clear
listPtrclear;
end clear
template
ItemType SortedListHasA::getEntryint position const
return listPtrgetEntryposition;
end getEntry
template
bool SortedListHasA::isEmpty const
return listPtrisEmpty;
end isEmpty
template
int SortedListHasA::getLength const
return listPtrgetLength;
end getLength
End of implementation file. To get this to compile on hills,
add definitions of template types we will use in this cpp file.
just strings for now, add more types if desired
template class SortedListHasA;
template class SortedLi
CAN YOU TELL ME WHAT DOES THE ERROR MESSAGE MEAN AND HOW TO FIX IT THANK YOU
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started