Question

In: Computer Science

In C++ please Your class could have the following member functions and member variables. However, it's...

In C++ please

Your class could have the following member functions and member variables. However, it's up to you to design the class however you like. The following is a suggestion, you can add more member variables and functions or remove any as you like, except shuffle() and printDeck(): (Note: operators must be implemented)

bool empty(); //returns true if deck has no cards

int cardIndex; //marks the index of the next card in the deck

Card deck[52];// this is your final deck of cards
const int DECK_SIZE = 52;// this is the size of your deck
void shuffle(); // puts cards in random order
friend ostream& operator<<(ostream& out, const Deck& deck); // prints all the cards to the console
Card dealCard(); // returns the next card in the deck
Card getCardAt(int index);// gets the Card at the given index
Deck(); // this is the constructor

Think about which member functions and member variables should be public and private.

Notice your Deck class has an array of size 52. This is because a classic that has 4 suits each containing 13 rankings.

Card Class

Notice in the Deck class, your deck array is of data type Card. You must define this class as well. A card consists of two entities, a suit and a value. There are four suits, (hearts, diamonds, clubs, and spades), and 13 values (numbers 2-10, A for ace, K for king, Q for queen and J for jack. Your Card class should look something like below, remember this is just a suggestion and you may add or omit to the list of member variables and function as you see suitable (Hint, you may want two string arrays to represent the suits and the values). Again, I will leave it up to you to determine the access for each member variable and member function. (Note: operators must be implemented)

    string suit;
    string value;
    string getSuit();
    string getValue();
    void setSuit(string suit);
    void setValue(string value);
    friend ostream& operator<<(ostream& out, const Card& card);
    Card(string suit, string value);
    Card(int suit, int string);
    Card();

Testing your Deck and Card Classes

To test your Deck and Card classes, write a program that will print out cards in random order).

Your program output should look like the following:

1: Jack of Diamonds
2: Ace of Spades
3: Six of Spades
4: Nine of Diamonds
5: Ten of Spades
6: Four of Spades
7: Four of Clubs
8: Jack of Clubs
9: Three of Spades
10: Seven of Clubs
11: Queen of Diamonds
12: Eight of Clubs
13: Ace of Clubs
14: Eight of Hearts
15: Seven of Hearts
16: Queen of Hearts
17: Three of Clubs
18: Eight of Spades
19: Four of Hearts
20: Eight of Diamonds
21: Queen of Spades
22: Five of Clubs
23: Ten of Clubs
24: Three of Diamonds
25: Queen of Clubs
26: Five of Hearts
27: Jack of Spades
28: Six of Diamonds
29: Five of Diamonds
30: Jack of Hearts
31: Two of Spades
32: Six of Hearts
33: Four of Diamonds
34: Ace of Diamonds
35: Ace of Hearts
36: King of Spades
37: King of Clubs
38: Two of Diamonds
39: Nine of Hearts
40: Seven of Spades
41: Nine of Clubs
42: Five of Spades
43: Two of Clubs
44: Ten of Hearts
45: Three of Hearts
46: Ten of Diamonds
47: Seven of Diamonds
48: Two of Hearts
49: King of Hearts
50: Nine of Spades
51: Six of Clubs
52: King of Diamonds

CardHand Class

Next, create a class called CardHand. Your class should have the following:

  • a vector to store all the cards in a player’s hand.
  • Remember in a card game, a player is usually dealt one card at a time, so make sure your CardHand class has the ability to take in one card at a time.
  • Accessors and Mutators where needed

Just like in the other classes, I will leave it up to you to determine access for member variable and member function.

CardHandScorer Class

Next, create another class, CardHandScorer that is used to analyze a players hand and determine a score for that hand. Because we are going to create a Poker game we will focus on making a scorer for Poker only, though in the future, we will add function for other card games such as Blackjack. The CardHandScorer class should have the following:

  • a static function that takes a CardHand object as an argument. The purpose of this static function is to return the score for the Poker hand. This score will be stored in a PokerScore object that is mention in the next section.

The function should analyze the CardHand and add all possible scores to the PokerScore object in which it will then return this object.

PokerScore Class

Next, create a PokerScore class. In the game of Poker, a player’s hand can have multiple scores. For example, if a player has four-of-a-kind, they also have, three of a kind, two pairs, one pair, or a high card . See the list of the different poker hand scores below. Your PokerScore class should be designed to hold all the possible scores a particular CardHand has. To do this, create an enumerator of Scores that holds all the possible poker scores. Then, create a vector that can hold the data type of your enumerator, Scores. Your CardHandScorer should have the ability to add scores to a PokerScore object. Here is the declaration of the PokerScore class: (Note: operators must be implemented)

    enum Scores{

        ROYAL_FLUSH, //A, K, Q, J, 10, all the same suit.

        STRAIGHT_FLUSH, //five cards of the same suit and consecutive ranking

        FOUR_OF_A_KIND, //four cards of the same ranking

        FULL_HOUSE, //three cards of the same rank along with two cards of the same rank

        FLUSH, //five cards of the same suit

        STRAIGHT, //five cards in consecutive ranking

        THREE_OK_A_KIND, //three cards of the same rank

        TWO_PAIR, //two cards of the same rank along with another two cards of the same rank

        ONE_PAIR, //two cards of the same rank

        HIGH_CARD //highest card in the player’s hand

   };

    vector<Scores> scores;   

    void operator+=(const Scores& score);

    friend bool operator==(const PokerScore& p, Scores score);
    int size();
    Score& operator[](unsigned int index);
    PokerScore();

Here’s an example of usage of the Deck, Card, CardHand, CardHandScorer, and PokerScore classes:

int main() {




    Deck deck;

    CardHand ch;




    //deal five cards to the card hand

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

        ch.addCard(deck.dealCard());




    //analyze card hand and get poker scores

    PokerScore pokerScore = CardHandScorer::scorePokerHand(ch);

   //add a score to pokerScore
   pokerScore += PokerScore::FULL_HOUSE; 

}

Analyzing the Poker Hands

After you have written and thoroughly tested your class, write a program to analyze the probability of each Poker score. Write a function that does the following:

  • Deal five cards to five different card hands.
  • Score one of card hands.
  • Return the scores for that card hand.

After running this function 1000 time, your program should output how many times each poker score was met. Here’s an example of your output:

        ROYAL_FLUSH: 0

        STRAIGHT_FLUSH: 10

        FOUR_OF_A_KIND: 30

        FULL_HOUSE: 47

        FLUSH; 105

        STRAIGHT; 146

        THREE_OK_A_KIND; 234

        TWO_PAIR: 759

        ONE_PAIR:823

        HIGH_CARD: 1000

Solutions

Expert Solution

Working code implemented in C++ and appropriate comments provided for better understanding.

Here I am attaching code for all files:

  • main.cpp
  • BaseCard.cpp
  • BaseCard.h
  • CardHand.cpp
  • CardHand.h
  • CardHandScorer.cpp
  • CardHandScorer.h
  • CardVariables.h
  • Deck.cpp
  • Deck.h
  • PokerScore.cpp
  • PokerScore.h

main.cpp:

#include <iostream>
#include <ctime>
#include "Deck.h"
#include "CardVariables.h"
#include "CardHand.h"
#include "CardHandScorer.h"
using namespace std;
int main() {
srand(time(nullptr));
PokerScore total;
for(int i=0;i<1000;i++) {
Deck deck;
deck.shuffle();

CardHand player1,player2,player3,player4,player5;
for (int j = 0; j < 5; j++) {
player1.addCard(deck.dealCard());
player2.addCard(deck.dealCard());
player3.addCard(deck.dealCard());
player4.addCard(deck.dealCard());
player5.addCard(deck.dealCard());

}
total+= CardHandScorer::scorePokerHand(player1);
}
std::cout<<total;

return 0;
}

BaseCard.cpp:

#include "BaseCard.h"
#include <string>
#include <iostream>

void BaseCard::setRank(cv::ranks rank) {
BaseCard::rank = rank;
}


void BaseCard::setSuit(cv::suits suit) {
BaseCard::suit = suit;
}

