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 70
|
#include <iostream>
#include <string>
using namespace std;
const int HEARTS = 0;
const int DIAMONDS = 1;
const int CLUBS = 2;
const int SPADES = 3;
class Card
{
public:
Card(int suit, int val);
int getValue();
int getSuit();
static const char *suitStrings[];
static const char *valueStrings[];
string toString();
private:
int mSuit, mValue;
};
Card::Card(int suit, int val)
{
mSuit = suit;
mValue = val;
}
int
Card::getValue()
{
return mValue;
}
int
Card::getSuit()
{
return mSuit;
}
const char *
Card::suitStrings[] = {
"HEARTS", "DIAMONDS", "CLUBS", "SPADES"
};
const char *
Card::valueStrings[] = {
"ACE", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX",
"SEVEN", "EIGHT", "NINE", "TEN", "JACK", "QUEEN", "KING"
};
string
Card::toString()
{
string result = valueStrings[mValue];
result += " of ";
result += suitStrings[mSuit];
return result;
}
int
main()
{
Card card(HEARTS, 9);
cout << card.toString();
return 0;
}
|