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

c++ program 1) Playing Card Class In this problem, you will implement a DeckOfCa

ID: 3807284 • Letter: C

Question

c++ program

1) Playing Card Class
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:

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:

A24 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):

A43 5

10 8 6 Q

Q52 Q

QJ6 A

43K J

75A 2

982 J

2K7 6

J5 10 K

964 7

10 9 3 9

10 8 8 K

7A3 4

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:

A24 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):

A43 5

10 8 6 Q

Q52 Q

QJ6 A

43K J

75A 2

982 J

2K7 6

J5 10 K

964 7

10 9 3 9

10 8 8 K

7A3 4

Explanation / Answer

public class Blackjack { public static void main(String[] args) { int money; // Amount of money the user has. int bet; // Amount user bets on a game. boolean userWins; // Did the user win the game? TextIO.putln("Welcome to the game of blackjack."); TextIO.putln(); money = 100; // User starts with $100. while (true) { TextIO.putln("You have " + money + " dollars."); do { TextIO.putln("How many dollars do you want to bet? (Enter 0 to end.)"); TextIO.put("? "); bet = TextIO.getlnInt(); if (bet < 0 || bet > money) TextIO.putln("Your answer must be between 0 and " + money + '.'); } while (bet < 0 || bet > money); if (bet == 0) break; userWins = playBlackjack(); if (userWins) money = money + bet; else money = money - bet; TextIO.putln(); if (money == 0) { TextIO.putln("Looks like you've are out of money!"); break; } } TextIO.putln(); TextIO.putln("You leave with $" + money + '.'); } // end main() static boolean playBlackjack() { // Let the user play one game of Blackjack. // Return true if the user wins, false if the user loses. Deck deck; // A deck of cards. A new deck for each game. BlackjackHand dealerHand; // The dealer's hand. BlackjackHand userHand; // The user's hand. deck = new Deck(); dealerHand = new BlackjackHand(); userHand = new BlackjackHand(); /* Shuffle the deck, then deal two cards to each player. */ deck.shuffle(); dealerHand.addCard( deck.dealCard() ); dealerHand.addCard( deck.dealCard() ); userHand.addCard( deck.dealCard() ); userHand.addCard( deck.dealCard() ); TextIO.putln(); TextIO.putln(); /* Check if one of the players has Blackjack (two cards totaling to 21). The player with Blackjack wins the game. Dealer wins ties. */ if (dealerHand.getBlackjackValue() == 21) { TextIO.putln("Dealer has the " + dealerHand.getCard(0) + " and the " + dealerHand.getCard(1) + "."); TextIO.putln("User has the " + userHand.getCard(0) + " and the " + userHand.getCard(1) + "."); TextIO.putln(); TextIO.putln("Dealer has Blackjack. Dealer wins."); return false; } if (userHand.getBlackjackValue() == 21) { TextIO.putln("Dealer has the " + dealerHand.getCard(0) + " and the " + dealerHand.getCard(1) + "."); TextIO.putln("User has the " + userHand.getCard(0) + " and the " + userHand.getCard(1) + "."); TextIO.putln(); TextIO.putln("You have Blackjack. You win."); return true; } /* If neither player has Blackjack, play the game. First the user gets a chance to draw cards (i.e., to "Hit"). The while loop ends when the user chooses to "Stand". If the user goes over 21, the user loses immediately. */ while (true) { /* Display user's cards, and let user decide to Hit or Stand. */ TextIO.putln(); TextIO.putln(); TextIO.putln("Your cards are:"); for ( int i = 0; i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote