'Interface' for subclass
#include <iostream>
using namespace std;
class AreaClass {
public:
double height;
double width;
};
class Rectangle : public AreaClass {
public:
Rectangle(double h, double w);
double area();
};
class Isosceles : public AreaClass {
public:
Isosceles(double h, double w);
double area();
};
Rectangle::Rectangle(double h, double w)
{
height = h;
width = w;
}
Isosceles::Isosceles(double h, double w)
{
height = h;
width = w;
}
double Rectangle::area()
{
return width * height;
}
double Isosceles::area()
{
return 0.5 * width * height;
}
int main()
{
Rectangle rectangleObject(10.0, 5.0);
Isosceles isoscelesObject(4.0, 6.0);
cout << "Rectangle: " << rectangleObject.area() << endl;
cout << "Triangle: " << isoscelesObject.area() << endl;
return 0;
}
Related examples in the same category