Question

Description: In this exercise, you are required to implement two classes which consists of class Card, class DeckOfCards TheThe class DeckOfCards should contain: b) An integer currentCard representing the next Card to deal. c) A default constructor

Hints: Face names (Ordered): Ace, Deuce, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen

//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 cardSuit);
std::string toString() const;

int getFace() const;
int getSuit() const;
  
private:
int face;
int suit;
static const char* faceNames[totalFaces];
static const char* suitNames[totalSuits];
};
#endif

//desk-of-cards.hpp

#ifndef DECK_OF_CARDS_HPP_
#define DECK_OF_CARDS_HPP_
#include <vector>
#include "card.hpp"

class DeckOfCards {
public:
DeckOfCards();
Card dealCard();
bool moreCards() const;
private:
std::vector<Card> deck;
int currentCard;
};
#endif

//card.cpp

??

//desk-of-cards.cpp

??

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

card.cpp

#include "card.hpp"
const char *Card::faceNames[Card::totalFaces] = {"Ace", "Deuce", "Three", "Four", "Five", "Six",
                              "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"};
const char *Card::suitNames[Card::totalSuits] = {"Hearts", "Diamonds", "Clubs", "Spades"};
Card::Card(int cardFace, int cardSuit) {
face = cardFace;
suit =cardSuit;
}
std::string Card::toString() const {
std::string result = "";
result = result + faceNames[face] + " of " + suitNames[suit];
return result;
}
int Card::getFace() const {
return face;
}
int Card::getSuit() const {
return suit;
}

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 cardSuit);
    std::string toString() const;

    int getFace() const;
    int getSuit() const;
  
private:
    int face;
    int suit;
    static const char* faceNames[totalFaces];
    static const char* suitNames[totalSuits];
};
#endif

deck-of-cards.cpp

#include "deck-of-cards.hpp"
DeckOfCards::DeckOfCards() {
currentCard = 0;
while (moreCards()) {
    deck.push_back(dealCard());
}
currentCard = 0;
}
Card DeckOfCards::dealCard() {
int face, suit;
suit = currentCard / Card::totalFaces;
face = currentCard % Card::totalFaces;
++currentCard;
Card card(face, suit);
return card;
}
bool DeckOfCards::moreCards() const {
return currentCard != 52;
}

deck-of-cards.hpp

#ifndef DECK_OF_CARDS_HPP_
#define DECK_OF_CARDS_HPP_
#include <vector>
#include "card.hpp"

class DeckOfCards {
public:
    DeckOfCards();
    Card dealCard();
    bool moreCards() const;
private:
    std::vector<Card> deck;
    int currentCard;
};
#endif

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;
}

Add a comment
Know the answer?
Add Answer to:
//main.cpp #include <iostream> #include <iomanip> #include "deck-of-cards.hpp" void RunAllTests() { int count; std::cin >> count; DeckOfCards...
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
  • 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...

  • 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...

  • 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....

  • 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...

  • Java Write a complete program that implements the functionality of a deck of cards. In writing...

    Java Write a complete program that implements the functionality of a deck of cards. In writing your program, use the provided DeckDriver and Card classes shown below. Write your own Deck class so that it works in conjunction with the two given classes. Use anonymous objects where appropriate. Deck class details: Use an ArrayList to store Card objects. Deck constructor: The Deck constructor should initialize your ArrayList with the 52 cards found in a standard deck. Each card is a...

  • HELP NEED!! Can some modified the program Below in C++ So that it can do what the Problem below asked it today???? #include <iostream> #include <stdlib.h> #include <string> #include...

    HELP NEED!! Can some modified the program Below in C++ So that it can do what the Problem below asked it today???? #include <iostream> #include <stdlib.h> #include <string> #include <time.h> /* time */ #include <sstream> // for ostringstream using namespace std; // PlayingCard class class PlayingCard{ int numRank; int numSuit; string rank; string suit; public: PlayingCard(); PlayingCard(int numRank,int numSuit); void setRankString(); void setSuitString(); void setRank(int numRank); void setSuit(int numSuit); string getRank(); string getSuit(); int getRankNum(); int getSuitNum(); string getCard(); };...

  • #ifndef PROCESSREQUESTRECORD_CLASS #define PROCESSREQUESTRECORD_CLASS #include <iostream> #include <string> using namespace std; class procReqRec { public: //...

    #ifndef PROCESSREQUESTRECORD_CLASS #define PROCESSREQUESTRECORD_CLASS #include <iostream> #include <string> using namespace std; class procReqRec { public: // default constructor procReqRec() {} // constructor procReqRec(const string& nm, int p); // access functions int getPriority(); string getName(); // update functions void setPriority(int p); void setName(const string& nm); // for maintenance of a minimum priority queue friend bool operator< (const procReqRec& left, const procReqRec& right); // output a process request record in the format // name: priority friend ostream& operator<< (ostream& ostr, const procReqRec&...

  • I'm currently writing a program based on stub poker and trying to deal cards to the...

    I'm currently writing a program based on stub poker and trying to deal cards to the players, show their hands, and determine the winner, and lastly ask them to if they want to play another hand. I'm probably going to have to write a method to compare hands but i really need to just deal the cards and store in their hands Any help or suggestions? Here are my current classes. public class PlayingCard {    private final Suit suit;...

  • 1. A standard deck of cards has 52 cards with 4 suits that include 13 clubs,...

    1. A standard deck of cards has 52 cards with 4 suits that include 13 clubs, 13 diamonds, 13 hearts, and 13 spades. Each suit includes an ace, a king, a queen, and a jack, and numbers 2 through 10. Assume that I choose one card from the deck. a. What is the probability that the card is either a queen or a 4? b. What is the probability that the card is not a queen and it is not...

  • 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...

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
ADVERTISEMENT