Question: This week you will continue your work on the Five Crowns program. 1. You will create an object Deck that consists of the following: a.

This week you will continue your work on the Five Crowns program. 1. You will create an object Deck that consists of the following: a. The vector of 116 cards from last weeks program. b. bool operator == that overloads the == operator to check if two cards are equal. c. bool operator

PROGRAM

#include #include #include #include #include #include #include

using namespace std;

class Card { public: int face; int suit;

Card(int face, int suit); Card (); int getValue(int face); string toString();

};

const string faceNames[12] = {"Three","Four","Five","Six","Seven","Eight","Nine","Ten","Jack","Queen","King","Joker"}; const string suitNames[6] = {"Clubs", "Diamonds", "Hearts", "Spades", "Stars"," "};

// toString returns "joker" or "face of suit" string Card::toString() { if (face == 11) { return "Joker"; } else return (faceNames[face] + " of " + suitNames[suit]); }

// constructor Card::Card(int face, int suit) { this-> face = face; this-> suit = suit;

}

// function to print deck

void printDeck (vector &fullDeck) { int i; for (i=0; i

} }

// function to shuffle deck

void shuffleDeck(vector &fullDeck) {

mt19937 range;

range.seed(random_device()());

uniform_int_distribution d(0, 115);

for (int i = 0; i < fullDeck.size(); i++) {

int rndIndex = d(range);

Card rndCard = fullDeck.at(rndIndex);

(fullDeck)[rndIndex] = (fullDeck)[i]; (fullDeck)[i] = rndCard;

}

}

// function takes integer assigned to each card face and returns point values

int getValue(int x) { int value; if(x == 11) { value = 20; } else { value = (x + 3); } return value; }

int main() {

srand(time(NULL));

int i; int j;

// vector to store deck vectorfullDeck;

// add all cards except jokers to vector twice for(i=0; i<11; i++) { for(j=0; j<5; j++) { Card newCard = Card(i,j); fullDeck.push_back(newCard); fullDeck.push_back(newCard);

} }

// add 6 jokers to vector for (i=0; i<6; i++) { Card newCard = Card(11,5); fullDeck.push_back(newCard);

}

// print deck in order printDeck(fullDeck);

// shuffle deck shuffleDeck(fullDeck);

// print shuffled deck printDeck(fullDeck);

return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!