Friday, 10 January 2014

1-A program in C++ using classes to calculate the area of a circle , a rectangle and a triangle on user’s choice.

#include<iostream.h>
#include<conio.h>
class ar
{private:float a;
 public:ar()
            {a=0;}
            ~ar()
            {a=0;}
            void area(float x)
            {a=3.4142*x*x;
            }
            void area(float x,float y)
            {a=x*y;
            }
            void area(float x,float y,int u)
            {a=(x*y)/2;
            }
            void showarea()
            {cout<<"\n the area of the figure is:"<<a;
            }
}n1;
void main()
{int n=0,i;
 float h,b,r;
 clrscr();
 while(n!=1)
 {clrscr();
  cout<<"\n enter the choice of figure whose area is to be calculated \n1-circle\n2-rectangle\n3-triangle\nenter your choice:";
  cin>>i;
  switch(i)
  {case 1:cout<<"\nfor circle\n";
              cout<<"\n enter the radius of the circle:";
              cin>>r;
              n1.area(r);
              n1.showarea();
              break;
   case 2:cout<<"\nfor rectangle\n";
              cout<<"\n enter the  length of the rectangle:";
              cin>>h;
              cout<<"\n enter the width of the rectangel:";
              cin>>b;
              n1.area(h,b);
              n1.showarea();
              break;
   case 3:cout<<"\nfor triangle\n";
              cout<<"\n enter the  height of the triangle:";
              cin>>h;
              cout<<"\n enter the base length of the triangel:";
              cin>>b;
              n1.area(h,b,1);
              n1.showarea();
              break;
   default:cout<<"\n sorry you have entered wrong choice\n";
  }
  cout<<"\n do you want to continue (yes:0,no:1):";
  cin>>n;
 }
 getch();
}



No comments:

Post a Comment