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
Get step-by-step solutions from verified subject matter experts
