Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

7.12 (Card Shuffling and Dealing) Modify the program in Fig. 7.24 so that the ca

ID: 3911324 • Letter: 7

Question

7.12 (Card Shuffling and Dealing) Modify the program in Fig. 7.24 so that the card-dealing
function deals a five-card poker hand. Then write the following additional functions:
a) Determine whether the hand contains a pair.
b) Determine whether the hand contains two pairs.
320 Chapter 7 C Pointers
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).
f) Determine whether the hand contains a straight (i.e., five cards of consecutive face values).

7.13 (Project: Card Shuffling and Dealing) Use the functions developed in Exercise 7.12 to
write a program that deals two five-card poker hands, evaluates each, and determines which is the
better hand.

I need the 7.13 please. Not 7.12 .

Thank you

// Fig. 7.24: fig07_24.c

// Card shuffling and dealing.

#include <stdio.h>

#include <stdlib.h>

#include <time.h>

#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);

    // 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 ? ' ' : ' '); // 2-column format

                }

            }

        }

    }

}

Explanation / Answer

#include <iostream>

#include <vector>

#include <ctime>

#include <sstream>

using namespace std;

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

string faces[12]={"Ace", "2", "3", "4", "5", "6", "7", "8", "9", "Jack", "Queen", "King"};

class Card

{

public:

int face,suit;

Card(int face,int suit)

{

this->face=face;

this->suit=suit;

}

string toString()

{

string nameSuit = suits[suit];

string nameFace = faces[face];

return nameFace+" of "+nameSuit;

}

  

};

class DeckOfCards

{

private:

vector<Card> deck;

int currentLocation, location;

public:

DeckOfCards()

/*create deck*/

{

for(int i=0;i<13;i++)

for(int k=0;k<4;k++)

{

Card card(i,k);

deck.push_back(card);

currentLocation++;

}

}

void shuffle()

/*shuffle the deck*/

{

for(int i=0;i<52;i++)

{

location=rand()%52+1;

Card holder=deck[location];

deck[location]=deck[i];

deck[i]=holder;

}

}

void dealCard()

/*deal the shuffled cards*/

{

while(currentLocation >0)

{

Card returnCard = deck[currentLocation];

returnCard.toString();

currentLocation--;

}

}

bool moreCards()

{

int size = (int) deck.size();

if(size == 0)

return false;

else

return true;

}

  

};

int main ()

/*main function*/

{

DeckOfCards deck;

deck.shuffle();

deck.dealCard();

};

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote