sahajjain01

Overload a function area.

Mar 30th, 2014
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. //Program to overload a function area.
  2. #include<iostream.h>
  3. #include<conio.h>
  4. #include<math.h>
  5.  
  6. void area(float);
  7. void area(float,float);
  8. void area(float,float,float);
  9.  
  10. void main()
  11. {
  12.     clrscr();
  13.     int a;
  14.     cout<<"Choose: "<<endl<<"1.Area of circle."<<endl<<"2.Area of rectangle"<<endl<<"3.Area of triangle: "<<endl;
  15.     cin>>a;
  16.     switch(a) {
  17.     case 1: cout<<"Enter radius: "<<endl;
  18.         int r;
  19.         cin>>r;
  20.         area(r);
  21.         break;
  22.  
  23.     case 2: cout<<"Enter length and width: "<<endl;
  24.         int l,w;
  25.         cin>>l>>w;
  26.         area(l,w);
  27.         break;
  28.  
  29.     case 3: cout<<"Enter the lengths of 3 sides of triangle: "<<endl;
  30.         int b,c,d;
  31.         cin>>b>>c>>d;
  32.         area(b,c,d);
  33.         break;
  34.     }
  35.     getch();
  36. }
  37.  
  38. void area(float r)
  39. {
  40.     float area=3.14*r*r;
  41.     cout<<"The area of circle of radius "<<r<<" is: "<<area;
  42. }
  43. void area(float l, float w)
  44. {
  45.     float area=l*w;
  46.     cout<<"The are of rectangle of length "<<l<<" and width "<<w<<" is: "<<area;
  47. }
  48. void area(float b, float c, float d)
  49. {
  50.     float s=(b+c+d)/2;
  51.     float area=sqrt(s*(s-b)*(s-c)*(s-d));
  52.     cout<<"The area of triangle is: "<<area;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment