/* Array practice 1.Create a deck of cards 2.Write a print function to print a card. 3.Write a print function to print a deck. 4.Shuffle a deck. 5.Create a random "hand". 6.Detect "three of a kind" in a hand. */ #include #include #include using namespace std; const int Decksize = 52; const int HandSize = 5; // function prototypes void createDeck(int*); void shuffle(int deck[]); void swap(int& a, int& b); void deal(int[], int hand[], int numberOfCards = HandSize); // overloaded functions void print(int); // print a card void print(const int [], int numberOfCard = Decksize); // print the deck int main() { int deck[Decksize]; int hand[5]; createDeck(deck); //print(deck); cout << endl << "--------------------------" << endl << endl; shuffle(deck); print(deck, 15); cout << endl << "==========================" << endl << endl; deal(deck,hand); print(hand,HandSize); cout << endl << "==========================" << endl << endl; deal(deck,hand); print(hand,HandSize); return 0; } void createDeck(int* d) { for (int i = 0; i < Decksize; i++) d[i] = i; } void print(int card) { string cardValues[] = {"two","three","four","five","six","seven", "eight","nine","ten","jack","queen","king","ace"}; string cardSuits[] = {"clubs","diamonds","hearts","spades"}; cout << cardValues[card%13] << " of " << cardSuits[card%4] << endl; } void print(const int somecards[], int numberOfCards) { for (int i = 0 ; i < numberOfCards; i++) print(somecards[i]); } void shuffle(int deck[]) { int randomCard; for (int i = 0 ; i < Decksize; i++) { randomCard = rand() % Decksize; swap(deck[i],deck[randomCard]); } } void swap(int& a, int& b) { int temp = a; a = b; b = temp; } void deal(int deck[], int hand[], int numberOfCards) { static int topOfDeck = 0; for (int i = 0; i < numberOfCards;++i) { hand[i] = deck[topOfDeck]; topOfDeck++; } }