Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

ADJUST previous program1. You will create a class Deck that consists of the foll

ID: 3808983 • Letter: A

Question

ADJUST previous program1. 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 program below with above instructions

cards.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();
};

cards.cpp

#include <iostream>
#include <string>
#include "cards.h"
using namespace std;

string getTextForSuit(suits suit)
{
   switch (suit)
   {
   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 getTextForFace(faces face) {
   switch (face) {
   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 face, suits suit) {
   this->face = face;
   this->suit = suit;
}

string Card::toString() {
   if (this->face == Joker)
       return "Joker";
   return getTextForFace(face) + " of " + getTextForSuit(suit);
}

cardsimplementation.cpp

#include <iostream>
#include <vector>
#include <string>
#include <random>
#include "cards.cpp"
using namespace std;

void shuffleDeck(vector<Card> *deck) {
   mt19937 rng;
   rng.seed(random_device()());
   uniform_int_distribution<std::mt19937::result_type> dist(0, 115);
   for (int i = 0; i < deck->size(); i++) {
       int randomIndex = dist(rng);
       Card randomCard = deck->at(randomIndex);
       (*deck)[randomIndex] = (*deck)[i];
       (*deck)[i] = randomCard;

   }

}

int main() {
   vector<Card> deck;
   for (int suit = Clubs; suit <= Stars; suit++) {
       for (int face = Three; face <= King; face++) {
           Card newCard = Card(static_cast<faces>(face), static_cast<suits>(suit));
           deck.push_back(newCard);
           deck.push_back(newCard);
       }
   }

   for (int i = 0; i < 6; i++) {
       Card newCard = Card(Joker, NotAvailable);
       deck.push_back(newCard);
   }

   for (int i = 0; i < deck.size(); i++) {
       cout << deck[i].toString() << endl;
   }

   shuffleDeck(&deck);
   cout << "************SHUFFLED DECK****************" << endl;

   for (int i = 0; i < deck.size(); i++) {
       cout << deck[i].toString() << endl;
   }
}

CAUsers charlie all stud 2015ProjectsAcardsimplementationVDebuglcardsimplementation.exe Nincspade KingDiamond ghtst Queenspad Eight Diamonds Queenspad espada ghtst Kingspade Four Spada rspada ghtspad kspada 2-13 PM 2/2s 2017 R190

Explanation / Answer

1) Solution of Question 1

//Save the file as Deck.cpp

# include<iostream>

# include<vector>

using namespace std;

Class Deck// creating a class named as Deck

{

public vectorcard <deck>;

int currentCard , index;

public Deck()

{

currentCard =1;

for(int i=0 ;i<=12;i++)

for(int j =0; j<=4;j++)

{

Card card(i,k);

deck.push_back(card);

currentCard++;

}

}

\shuffle the existing deck

public void shuffle_deck()

{

for(int i =0; i<52;i++)

location = rand%52 + 1;

Card holder =Deck[location];

Deck[location]= Deck[i];

Deck[i]= holder;

}

public void deal_deck()// method initialize to deal with the deckof cards

{

while(currentLocation >0)

{

Card returnCard =deck[currentLocation];

returnCard.toString();

currentLocation--;

}

}

bool(moreCards)

{ int currentCard = (int)Deck.currentCard();

if (currentCard==52)

return false;

else

return true ;

//Question 2 solutions

// overloading bool == and < operators

public bool operator ==(int DcurrentCard) //overloaded assignment operator

{

currentCard = DcurrentCard;

return currentCard;

}

public bool operator <(enum Dfaces)//overloaded relational operator

{

enum faces;

Card ab = new Card();

ab.faces();

faces = Dfaces();

return faces;

}

}

#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();
};

cards.cpp

#include <iostream>
#include <string>
#include "cards.h"
using namespace std;

string getTextForSuit(suits suit)
{
   switch (suit)
   {
   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 getTextForFace(faces face) {
   switch (face) {
   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 face, suits suit) {
   this->face = face;
   this->suit = suit;
}

string Card::toString() {
   if (this->face == Joker)
       return "Joker";
   return getTextForFace(face) + " of " + getTextForSuit(suit);
}

cardsimplementation.cpp

#include <iostream>
#include <vector>
#include <string>
#include <random>
#include "cards.cpp"
using namespace std;

void shuffleDeck(vector<Card> *deck) {
   mt19937 rng;
   rng.seed(random_device()());
   uniform_int_distribution<std::mt19937::result_type> dist(0, 115);
   for (int i = 0; i < deck->size(); i++) {
       int randomIndex = dist(rng);
       Card randomCard = deck->at(randomIndex);
       (*deck)[randomIndex] = (*deck)[i];
       (*deck)[i] = randomCard;

   }

}

int main()

{

Deck deck;

deck.deal_deck();

deck.shuffle_deck();

for (int i =0;i<52;i++)

{

cout<<Deck of Cards.deck[i].toString()<<endl;

}
   vector<Card> deck;
   for (int suit = Clubs; suit <= Stars; suit++) {
       for (int face = Three; face <= King; face++) {
           Card newCard = Card(static_cast<faces>(face), static_cast<suits>(suit));
           deck.push_back(newCard);
           deck.push_back(newCard);
       }
   }

   for (int i = 0; i < 6; i++) {
       Card newCard = Card(Joker, NotAvailable);
       deck.push_back(newCard);
   }

   for (int i = 0; i < deck.size(); i++) {
       cout << deck[i].toString() << endl;
   }

   shuffleDeck(&deck);
   cout << "************SHUFFLED DECK****************" << endl;

   for (int i = 0; i < deck.size(); i++) {
       cout << deck[i].toString() << endl;
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote