Friday, September 26, 2014

WAP with classes to represent circle, rectangle and triangle. Each classes should have data members to represent the actual objects and member functions to read and display objects , find perimeter and area of the object with other useful functions. Use the classes to create objects in your program.

#include
#include
#include
#define PI 3.14159
class circle
{
      private:
      float r,a1,p1;
      public:
      void get()
      {
                  cout<
                  cin>>r;
      }
      void show()
      {
                  cout<
                  cout<
      }
      friend float a(float r);
      friend float b(float r);
};
class rectangle
{
      private:
      float l,b;
      public:
      void get()
      {
                  cout<
                  cin>>l>>b;
      }
      void show()
      {
                  cout<
                  cout<
      }
      friend float c(float l,float b);
      friend float d(float l,float b);
};
class triangle
{
      private:
      float s,s1,s2,s3,a3,p3;
      public:
      void get()
      {
                  cout<
                  cin>>s1>>s2>>s3;
      }
      void show()
      {
                  cout<
                  cout<
      }
      friend float e(float s,float s1,float s2,float s3);
      friend float f(float s,float s1,float s2,float s3);

};
float a(float r)
{
      return (PI*r*r);
}
float b(float r)
{
      return (2*PI*r);
}
float c(float l,float b)
{
      return (l*b);
}
float d(float l,float b)
{
      return (2*(l+b));
}
float e(float s,float s1,float s2,float s3)
{
      s=(s1+s2+s3)/2;
      return (pow((s-s1)*(s-s2)*(s-s3),1/2));
}
float f(float s,float s1,float s2,float s3)
{
      return (s1+s2+s3);
}


void main()
{
      clrscr();
      circle c;
      c.get();
      c.show();
      rectangle r;
      r.get();
      r.show();
      triangle t;
      t.get();
      t.show();
      getch();

}

No comments:

Post a Comment