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 ;
Shapestring lineColor, string fillColor: lineColorlineColor fillColorfillColor
void setLineColorstring lineColor thislineColor lineColor;
void setFillColorstring fillColor thisfillColor fillColor;
string getLineColor return lineColor;
string getFillColor return fillColor;
;
class Rectangle: public Shape
private:
double width, height;
public:
Rectanglestring lineColor, string fillColor, double width, double height:
ShapelineColor fillColor widthwidth heightheight
double area
return width height;
;
class Circle: public Shape
private:
double radius;
public:
Circlestring lineColor, string fillColor, double radius:
ShapelineColor fillColor radiusradius
double area
return radius radius;
;
int main
vector toyBox;
What is going on here?
makeunique make a new object that is pointed to be a smart pointer
Rectangle is the class of object that is being created
are the arguments to the constructor
toyBox.pushbackmakeuniqueab;
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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
