Answered step by step
Verified Expert Solution
Link Copied!

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 1. 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::SortedListHasA(const SortedListHasA& sList)
{
// First, create our own list
listPtr = new LinkedList();
// Then add items to it using public methods
for(int position =1; position = sList.getLength(); position++)
{
listPtr->insert(position, sList.getEntry(position));
}// end for
}// end copy constructor
template
SortedListHasA::~SortedListHasA()
{
clear();
}// end destructor
template
void SortedListHasA::insertSorted(const ItemType& newEntry)
{
int newPosition = fabs(getPosition(newEntry));
listPtr->insert(newPosition, newEntry);
}// end insertSorted
template
bool SortedListHasA::removeSorted(const ItemType& anEntry)
{
bool ableToRemove = false;
if (!isEmpty())
{
int position = getPosition(anEntry);
ableToRemove = position >0;
if (ableToRemove)
{
ableToRemove = listPtr->remove(position);
}// end if
}// end if
return ableToRemove;
}// end removeSorted
template
int SortedListHasA::getPosition(const ItemType& anEntry) const
{
// this version of getPosition always returns 1. 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 =1;
return position;
}// end getPosition
//=====================
// List operations:
template
bool SortedListHasA::remove(int position)
{
return listPtr->remove(position);
}// end remove
template
void SortedListHasA::clear()
{
listPtr->clear();
}// end clear
template
ItemType SortedListHasA::getEntry(int position) const
{
return listPtr->getEntry(position);
}// end getEntry
template
bool SortedListHasA::isEmpty() const
{
return listPtr->isEmpty();
}// end isEmpty
template
int SortedListHasA::getLength() const
{
return listPtr->getLength();
}// 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
Thank you for your big help. I was able to fix the code. However, the Output was from the Low Score to Hight Score. What it neees to be done for this so it can be from High Score to Low Score? the main() cpp and the output below. Thank you.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 24th International Conference Dexa 2013 Prague Czech Republic August 2013 Proceedings Part 2 Lncs 8056

Authors: Hendrik Decker ,Lenka Lhotska ,Sebastian Link ,Josef Basl ,A Min Tjoa

2013th Edition

3642401724, 978-3642401725

More Books

Students also viewed these Databases questions

Question

What is business strategy?

Answered: 1 week ago