C++ Program – Function Overloading

by Nideesh C on May 2, 2011 · 0 comments

in C++




//Downloaded From theonlinetutorials.com
//Function Overloading to calculate the area of a circle,rectangle and triangle
 #include<iostream.h>
 #include<conio.h>
 #include<stdio.h>
 #include<math.h>
void area(float r)
 {
 float area;
 cout<<"\nArea:"<<(3.14*r*r);
 }
void area(float l,float b)
 {
 float area ;
 cout<<"\nArea:"<<l*b;
 }
void area(float x,float y,float z)
 {
 float s;
 s=(x+y+z)/2;
 cout<<"\nArea:"<<sqrt(s*s-x*s-y*s-z);
 }
 void main()
 {
 clrscr();
 int opt,x,y,z,l,b,r;
 char ch='y';
 while(ch=='y'||ch=='Y')
 {
 cout<<"\nMENU\n\n1.Area of circle\n2.Area of Rectangle\n3.Area of Triangle";
 cout<<"\nEnter your Option:";
 cin>>opt;
 switch(opt)
 {
 case 1:cout<<"\nEnter radius of the circle:";
 cin>>r;
 area(r);
 break;
 case 2:cout<<"\nEnter the length and breadth of the rectangle:";
 cin>>l>>b;
 area(l,b);
 break;
 case 3:cout<<"\nEnter side 1:";
 cin>>x;
 cout<<"\nEnter side 2:";
 cin>>y;
 cout<<"\nEnter side 3:";
 cin>>z;
 area(x,y,z);
 break;
 default:cout<<"Wrong Option!!";
 }
 cout<<"\nDo you wnat to continue?(Y/N):";
 cin>>ch;
 }
 getch();
 }



Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. C program to accept a figure code and find the ares of different geometrical figures such as circle, square, rectangle etc using switch
  2. C++ program – Swap two variables using function overloading
  3. C++ program – Perform arithmetic operations of two complex numbers using operator overloading
  4. C++ Program – Calculator
  5. C++ Program – Binary File Handling

Leave a Comment

Previous post:

Next post: