... = i / faces; // suits in order
14 deck[i].color = i / (faces * colors); // colors in order
15 }
16 }
17
18 // deal cards in deck
19 void DeckOfCards::deal() const {
20 for (size_t k1{0}, k2{k1 + deck.size() / 2};
21 k1 < deck.size() / 2 - 1; ++k1, ++k2) {
22 cout << "Card:" << setw(3) << deck[k1].face
23 << " Suit:" << setw(2) << deck[k1].suit
24 << " Color:" << setw(2) << deck[k1].color
25 << " " << "Card:" << setw(3) << deck[k2].face
26 << " Suit:" << setw(2) << deck[k2].suit
27 << " Color:" << setw(2) << deck[k2].color << endl;
28 }
29 }

Fig. 22.16 Bit fields used to store a deck of cards.
Alternate View
1 // Fig. 22.16: fig22_16.cpp ...
Get C++ How to Program, 10/e now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.