-
August 3rd, 2010, 08:34 PM
#1
Deck of card class
I am having trouble with a program I am trying to write and was wondering if I could get some help. I am supposed to use two arrays to store the suit and denomination of cards in a deck.
const String suits["Clubs","Diamonds","Hearts","Spades" ]; // initialise suit array
const String denomination["Ace","2","3","4","5","6","7","8","9","10","Jack","Queen","King"]; // initialise denom array
Next I am supposed to have two constructors, the first takes an int between 0 and 51 inclusive as its argument, then it computes which card has that value in the deck based on the table below.
Card number Actual Card
----------- -----------
0 Ace of Clubs
1 2 of Clubs
2 3 of Clubs
.
.
.
9 10 of Clubs
10 Jack of Clubs
11 Queen of Clubs
12 King of Clubs
13 Ace of Diamonds
.
.
.
25 King of Diamonds
26 Ace of hearts
.
.
.
38 King of Hearts
39 Ace of Spades
.
.
.
51 King of Spades
Here is how I did it
if (number < 0 || number > 51)
{
printf("Invalid");
}
if (number >= 0 && number <= 12)
suit = suits[0];
else if (number >= 13 && number <= 25)
suit = suits[1];
else if (number >= 26 && number <= 38)
suit = suits[2];
else
suit = suits[3];
// int temp1 = number / 13;
int temp2 = number % 13;
value = denomination[temp2];
The problem I am having is with the second constructor, it accepts two strings as arguments, the denomination of a card and the suit ("King","Diamonds"), I am then supposed to generate the value of this card based on the same table above. Meaning the King of Diamonds would be 25.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|