std::string BaseCard::convertRankToString(cv::ranks rank) const {
switch(rank){
case cv::ACE:
return "A" ;
case cv::TWO:
return "2"; ;
case cv::THREE:
return "3";
case cv::FOUR:
return "4";
case cv::FIVE:
return "5";
case cv::SIX:
return "6";
case cv::SEVEN:
return "7";
case cv::EIGHT:
return "8";
case cv::NINE:
return "9";
case cv::TEN:
return "10";
case cv::JACK:
return "J";
case cv::QUEEN:
return "Q";
case cv::King:
return "K";
default:
return "A";
}
}
std::string BaseCard::convertSuitToString(cv::suits suit) const {
switch(suit){
case cv::SPADES:
return "Spades";
case cv::CLUBS:
return "Clubs";
case cv::DIAMONDS:
return "Diamonds";
case cv::HEARTS:
return "Hearts";

}
}


BaseCard::BaseCard(cv::ranks rank, cv::suits suit) : rank(rank), suit(suit) {

}

BaseCard::BaseCard() {
rank= cv::ACE;
suit= cv::HEARTS;

}

int BaseCard::getRankValue() const {
switch(rank){
case cv::ACE:
return 1;
case cv::TWO:
return 2;
case cv::THREE:
return 3;
case cv::FOUR:
return 4;
case cv::FIVE:
return 5;
case cv::SIX:
return 6;
case cv::SEVEN:
return 7;
case cv::EIGHT:
return 8;
case cv::NINE:
return 9;
case cv::TEN:
return 10;
case cv::JACK:
return 11;
case cv::QUEEN:
return 12;
case cv::King:
return 13;
}
  
}

int BaseCard::getSuitValue() {
return suit+1;
}

cv::suits BaseCard::getSuit() const {
return suit;
}

cv::ranks BaseCard::getRank() const {
return rank;
}

std::ostream &operator<<(std::ostream &out, const BaseCard &card) {
std::cout << card.convertRankToString(card.getRank()) <<" of "<< card.convertSuitToString(card.getSuit());
return out;
}

int operator+(const BaseCard &card1,const BaseCard &card2) {
int sum =card1.getRankValue()+card2.getRankValue();
return sum;
}

BaseCard.h:

#ifndef PLAYINGCARD_BASECARD_H
#define PLAYINGCARD_BASECARD_H

#include "CardVariables.h"
#include <string>

class BaseCard {
protected:
cv::suits suit;
cv::ranks rank;
public:
cv::suits getSuit() const;

cv::ranks getRank() const;

BaseCard(cv::ranks rank, cv::suits suit);
BaseCard();
void setRank(cv::ranks rank);
void setSuit(cv::suits suit);

int getRankValue() const;
int getSuitValue();

std::string convertRankToString(cv::ranks rank) const;
std::string convertSuitToString(cv::suits suit) const;
friend std::ostream &operator<<(std::ostream &out,const BaseCard &card);
friend int operator+(const BaseCard&card1,const BaseCard &card2);

};

#endif //PLAYINGCARD_BASECARD_H

CardHand.cpp:

#include "CardHand.h"

void CardHand::addCard(BaseCard card) {
//adds a space to the vector and inserts the top card;
hand.push_back (card);
}

CardHand::CardHand()= default;
std::ostream &operator<<(std::ostream &out, const CardHand &hand) {
for(int i=0;i< hand.getSize();i++){
std::cout<< hand.hand[i] <<std::endl;
}
return out;
}

int CardHand::getSize() const{
return hand.size();
}

int CardHand::getCardValueAt(int index) {
return hand[index].getRankValue();
}

BaseCard& CardHand::getCardAt(int index) {
return hand[index];
}

CardHand.h:

#ifndef POKERANALYSIS_CARDHAND_H
#define POKERANALYSIS_CARDHAND_H

#include "Deck.h"

#include <iostream>
#include <vector>

class CardHand {
private:
std::vector<BaseCard> hand;
public:
CardHand();
void addCard(BaseCard card);
friend std::ostream& operator<<(std::ostream& out, const CardHand& hand);
int getSize() const;
int getCardValueAt(int index);
BaseCard& getCardAt(int index);


};
#endif //POKERANALYSIS_CARDHAND_H

CardHandScorer.cpp:

static int ROYAL_FLUSH=0; //A, K, Q, J, 10, all the same suit.
static int STRAIGHT_FLUSH=0; //five cards of the same suit and consecutive ranking
static int FOUR_OF_A_KIND=0; //four cards of the same ranking
static int FULL_HOUSE=0;
static int FLUSH =0;
static int STRAIGHT=0;
static int THREE_OF_A_KIND=0;
static int TWO_PAIR=0;
static int ONE_PAIR=0;
static int HIGH_CARD =0;

