Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(Card Shuffling and Dealing) Modify the program below so that the card-dealing function deals a five-card poker hand. Then write the following additional functions: a)

(Card Shuffling and Dealing) Modify the program below so that the card-dealing function deals a five-card poker hand.

Then write the following additional functions:

a) Determine whether the hand contains two pairs

b) Determine whether the hand contains a full house (i.e., three of a kind with pair).

c) Determinewhetherthehandcontainsastraight flush (i.e.,fivecardsofconsecutivefacevalues).

d) Determine whether the hand contains a flush (i.e., five of the same suit)

#include

#include

#include

#define SUITS 4

#define FACES 13

#define CARDS 52

// prototypes

void shuffle(unsigned int wDeck[][FACES]); // shuffling modifies wDeck

void deal(unsigned int wDeck[][FACES], const char *wFace[],

const char *wSuit[]); // dealing doesn't modify the arrays

int main(void)

{

// initialize deck array

unsigned int deck[SUITS][FACES] = { 0 };

srand(time(NULL)); // seed random-number generator

shuffle(deck); // shuffle the deck

// initialize suit array

const char *suit[SUITS] =

{"Hearts", "Diamonds", "Clubs", "Spades"};

// initialize face array

const char *face[FACES] =

{"Ace", "Deuce", "Three", "Four",

"Five", "Six", "Seven", "Eight",

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

deal(deck, face, suit); // deal the deck

}

// shuffle cards in deck

void shuffle(unsigned int wDeck[][FACES])

{

// for each of the cards, choose slot of deck randomly

for (size_t card = 1; card <= CARDS; ++card) {

size_t row; // row number

size_t column; // column number

// choose new random location until unoccupied slot found

do {

row = rand() % SUITS;

column = rand() % FACES;

} while(wDeck[row][column] != 0); // end do...while

// place card number in chosen slot of deck

wDeck[row][column] = card;

}

}

// deal cards in deck

void deal(unsigned int wDeck[][FACES], const char *wFace[],

const char *wSuit[])

{

// deal each of the cards

for (size_t card = 1; card <= CARDS; ++card) {

// loop through rows of wDeck

for (size_t row = 0; row < SUITS; ++row) {

// loop through columns of wDeck for current row

for (size_t column = 0; column < FACES; ++column) {

// if slot contains current card, display card

if (wDeck[row][column] == card) {

printf("%5s of %-8s%c", wFace[column], wSuit[row],

card % 2 == 0 ? ' ' : '\t'); // 2-column format

}

}

}

}

}

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

Step: 3

blur-text-image

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

Databases Illuminated

Authors: Catherine Ricardo

2nd Edition

1449606008, 978-1449606008

More Books

Students also viewed these Databases questions

Question

12.6 Analyze the emerging emphasis on employee recognition.

Answered: 1 week ago