我的教授给我们布置了这个作业,但是我不知道如何做第一步。我不是要求任何人做作业,只是请有人帮我解决第一个问题
- 动态创建甲板
这个问题基于两个文件(他提供)
“卡.h”
//*********************************************************
// CLASS DECLARATION
//*********************************************************
class Card
{
//*****************************************************
// Public Members
//*****************************************************
public:
// Exception classes
class NotInitalized {};
// Enumeration for Suit
enum Suit { Clubs, Diamonds, Hearts, Spades,
UNKNOWN };
// Enumeration for Card Name
enum CardName { Ace, Two, Three, Four, Five, Six,
Seven, Eight, Nine, Ten, Jack,
Queen, King, UNKNOWN };
// constructors
//*****************************************************
// Card
//
// Create uninitialized card. Must be initialized with
// 'setCard()' before use.
//*****************************************************
Card(); // card is not initialized
//*****************************************************
// Card
//
// Create a card based its ordinal position.
// cards are ordered by suit first in the order
// Clubs, Diamonds, Hearts and Spades, and within
// the suit they are ordered Act thru King.
//******************************************************
Card(int); // number between 1-52
//******************************************************
// Card
//
// Create a card with the given name and suit.
//*******************************************************
Card(Suit, CardName);
// methods
//*******************************************************
// setCard
//
// Set the Suit and Name of the card
//*******************************************************
void setCard(Suit, CardName);
//*******************************************************
// getSuit
//
// returns the element of the Suit enumeration
// representing the suit of the card
//*******************************************************
int getSuit();
//*******************************************************
// getCardName
//
// returns the element of the CardName enumeration
// representing the card
//*******************************************************
int getCardName();
//*******************************************************
// getCardValue
//
// returns face value of card. For Ace -1 is the value.
//*******************************************************
int getCardValue();
//*****************************************************
// toString
//
// return the string representation of the card.
// e.g.,"Ace of Spades"
//*****************************************************
string toString();
//************************************************
// Private Members
//************************************************
private:
// the Card’s suit (uses Suit enum)
Suit suit = Suit::UNKNOWN;
// the Card’s name (uses CardName enum)
CardName name = CardName::UNKNOWN;
};
第二类是甲板类。此类代表标准扑克牌中的 52 张牌。在内部,卡片组中的卡片应保存在 Card 对象数组中。还应该有一个并行的卡片指针数组,可以存储每次洗牌后卡片的顺序。
创建 Deck 对象时,它会创建 52 张牌并将它们洗牌。如果牌组在重新洗牌之前用完牌,则 dealCard() 方法应抛出 DeckEmpty 异常。
因为这个类创建了卡片对象,所以它应该有一个析构函数,当 Deck 被删除时,它会删除所有相关的卡片对象。
下面是 Deck 类的类声明。
//*********************************************************
// CLASS DECLARATION
//*********************************************************
#include “Card.h”
class Deck
{
//*****************************************************
// Public Members
//*****************************************************
public:
// Exception classes
class DeckEmpty {};
// Constructors/Destructors
Deck(); // creates the cards and sorts them
~Deck(); // frees all the cards
// Methods
//****************************************************
// dealCard
//
// return the next available card in the shuffled deck
//****************************************************
Card dealCard();
//****************************************************
// shuffle
//
// shuffle the cards
//****************************************************
Void shuffle(); // shuffle the deck
//****************************************************
// getCardCount
//
// return the number of unused cards in the shuffled
// deck
//****************************************************
int getCardCount(); // how many cards left
//****************************************************
// toString
//
// return a newline (\n) delimited list of the shuffled
// cards
//*****************************************************
string toString();
//*****************************************************
// Private Members
//*****************************************************
private:
// array to hold unshuffled cards
Card cards[DECK_SIZE];
// array to hold shuffled cards
Card* shuffledCards[DECK_SIZE];
// index of next card to deal from shuffled cards
int nextCardIndex;
};