/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <iostream>
class Shape {
public:
virtual float area() { return 0;}
static float Total;
static int usuniete;
Shape (){
// std::cout<<
usuniete++;//<<std::endl;
}
virtual ~Shape (){
std::cout<<usuniete--<<std::endl;
}
};
class Circle : public Shape {
float r;
public:
Circle( float r) {
this->r = r;
Shape::usuniete++;
}
float area() { return r*r*3.14;}
virtual ~Circle (){
std::cout<<Shape::usuniete--<<std::endl;
}
};
class Rectangle : public Shape{
int firstSize;
int secondSize;
public:
Rectangle(int first, int second):firstSize(first), secondSize(second) {
Shape::usuniete++;
}
float area() { return firstSize*secondSize;}
virtual ~Rectangle (){
std::cout<<Shape::usuniete--<<std::endl;
}
};
using namespace std;
float Shape::Total=0;
int Shape::usuniete=0;
int main()
{
const int n=9;
Rectangle r1(3,5);
Rectangle r2(7,3);
Rectangle r3(6,8);
Circle c1(4);
Circle c2(2);
Shape* tab[n] = {&r1, &r2,&r3, &c1, &c2, new Rectangle(7,4), new Rectangle(9,7), new Circle(3), new Circle(4)};
for(int i=0; i<n; i++) {
tab[i] ->Total= tab[i]->area();
cout<<tab[i] ->Total<<endl;
}
for(int i=5; i<n; i++) {
delete tab[i];
}
cout<<endl;
return 0;
}