What Is The Program To Calculate Area Of Circle Square Rectangle Triangle Using Function Overloading In C++?

3

3 Answers

Florio Potter Profile
Florio Potter answered

Function overloading allows to use the same function name for different functions. It is used to enhance the readability of the program. You can change the number of arguments or have different data types of arguments to overload a function.

area() function is overloaded to calculate the area of triangle, rectangle and circle using function overloading.

#include<iostream>
#include<cstdlib>
using namespace std;

float area(float r)
{
return(3.14 * r * r);
}
float area(float b,float h)
{
return(0.5 * b * h);
}
float area(float l,float b)
{
return (l * b);
}
int main()
{
float b,h,r,l;
int ch;

do
{
cout<<"nn *****Menu***** n";
cout<<"n 1. Area of Circle";
cout<<"n 2. Area of Triangle";
cout<<"n 3. Area of Rectangle";
cout<<"n 4. Exit";
cout<<"nn Enter Your Choice : ";
cin>>ch;
switch(ch)
{
case 1:
{
cout<<"n Enter the Radius of Circle : ";
cin>>r;
cout<<"n Area of Circle : "<<area(r);
break;
}
case 2:
{
cout<<"n Enter the Base & Height of Triangle : ";
cin>>b>>h;
cout<<"n Area of Triangle : "<<area(b,h);
break;
}
case 3:
{
cout<<"n Enter the Length & Bredth of Rectangle : ";
cin>>l>>b;
cout<<"n Area of Rectangle : "<<area(l,b);
break;
}
case 4:
exit(0);
default:
cout<<"n Invalid Choice... ";
}
}while(ch!=4);
return 0;
}

If you want to help in C++ then you can get help from experts at CodeAvail-
Online Computer Science Assignment help

Anonymous Profile
Anonymous answered
#include
#include
#include
#define PI 3.14

class Area
{
private:
Int x,y;
float z;
public:
Void area(int);
void area(int,int);
void area(float);
};

void Area::area(int x) //FUNCTION DEFENITION OUTSIDE THE CLASS WITH ONLY //ONE ARGUMENT AS INTEGER DATA TYPE
{
int A;
A=x*x;
cout
Anonymous Profile
Anonymous answered
Area of circle,rectangle,triangle,square using function overloading c++ program

Answer Question

Anonymous