Question

S12 Five Crowns – Part 2 This week you will continue your work on the Five...

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");

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Ans:-

#include &lt;iostream&gt;

using namespace std;

class Card


int getvalue()
come back value;
}

string getsuit()
come back suit;
}
};

int main()

}
}

for(j = 0; j &lt; 52; j++)

NOTE:- If u have any doubts please comment below and I am happily help to u brother please thumsup bro and don't give any negative reviews please ????

Add a comment
Know the answer?
Add Answer to:
S12 Five Crowns – Part 2 This week you will continue your work on the Five...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ Your solution should for this assignment should consist of five (5) files: Card.h (class specification...

    C++ Your solution should for this assignment should consist of five (5) files: Card.h (class specification file) Card.cpp (class implementation file) DeckOfCards.h (class specification file) DeckOfCards.cpp (class implementation file) 200_assign6.cpp (application program) NU eelLS Seven UT Diamonds Nine of Hearts Six of Diamonds For your sixth programming assignment you will be writing a program to shuffle and deal a deck of cards. The program should consist of class Card, class DeckOfCards and an application program. Class Card should provide: a....

  • //main.cpp #include <iostream> #include <iomanip> #include "deck-of-cards.hpp" void RunAllTests() { int count; std::cin >> count; DeckOfCards...

    //main.cpp #include <iostream> #include <iomanip> #include "deck-of-cards.hpp" void RunAllTests() { int count; std::cin >> count; DeckOfCards myDeckOfCards; for (int i = 0; myDeckOfCards.moreCards() && i < count; ++i) { std::cout << std::left << std::setw(19) << myDeckOfCards.dealCard().toString(); if (i % 4 == 3) std::cout << std::endl; } } int main() { RunAllTests(); return 0; } //card.hpp #ifndef CARD_HPP_ #define CARD_HPP_ #include <string> class Card { public: static const int totalFaces = 13; static const int totalSuits = 4; Card(int cardFace, int...

  • I've created a Card class and I'm asked to implement a class called DeckOfCards that stores...

    I've created a Card class and I'm asked to implement a class called DeckOfCards that stores 52 objects of the Card class. It says to include methods to shuffle the deck, deal a card, and report the number of cards left in the deck, and a toString to show the contents of the deck. The shuffle methods should assume a full deck. I also need to create a separate driver class that first outputs the populated deck to prove it...

  • A standard 52-card deck has four 13-card suits: diamonds, hearts, 13-card suit contains cards numbered f...

    A standard 52-card deck has four 13-card suits: diamonds, hearts, 13-card suit contains cards numbered f probability of drawing a black king of hearts clubs, and spades. The diamonds and hearts are red, and the clubs and spades are black Each from 2 to 10, a jack, a queen, a king, and an ace. An experiment consists of drawing 1 card from the standard deck. Find the The probability of choosing a black king of hearts is ype an integer...

  • NEED HELP TO CREATE A BLACKJACK GAME WITH THE UML DIAGRAM AND PROBLEM SOLVING TO GET...

    NEED HELP TO CREATE A BLACKJACK GAME WITH THE UML DIAGRAM AND PROBLEM SOLVING TO GET CODE TO RUN!! THANKS Extend the DeckofCards and the Card class in the book to implement a card game application such as BlackJack, Texas poker or others. Your game should support multiple players (up to 5 for BlackJack). You must build your game based on the Cards and DeckofCards class from the book. You need to implement the logic of the game. You can...

  • Given these three classes: Card, DeckOfCards, and DeckOfCardsTest. Extend the DeckofCards class to implement a BlackJack...

    Given these three classes: Card, DeckOfCards, and DeckOfCardsTest. Extend the DeckofCards class to implement a BlackJack class, which implements a BlackJack game. Please do not use any java applet on the coding. Hint: Use a test class to test above classes. Pulic class Card {    private final String face; // face of card ("Ace", "Deuce", ...)    private final String suit; // suit of card ("Hearts", "Diamonds", ...)    // two-argument constructor initializes card's face and suit    public...

  • 7.12 (Card Shuffling and Dealing) Modify the program in Fig. 7.24 so that the card-dealing function deals a five-card...

    7.12 (Card Shuffling and Dealing) Modify the program in Fig. 7.24 so that the card-dealing function deals a five-card poker hand. Then write the following additional functions: a) Determine whether the hand contains a pair. b) Determinewhetherthehandcontainstwopairs. c) Determine whether the hand contains three of a kind (e.g., three jacks). d) Determinewhetherthehandcontainsfourofakind(e.g.,fouraces). e) Determine whether the hand contains a flush (i.e., all five cards of the same suit). f) Determine whether the hand contains a straight (i.e., five cards of...

  • (Card Shuffling and Dealing) Modify the program below so that the card-dealing function deals a five-card...

    (Card Shuffling and Dealing) Modify the program below so that the card-dealing function deals a five-card poker hand. Then write the following additional functions: a) Determine whether the hand contains two pairs b) Determine whether the hand contains a full house (i.e., three of a kind with pair). c) Determinewhetherthehandcontainsastraight flush (i.e.,fivecardsofconsecutivefacevalues). d) Determine whether the hand contains a flush (i.e., five of the same suit) #include <stdio.h> #include <stdlib.h> #include <time.h> #define SUITS 4 #define FACES 13 #define CARDS...

  • how many diamonds are in a deck of cards?

    A deck of cards contains 52 cards. They are divided into four suits: spades, diamonds, clubs and hearts. Each suit has 13 cards: ace through 10, and three picture cards: Jack, Queen, and King. Two suits are red in color: hearts and diamonds. Two suits are black in color: clubs and spades.Use this information to compute the probabilities asked for below and leave them in fraction form. All events are in the context that three cards are dealt from a...

  • You have a standard deck of 52 cards that is made up of four suits (spades,...

    You have a standard deck of 52 cards that is made up of four suits (spades, hearts, diamonds and clubs). Each suit has 13 distinct cards known as denominations (ace, king, queen, jack, ten, nine, ..., three and two). "Bridge" is a card game that evenly deals the entire deck to four players. What is the probability that a bridge hand contains one card of each denomination (i.e., 13 cards with one ace, one king, one queen, ..., one three...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT