C++ Program to overload a Function area

How to write a (C++ function overloading program)  C++ Program to overload a function area ?


Search Results Simple Program for Function Overloading Using C++ C++ Program to overload a function area C++ function overloading programs Function Overloading in Classes in C++ C++ Overloading and Operator Overloading Function Overloading C++  C++ program to swap two variables using function overloading Find the Area of shapes using function overloading C++ Function Overloading
C++ Program to overload a Function area



Solution:
//Program to overload a function area.
//C++ function overloading program.
#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;
}

This C++ Program to overload a function area.


Learn More :