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

Please dont give incorrect or incomeplete answer, your solution will be reported

ID: 3811572 • Letter: P

Question

Please dont give incorrect or incomeplete answer, your solution will be reported.

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: 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] 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: 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 :
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

2) Casino Blackjack

In this version of Blackjack, a player initially receives 2 cards and optionally draws 1, 2 or 3 more in an attempt to bring the total value of the cards as close as possible to 21 without going over. To determine the value of the hand, the cards labeled 2 through 10 are scored respectively 2 through 10 points each, so-called "Face cards" (jack, queen, and king) are scored as 10 points, and the ace can count as either 1 or 11, whichever is better for the player. If the score is over 21 the player loses (the player is “busted”), regardless what the dealer does. When played in a casino, the dealer plays according to fixed rules. For this simulation, we'll assume the casino employs the "stand on soft-17" rule that is more advantageous for the player.

Regardless the player's score, the dealer is required to continue drawing cards until his/her hand achieves a value of 17 or more, or goes bust. Since an ace counts as either 1 or 11 points, each ace results in two possible scores for a hand. A "soft score" is a score that includes one or more aces. 5 For example, ace-ace-3-2 could be one of three possible scores: 27 (busted), 17 (soft-17), or 7. The actual "score" of a soft hand is the largest score that is less than or equal to 21; in this case 17. Therefore, ace-ace-3-2 is an example of a "soft-17" and would require the dealer to stop taking cards.

Write a program that does the following:

• Includes a function, scoreDealer() that takes an array of integers representing a Blackjack "hand" and an integer number of cards as arguments and returns the dealer's score. If the hand is a "soft hand", your function must determine the largest soft score less than 21 (one or more aces counted as 1). If that is not possible, your function should return the lowest score over 21 with all the aces in the hand counted as 1.

• Using the DeckOfCards object, deal 10,000 Blackjack hands with the "stand on soft-17" rule (i.e. for each hand, continue to deal cards until the score reaches 17 or more). Your program must call the scoreDealer() function to determine the score of each hand as it is dealt.

• For each of the 10,000 hands, count the number of occurrences of the following (note: that natural blackjacks are counted both in the ‘natural blackjack’ and the ‘dealer scores 21’ categories): dealer scores 17 dealer scores 18 dealer scores 19 dealer scores 20 dealer scores 21 dealer "busted" "natural" blackjack (score equal to 21 with first two cards dealt)

• Display each of these statistics on the terminal as both frequency (count) and the percentage of total hands played.

Example:

Number of natural blackjack hands: 490 (4.9%)

hands of 17: 1443 (14.43%) hands of 18: 1396 (13.96%)

hands of 19: 1372 (13.72%) hands of 20: 1681 (16.81%)

hands of 21: 1234 (12.34%) dealer bust: 2874 (28.74%)

Note: theoretical value is ~29% for a dealer bust.

C++ code please

Explanation / Answer

The code to implement the above specified problems is :

#include <string>
#include <vector>
#include <iostream>

class DeckOfCards2 : public std::enable_shared_from_this<DeckOfCards2>

{ static void main(std::vector<std::wstring> &args);

};

void DeckOfCards2::main(std::vector<std::wstring> &args)
{
std::vector<int> deck(52);
std::vector<std::wstring> suits = {L"Spades", L"Hearts", L"Diamonds", L"Clubs"};
std::vector<std::wstring> ranks = {L"Ace", L"2", L"3", L"4", L"5", L"6", L"7", L"8", L"9", L"10", L"Jack", L"Queen", L"King"};

// Initialize cards
for (int i = 0; i < deck.size(); i++)
{
deck[i] = i;
}

// Shuffle the cards
for (int i = 0; i < deck.size(); i++)
{
int index = static_cast<int>(Math::random() * deck.size());
int temp = deck[i];
deck[i] = deck[index];
deck[index] = temp;
}

// Display the all the cards
for (int i = 0; i < 52; i++)
{
std::wstring suit = suits[deck[i] / 13];
std::wstring rank = ranks[deck[i] % 13];
std::wcout << rank << std::wstring(L" of ") << suit << std::endl;
}
}

----------------------------------------------------------------------------------------------------------------------------

#include <string>
#include <iostream>
#include <memory>

class DeckOfCards : public std::enable_shared_from_this<DeckOfCards>
{
private:
std::shared_ptr<Card> theCard;
int remainingCards = 52;

public:
DeckOfCards();

virtual void shuffle();

virtual void deal();
};

DeckOfCards::DeckOfCards()
{
theCard = std::make_shared<Card>();
}

void DeckOfCards::shuffle()
{
for (int i = 0; i < deck->length; i++)
{
int index = static_cast<int>(Math::random() deck->length);
int temp = deck[i];
deck[i] = deck[index];
deck[index] = temp;
remainingCards--;
}
}

void DeckOfCards::deal()
{
for (int i = 0; i < 52; i++)
{
std::wstring suit = suits[deck[i] / 13];
std::wstring rank = ranks[deck[i] % 13];
std::wcout << rank << std::wstring(L" of ") << suit << std::endl;
std::wcout << std::wstring(L"Remaining cards: ") << remainingCards << std::endl;
}
}

---------------------------------------------------------------------------------------------------------------------------

#include <string>
#include <vector>

class Card : public std::enable_shared_from_this<Card>
{
public:
std::vector<int> deck(52);
std::vector<std::wstring> suits = {L"Spades", L"Hearts", L"Diamonds", L"Clubs"};
std::vector<std::wstring> ranks = {L"Ace", L"2", L"3", L"4", L"5", L"6", L"7", L"8", L"9", L"10", L"Jack", L"Queen", L"King"};

Card();
};

Card::Card()
{
for (int i = 0; i < deck.size(); i++)
{
deck[i] = i;
}
}

-----------------------------------------------------------------------------------------------------------------------------

#include <string>
#include <vector>
#include <iostream>
#include <memory>

class Dealer : public std::enable_shared_from_this<Dealer>
{
static void main(std::vector<std::wstring> &args);
};

void Dealer::main(std::vector<std::wstring> &args)

{
std::wcout << std::wstring(L"The deck will randomly print out a card from a full deck each time") << std::endl;

std::shared_ptr<DeckOfCards> player = std::make_shared<DeckOfCards>();
player->deal();
}