Question: INSTRUCTION: please read the instruction before doing the code. 1. Don't send me same code back. 2. The code below works fine, the only error
INSTRUCTION: please read the instruction before doing the code.
1. Don't send me same code back.
2. The code below works fine, the only error is that the cards are not shuffeling upon printing, and question 3 is not working.
3. I included the quetion below for reference purpose.
4. if possible include question 3, Ask the user for his choice.
Thank you.

using namespace std;
#include
#include
#include
#include
enum cards{Spades, Hearts, Diamonds, Clubs};
class Card{
string suits[4] = {"Spades","Hearts","Diamonds","Clubs"};
string description;
public:
int suit, rank, card;
Card(){}
Card(int c){
setCard(c);
}
void setCard(int c){
card = c;
suit = c/13;
rank = c%13;
switch(rank){
case 0:
description = "Ace of " + suits[suit];
break;
case 10:
description = "Jack of " + suits[suit];
break;
case 11:
description = "Queen of " + suits[suit];
break;
case 12:
description = "King of " + suits[suit];
break;
default:
description = "" + std::to_string(rank + 1);
description += " of " + suits[suit];
break;
}
}
bool operator
if(suit == c.suit){
if(rank == 0)
return false;
else if(c.rank == 0)
return true;
else
return rank
}
else
return suit
}
string getDescription(){
return description;
}
int getCard(){
return card;
}
};
class Deck{
Card cards[52];
Card * deals[4][13];
public:
Deck(){}
void initialize(){
for(int i=0;i
cards[i].setCard(i);
}
void display(){
for(int j=1;j
printf("%-25s", ("HAND "+ std::to_string(j)).c_str());
cout
for(int j=1;j
printf("%-25s", "------------------");
cout
for(int j=0;j
printf("%-25s", deals[0][j]->getDescription().c_str());
//printf("%-25d", deals[0][j]->suit);
printf("%-25s", deals[1][j]->getDescription().c_str());
printf("%-25s", deals[2][j]->getDescription().c_str());
printf("%-25s", deals[3][j]->getDescription().c_str());
cout
}
}
void deal(){
for(int i=0;i
for(int j=0;j
deals[i][j] = &cards[(13 * i) + j];
}
void shuffle(){
int random;
Card temp;
std::mt19937 rng;
rng.seed(std::random_device()());
std::uniform_int_distribution<:mt19937::result_type> dist6(1,20);
for(int i=0;i
random = dist6(rng);//rand() % 52 + 1;
temp = cards[i];
cards[i] = cards[random];
cards[random] = temp;
}
}
void sort(){
for(int i=0;i
for(int j=0;j
for(int k=j+1;k
if(!(*deals[i][j]
Card *temp = deals[i][j];
deals[i][j] = deals[i][k];
deals[i][k] = temp;
}
}
}
}
}
};
int main(void)
{
Deck d;
d.initialize();
d.deal();
d.shuffle();
d.sort();
d.display();
}
Homework 4-Deck of Cards Write a program that creates a deck of cards, shuffles it, deals four hands, and displays each hand on the console 1) Write a class Card with these member attributes .Suit (use enumerated data type for spades, hearts, diamonds, clubs) . Number (1 through 13 jack' is 11, queen' is 12, 'king' is 13) Description (string which displays name of card, such as 'Ace of Hearts') Card has an overloaded'operator, which returns true or false based on these rules: Regardless of card number, spades>hearts> diamonds>clubs Within a suit, the numeric value determines , except for aces (value 1) which are > all numeric values . * Create additional member functions as needed 2) Write a class Deck with just one member attribute, and array of 52 cards. Deck has these member functions nitialize -initializes values for deck of cards Shuffle- shuffles deck Deal-deals cards to four hands Sort-sorts each hand into order Display-displays four hands on console as follows HAND 1 HAND 2 HAND 3 HAND 4 Spade Ace Spade 2 Heart Queen Heart 4 Diamond Jack Spade Jack Spade 8 Spade 4 Heart Ace Heart King Heart 7 Diamond Ace Diamond King Diamond Queen Club 10 Spade King Spade Queen Spade 10 Spade 9 Spade 7 Do not use library functions for sort or shuffle - you must write your own. Create additional member functions as needed 3) Write a main program which asks if user wants to shuffle deck, deal cards, or end. After each deal, it should display cards
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