#include "CardHandScorer.h"

void CardHandScorer::swap(BaseCard& card1, BaseCard& card2) {
BaseCard temp;
temp=card1;
card1=card2;
card2 =temp;
}

PokerScore CardHandScorer::scorePokerHand(CardHand hand) {
PokerScore score;
//Sort the Cards first
CardHandScorer::sort(hand);
//now we do the scoring.
if(PokerScore::hasRoyalFlush(hand))
score.addScore(PokerScore::ROYAL_FLUSH);
if(PokerScore::hasStraightFlush(hand))
score.addScore(PokerScore::STRAIGHT_FLUSH);
if(PokerScore::hasFourOfAKind(hand))
score.addScore(PokerScore::FOUR_OF_A_KIND);
if(PokerScore::hasFullHouse(hand))
score.addScore(PokerScore::FULL_HOUSE);
if(PokerScore::hasFlush(hand))
score.addScore(PokerScore::FLUSH);
if(PokerScore::hasStraight(hand))
score.addScore(PokerScore::STRAIGHT);
if(PokerScore::hasThreeOfAKind(hand))
score.addScore(PokerScore::THREE_OF_A_KIND);
if(PokerScore::hasTwoPair(hand))
score.addScore(PokerScore::TWO_PAIR);
if(PokerScore::hasOnePair(hand))
score.addScore(PokerScore::ONE_PAIR);
if(PokerScore::hasHighCard(hand))
score.addScore(PokerScore::HIGH_CARD);

return score;
}

void CardHandScorer::sort(CardHand& hand) {
bool swapped;

for(int i=0;i<hand.getSize();i++){
swapped=false;
for(int j=0;j<hand.getSize()-1;j++) {
if (hand.getCardValueAt(j) > hand.getCardValueAt(j + 1)) {
swap(hand.getCardAt(j), hand.getCardAt(j + 1));
swapped=true;
}
}
if(!swapped)
break;
}

}

void CardHandScorer::displayScores(const PokerScore &score) {
for(int i=0;i<score.size();i++)
switch(score.getScoreAt(i)) {
case PokerScore::ROYAL_FLUSH:
ROYAL_FLUSH++;
break;
case PokerScore::STRAIGHT_FLUSH:
STRAIGHT_FLUSH++;
break;
case PokerScore::FOUR_OF_A_KIND:
FOUR_OF_A_KIND++;
break;
case PokerScore::FULL_HOUSE:
FULL_HOUSE++;
break;
case PokerScore::FLUSH:
FLUSH++;
break;
case PokerScore::STRAIGHT:
STRAIGHT++;
break;
case PokerScore::THREE_OF_A_KIND:
THREE_OF_A_KIND++;
break;
case PokerScore::TWO_PAIR:
TWO_PAIR++;
break;
case PokerScore::ONE_PAIR:
ONE_PAIR++;
break;
case PokerScore::HIGH_CARD:
HIGH_CARD++;
break;
};
std::cout<<"Royal Flush: " << ROYAL_FLUSH <<std::endl
<< "Straight Flush: " << STRAIGHT_FLUSH <<std::endl
<< "Four of a Kind: "<< FOUR_OF_A_KIND <<std::endl
<< "Full House: "<< FULL_HOUSE <<std::endl
<< "Flush: " << FLUSH <<std::endl
<< "Straight: "<< STRAIGHT <<std::endl
<< "Three of a Kind: "<<THREE_OF_A_KIND <<std::endl
<< "Two Pair: "<< TWO_PAIR <<std::endl
<< "One Pair: "<< ONE_PAIR <<std::endl
<< "High Card: "<< HIGH_CARD <<std::endl;
// YAY!
}

CardHandScorer.h:

#ifndef POKERANALYSIS_CARDHANDSCORER_H
#define POKERANALYSIS_CARDHANDSCORER_H

#include "PokerScore.h"

class CardHandScorer {
public:
static void sort(CardHand& hand);
static void swap(BaseCard& card1, BaseCard& card2);
static PokerScore scorePokerHand(CardHand hand);
static void displayScores(const PokerScore& score);
};


