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 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 } } // function to shuffle deck void shuffleDeck(vector mt19937 range; range.seed(random_device()()); uniform_int_distribution 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 vector // 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
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