Select Page

Card
The first thing to do is to implement a class to represent a playing card. Use the following UML diagram to guide you on what this class will need:
UML for Card
Card
– value : char*
– suit : char*
– playerId : unsigned*
– discard : bool*
+ Card(v : char, s : char)
+ ~Card()
+ getValue() const : char
+ getSuit() const : char
+ getPlayerId() const : unsigned
+ isDiscard() const : bool
+ setPlayerId(p : unsigned) : void
+ flipDiscard() : void
The following are implementation notes for the class:
You must separate the class into two files (specification and implementation)
All attributes are dynamic
Make sure to release their memory to avoid memory leaks
The value of the card is represented as a char so that it can be digits (2 through 9), as well as the (J)ack, (Q)ueen, (K)ing, and (A)ce; the 0 character represents the value 10
The suit of the card must take on the values (D)iamond, (H)eart, (C)lub, and (S)pade
Use 0 as the initial value for the playerId attribute; this will allow you to check if a player owns the card or not in other code later on
The discard flag is used to determine if the card is currently in the player’s discard pile or is still active in the game
In the constructor, the first parameter represents the value of the card and the second parameter represents the suit of the card
Use a member initializer list to assign starting values to the attributes
The flipDiscard method changes the value of the discard flag to its opposite value
Player
The second task to complete is to implement a class to represent a player in the game. Use the following UML diagram to guide you on what this class will need:
UML for Player
Player
– id : unsigned*
– name : string*
– score : unsigned*
+ Player(n : string)
+ ~Player()
+ getId() const : unsigned
+ getName() const : string
+ getScore() const : unsigned
+ updateScore() : void
+ ask(deck : Card*[], DECK_SIZE : const unsigned) const : char
+ check(deck : Card*[], DECK_SIZE : const unsigned, value : char) const : bool
The following are implementation notes for the class:
You must separate the class into two files (specification and implementation)
All attributes are dynamic
Make sure to release their memory to avoid memory leaks
The id must be initialized to a random value between 1000 and 9999 (inclusive)
In the constructor, the parameter represents the name of the player
Use a member initializer list to assign starting values to the attributes
The updateScore method needs to increment the value that the score attribute is pointing to by 1
The ask method allows the player to ask which card value they want
Use a loop to perform this so that the player must pick a card value that is currently in their hand
Return the valid card value
The check method determines if the given value parameter is for a card that is currently in the player’s hand
Make sure to only consider non-discarded cards
Return true if one of the cards in the player’s hand matches value, otherwise return false

Do you need any assistance with this question?
Send us your paper details now
We'll find the best professional writer for you!