Using the cards class
Class:
Cards
The
object : a
deck of 52 playing cards.
Methods
or operations:
1.
void shuffle()
shuffles the deck
2.
int deal ()
deals one card from the deck
returns the card as a 3-digit
integer
The first digit represents the
suit (e.g. Hearts is 1; Diamonds is 2..)
The second two digits (1..13)
represent the value (eg. 1(Ace) to 13(King)
3.
int remaining()
returns the number of cards
remaining in the deck
Declaring
a cards object:
Cards deck;
Important:
When
a deck is created, the cards are in order.
You must shuffle
the deck if you would like to deal
random cards.
Example:
#include
<iostream>
#include
“cards.h”
using namespace std;
void
main()
{
Cards deck; //
declare a Cards object
int card; // three digit
number representing the card
deck.shuffle(); // shuffle the deck;
// deal five cards
for (int i = 1; i <= 5; i++)
{
card = deck.deal();
cout<<”The number of remaining cards
is “<<deck.remaining();
}
}