
#include <iostream>
using namespace std;
const double PI = 3.1415926;
class Shape
{
public:
virtual double getArea() const = 0;
Shape() {}
~Shape() {}
};
class Rectangle :public Shape {
public:
Rectangle() { length = 0.0; width = 0.0; }
~Rectangle() {}
Rectangle(double length, double width) :length(length), width(width) {}
virtual double getArea() const{
return length * width;
}
private:
double length, width;
};
class Circle :public Shape {
public:
Circle() { radius = 0.0; }
Circle(double radius) :radius(radius) {}
~Circle() {}
virtual double getArea() const{
return radius * PI * radius;
}
private:
double radius;
};
class Total {
public:
Total(Shape* shape1, Shape* shape2) :shape1(shape1), shape2(shape2) {}
double sumArea() {
return shape1->getArea() + shape2->getArea();
}
private:
Shape* shape1;
Shape* shape2;
};
int main()
{
Rectangle r(3.0 ,2.0);
Circle c(1.0);
Total t(&r, &c);
std::cout << t.sumArea();
}