//----------------------------------------------------------------------
// SPECIFICATION FILE (newdeal.h)
// This module exports CardValType, SuitType, CardDeckType,
// and CardType to randomly deal playing cards.
// Machine dependency: long ints must be at least 32 bits (4 bytes).
//----------------------------------------------------------------------
#ifndef _NEWDEAL_H
#define _NEWDEAL_H
#include "rand2.h"
enum CardValType { two=2, three, four, five, six, seven, eight,
nine, ten, jack, queen, king, ace };
enum SuitType { clubs, diamonds, hearts, spades };
class CardType
{
friend class CardDeckType;
public:
CardType();
// POST: the ace of spades has been created
CardType(CardValType rank, SuitType suit);
// POST: the card, "rank of suit", has been created
CardValType rank() const;
// POST: FCTVAL == the rank of this CardType
SuitType suit() const;
// POST: FCTVAL == the suit of this CardType
void display() const;
// POST: This card has been written to cout as:
// where is a single character representing
// the rank of the card ('2'-'9','T','J','Q','K','A')
// and is one of: "Clubs" "Diamonds" "Hearts" "Spades"
private:
CardValType _rank;
SuitType _suit;
};
class CardDeckType {
public:
void ShuffleDeck();
// POST: All 52 cards have been returned to the deck
CardType DealACard();
// PRE: At least one card remains in the deck
// POST: FCTVAL == a playing card not dealt
// since most recent ShuffleDeck
// && This card has been removed from the deck
int CardsInDeck() const;
// POST: FCTVAL == number of cards remaining in the deck
CardDeckType( /* in */ long initSeed );
// Constructor
// PRE: initSeed >= 1
// POST: Random no. generator has been initialized with initSeed
// && The deck has been shuffled
private:
RandGen cardGen;
int cardsRemaining;
CardType card[52];
};
#endif