S12 Five Crowns – Part 2 This week you will continue your work on the Five Crown
ID: 3813372 • Letter: S
Question
S12 Five Crowns – Part 2
This week you will continue your work on the Five Crowns program.
1. You will create a class Deck that consists of the following:
a. The vector of 116 cards from last week’s program.
b. a method to deal a card from the deck
2. Create overloaded operators:
a. bool operator == that overloads the == operator to check if two cards are equal.
b. bool operator < that overload the < operator and checks to see if the face value of one card is less than the face value of another.
3. Create a Hand for each player that consists of nine cards from last week’s program.
Program main that will do the following:
• Create the deck.
• Shuffle the deck.
• Print the deck.
• Prompt the user for the number of players, and accept a value from 2 to 7 (reject any other values).
• Deal hands of nine cards to each player.
• Print the hands.
• Evaluate each hand. Determine if any cards are equal to each other (i.e. ‘pairs’) and print the result.
Adjust previous program below in c++ with above instructions
card.h
#include <iostream>
#include <string>
using namespace std;
enum Faces {Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King, Joker};
enum Suits {Clubs, Diamonds, Hearts, Spades, Stars, NotAvailable};
class Card {
public:
Faces face;
Suits suit;
Card(Faces face, Suits suit);
string toString();
};
card.cpp
#include "cards.h"
#include <iostream>
#include <string>
using namespace std;
string getSuit(Suits s )
{
switch( s)
{
case Clubs:
return "Clubs";
case Diamonds:
return "Diamonds";
case Hearts:
return "Hearts";
case Spades:
return "Spades";
case Stars:
return "Stars";
default:
return "Not recognized..";
}
}
string getFace(Faces f) {
switch( f ) {
case Three:
return "Three";
case Four:
return "Four";
case Five:
return "Five";
case Six:
return "Six";
case Seven:
return "Seven";
case Eight:
return "Eight";
case Nine:
return "Nine";
case Ten:
return "Ten";
case Jack:
return "Jack";
case Queen:
return "Queen";
case King:
return "King";
default:
return "Not recognized..";
}
}
Card::Card(Faces f, Suits s) {
this->face = f;
this->suit = s;
}
string Card::toString() {
if (this->face == Joker)
return "Joker";
return getFace(face) + " of " + getSuit(suit);
}
Main.cpp
#include "cards.h"
#include <iostream>
#include <vector>
#include <string>
#include <random>
using namespace std;
void shuffleDeck(vector<Card> *carddeck) {
mt19937 range;
range.seed(random_device()());
uniform_int_distribution<std::mt19937::result_type> d(0,115);
for (int i = 0; i < carddeck->size(); i++) {
int rndIndex = d(range);
Card rndCard = carddeck->at(rndIndex);
(*carddeck)[rndIndex] = (*carddeck)[i];
(*carddeck)[i] = rndCard;
}
}
int main() {
vector<Card> carddeck;
for (int s = Clubs; s <= Stars; s++) {
for (int f = Three; f <= King; f++) {
Card card = Card(static_cast<Faces>(f), static_cast<Suits>(s));
carddeck.push_back(card);
carddeck.push_back(card);
}
}
for (int i = 0; i < 6; i++) {
Card card = Card(Joker, NotAvailable);
carddeck.push_back(card);
}
for (int i = 0; i < carddeck.size(); i++) {
cout << carddeck[i].toString() << endl;
}
shuffleDeck(&carddeck);
cout << "-------------SHUFFLED DECK-------------" << endl;
for (int i = 0; i < carddeck.size(); i++) {
cout << carddeck[i].toString() << endl;
}
system("pause");
}
OO Verizon LT 49%Explanation / Answer
#include <iostream>
using namespace std;
class Card
int getvalue()
come back value;
}
string getsuit()
come back suit;
}
};
int main()
}
}
for(j = 0; j < 52; j++)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.