1 #ifndef SHAPES_H 2 #define SHAPES_H 3 4 namespace shapes { 5 6 int constructor_count = 0; 7 int destructor_count = 0; 8 9 class Shape 10 { 11 public: 12 virtual float area() const = 0; Shape()13 Shape() { constructor_count++; } ~Shape()14 virtual ~Shape() { destructor_count++; } 15 }; 16 17 class Rectangle : public Shape 18 { 19 public: Rectangle()20 Rectangle() { } Rectangle(int width,int height)21 Rectangle(int width, int height) 22 { 23 this->width = width; 24 this->height = height; 25 } 26 area()27 float area() const { return width * height; } 28 int width; 29 int height; 30 method(int arg)31 int method(int arg) { 32 return width * height + arg; 33 } 34 35 }; 36 37 class Square : public Rectangle 38 { 39 public: Square(int side)40 Square(int side) : Rectangle(side, side) { this->side = side; } 41 int side; 42 }; 43 44 class Ellipse : public Shape { 45 public: Ellipse(int a,int b)46 Ellipse(int a, int b) { this->a = a; this->b = b; } area()47 float area() const { return 3.1415926535897931f * a * b; } 48 int a, b; 49 }; 50 51 class Circle : public Ellipse { 52 public: Circle(int radius)53 Circle(int radius) : Ellipse(radius, radius) { this->radius = radius; } 54 int radius; 55 }; 56 57 class Empty : public Shape { 58 public: area()59 float area() const { return 0; } 60 }; 61 62 } 63 64 #endif 65