Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

CS2360 Simulate Deck Of Cards

Requirement

The objective of this assignment is to write classes to simulate a deck of cards. Recall that a deck of cards consists of 52 cards consisting of the 13 ranks (2, 3, 4, 5, 6, 7, 8, 9, T(ten), J(jack), Q(queen), K(kind), and A(ace) paired with the four suits CLUBS, DIAMONDS, HEARTS, and SPADES. Consider the following header file carddeck.h:

#ifndef CARDDECK_H

#define CARDDECK

#include <string>

using namespace std;

enum Suit

{

CLUBS, DIAMONDS, HEARTS, SPADES

10 };

11 

12 class Card

13 {

14 private:

15 char rank; // use digit (e.g., 4) for cards valued 2 through 9, 'T' for 10,

16 // 'J','Q','K','A' for Jack, Queen, King, and Ace

17 Suit suit;

18 public:

19 Card(); // creates Ace of Spades as default card

20 Card(char, Suit); // creates card with given rank and suit

21 char getRank() const;

22 Suit getSuit() const;

23 void setRank(char);

24 void setSuit(Suit);

25 string toString() const; // creates text representation of card, e.g. "2C" for 2

26 // of Clubs, "KH" for King of Hearts, etc.

27 };

28 

29 class CardDeck

30 {

31 private:

32 Card* deck;

33 Card* next_card; // keeps track of where we are in a deck after dealing some

34 // (initially, next_card == deck)

35 public:

36 CardDeck(); // sets member variable deck to be an array of 52 Card obje

37 // representing deck of cards

38 ~CardDeck();

39 void shuffle(); // randomly shuffles the deck (you will need to think about

40 // to do this). also, this function should reset next_card

41 // deck

42 Card* dealHand(int); // deals a hand of N cards where N is the input to the

43 // function. this function should also increment the

44 // next_card pointer by N cards.

45 };

46 

47 #endif

This header file has been attached for your convenience.

Problem 1

In a source file carddeck.cpp, provide an implementation for the Card class, i.e., please provide an implementation for all the member functions defined in the class. Observe that there are two constructors: a default constructor to create the card representing Ace of Spades (or AS) and a second constructor that defines a custom card with given rank and suit. The member function toString() should return a two character string representation of a card, i.e. it would return QH for Queen of Hearts, TD for Ten of Diamonds, 5S for Five of Spades, etc.

Problem 2

In the same source file carddeck.cpp, provide an implementation of the CardDeck class.

The constructor of this class should dynamically allocate an array of 52 cards and set them to all of the appropriate values (all ranks with all suits). The destructor should deallocate this array. The shuffle function should use random numbers to shuffle the cards, i.e., to re-arrange them in a random order such that no cards are repeated. The dealHand(int N) function should accept an integer and return a pointer to a sub-array consisting of N cards. If dealHand(int) is called twice after a shuffle, then the cards returned during the second call should be completely different from the cards returned during the first call. Notice that the CardDeck class contains a next_card pointer. You should use this pointer to keep track of which cards remain in the deck after dealing out hands.

Write a main function that generates a deck of cards, shuffles it, and deals two hands of 5 cards each. Have your function print out the cards in each hand.

When submitting this assignment, please only submit the file carddeck.cpp that you wrote. No other files should be included.