Question
c++, In the classroom use the files bellow as a starting point for creating an inherited class called Box from the class Rectangle. It will
c++, In the classroom use the files bellow as a starting point for creating an inherited class called Box from the class Rectangle. It will enhance the Rectangle class by adding a 3rd dimension to the shape.
#include
using namespace std;
class Polygon {
protected:
int width, height;
public:
void set_values(int a, int b)
{
width = a; height = b;
}
virtual int area()
{
return 0;
}
};
class Rectangle : public Polygon {
public:
int area()
{
return width * height;
}
};
class Triangle : public Polygon {
public:
int area()
{
return (width * height / 2);
}
};
int main() {
Rectangle rect;
Triangle trgl;
Polygon poly;
Polygon * ppoly1 = ▭
Polygon * ppoly2 = &trgl;
Polygon * ppoly3 = &poly;
ppoly1->set_values(4, 5);
ppoly2->set_values(4, 5);
ppoly3->set_values(4, 5);
cout << ppoly1->area() << ' ';
cout << ppoly2->area() << ' ';
cout << ppoly3->area() << ' ';
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started