#include <iostream>
#include <vector>
#include <memory>
class Shape {
public:
virtual double area() const = 0;
virtual ~Shape() = default;
};
class Rectangle : public Shape {
double width, height;
public:
Rectangle(double w, double h) : width(w), height(h) {}
double area() const override {
return width * height;
}
};
class Square : public Shape {
double side;
public:
Square(double s) : side(s) {}
double area() const override {
return side * side;
}
};
void printArea(const Shape& shape) {
std::cout << "Area: " << shape.area() << std::endl;
}
int main() {
Rectangle rect(3.0, 4.0);
Square sq(5.0);
printArea(rect);
printArea(sq);
std::vector<std::unique_ptr<Shape>> shapes;
shapes.push_back(std::make_unique<Rectangle>(2.0, 3.0));
shapes.push_back(std::make_unique<Square>(4.0));
for (const auto& s : shapes) {
printArea(*s);
}
return 0;
}