#ifndef DANS_DECK #define DANS_DECK /* This class provides the functions needed by a deck of cards. This class relies on the random number generator to shuffle the deck and srand() should be called before the Shuffle routine is employed. The following operations are supported: TopCard : Input: none Output: the top card on the deck. This routine removes the top card from the deck. If the deck is empty an error is thrown. InsertCard: Input: a card Output: None This routine inserts a card on the bottom of the deck. MakeEmpty: Input: None Output: None This routine removes all cards from the deck. After a call to this routine, the deck will be empty. Shuffle: Input: None Output: None Randomize the cards in the deck. AddDeck: Input: a deck (source). Output: an empty source deck This routine will remove the cards for the source deck and add them to the deck. On output the source deck will be empty and the deck will contain all of the cards. IsEmpty Input: None Output: Bool This routine returns true if the deck is empty. Size Input: None Output: An integer This routine will return an iteger representing the number of cards in the deck. Please do not follow the example of this file and place code in your specification file. We will discuss this later, but for now, you should only place definitions in a specification file. I am doing this because my code, in some sense, is a definition for a class that the compiler creates. You should understand better in CSCI 330 */ #include #include #include using std::list; using std::vector; template class DeckT { public: DeckT(){}; ~DeckT(){}; // insert a card into a deck void InsertCard(CardT card) { myDeck.push_back(card); return; } // return the top card from the deck. // This throws an exception if called on an empty deck CardT TopCard() { CardT tmp; if (myDeck.size() > 0) { tmp = myDeck.front(); myDeck.pop_front(); return tmp; } else { throw -1; } } // shuffle the deck. // This uses a vector to make it O(n), not O(n^2), // but it takes O(n) memory to do so void Shuffle(){ int i; int pos; CardT tmp; vector cards; while (myDeck.size() > 0) { cards.push_back(myDeck.front()); myDeck.pop_front(); } for(i=0;i 0) { myDeck.push_back(src.myDeck.front()); src.myDeck.pop_front(); } return; } // a function to return the number of cards in the deck. int Size() const { return myDeck.size(); } private: list myDeck; }; #endif