Polymorphism and Inheritance Shape.h class Shape {             string color;             bool filled; public:             Shape();             Shape(string, bool);             string getColor();             bool isFilled();             void setColor(string);             void setFilled(bool);             string toString(); //virtual string toString(); }; Rectangle.h class...

80.2K

Verified Solution

Question

Programming

Polymorphism and Inheritance

Shape.h

class Shape {

           string color;

           bool filled;

public:

           Shape();

           Shape(string, bool);

           string getColor();

           bool isFilled();

           void setColor(string);

           void setFilled(bool);

           string toString();

//virtual string toString();

};

Rectangle.h

class Rectangle : public Shape {

           double length;

           double width;

public:

           Rectangle();

           Rectangle(double, double);

           Rectangle(double, double, string, bool);

           double getLength();

           double getWidth();

           void setLength(double);

           void setWidth(double);

           double getArea();

           double getPerimeter();

printShape() function prototypes:

void printShape(Shape); or

void printShape(Shape &);

^^test which works correctly

Make a Rectangle class and a Triangle class that extend Shapeclass

^^not sure how to do this

the main that has to be used

int main() {

Shape s;

Rectangle r(5,6, \"red\", true);

Triangle t(6, 10, \"blue\", true);

printShape(s);

Shape s1(\"blue\", false);

printShape(s1);

//add virtual and pass the object by reference

printShape(r);

printShape(t);

return 0;

}

the instances need to be created and printShape() method needsto be called

triangle formula used is =1/2base*height

Answer & Explanation Solved by verified expert
4.3 Ratings (542 Votes)
The C code for the above problem statement is as follows include using namespace std    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students