#endif //POKERANALYSIS_CARDHANDSCORER_H

CardVariables.h:

#ifndef PLAYINGCARD_CARDVARIABLES_H
#define PLAYINGCARD_CARDVARIABLES_H
namespace cv{
enum suits{
CLUBS,
SPADES,
HEARTS,
DIAMONDS
};
enum ranks{
ACE,
TWO,
THREE,
FOUR,
FIVE,
SIX,
SEVEN,
EIGHT,
NINE,
TEN,
JACK,
QUEEN,
King

};
}

#endif //PLAYINGCARD_CARDVARIABLES_H

Deck.cpp:

#include "Deck.h"
#include <iostream>
#include <ctime>

bool Deck::empty() {
return (cardIndex>DECK_SIZE);
}

Deck::Deck() {

// Fill by suits (i) then fill in numbers(j)
for(int i=0;i<4;i++){
for(int j=0;j<13;j++) {
deck[j+(13*i)].setSuit(static_cast<cv::suits>(i));
deck[j+(13*i)].setRank(static_cast<cv::ranks>(j));
}

}
cardIndex=0;
}

BaseCard Deck::getCardAt(int index) {
return deck[index];
}

std::ostream &operator<<(std::ostream &out, const Deck &deck) {
for(int i=0;i< deck.getSize();i++){
std::cout<< deck.deck[i] <<std::endl;
}
return out;
}

BaseCard Deck::dealCard() {
// Copies the value of cardIndex first so that it doesnt get changed when you add 1 to it.
int index = cardIndex;
cardIndex++;
return deck[index];

}

void Deck::shuffle() {
for(int i=0;i<DECK_SIZE;i++){
// selecting an index from 0- index
int j = rand()% (i+1);
swap(deck[i],deck[j]);
}
//Shuffle it twice because I am cool like that
for(int i=0;i<DECK_SIZE;i++){
// selecting an index from 0- index
int j = rand()% (i+1);
swap(deck[i],deck[j]);
}
}

void Deck::swap(BaseCard &card1, BaseCard &card2) {
BaseCard temp;
temp=card1;
card1=card2;
card2 =temp;
}

int Deck::getSize() const {
return DECK_SIZE;
}


Deck.h:

#ifndef POKERANALYSIS_DECK_H
#define POKERANALYSIS_DECK_H

#include "BaseCard.h"
#include "CardVariables.h"
class Deck {
private:
int cardIndex; //marks the index of the next card in the deck
BaseCard deck[52];// this is your final deck of cards
const int DECK_SIZE = 52;// this is the size of your deck
public:
bool empty(); //returns true if deck has no cards
void shuffle(); // puts cards in random order
friend std::ostream& operator<<(std::ostream& out, const Deck& deck); // prints all the cards to the console
BaseCard dealCard(); // returns the next card in the deck
BaseCard getCardAt(int index);// gets the Card at the given index
Deck(); // this is the constructor
void swap(BaseCard& card1,BaseCard& card2);
int getSize() const;
};


#endif //POKERANALYSIS_DECK_H

PokerScore.cpp:

#include "PokerScore.h"

PokerScore::PokerScore() = default;

PokerScore::Scores &PokerScore::operator[](unsigned int index) {
return scores[index];
}

int PokerScore::size() const{
return scores.size();
}

bool PokerScore::hasRoyalFlush(CardHand sortedHand) {
//check if all the cards are the same suit first;
for(int i=0;i<sortedHand.getSize()-1;i++) {
if (sortedHand.getCardAt(i).getSuit()!=sortedHand.getCardAt(i+1).getSuit())
return false;
}
// Then check if it contains all the cards required;
if(sortedHand.getCardAt(0).getRank()!= cv::ACE)
return false;

for(int i=1;i<sortedHand.getSize();i++) {
if (sortedHand.getCardAt(i).getRankValue() != i+9)
return false;
}
return true;
}

bool PokerScore::hasStraightFlush(const CardHand& sortedHand) {
//check if all the cards are the same suit first;
return hasStraight(sortedHand) && hasFlush(sortedHand);
}

