Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ programing Use inheritance and pure virtual functions. Implement some code that could be part of a program to play a popular card game called

C++ programing

Use inheritance and pure virtual functions. 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. Need to 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: It needs to 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 Driver3.cpp. Please treat the file names and class/method names as case-sensitive.

1. The Card class (in card.h)

a. 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

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

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

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

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

2. The MatchingCardGame class (in matchingCardGame.h)

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

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

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

d. 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

3. The Crazy8s class (in crazy8s.h)

a. This is a subclass of MatchingCardGame

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

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

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

iii. 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)

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

a. Must hard-code the test cases to save time and to make sure you cover the different scenarios

b. 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 to test canPlay() Comment each function.

therefore 4 parts:

- Card.h

- MatchingCardGame.h

- Crazy8s.h

- Driver3.cpp

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Murach's SQL Server 2012 For Developers

Authors: Bryan Syverson, Joel Murach, Mike Murach

1st Edition

1890774693, 9781890774691

More Books

Students also viewed these Databases questions