#include<iostream.h>
#include<math.h>
class Figure{
public:
virtual double getArea()=0;
};
class Rectangle:public Figure{
protected:double height,width;
public:
Rectangle(double h=0,double w=0){height=h;width=w;}
double getArea(){return height*width;}
};
class Square:public Figure{
protected:double width;
public:Square(double w=0){width=w;}
double getArea(){return width*width;}
};
class Triangle:public Figure{
protected:double a,b,c;
public:Triangle(double a1=0,double b1=0,double c1=0){a=a1;b=b1;c=c1;}
double getArea(){double s=(a+b+c)/2.0;return sqrt(s*(s-a)*(s-b)*(s-c));}
};
void main()
{Figure *fig[3]={new Triangle(2,3,3),new Rectangle(5,8),new Square(6)};
for(int i=0;i<3;i++)
cout<<"figure["<<i<<"] area="<<fig[i]->getArea()<<endl;
}
#include<math.h>
class Figure{
public:
virtual double getArea()=0;
};
class Rectangle:public Figure{
protected:double height,width;
public:
Rectangle(double h=0,double w=0){height=h;width=w;}
double getArea(){return height*width;}
};
class Square:public Figure{
protected:double width;
public:Square(double w=0){width=w;}
double getArea(){return width*width;}
};
class Triangle:public Figure{
protected:double a,b,c;
public:Triangle(double a1=0,double b1=0,double c1=0){a=a1;b=b1;c=c1;}
double getArea(){double s=(a+b+c)/2.0;return sqrt(s*(s-a)*(s-b)*(s-c));}
};
void main()
{Figure *fig[3]={new Triangle(2,3,3),new Rectangle(5,8),new Square(6)};
for(int i=0;i<3;i++)
cout<<"figure["<<i<<"] area="<<fig[i]->getArea()<<endl;
}