COP 3331 USF C++ Programming with Inheritance Computer Science Task

As you have worked your way into doing projects 1 and 2, you went  from typically solving the problem using a functional approach in  project #1 and then an object-oriented approach in project #2.

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

However the object-oriented approach used in project #2 did not make  use of a very powerful concept in object-oriented programming.

That concept is Inheritance. Through inheritance you can create  classes with states and methods that can be reused by other classes that  are descended from those classes.

Those classes are called “Base classes”.

Classes derived from them are called “derived” classes.

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

In this project, you will redo project 2, but WILL HAVE TO USE INHERITANCE!

However, working on project #2 you might have noticed certain common  traits between our aDie, aCoin and aDeckOfCards classes. Those traits  could be common properties or common methods. Those common traits can  then be “factored” into a base class and then used by the derived  classes through inheritance from your base class.

You may have noticed that the aDie, aCoin, aDeckOfCards classes all use  an object of class Random.

This suggests that all these classes could be derived from a base class handling the random aspect of these classes.

Project 2 code is attached   aDie.h
#ifndef ADIE_H_
#define ADIE_H_
class aDie {
private:
int rollValue;
public:
aDie();
int getRoll();
};
#endif
aDie.cpp
#include “aDie.h”
#include
#include
aDie::aDie() {
rollValue = (rand() % 6) + 1;
}
int aDie::getRoll() {
return rollValue;
}
aCoin.h
#ifndef ACOIN_H_
#define ACOIN_H_
#include
using namespace std;
class aCoin {
private:
string flipResult;
public:
aCoin();
string getFlip();
};
#endif
aCoin.cpp
#include “aCoin.h”
#include
#include
aCoin::aCoin() {
int flipValue = (rand() % 2);
if(flipValue == 0) {flipResult = “H”;}
else {flipResult = “T”;}
}
string aCoin::getFlip() {
return flipResult;
}
aDeckOfCards.h
#ifndef ADECKOFCARDS_H_
#define ADECKOFCARDS_H_
#include
#include
using namespace std;
class aDeckOfCards {
private:
vector deck;
public:
aDeckOfCards();
string draw(int);
};
#endif
aDeckOfCards.cpp
#include
#include
#include
#include
#include
“aDeckOfCards.h”
aDeckOfCards::aDeckOfCards() {
string value[] = {“A”,”2″,”3″,”4″,”5″,”6″,”7″,”8″,”9″,”T”,”J”,”Q”,”K”};
string suit[] = {“-C”,”-D”,”-H”,”-S”};
for(int i=0; i

Still stressed from student homework?
Get quality assistance from academic writers!

Order your essay today and save 25% with the discount code LAVENDER