/******************************************************************************
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.
*******************************************************************************/
class Shape {
public:
virtual float area() { return 0;}
static float Total;
};
class Circle : public Shape {
float r;
public:
Circle( float r) {
this->r = r;
}
float area() { return r*r*3.14;}
};
class Rectangle : public Shape{
int firstSize;
int secondSize;
public:
Rectangle(int first, int second):firstSize(first), secondSize(second) { }
float area() { return firstSize*secondSize;}
};
#include <iostream>
using namespace std;
float Shape::Total=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<9; i++) {
delete tab[i];
}
cout<<endl;
return 0;
}