Question: [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;

}

[IN C CODE PLEASE] #include #include #include #define NCARDS 52 #define NPROPS

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!