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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
|
// DeckOfCards.cpp
#include <iostream>
using std::cout;
using std::left;
using std::right;
#include <iomanip>
using std::setw;
#include <cstdlib>
using std::rand;
using std::srand;
#include <ctime>
using std::time;
#include "DeckOfCards.h"
DeckOfCards::DeckOfCards() {
for(int row = 0; row <= 3; row++) {
for(int column = 0; column <= 12; column++) {
deck[row][column] = 0;
}
}
srand(time(0));
}
void DeckOfCards::shuffle() {
int row;
int column;
for(int card = 1; card <= 52; card++) {
do {
row = rand() % 4;
column = rand() %13;
}while(deck[row][column] != 0);
deck[row][column] = card;
}
}
void DeckOfCards::deal() {
static const char *suit[4] = {"Hearts", "Diamonds", "Clubs", "Spades"};
static const char *face[13] = {"Ace", "Deuce", "Three", "Four", "Five", "Six",
"Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"};
for(int card = 1; card <= 52; card++) {
for(int row = 0; row <= 3; row++) {
for(int column = 0; column <= 12; column++) {
if(deck[row][column] == card) {
cout << setw(5) << right << face[column] << " of " << setw(8) << left <<
suit[row] << (card % 2 == 0 ? '\n' : '\t');
}
}
}
}
}
|