1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
#include <iostream>
enum suit{ HEARTS, CLUBS, DIAMONDS, SPADES };
enum face{ TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING, ACE };
const char* const suitStr[4] =
{
"Hearts",
"Clubs",
"Diamonds",
"Spades"
};
const char* const faceStr[13] =
{
"Two", "Three", "Four", "Five", "Six", "Seven", "Eight",
"Nine", "Ten", "Jack", "Queen", "King", "Ace"
};
struct Card{
suit suitType;
face faceType;
};
std::ostream& operator<<(std::ostream& os, const Card& c)
{
return os << faceStr[c.faceType] << " of " << suitStr[c.suitType];
}
typedef Card Deck[4][13];
void fillAll(Deck& fullDeck)
{
for (unsigned i = 0; i < 52; ++i)
{
suit s = suit(i / 13) ;
face f = face(i % 13) ;
fullDeck[s][f].suitType = s;
fullDeck[s][f].faceType = f;
}
}
int main()
{
Deck deck;
fillAll(deck);
for (unsigned i = 0; i < 4; ++i)
for (unsigned j = 0; j < 13; ++j)
std::cout << deck[i][j] << '\n';
}
|