Question
C++ program. I need to implement Deck.cpp and Card.cpp with the following Card.h and Deck.h files. DO NOT ALTER .h files. I also have to
C++ program. I need to implement Deck.cpp and Card.cpp with the following Card.h and Deck.h files. DO NOT ALTER .h files.
I also have to create a main.cpp file to test the deckOfCards and Cards files.
// Card.h
#ifndef CARD_H_ #define CARD_H_
#include
/* String constants for the suits */ static const std::string suitNames[] = { "Spades", "Hearts", "Diamonds", "Clubs" };
/* String constants for the rank */ static const std::string rankNames[] = { "Joker", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King", "Ace" };
/* Card class to represent a single playing card */ class Card { public: /* Suit enumerations */ enum Suit { Spades = 0, Hearts, Diamonds, Clubs };
/* Rank enumerations ordered by value for game of war */ enum Rank { Joker = 0, Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King, Ace };
/** * Constructor * @param s * @param r */ Card(Suit s, Rank r);
/* Constructor. This empty constructor will create a joker card. */ /* The joker card is a special card given to the player going first. */ Card();
/* Destructor */ virtual ~Card() {}
/* Return true if this card is a joker */ bool isJoker() const { return (cardRank == Joker); }
/* Output the card to an output stream as "rank of suit" */ friend std::ostream& operator <<(std::ostream&, const Card&);
/* Compare operators. For the game of war we only care about the rank */ friend bool operator ==(const Card &lhs, const Card &rhs); friend bool operator <(const Card &lhs, const Card &rhs);
private: Suit cardSuit; Rank cardRank; };
#endif /* CARD_H_ */
/* Deck.h */
#ifndef DECK_H_ #define DECK_H_
#include
#include "Card.h"
#define MaxCards 52
class Deck { public: /* Constructor and destructor */ Deck(); virtual ~Deck();
/* Shuffle the deck and reset the next available card to the beginning of the deck */ void shuffle();
/* Return true if the deck is empty (next available card is past the end of the deck) */ bool isEmpty() const;
/* Draw a card from the deck. If someone attempts to draw a card when the deck is */ /* empty then throw an exception. */ const Card draw();
private: unsigned nextCard; std::vector
#endif /* DECK_H_ */
// Card.cpp
#include
// Constructor with parameters Card::Card(Suit s, Rank r) { cardSuit = s; cardRank = r; }
// Constructor defaults to a Joker Card::Card() { cardSuit = Spades; cardRank = Joker; }
// Output card to an output stream as "Rank of Suit" ostream& operator<<(ostream& out, const Card& aCard) { string s, r; // Suit if (aCard.Spades) s = "Spades"; else if (aCard.Hearts) s = "Hearts"; else if (aCard.Diamonds) s = "Diamonds"; else if (aCard.Clubs) s = "Clubs";
// Rank if (aCard.Joker) r = "Joker"; else if (aCard.Two) r = "Two"; else if (aCard.Three) r = "Three"; else if (aCard.Four) r = "Four"; else if (aCard.Five) r = "Five"; else if (aCard.Six) r = "Six"; else if (aCard.Seven) r = "Seven"; else if (aCard.Eight) r = "Eight"; else if (aCard.Nine) r = "Nine"; else if (aCard.Ten) r = "Ten"; else if (aCard.Jack) r = "Jack"; else if (aCard.Queen) r = "Queen"; else if (aCard.King) r = "King"; else if (aCard.Ace) r = "Ace"; return out << s << " of " << r; }
// Rank compare operators bool operator<(const Card &lhs, const Card &rhs) { return lhs < rhs; }
bool operator==(const Card &lhs, const Card &rhs) { return lhs < rhs; }
#include "Deck.h" #include "Card.h" #include
Deck::Deck() // Construct a deck {
}
void Deck::shuffle() { }
bool Deck::isEmpty() const { }
Card Deck::draw() { }
What I need Answered: Deck.cpp Card.cpp Main.cpp
PLEASE USE HEADER FILES ABOVE. I GOT A PREVIOUS ANSWER AND THEY DIDN'T USE THE ENUM'S AND CODE DID NOT WORK.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started