bool PokerScore::hasFourOfAKind(CardHand sortedHand) {
int tracker = 0;
for (int i = 0; i < 2; i++)
if (sortedHand.getCardAt(i).getRankValue() != sortedHand.getCardAt(i + 3).getRankValue())
tracker++;

return (tracker == 1);
}
bool PokerScore::hasFullHouse(CardHand sortedHand) {
// has to check either to see if first 2 are pair then if rest 3 are 3 of kind.
//case 1 : Pairs then set of 3
// Checks to see if its a pair and not a 3 of a kind
if(sortedHand.getCardAt(0).getRankValue()==sortedHand.getCardAt(1).getRankValue()&&
sortedHand.getCardAt(0).getRankValue()!=sortedHand.getCardAt(2).getRankValue()){
// now check for 3 of a kind.
if(hasThreeOfAKind(sortedHand))
return true;
}
//case 2: 3 of a kind then a pair
// checks for 3 of a kind first
if(sortedHand.getCardAt(0).getRankValue()==sortedHand.getCardAt(1).getRankValue()&&
sortedHand.getCardAt(0).getRankValue()==sortedHand.getCardAt(2).getRankValue()){
// now check for pair
if(sortedHand.getCardAt(3).getRankValue()==sortedHand.getCardAt(4).getRankValue())
return true;
}
return false;
}


bool PokerScore::hasFlush(CardHand sortedHand) {
for(int i=0;i<sortedHand.getSize()-1;i++) {
if (sortedHand.getCardAt(i).getSuit()!=sortedHand.getCardAt(i+1).getSuit())
return false;
}
return true;
}

bool PokerScore::hasStraight(CardHand sortedHand) {
for(int i=0;i<sortedHand.getSize()-1;i++) {
if (sortedHand.getCardAt(i).getRankValue()!=sortedHand.getCardAt(i+1).getRankValue()-1)
return false;
}
return true;
}

bool PokerScore::hasThreeOfAKind(CardHand sortedHand) {
// save some time
if(!hasOnePair(sortedHand))
return false;
// check first set
if(sortedHand.getCardAt(0).getRankValue()==sortedHand.getCardAt(1).getRankValue()&&
sortedHand.getCardAt(0).getRankValue()==sortedHand.getCardAt(2).getRankValue())
return true;
// check set set
if(sortedHand.getCardAt(1).getRankValue()==sortedHand.getCardAt(2).getRankValue()&&
sortedHand.getCardAt(1).getRankValue()==sortedHand.getCardAt(3).getRankValue())
return true;
// check third set
if(sortedHand.getCardAt(2).getRankValue()==sortedHand.getCardAt(3).getRankValue()&&
sortedHand.getCardAt(2).getRankValue()==sortedHand.getCardAt(3).getRankValue())
return true;


return false;
}

bool PokerScore::hasTwoPair(CardHand sortedHand) {
int tracker=0;
if(hasThreeOfAKind(sortedHand))
return false;
for(int i=0;i<sortedHand.getSize()-1;i++){
if(sortedHand.getCardAt(i).getRankValue()==sortedHand.getCardAt(i+1).getRankValue()) {
tracker++;
}
}

return (tracker==2);
}
bool PokerScore::hasOnePair(CardHand sortedHand) {
for(int i=0;i<sortedHand.getSize()-1;i++){
if(sortedHand.getCardAt(i).getRankValue()==sortedHand.getCardAt(i+1).getRankValue())
return true;
}
return false;
}
bool PokerScore::hasHighCard(const CardHand& sortedHand) {
if(sortedHand.getSize()>0)
return true;
}

void PokerScore::addScore(PokerScore::Scores score) {
scores.push_back(score);
}

void PokerScore::operator+=(const PokerScore::Scores &score) {
this->addScore(score);
}

bool operator==(const PokerScore &p, PokerScore::Scores score) {
// I think this is how this is supposed to work?
for(int i=0;i<p.size();i++){
if(p.getScoreAt(i)==score)
return true;


}
}

PokerScore::Scores PokerScore::getScoreAt(int index) const{
return scores[index];
}

void PokerScore::operator+=(const PokerScore &score) {
for(int i=0;i<score.size();i++){
this->addScore(score.getScoreAt(i));
}

}

