Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Part 1: Write a c++ code that will generate random cards until all the different

ID: 3886428 • Letter: P

Question

Part 1: Write a c++ code that will generate random cards until all the different face cards have been seen for a given suit (i.e., "Jack", "Queen", and "King"). then print a table showing how many cards of each suit and rank you were dealt along the way. Flag the suit that caused termination by adding "**" at the end its output line.

Part 2:  Write the next c++ code and have it keep track of the order in which a card rank is observed for each suit. You do this by inserting the cards at the back of linked lists, using one list for each suit. The exception applies: each time a rank is seen again, the card gets moved to the front of the list. When the stopping criterion from Prog2a is encountered, break the infinite-loop and print the contents of each linked list to stdout as shown below. Add an array of linked lists: the length of the array is fixed at 4 like before, while the length of each linked list varies from suit to suit. Each new card is added to the appropriate list thru use of an insert() function. Declare a list class based on a single linked list. The list class needs to define a private node datatype, and it must include a constructor for properly initializing an empty list, a destructor for deallocating all the nodes in a list as well as the list itself, and the mentioned insert function which works as described next; no other list class functions are needed. Overload operator<<() used by ostream and have it print the contents of the list. Since access is needed to private data members, make the overloaded output operator a friend of the list class. See the code handouts for how to set this up.

Explanation / Answer

#include "card_games.h" #include #include #include #include using namespace std; Deck::Deck() { createDeck(); } void Deck::createDeck() { deck.clear(); static const char suits[] = {'C','D','H','S'}; for (int suit=0; suit < 4; suit++) for (int val=1; val