Write a program to implement area of geometrical figures

#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<iomanip.h>
const float pi=3.1416;
class shape
{
    public:
       virtual void getdata()=0;
       virtual float area()=0;
};
class square : public shape
{
   private:
      float side;
   public:
     void getdata()
     {
       cout<<"\nType Value of side:";
       cin>>side;
     }
     float area()
     {
    return side*side;
     }
};
class triangle : public shape
{
   private:
     float a,b,c;
   public:
     void getdata()
     {
    cout<<"\nType Value of a:";
    cin>>a;
    cout<<"\nType Value of b:";
    cin>>b;
    cout<<"\nType Value of c:";
    cin>>c;
     }
     float area()
     {
    float s=(a+b+c)/2.0;
    return sqrt(s*(s-a)*(s-b)*(s-c));
     }
};
class circle : public shape
{
   private:
      float r;
   public:
      void getdata()
      {
      cout<<"\nType Value of radius r:";
      cin>>r;
       }
       float area()
       {
     return pi*r*r;
       }
};
void main()
{
   square S;
   triangle T;
   circle C;
   clrscr();
   cout<<setprecision(2);
   cout<<"\nSquare Input :\n";
   S.getdata();
   cout<<"Area="<<S.area()<<endl;
   cout<<"\nTriangle Inputs:\n";
   T.getdata();
   cout<<"Area="<<T.area()<<endl;
   cout<<"\nCircle Input :\n";
   C.getdata();
   cout<<"Area="<<C.area()<<endl;
   getch();
}

No comments:

Post a Comment