// File: ex4-4.cpp #include <iostream> #include <cstdlib> // needed for rand() function using namespace std; const char* ValueName[13] = {"two","three","four","five","six", "seven","eight","nine","ten","jack","queen","king","ace"}; const char* SuitName[4] = {"clubs","diamonds","hearts","spades"}; class Card { private: int value; int suit; public: Card() {} Card(int); int get_value() { return value;} // accessor function int get_suit() { return suit;} // accessor function void print(); }; Card::Card(int x) // constructor { value = x % 13; suit = x / 13; } void Card::print() { cout << (ValueName[value]) << " of " << (SuitName[suit]) << endl; } class Deck { private: Card d[52]; int next_Card; public: Deck(); void shuffle(); void deal(int=5); void print(); }; Deck::Deck() { for (int i = 0; i < 52; i++) d[i] = Card(i); next_Card = 0; } void Deck::shuffle() { int i, k; Card temp; cout << "I am shuffling the Deck\n"; for (i = 0; i < 52; i++) { k = rand() % 52; temp = d[i]; d[i] = d[k]; d[k] = temp; } } void Deck::print() { for (int i = 0; i < 52; i++) d[i].print(); } void Deck::deal(int no_of_Cards) { cout << "\nOk, I will deal you " << no_of_Cards << " Cards:\n"; for (int i = 0; i < no_of_Cards; i++) d[next_Card++].print(); } int main (void) { Deck poker; poker.shuffle(); poker.print(); poker.deal(); poker.deal(3); }