Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Program to overload a function area.
- #include<iostream.h>
- #include<conio.h>
- #include<math.h>
- void area(float);
- void area(float,float);
- void area(float,float,float);
- void main()
- {
- clrscr();
- int a;
- cout<<"Choose: "<<endl<<"1.Area of circle."<<endl<<"2.Area of rectangle"<<endl<<"3.Area of triangle: "<<endl;
- cin>>a;
- switch(a) {
- case 1: cout<<"Enter radius: "<<endl;
- int r;
- cin>>r;
- area(r);
- break;
- case 2: cout<<"Enter length and width: "<<endl;
- int l,w;
- cin>>l>>w;
- area(l,w);
- break;
- case 3: cout<<"Enter the lengths of 3 sides of triangle: "<<endl;
- int b,c,d;
- cin>>b>>c>>d;
- area(b,c,d);
- break;
- }
- getch();
- }
- void area(float r)
- {
- float area=3.14*r*r;
- cout<<"The area of circle of radius "<<r<<" is: "<<area;
- }
- void area(float l, float w)
- {
- float area=l*w;
- cout<<"The are of rectangle of length "<<l<<" and width "<<w<<" is: "<<area;
- }
- void area(float b, float c, float d)
- {
- float s=(b+c+d)/2;
- float area=sqrt(s*(s-b)*(s-c)*(s-d));
- cout<<"The area of triangle is: "<<area;
- }
Advertisement
Add Comment
Please, Sign In to add comment