Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

[IN C CODE PLEASE] #include #include #include #define NCARDS 52 #define NPROPS 2 #define NSUITS 4 #define NFACES 13 // card text values using array

[IN C CODE PLEASE]

#include

#include

#include

#define NCARDS 52

#define NPROPS 2

#define NSUITS 4

#define NFACES 13

// card text values using array of pointers to preinitialized constant text strings

char* suit[NSUITS]={"hearts","spades","clubs","diamonds"};

char* face[NFACES]={"ace","two","three","four","five","six","seven","eight","nine",

"ten","jack","queen","king"};

// function prototypes used for manipulating cards

void PrintCard(int deck[NCARDS][NPROPS], int card);

void InitDeck(int deck[NCARDS][NPROPS]);

void SwapCards(int deck[NCARDS][NPROPS], int src, int dest);

void ShuffleDeck(int deck[NCARDS][NPROPS]);

int GetPlayValue(int deck[NCARDS][NPROPS], int card);

int main()

{

//deck of cards

// face, suite, card value

int deck[NCARDS][NPROPS];

time_t rawtime=time(NULL);

int i;

srand(time(NULL));

// init the deck

// loop on the chards

InitDeck(deck);

ShuffleDeck(deck);

// print the deck

puts("The shuffled deck is:");

for (i=0; i

{

PrintCard(deck,i);

}

//deal 5 cards each to two players one at a time; repeat until 5 cards

//add the total points in each player's hand

//determine winner

printf("Printed on %s",ctime(&rawtime));

return 0;

}

void InitDeck(int deck[NCARDS][NPROPS])

{

int suit, face, card;

card=0;

for (suit=0; suit

for (face=0; face

{

deck[card][0] = suit;

deck[card][1] = face;

card++;

}

}

void PrintCard(int deck[NCARDS][NPROPS], int card)

{

int tempface, tempsuit;

tempface = deck[card] [1];

tempsuit = deck[card] [0];

//printf("Card %d of suit %d has a face %d ", card, tempsuit, tempface);

printf("Card %d suit %s has face %s ", card, suit[tempsuit], face[tempface]);

}

void ShuffleDeck(int deck[NCARDS][NPROPS])

{

int card, dest;

for (card=0; card

{

dest = rand()%NCARDS;

SwapCards(deck, card, dest);

}

}

void SwapCards(int deck[NCARDS][NPROPS], int src, int dest)

{

int tempface, tempsuit;

tempface = deck[src] [0];

tempsuit = deck[dest] [1];

deck[src] [0] = deck[dest] [0];

deck[dest][0] = tempsuit;

}

int GetPlayValue(int deck[NCARDS][NPROPS], int card)

{

int playval, tface;

tface = deck[card][1];

if(tface

playval = tface+1;

else

playval = 10;

return playval;

}

image text in transcribed

Play Cards Take the program written last weekend that creates a deck of cards, shuffles them, and then lists them out. Modify the program to 'deal' two hands of cards (two players). Each player will be dealt 5 cards. Deal one to the first player, then one to second player. Repeat until both players have 5 cards in their hand. Then compute the total points in each player's hand and determine the winner with the most points. If a player has an ace, then count that as 11 points. Print out the winning player total points and then his cards. Then print out the losing player total points and his cards. Turn in both your code and a copy of the screen output. Play Cards Take the program written last weekend that creates a deck of cards, shuffles them, and then lists them out. Modify the program to 'deal' two hands of cards (two players). Each player will be dealt 5 cards. Deal one to the first player, then one to second player. Repeat until both players have 5 cards in their hand. Then compute the total points in each player's hand and determine the winner with the most points. If a player has an ace, then count that as 11 points. Print out the winning player total points and then his cards. Then print out the losing player total points and his cards. Turn in both your code and a copy of the screen output

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

DATABASE Administrator Make A Difference

Authors: Mohciine Elmourabit

1st Edition

B0CGM7XG75, 978-1722657802

More Books

Students also viewed these Databases questions

Question

What are Decision Trees?

Answered: 1 week ago

Question

What is meant by the Term Glass Ceiling?

Answered: 1 week ago