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.
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;
}
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 4 images