std::ostream &operator<<(std::ostream &out,const PokerScore &score) {

int ROYAL_FLUSH=0,STRAIGHT_FLUSH=0,FOUR_OF_A_KIND=0,FULL_HOUSE=0,FLUSH=0,
STRAIGHT=0,THREE_OF_A_KIND=0,TWO_PAIR=0,ONE_PAIR=0,HIGH_CARD=0;
for(int i=0;i<score.size();i++)
switch(score.getScoreAt(i)) {
case PokerScore::ROYAL_FLUSH:
ROYAL_FLUSH++;
break;
case PokerScore::STRAIGHT_FLUSH:
STRAIGHT_FLUSH++;
break;
case PokerScore::FOUR_OF_A_KIND:
FOUR_OF_A_KIND++;
break;
case PokerScore::FULL_HOUSE:
FULL_HOUSE++;
break;
case PokerScore::FLUSH:
FLUSH++;
break;
case PokerScore::STRAIGHT:
STRAIGHT++;
break;
case PokerScore::THREE_OF_A_KIND:
THREE_OF_A_KIND++;
break;
case PokerScore::TWO_PAIR:
TWO_PAIR++;
break;
case PokerScore::ONE_PAIR:
ONE_PAIR++;
break;
case PokerScore::HIGH_CARD:
HIGH_CARD++;
break;
};
out <<"Royal Flush: " << ROYAL_FLUSH <<std::endl
<< "Straight Flush: " << STRAIGHT_FLUSH <<std::endl
<< "Four of a Kind: "<< FOUR_OF_A_KIND <<std::endl
<< "Full House: "<< FULL_HOUSE <<std::endl
<< "Flush: " << FLUSH <<std::endl
<< "Straight: "<< STRAIGHT <<std::endl
<< "Three of a Kind: "<<THREE_OF_A_KIND <<std::endl
<< "Two Pair: "<< TWO_PAIR <<std::endl
<< "One Pair: "<< ONE_PAIR <<std::endl
<< "High Card: "<< HIGH_CARD <<std::endl;
// YAY!

return out;
}


PokerScore.h:

#ifndef POKERANALYSIS_POKERSCORE_H
#define POKERANALYSIS_POKERSCORE_H

#include "CardHand.h"
class PokerScore {


public:
enum Scores{

ROYAL_FLUSH, //A, K, Q, J, 10, all the same suit.

STRAIGHT_FLUSH, //five cards of the same suit and consecutive ranking

FOUR_OF_A_KIND, //four cards of the same ranking

FULL_HOUSE, //three cards of the same rank along with two cards of the same rank

FLUSH, //five cards of the same suit

STRAIGHT, //five cards in consecutive ranking

THREE_OF_A_KIND, //three cards of the same rank

TWO_PAIR, //two cards of the same rank along with another two cards of the same rank

ONE_PAIR, //two cards of the same rank

HIGH_CARD //highest card in the player’s sortedHand

};

void operator+=(const Scores& score);
void operator+=(const PokerScore& score);
friend bool operator==(const PokerScore& p, Scores score);
friend std::ostream& operator<<(std::ostream& out,const PokerScore& score);
int size() const;
Scores& operator[](unsigned int index);
PokerScore();
static bool hasRoyalFlush(CardHand sortedHand);
static bool hasStraightFlush(const CardHand& sortedHand);
static bool hasFourOfAKind(CardHand sortedHand);
static bool hasFullHouse(CardHand sortedHand);
static bool hasFlush(CardHand sortedHand);
static bool hasStraight(CardHand sortedHand);
static bool hasThreeOfAKind(CardHand sortedHand);
static bool hasTwoPair(CardHand sortedHand);
static bool hasOnePair(CardHand sortedHand);
static bool hasHighCard(const CardHand& sortedHand);

void addScore(Scores score);
Scores getScoreAt(int index) const;
private:
std::vector<Scores> scores;

};


#endif //POKERANALYSIS_POKERSCORE_H

Sample Output Screenshots:


Related Solutions

