Write a program to calculate the area of circle, rectangle and square using function overloading.
#include<iostream>
using namespace std;
void area(float r)
{
cout<<"\n Area of circle is :";
float ans=3.14*r*r;
cout<<ans;
}
void area(int l,int w)
{
cout<<"\n Area of rectangle is: ";
int ans= l*w;
cout<<ans;
}
void area(int l)
{
cout<<"\n Area of square is: ";
int ans=l*l;
cout<<ans;
}
void main()
{
float r;
cout<<"\n Enter radius to find area of circle";
cin>>r;
area(r);
cout<<"\n Enter length and width for rectangle";
int l,w;
cin>>l>>w;
area(l,w);
cout<<"\n Enter length for square";
int l1;
cin>>l1;
area(l1);
}
#include<iostream>
using namespace std;
void area(float r)
{
cout<<"\n Area of circle is :";
float ans=3.14*r*r;
cout<<ans;
}
void area(int l,int w)
{
cout<<"\n Area of rectangle is: ";
int ans= l*w;
cout<<ans;
}
void area(int l)
{
cout<<"\n Area of square is: ";
int ans=l*l;
cout<<ans;
}
void main()
{
float r;
cout<<"\n Enter radius to find area of circle";
cin>>r;
area(r);
cout<<"\n Enter length and width for rectangle";
int l,w;
cin>>l>>w;
area(l,w);
cout<<"\n Enter length for square";
int l1;
cin>>l1;
area(l1);
}