Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
The card shuffling and dealing program in Figs. 21.2–21.4 is similar to the one described in Exercise 10.10. This program represents the deck of cards as a vector of structures and uses high-performance shuffling and dealing algorithms.
|
Code View:
Scroll
/
Show All 1 // Fig. 21.2: DeckOfCards.h 2 // Definition of class DeckOfCards that 3 // represents a deck of playing cards. 4 #include <string> 5 #include <vector> 6 using namespace std; 7 8 // Card structure definition 9 struct Card 10 { 11 string face; 12 string suit; 13 }; // end structure Card 14 15 // DeckOfCards class definition 16 class DeckOfCards 17 { 18 public: 19 static const int numberOfCards = 52; 20 static const int faces = 13; 21 static const int suits = 4; 22 23 DeckOfCards(); // constructor initializes deck 24 void shuffle(); // shuffles cards in deck 25 void deal() const; // deals cards in deck 26 27 private: 28 vector< Card > deck; // represents deck of cards 29 }; // end class DeckOfCards |