Can someone please help me with this C++ assignment. Assignment 8 - Managing a S
ID: 3843929 • Letter: C
Question
Can someone please help me with this C++ assignment.
Assignment 8 - Managing a Sorted STL List
Select one option from below. All (both) options are worth the same number of points. The more advanced option(s) are provided for students who find the basic one too easy and want more of a challenge. Make sure you have read and understood
both modules A and B this week, and
module 2R - Lab Homework Requirements
before submitting this assignment.
OPTION A (Basic): A Sorted Card List
Understand the Problem
An stl list application
In the lectures we instantiated an stl list of floats and, above it, built some insert() and remove() methods on the client side that managed the list in increasing sorted order. In this assignment we will do the same for Card objects, using a natural ordering and a random Card generator that will be provided at the end of this document.
You will provide global scope insert(), remove() and removeAll() like in the lessons. They take an stl list of Cards (first parameter) and a Card (second parameter). This is very much like the iTunes example that follows the float example, so you'll want to study that.
Part 1: STL list Spec
There are very few changes you'll need to make to the overall design of what you saw:
bool removeAll(CardList &myList, Card &x) - Notice that this method returns a bool which should be true if x was in the list, and false if it was not.
For Cards, there is no < operator. Use compareTo() in your insert() and/or remove() methods, as needed.
Nothing should be changed in any of the classes or methods brought in from the earlier assignments. Everything you do should be added as client scope code.
Client Notes for Part 1
Instantiate about five to ten cards randomly, but produce duplicates of every card in the list: every card you generate goes into your list twice. Display the list immediately after you build it. (Note, you might have four, not two, of some cards because of generateRandomCard(), and that's fine. (Maybe even six or eight or ... .)
Display the list.
Next, pick up to half of the cards you inserted for removal, but do it as follows. If you instantiated five cards initially and put them into the list twice, then your list has 10 cards. Pick, say, two (or three or all five) distinct cards from your initial five and remove() all traces of each of those two cards. I don't want you to use removeAll() for this step. Instead useremove(), which only removes one instance of a card. So you'll have to use remove() on the same card repeatedly. I.e., if 3 of diamonds is a card, remove all copies of 3 of Diamonds, not just the first. Don't rely on any knowledge you might have about how many copies of the 3 of diamonds are in the list, but use an intelligent loop to keep remove()-ing it until the return value of remove() tells you the loop is done.
Display the list and confirm that it looks right after the removal.
Finally, test removeAll()'s return value somehow after the above test.
Resources
Here are the additional Card class members and a new global scope random Card generator that you will need. Add this to the existing Card class (mine or yours) from Assignment #1 and test it out with the provided main() to be sure it works. Then you can use this as a basis for this week's assignment.
That's it.