27 lines
603 B
C++
27 lines
603 B
C++
/// @file
|
|
/// @brief Task1: simple hierarchy to be used in task1.main.cpp
|
|
|
|
#pragma once
|
|
|
|
#include <numbers> // std::numbers::pi
|
|
|
|
namespace task1 {
|
|
|
|
struct Interface {
|
|
double virtual area() const = 0;
|
|
virtual ~Interface() {}
|
|
};
|
|
|
|
struct Circle : Interface {
|
|
Circle(double radius) : radius(radius) {}
|
|
double radius;
|
|
double virtual area() const final override { return std::numbers::pi * radius * radius; }
|
|
};
|
|
|
|
struct Square : Interface {
|
|
Square(double length) : length(length) {}
|
|
double length;
|
|
double virtual area() const final override { return length * length; }
|
|
};
|
|
|
|
} // namespace task1
|