#include #include // needed for rand() function #include using namespace std; class Card { public: enum suitType { clubs, diamonds, hearts, spades }; static const string value_name[13]; static const string suit_name[4]; Card (); Card (int); int get_value(void) const { return value; } suitType get_suit(void) const { return suit; } private: int value; suitType suit; static int default_card_initializer; friend ostream& operator<<(ostream& out, const Card& card); }; int Card::default_card_initializer = 0; const string Card::value_name[13] = { "two","three","four","five","six","seven", "eight","nine","ten","jack","queen","king","ace" }; const string Card::suit_name[4] = {"clubs","diamonds","hearts","spades"}; Card::Card() : value(default_card_initializer % 13), suit(static_cast(default_card_initializer % 4)) { ++default_card_initializer; } Card::Card(int x) : value(x % 13), suit(static_cast(x % 4)) {} ostream& operator<<(ostream& out, const Card& card) { out << (Card::value_name[card.value]) << " of " << (Card::suit_name[card.suit]); return out; } class Deck { public: Deck(); Deck(const Deck&); ~Deck() { delete [] cards; cards = 0;} Deck& operator= (const Deck&); const Card* get_cards() const { return cards; } Card get_cards(int index) const { return cards[index]; } private: static const unsigned short DeckSize; Card* cards; void shuffle(); friend ostream& operator<<(ostream& out, const Deck& deck); }; const unsigned short Deck::DeckSize = 52; Deck::Deck() : cards(new Card[DeckSize]) { shuffle(); } Deck::Deck(const Deck& anotherDeck) : cards(new Card[DeckSize]) { for (auto i = 0; i < DeckSize; ++i) { cards[i] = anotherDeck.cards[i]; } } Deck& Deck::operator=(const Deck& anotherDeck) { if (cards) delete [] cards; cards = new Card[DeckSize]; for (auto i = 0; i < DeckSize; ++i) { cards[i] = anotherDeck.cards[i]; } return *this; } void Deck::shuffle() { int k; Card temp; cout << "I am shuffling the Deck\n"; for (auto i = 0; i < DeckSize; i++) { k = rand() % DeckSize; temp = cards[i]; cards[i] = cards[k]; cards[k] = temp; } } ostream& operator<<(ostream& out, const Deck& deck) { for (auto i = 0; i < Deck::DeckSize; ++i) out << deck.cards[i] << endl; return out; } int main(void) { Deck poker; cout << poker << endl; }