1) Modify the DeckOfCards class from lab 8 to use the C++ built in functions ran
ID: 3656067 • Letter: 1
Question
1) Modify the DeckOfCards class from lab 8 to use the C++ built in functions rand() and srand(). Put the class definition in a file called DeckOfCards.h and the member function definitions in a file called DeckOfCards.cpp, then create a sepate file for your driver program containing the main() function, e.g., blackjack.cpp. You can compile your program using the command: g++ blackjack.cpp DeckOfCards.cpp 2) 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. 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: dealer scores 17, 18, 19, 20, 21, natural blackjack, or busts. ---Display each of these statistics on the terminal as both frequency and the percentage of total hands played.. . . . . Below is the previous lab for a deck of cards: #include #include #include using namespace std; void displayHand(int hand[], int size); class RandomVariable { public: RandomVariable(); RandomVariable(unsigned int); unsigned int getRand(); unsigned int maxRand(); void seedRand(unsigned int); void display(); private: unsigned int currentValue; }; class DeckOfCards { public: DeckOfCards(); int dealCard(); void shuffle(); private: int deck[52]; int nextCard; RandomVariable randomNum; }; int main() { DeckOfCards deck; int hand[4]; for(int j=0; j<13; j++) { for (int i=0; i<4; i++) hand[i]=deck.dealCard(); displayHand(hand,4); } return 0; } DeckOfCards::DeckOfCards() { nextCard=0; for (int i=0; i<52; i++) deck[i]=i; shuffle(); } int DeckOfCards::dealCard() { if (nextCard==52) { shuffle(); nextCard=0; } return deck[nextCard++]; } void DeckOfCards::shuffle() { int j=0; int placeHolder; for (int i=51; i>0; i--) { j=static_cast(randomNum.getRand()) / randomNum.maxRand() * i; placeHolder=deck[i]; deck[i]=deck[j]; deck[j]=placeHolder; } } RandomVariable::RandomVariable() { currentValue=time(0); } RandomVariable::RandomVariable(unsigned int seed) { currentValue=seed; } unsigned int RandomVariable::getRand() { int a=22695477, c=1; currentValue=a*currentValue+c; return currentValue; } unsigned int RandomVariable:: maxRand() { return pow(2,32)-1; } void RandomVariable:: seedRand(unsigned int seed) { currentValue=seed; } void RandomVariable::display() { cout<< currentValue; } void displayHand(int hand[], int size) { for (int i=0; i<<"A "; else if (hand[i]==10) cout<<"J "; else if (hand[i]==11) cout<<"Q "; else if (hand[i]==12) cout<<"K "; else cout<<(hand[i]+1)<<' '; } cout<<endl; }Explanation / Answer
#include #include #include #include int p_ace=0, d_ace=0; int a=0; int cards[53]; char names2[53][25]; char names[53][25] = { //this is for filling the arrays with the names of the cards "Zero", "Ace of Spades", "Two of Spades", "Three of Spades", "Four of Spades", "Five of Spades", "Six of Spades", "Seven of Spades", "Eight of Spades", "Nine of Spades", "Ten of Spades", "Jack of Spades", "Queen of Spades", "King of Spades", "Ace of Hearts", "Two of Hearts", "Three of Hearts", "Four of Hearts", "Five of Hearts", "Six of Hearts", "Seven of Hearts", "Eight of Hearts", "Nine of Hearts", "Ten of Hearts", "Jack of Hearts", "Queen of Hearts", "King of Hearts", "Ace of Clubs", "Two of Clubs", "Three of Clubs", "Four of Clubs", "Five of Clubs", "Six of Clubs", "Seven of Clubs", "Eight of Clubs", "Nine of Clubs", "Ten of Clubs", "Jack of Clubs", "Queen of Clubs", "King of Clubs", "Ace of Diamonds", "Two of Diamonds", "Three of Diamonds", "Four of Diamonds", "Five of Diamonds", "Six of Diamonds", "Seven of Diamonds", "Eight of Diamonds", "Nine of Diamonds", "Ten of Diamonds", "Jack of Diamonds", "Queen of Diamonds", "King of Diamonds" }; void rules(); void shuffle(); void shuffle2(); void init(); void display(int *, int*); void input(char *); void process(int *, int *, int*); void exit(int *, int *, int *, int *); int menu(); void welcome(); int option; void welcome() { std::coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.