Question
C++ In this problem, you will implement a DeckOfCards class that simulates a deck of playing cards. The class will utilize an important algorithm to
C++
In this problem, you will implement a DeckOfCards class that simulates a deck of playing cards. The class will utilize an important algorithm to "shuffle" the simulated card deck. Part 1: Create an object class named DeckOfCards that models a randomized deck of playing cards. Individual "cards" will be represented by integer values as follows: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 . . . 51 A 2 3 4 5 6 7 8 9 10 J Q K A 2 3 4 . . . K Where the value 0 represents the Ace of the "first" suit, 1 is the 2 of the first suit, 13 is the Ace of the "second" suit, and so on. The actual "suit" of the card will not be needed for now and can be ignored. Also note that in this problem we start counting with 0, rather than with 1. The DeckOfCards class should include the following private data members: A 52 element integer array to represent the shuffled deck of cards An integer index to maintain the "next card" to be dealt from the deck The DeckOfCards class must also provide the following public (member) functions: A default constructor that will initialize the values of the card deck array with integer values 0...51, and then "shuffle" the card deck (see description below) A member function dealCard() that will return the "next" card value from the shuffled deck. If no cards remain, then the deck should be reshuffled (and reset) A member function shuffle() that takes no arguments and "shuffles" (randomizes) the values in the card "deck" using the Knuth Shuffle algorithm. Given an array a with n elements, the Knuth Shuffle algorithm is as follows: FOR i = n-1 TO 1 REPEAT the following two lines: j = a pseudo-random integer from the interval 0 <= j <= i exchange a[i] and a[j] Part 2. Write a main() driver function to verify the correct operation of all DeckOfCards member functions. At a minimum, do the following: Instantiate a DeckOfCards object Create an array that will represent a 4-card "hand" of dealt cards Write a user-defined function (not part of any class) that will take as arguments an array of cards representing a single hand," and the number of cards in the array; the function should display the card values of the hand on the terminal in the following format: A 2 4 K Using the DeckOfCards object, deal 13 separate 4-card "hands" and display them on the terminal, each on a separate line. Verify that you've dealt exactly 4 aces, 4 twos, 4 threes, etc. in a "reasonably" random fashion. Example (user input is underlined): A 4 3 5 10 8 6 Q Q 5 2 Q Q J 6 A 4 3 K J 7 5 A 2 9 8 2 J 2 K 7 6 J 5 10 K 9 6 4 7 10 9 3 9 10 8 8 K 7 A 3 4
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