Question: C++ help This assignment gives you practice with inheritance and pure virtual functions. You will implement some code that could be part of a program

C++ help

This assignment gives you practice with inheritance and pure virtual functions. You will implement some code that could be part of a program to play a popular card game called Crazy 8s, which is the basis for the game Uno. You will start to implement the rules, as described at: https://www.pagat.com/eights/crazy8s.html . Note that the inheritance relationship below is also based on the organization of card games described on that website.

Requirements: your work will be split into 3 classes, which should be in the files card.h, matchingCardGame.h and crazy8s.h. There will be a test driver again in the file hw3driver.cpp. Please treat the file names and class/method names as case-sensitive.

The Card class (in card.h)

Private fields for rank and suit, both of which are of type string. Ex: 2 and Hearts you are to assume the values are valid

The method functions, here and in the other classes, are all public

A constructor that takes the rank and the suit as parameters and initializes the fields from the parameters

sameRank(Card &) const : returns true if this and the parameter card have the same rank, false if not

sameSuit(Card &) const: returns true if this and the parameter card have the same suit, false if not

The MatchingCardGame class (in matchingCardGame.h)

This is supposed to only be a partial implementation you will get to fill in the rest on a later assignment

A protected pointer to a Card variable that points to the top card of the deck this is in place of the deck

A setter setTop(Card *) which initializes the field. Note that when you complete the implementation, you will be replacing the pointer and this setter.

A pure virtual function canPlay(Card &) which returns true if it is valid to play the parameter card on top of the above top card

The Crazy8s class (in crazy8s.h)

This is a subclass of MatchingCardGame

The only thing required here is an implementation of canPlay which satisfies the following:

A card can be played if it is of the same rank as the top card

A card can be played if it is of the same suit as the top card

A card can be played if its rank is 8 (there is a feature that whoever plays the 8 then chooses what the next suit must be, but we will skip that requirement for now)

The driver should, as usual, test the above code.

As with hw2, hard-code the test cases to save time and to make sure you cover the different scenarios

To make sure you have implemented the inheritance relationship properly, declare a pointer to a MatchingCardGame and use that to point to a Crazy8s object. This would be like how the in-class exercise had you declare a pointer to a Polygon and use that to point to the Rectangle or the Triangle. Use this pointer to make the calls to test canPlay()

Grading:

Card 20%

MatchingCardGame 20%

Crazy8s 20%

Comments count for 10%: something for each file/class, something for each method/function, other comments to explain parts of the code when it's not clear

<>Choosing appropriate names for variables, functions, constants, classes counts for 10%

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!