Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts Of Database Management

Authors: Joy L. Starks, Philip J. Pratt, Mary Z. Last

9th Edition

1337093424, 978-1337093422

More Books

Students also viewed these Databases questions

Question

What are Measures in OLAP Cubes?

Answered: 1 week ago

Question

How do OLAP Databases provide for Drilling Down into data?

Answered: 1 week ago

Question

How are OLAP Cubes different from Production Relational Databases?

Answered: 1 week ago