#include <iostream>
#include <vector>
#include <memory>
#include <math.h>
using namespace std;
class Shape {
float x, y;
public:
virtual float area() = 0;
};
class Circle : public Shape {
float radius;
public:
Circle(float radius) : radius{radius} { }
virtual float area() {
return M_PI * radius * radius;
}
};
class Rect : public Shape {
float width;
float height;
public:
Rect(float width, float height) : width{width}, height{height} { }
virtual float area() {
return width * height;
}
};
int main()
{
vector<unique_ptr<Shape>> shapes;
shapes.push_back(make_unique<Circle>(5));
shapes.push_back(make_unique<Rect>(4,6));
float total_area = 0;
for(auto&& shape: shapes) {
total_area += shape->area();
}
cout << "Total area is " << total_area << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8bWVtb3J5PgojaW5jbHVkZSA8bWF0aC5oPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmNsYXNzIFNoYXBlIHsKICAgIGZsb2F0IHgsIHk7CnB1YmxpYzoKICAgIHZpcnR1YWwgZmxvYXQgYXJlYSgpID0gMDsKfTsKCmNsYXNzIENpcmNsZSA6IHB1YmxpYyBTaGFwZSB7CiAgICBmbG9hdCByYWRpdXM7CnB1YmxpYzoKICAgIENpcmNsZShmbG9hdCByYWRpdXMpIDogcmFkaXVze3JhZGl1c30geyB9CiAgICAKICAgIHZpcnR1YWwgZmxvYXQgYXJlYSgpIHsKICAgICAgcmV0dXJuIE1fUEkgKiByYWRpdXMgKiByYWRpdXM7CiAgICB9Cn07CgpjbGFzcyBSZWN0IDogcHVibGljIFNoYXBlIHsKICAgIGZsb2F0IHdpZHRoOwogICAgZmxvYXQgaGVpZ2h0OwpwdWJsaWM6CglSZWN0KGZsb2F0IHdpZHRoLCBmbG9hdCBoZWlnaHQpIDogd2lkdGh7d2lkdGh9LCBoZWlnaHR7aGVpZ2h0fSB7IH0KCQogICAgdmlydHVhbCBmbG9hdCBhcmVhKCkgewogICAgICByZXR1cm4gd2lkdGggKiBoZWlnaHQ7CiAgICB9Cn07C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