C++ Card classThe Card class is used to represent a single playing - C Card class The Card class is used to represent a single playing card Data

C++ Card classThe Card class is used to represent a single playing

This preview shows page 1 - 5 out of 10 pages.

C++ Card class The Card class is used to represent a single playing card. Data Members The class contains two data members. An integer that holds the value of the face of the card A character variable that holds the suit of the card. The range of possible values for the integer data member (the face of the card) is 1 through 13 inclusive, with 1 representing an Ace, 11 representing a Jack, 12 representing a Queen, and 13 representing a King. All of the other values represent that specific card. The possible values for the character data member are: 'C' to represent clubs, 'D' to represent diamonds, 'H' to represent hearts, and 'S' to represent spades. Constructor This class has one constructor, a default constructor (ie. one that takes no arguments). It should create a random card by using the random number generator. For the face value (the integer), generate a random number between 1 and 13, inclusive. For the suit value (the character), generate a random number between 1 and 4, inclusive. If the random number is 1, assign 'C' to the character data member. If the random number is 2, assign 'D' to the character data member. If the random number is 3, assign 'H' to the character data member. If the random number is 4, assign 'S' to the character data member. Note: DO NOT set the seed value for the random number
generator in the constructor. It has already been done in main. Methods void setCard( int newFace, char newSuit ) This method sets both the face and the suit for the Card object. It takes two arguments: an integer that represents the new face value for the card and a character that represents the new suit value for the card. It returns nothing. No error checking is required. Simply take the passed-in values and assign them to the corresponding data members. int getFace() This accessor method returns the face value of the Card. It takes no arguments and returns an integer. char getSuit() This accessor method returns the suit value of the Card. It takes no arguments and returns a character. void displayCard() This method displays a text version of the Card. It takes no arguments and returns nothing. For the face value, if the value is: 1, display "Ace" 11, display "Jack" 12, display "Queen" 13, display "King" any other value, display the value For the suit value, if the value is 'C' display "Clubs" 'D' display "Diamonds"
'H' display "Hearts" 'S' display "Spades"

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture