Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is the code for 9.23; please make changes to the code how 9.24 asks. C++ using 3 file architecture. /** C++program that creates a

This is the code for 9.23; please make changes to the code how 9.24 asks.
C++ using 3 file architecture.

/**

C++program that creates a deck of 52 cards

and shuffle the cards and decal 52 cards to console.

*/

//include header files

#include

#include

#include

//include Card and DeckOfCards header files

#include "Card.h"

#include "DeckOfCards.h"

using namespace std;

int main()

{

//seed a random generator

srand(time(0));

//object of DeckOfCards class

DeckOfCards myDeckOfCards;

//calling shuffle to shuffle the deck

myDeckOfCards.shuffle();

// print the cards of deal

for ( int i = 0; i

{

//print four cards

cout

}

//pause program output on console

system("pause");

return 0;

} // end main

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

//Card.h

#ifndef CARD_H

#define CARD_H

#include

#include

using namespace std;

//Card declaration

class Card

{

private:

string face;

string suit;

public:

Card(){}

Card( string face, string suit )

{

this->face = face;

this->suit = suit;

}

string toString()

{

return face + " of " + suit;

}

};

#endif CARD_H

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

#ifndef DECK_OF_CARDS_H

#define DECK_OF_CARDS_H

#include

#include

#include

#include

#include "Card.h"

using namespace std;

//set constant for number of cards

const int NUMBER_OF_CARDS = 52;

class DeckOfCards

{

private:

//array of type Card of size,NUMBER_OF_CARDS

Card deck[NUMBER_OF_CARDS];

int currentCard;

public:

DeckOfCards()

{

//array of face

string faces[] = {

"Ace", "Deuce", "Three",

"Four", "Five", "Six",

"Seven", "Eight", "Nine",

"Ten", "Jack", "Queen", "King" };

//array of suit

string suits[] = { "Hearts", "Diamonds", "Clubs", "Spades" };

currentCard = 0;

for ( int pos = 0; pos

deck[ pos ] = Card( faces[ pos % 13 ], suits[ pos / 13 ] );

}

//Method to shuffle the deck

void shuffle()

{

currentCard = 0;

//shuffle the 52 cards with a random number

for ( int first = 0; first

{

// select a random number between 0 and 51

int second = rand()%( NUMBER_OF_CARDS);

//swap cards

Card temp = deck[ first ];

deck[ first ] = deck[ second ];

deck[ second ] = temp;

}

}

//Method to deal a card and return a new deal card

Card dealCard()

{

if ( currentCard

return deck[ currentCard++ ];

else

//return empty construtor

return Card();

}

};

#endif DECK_OF_CARDS_H

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

image text in transcribed
image text in transcribed
he driver program should create a DeckofCards object, shuttle the cards, then deal the z cards the output should be similar to Fig. 9.31. 9.24 (Card Shuffling and Dealing) Modify the program you developed in Exercise 9.23 so that it deals a five-card poker hand. Then write functions to accomplish each of the following: a) Determine whether the hand contains a pair. b) Determine whether the hand contains two pairs. c) Determine whether the hand contains three of a kind (e.g., three jacks). d) Determine whether the hand contains four of a kind (e.g., four aces). e) Determine whether the hand contains a flush (i.e., all five cards of the same suit)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

T Sql Window Functions For Data Analysis And Beyond

Authors: Itzik Ben Gan

2nd Edition

0135861446, 978-0135861448

More Books

Students also viewed these Databases questions

Question

Develop successful mentoring programs. page 400

Answered: 1 week ago