PLEASE WRITE THIS IN C++ Write a ComplexNumber class that has two member variables realNum and...
PLEASE WRITE THIS IN C++ Write a ComplexNumber class that has two member variables realNum and complexNum of type double. Your class shall have following member functions Complex(); Complex(double, double); Complex add(Complex num1, Complex num2); Complex subtract(Complex num1, Complex num2); string printComplexNumber(); Write a driver program to test your code. Please make sure your code is separated into Complex.h Containing definition of the class Complex.cpp Containing the implementation ComplexTestProgram.cpp Containing main program Use the following directive in class definition to...
C++ PersonData and CustomerData classes Design a class named PersonData with the following member variables: lastName...
C++ PersonData and CustomerData classes Design a class named PersonData with the following member variables: lastName firstName address city state zip phone Write the appropriate accessor and mutator functions for these member variables. Next, design a class named CustomerData, which is derived from the PersonData class. The CustomerData class should have the following member variables: customerNumber mailingList The customerNumber variable will be used to hold a unique integer for each customer. The mailingList variable should be a bool. It will...
directions: use c++ Create a  ContactInfo class that contains the following member variables: name age phoneNumber The...
directions: use c++ Create a  ContactInfo class that contains the following member variables: name age phoneNumber The ContactInfo class should have a default constructor that sets name = "", phoneNumber = "", and age = 0. The ContactInfo class should have a constructor that accepts the name and phone number as parameters and sets name = <value of parameter name>, aAge = 0, and phoneNumber = <value of parameter phone number>. The ContactInfo class should have accessor and mutator functions for...
Give a C++ class declaration called SavingsAccount with the following information: Operations (Member Functions) 1. Open...
Give a C++ class declaration called SavingsAccount with the following information: Operations (Member Functions) 1. Open account (with an initial deposit). This is called to put initial values in dollars and cents. 2. Make a deposit. A function that will add value to dollars and cents 3. Make a withdrawal. A function that will subtract values from dollars and cents. 4. Show current balance. A function that will print dollars and cents. Data (Member Data) 1. dollars 2. cents Operations...
Circle Class Write a Circle class that has the following member variables: • radius: a double...
Circle Class Write a Circle class that has the following member variables: • radius: a double • pi: a double initialized with the value 3.14159 The class should have the following member functions: • Default Constructor. A default constructor that sets radius to 0.0. • Constructor. Accepts the radius of the circle as an argument. • setRadius. A mutator function for the radius variable. • getRadius. An accessor function for the radius variable. • getArea. Returns the area of the...
Circle Class Write a Circle class that has the following member variables: • radius: a double...
Circle Class Write a Circle class that has the following member variables: • radius: a double • pi: a double initialized with the value 3.14159 The class should have the following member functions: • Default Constructor. A default constructor that sets radius to 0.0. • Constructor. Accepts the radius of the circle as an argument. • setRadius. A mutator function for the radius variable. • getRadius. An accessor function for the radius variable. • getArea. Returns the area of the...
Car Class Write a class named Car that has the following member variables: • year. An...
Car Class Write a class named Car that has the following member variables: • year. An int that holds the car’s model year. • make. A string object that holds the make of the car. • speed. An int that holds the car’s current speed. In addition, the class should have the following member functions. • Constructor. The constructor should accept the car’s year and make as arguments and assign these values to the object’s year and make member variables....
C++ make a rational class that includes these members for rational -private member variables to hold...
C++ make a rational class that includes these members for rational -private member variables to hold the numerator and denominator values -a default constructor -an overloaded constructor that accepts 2 values for an initial fraction -member fractions add(), sub(), mul(), div(), less(), eq(), and neq() (less should not return true if the object is less than argument) -a member function that accepts an argument of type of ostream that writes the fraction to that open output stream do not let...
Java Write a Payroll class as demonstrated in the following UML diagram. Member variables of the...
Java Write a Payroll class as demonstrated in the following UML diagram. Member variables of the class are: NUM_EMPLOYEES: a constant integer variable to hold the number of employees. employeeId. An array of integers to hold employee identification numbers. hours. An array of integers to hold the number of hours worked by each employee payRate. An array of doubles to hold each employee’s hourly pay rate wages. An array of seven doubles to hold each employee’s gross wages The class...
Write a Circle class that has the following member variables: radius as a double PI as...
Write a Circle class that has the following member variables: radius as a double PI as a double initialized with 3.14159 The class should have the following member functions: Default constructor Sets the radius as 0.0 and pi as 3.14159 Constructor Accepts the radius of the circles as an argument setRadius A mutator getRadius An accessor getArea Returns the area of the circle getDiameter Returns the diameter of the circle getCircumference Returns the circumference of the circle Write a program...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT