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

Requested files: PokerHand.h PokerHand.cpp PokerHand_test.cpp Type of work: Indi

ID: 3596648 • Letter: R

Question

Requested files:

PokerHand.h

PokerHand.cpp

PokerHand_test.cpp

Type of work: Individual work

Write a program that reads five cards from the user, then analyzes the cards and prints out the category of hand that they represent.  

Poker hands are categorized according to the following labels: Straight flush, four of a kind, full house, straight, flush, three of a kind, two pairs, pair, high card.

To simplify the program we will ignore card suits, and face cards. The values that the user inputs will be integer values from 2 to 9. When your program runs it should start by collecting five integer values from the user. It might look like this (user input is in orange for clarity):

Enter five numeric cards, no face cards. Use 2 - 9.

Card 1: 8

Card 2: 7

Card 3: 8

Card 4: 2

Card 5: 3

(This is a pair, since there are two eights)

Since we are ignoring card suits there won’t be any flushes. Your program should be able to recognize the following hand categories, listed from least valuable to most valuable:

Hand Type

Description

Example

High Card

There are no matching cards, and the hand is not a straight

2, 5, 3, 8, 7

Pair

Two of the cards are identical

2, 5, 3, 5, 7

Two Pair

Two different pairs

2, 5, 3, 5, 3

Three of a kind

Three matching cards

5, 5, 3, 5, 7

Full House

A pair, and a three of a kind

5, 7, 5, 7, 7

Straight

Card values can be arranged in order

3, 4, 5, 6, 7

Four of a kind

Four matching cards

2, 5, 5, 5, 5

(A note on straights: a hand is a straight regardless of the order. So the values 3, 4, 5, 6, 7 represent a straight, but so do the values 7, 4, 5, 6, 3)

Your program should read in five values and then print out the appropriate hand type. If a hand matches more than one description, the program should print out the most valuable hand type.

Here is are two sample runs of the program:

Enter five numeric cards, no face cards. Use 2 - 9.

Card 1: 8

Card 2: 7

Card 3: 8

Card 4: 2

Card 5: 7

Two Pair!

Enter five numeric cards, no face cards. Use 2 - 9.

Card 1: 4

Card 2: 5

Card 3: 6

Card 4: 8

Card 5: 7

Straight!

Enter five numeric cards, no face cards. Use 2 - 9.

Card 1: 9

Card 2: 2

Card 3: 3

Card 4: 4

Card 5: 5

High Card!

Requirements

You must write a method for each hand type. Each method should accept an int array. You can assume that the array will have five elements. The methods should have the following signatures.  

bool containsPair(int hand[])

bool containsTwoPair(int hand[])

bool containsThreeOfaKind(int hand[])

bool containsStraight(int hand[])

bool containsFullHouse(int hand[])

bool containsFourOfaKind(int hand[])

You do not need to write a containsHighCard method. 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.

Explanation / Answer

Program for the above question:(go through program and give ur feedback)

#include<iostream>
#include<algorithm>
using namespace std;
void display(int*);
int main()
{
//function declarations  
bool containsPair(int*);
bool containsTwoPair(int *);
bool containsThreeOfaKind(int *);
bool containsStraight(int *);
bool containsFullHouse(int *);
bool containsFourOfaKind(int *);
   int a[5];int i;
// input of 5 card values by user  
   cout<<"enter the card values Dont use face value use only 2-9 ";
   for(i=0;i<5;i++)
   {
   cin>>a[i];
  
    }
  
  
   // checking for condition
   if(containsFourOfaKind(a)==true)
   cout<<"Four of a kind !!!!!";
   else if(containsFullHouse(a)==true)
   cout<<"Full House !!!!";
   else if(containsStraight(a)==true)
   cout<<"Straight !!! ";
   else if(containsThreeOfaKind(a)==true)
   cout<<"Three of a kind!! ";
   else if(containsTwoPair(a)==true)
   cout<<"Two pairs! ";
   else if(containsPair(a)==true)
   cout<<"Pair ";
   else
   cout<<"High Card ";
  
}
// function definations
bool containsPair(int *a)
{
   int numa[5]={0},i,j;
   for(i=0;i<5;i++)
   {
       for(j=0;j<5;j++)
       {
           if(a[i]==a[j])
           numa[i]++;
       }
   }
   //display(numa);
   for(i=0;i<5;i++)
   {
       if(numa[i]==2)
       {
           break;
       }
   }
   if(i==5)
   return false;
   else
   return true;
}

bool containsTwoPair(int *a)
{
   int numa[5]={0},i,j,count=0;
   for(i=0;i<5;i++)
   {
       for(j=0;j<5;j++)
       {
           if(a[i]==a[j])
           numa[i]++;
       }
   }
   //display(numa);
   for(i=0;i<5;i++)
   {
       if(numa[i]==2)
       {
           count++;
       }
   }
   if(count>=2)
   return true;
   else
   return false;
}

bool containsThreeOfaKind(int *a)
{
   int numa[5]={0},i,j;
   for(i=0;i<5;i++)
   {
       for(j=0;j<5;j++)
       {
           if(a[i]==a[j])
           numa[i]++;
       }
   }
   //display(numa);
   for(i=0;i<5;i++)
   {
       if(numa[i]==3)
       {
           break;
       }
   }
   if(i==5)
   return false;
   else
   return true;
}


bool containsFullHouse(int *a)
{
   int numa[5]={0},i,j,count1=0,count2=0;
   for(i=0;i<5;i++)
   {
       for(j=0;j<5;j++)
       {
           if(a[i]==a[j])
           numa[i]++;
       }
   }
   //display(numa);
   for(i=0;i<5;i++)
   {
       if(numa[i]==2||numa[i]==3)
       {
           if(numa[i]==2)
           count1++;
           if(numa[i]==3)
           count2++;
       }
   }
   if(count1>=1&&count2>=1)
   return true;
   else
   return false;
}

bool containsFourOfaKind(int *a)
{
   int numa[5]={0},i,j;
   for(i=0;i<5;i++)
   {
       for(j=0;j<5;j++)
       {
           if(a[i]==a[j])
           numa[i]++;
       }
   }
   //display(numa);
   for(i=0;i<5;i++)
   {
       if(numa[i]==4)
       {
           break;
       }
   }
   if(i==5)
   return false;
   else
   return true;
}

bool containsStraight(int *a)
{
   int i;
   sort(a,a+5);
   for(i=0;i<5;i++)
   {
      
           if(i!=4&&a[i]+1!=a[i+1])
           break;
          
      
   }
   if(i==5)
   return true;
   else
   return false;
  
}

void display(int *a)
{
   for(int i=0;i<5;i++)
   cout<<"a[i]"<<a[i]<<" ";
   cout<<" ";
}

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