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: 3886450 • 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.

EXAMPLE OUTPUT:

Code 1:

Code 2:

Explanation / Answer



main.cpp

Edit & Run



card_games.h

  2  3  4  5  6  7  8  9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  
  #include "card_games.h"  #include <iostream>  #include <ctime>  #include <cstdlib> //for rand and srand  #include <cstdio>   #include <string>    using std::cin;  using std::cout;  using std::endl;    string StudPoker::deckFunction () {                    srand(time(0));             struct card deck[52];  // An array of cards named deck, size 52                    const string ranks[ ] = { "Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight",          "Nine", "Ten", "Jack", "Queen", "King" };                            const string suits[ ] = { "Diamonds", "Hearts", "Spades", "Clubs" };            int k = 0;             for ( int i = 0; i < 13; i++)          {                  for ( int j = 0; j < 4; j++)                  {                          deck[ k ].rank = ranks[ i ];                          deck[ k ].suit = suits[ j ];                          k++;                  }          }          int RandIndex = rand() % 13;          int RandIndex2 = rand() % 4;          return ranks[RandIndex] + " of " + suits[RandIndex2];  }    void StudPoker::player1hand() {                      }