Question: #include #include #include using namespace std; class Shape { private: string lineColor; string fillColor; public: virtual double area ( ) { return 0 ; }

#include
#include
#include
using namespace std;
class Shape {
private:
string lineColor;
string fillColor;
public:
virtual double area(){
return 0;
}
Shape(string lineColor, string fillColor): lineColor(lineColor), fillColor(fillColor){}
void setLineColor(string lineColor){ this->lineColor = lineColor; }
void setFillColor(string fillColor){ this->fillColor = fillColor; }
string getLineColor(){ return lineColor; }
string getFillColor(){ return fillColor; }
};
class Rectangle: public Shape {
private:
double width, height;
public:
Rectangle(string lineColor, string fillColor, double width, double height):
Shape(lineColor, fillColor), width(width), height(height){}
double area(){
return (width * height);
}
};
class Circle: public Shape {
private:
double radius;
public:
Circle(string lineColor, string fillColor, double radius):
Shape(lineColor, fillColor), radius(radius){}
double area(){
return 3.14* radius * radius;
}
};
int main(){
vector> toyBox;
/**
* What is going on here?
* make_unique make a new object that is pointed to be a smart pointer
* Rectangle is the class of object that is being created
*(10,10) are the arguments to the constructor
**/
toyBox.push_back(make_unique("a","b",10,10));
Take the above toybox example and make the following changes:
Add Box and Triangle as derived classes
-
similar to what you did in the last module.
Add a new virtual function for number of sides and add that to all of the derived classes: Make a rule of how that would work for circle.
Show examples of all of these derived classes in the main program.
Explain at the end of your code how the computer knows which type of object is being taken out of the toybox.
Remember to put comments in your program along with name
/
date
/
e
-
mail and a program overview at the top of the program.

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 Programming Questions!