Question
C++ Programming I need some help with creating a poker hand class. Create a PokerHand class. It should have a way to represent a 5
C++ Programming
I need some help with creating a poker hand class.
Create a PokerHand class.
It should have a way to represent a 5 card poker hand as a private data member.
There should be a constructor method that randomly creates a 5 card poker hand from a DeckOfCards.
It should also have a method to set the poker hand to a particular 5 card hand that the programmer specifies.
It should have methods that return booleans and take in 0 arguments to accomplish each of the following:
Determine whether the hand contains a pair.
Determine whether the hand contains two pairs.
Determine whether the hand contains three of a kind (e.g., three jacks).
Determine whether the hand contains four of a kind (e.g., four aces).
Determine whether the hand contains a flush (i.e., all five cards of the same suit).
Determine whether the hand contains a straight (i.e., five cards of consecutive face values).
Add to the driver program the following.
Create a randomly generated PokerHand using your constructor and output the results of your PokerHand methods that determine what type of hand it has.
You should also create other PokerHands and set them to have a pair, two pair, three of a kind, four of a kind a flush and a straight respectively. Call each of the hand determination methods you wrote on each hand and output the results to standard output to show that the methods are working correctly.
Use const where appropriate. I/O should be via the console
Card.h, Card.cpp, DeckOfCards.h, DeckOfCards.cpp, PokerHand.h, PokerHand.cpp and pokerdriver.cpp that has your main.
My program so far.
// Card.cpp
#include
using namespace std;
string Card::suits[4] = {"Diamonds","Clubs","Hearts","Spades"}; string Card::faces[13] = {"Ace","Two","Three","Four","Five","Six","Seven","Eight","Nine", "Ten","Jack","Queen","King"};
Card::Card(int type,int num) { suit = suits[type]; face = faces[num]; }
void Card::toString() { string printout = face + " of " + suit; cout << printout << endl; }
string Card::getFace() { return face; }
string Card::getSuit() { return suit; }
-----------------------------------------------------------
// Card.h
#ifndef CARD_H #define CARD_H
#include
class Card { private: string face; string suit; public: static string faces[13]; static string suits[4]; string getFace(); string getSuit(); Card(int, int); void toString(); };
#endif
-------------------------------------------------------------------------
//DeckOfCards.h
#ifndef DECKOFCARD_H #define DECKOFCARD_H #include
class DeckOfCards { private: vector
#endif
--------------------------------------------------------------------
//DeckOfCards.cpp
#include
DeckOfCards::DeckOfCards() { currentCard = 0; for( int i=0; i<4; i++){ for(int j=0; j<13; j++){ Card c = Card(i,j); deck.push_back(c); } }
} void DeckOfCards::swap(Card &first, Card &second) { Card temp = first ; first = second; second = temp; } void DeckOfCards::shuffle(){ time_t t; srand(time(&t)); for(int i=0; i<52; i++) { int s = rand()%52; swap (deck.at(i),deck.at(s)); } }
Card DeckOfCards::dealCard() { currentCard++; shuffle(); if (moreCards()) { return deck[currentCard - 1]; } else { cout << "The deck is empty " << endl; } }
bool DeckOfCards::moreCards() {
if (currentCard < 52) { return true; } else { return false; }
}
-----------------------------------------------------------------------------
// main.cpp
#include
using namespace std;
int main(int argc, char *argv[]) { DeckOfCards d = DeckOfCards(); vector
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started