You must write a function for each hand type. Each function must accept a const int array that contains HAND_SIZE integers, each representing one of the HAND_SIZE cards in the hand, and must return "true" if the hand contains the cards indicated by the name of the function, "false" if it does not. The functions must have the following prototypes. bool  containsPair(const int hand[]); bool  containsTwoPair(const int hand[]); bool  containsThreeOfaKind(const int hand[]); bool  containsStraight(const int hand[]); bool  containsFullHouse(const int hand[]); bool  containsFourOfaKind(const int hand[]);   Important! In the descriptions below, a pair is defined as exactly two of the same card. If there are more than two of the same card, that is not a pair. Similarly, a three-of-a-kind is defined as exactly three of the same card. If there are more than three of the same card, that is not a three-of-a-kind. However! Since there is no such hand as five-of-a-kind or more, four-of-a-kind must return true if there are four or more of the same card. 2) You do not need to write a containsHighCard function. All hands contain a highest card. If you determine that a particular hand is not one of the better hand types, then you know that it is a High Card hand. 3) Do not sort the cards in the hand. Also, do not make a copy of the hand and then sort that.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Additional Requirements

1) You must write a function for each hand type. Each function must accept a const int array that contains HAND_SIZE integers, each representing one of the HAND_SIZE cards in the hand, and must return "true" if the hand contains the cards indicated by the name of the function, "false" if it does not. The functions must have the following prototypes.

bool  containsPair(const int hand[]);

bool  containsTwoPair(const int hand[]);

bool  containsThreeOfaKind(const int hand[]);

bool  containsStraight(const int hand[]);

bool  containsFullHouse(const int hand[]);

bool  containsFourOfaKind(const int hand[]);

 

Important! In the descriptions below, a pair is defined as exactly two of the same card. If there are more than two of the same card, that is not a pair. Similarly, a three-of-a-kind is defined as exactly three of the same card. If there are more than three of the same card, that is not a three-of-a-kind. However! Since there is no such hand as five-of-a-kind or more, four-of-a-kind must return true if there are four or more of the same card.

2) You do not need to write a containsHighCard function. All hands contain a highest card. If you determine that a particular hand is not one of the better hand types, then you know that it is a High Card hand.

3) Do not sort the cards in the hand. Also, do not make a copy of the hand and then sort that.

#include <iostream>

using namespace std;

const int HAND_SIZE = 5;

int countNumPairs(const int card_value[]);

bool checkThreeOfaKind(const int card_value[]);

int countFrequency(const int card_value[], int cnt);

int findConsecutive(const int card_value[]);

bool Pair(const int card_value[])

{

    if (countNumPairs(card_value) == 2)

    {

        return true;

    }

    else

    {

        return false;

    }

}

bool TwoPair(const int card_value[]) 

{

    if (countNumPairs(card_value) == 4) 

    {

        return true;

    }

    else

    {

        return false;

    }

}

bool ThreeOfaKind(const int card_value[])

{

    if (checkThreeOfaKind(card_value) && countNumPairs(card_value) == 0)

    {

        return true;

    }

    else

    {

        return false;

    }

}

bool Straight(const int card_value[])

{

    if (findConsecutive(card_value) == 4)

    {

        return true;

    } 

    else

    {

        return false;

    }

}

bool FullHouse(const int card_value[])

{

    if (countNumPairs(card_value) >= 1 && checkThreeOfaKind(card_value)) 

    {

        return true;

    }

    else

    {

        return false;

    }

}

bool FourOfaKind(const int card_value[]) 

{

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

    {

        if (countFrequency(card_value, card_value[i]) == 4)

        {

            return true;

        }

    }

    return false;

}

int countNumPairs(const int card_value[])

{

    int numPairs = 0;

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

    {

        if (countFrequency(card_value, card_value[i]) == 2)

        {

            numPairs++;

        }

    }

    return numPairs;

}

bool checkThreeOfaKind(const int card_value[])

{

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

    {

        if (countFrequency(card_value, card_value[i]) == 3) 

        {

            return true;

        }

    }

    return false;

}

int countFrequency(const int card_value[], int value)

{

    int frequency = 0;

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

    {

        if (card_value[i] == value) 

        {

            frequency++;

        }

    }

    return frequency;

}

int findConsecutive(const int card_value[]) 

{

    int consecutive = 0;

    for (int i = 2; i <= 9; i++) 

    {

        if (countFrequency(card_value, i) == 1 && countFrequency(card_value, i + 1) == 1)

            consecutive++;

    }

    return consecutive;

}

 

int main() 

{

    int card_value[HAND_SIZE];

    cout << "Enter " << HAND_SIZE << " numeric cards, no face cards. Use 2 - 9." << endl;

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

    {

        cout << "Card " << i + 1 << ": ";

        cin >> card_value[i];

    }

    if (FourOfaKind(card_value))

    {

        cout << "Four Of a Kind!" << endl;

    }

    else if (FullHouse(card_value))

    {

        cout << "Full House!" << endl;

    } 

    else if (Straight(card_value)) 

    {

        cout << "Straight!" << endl;

    } 

    else if (ThreeOfaKind(card_value))

    {

        cout << "ThreeOfaKind" << endl;

    } 

    else if (TwoPair(card_value))

    {

        cout << "Two Pair!" << endl;

    } 

    else if (Pair(card_value)) 

    {

        cout << "Pair!" << endl;

    } 

    else

    {

        cout << "High Card!" << endl;

    }

}

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 4 images

Blurred answer
Knowledge Booster
Arrays
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education