Answer to Question #263857 in C++ for Aashi

Question #263857

WAP to calculate and display the area of triangle, rectangle, square and



circle demonstrating the concept of function overloading.

1
Expert's answer
2021-11-10T03:01:03-0500
/* A program to implement function overloading in c++*/
#include<iostream>
using namespace std;
int area(int);
int area(int,int);
float area(float);
float area(float,float);
int main()
{
        int a,length,b;
        float radius,base,ht;
        cout<<"enter one side of the square";
        cin>>a;
        cout<<"enter length and breadth the rectangle:";
        cin>>length>>b;
        cout<<"enter the radius of the circle:";
        cin>>radius;
        cout<<"enter the base  and height of  the triangle:";
        cin>>base>>ht;
        cout<<"Area of square  = "<<area(a);
        cout<<"\nArea of rectangle  = "<<area(length,b);
    cout<<"\nArea of circle =  "<<area(radius);
    cout<<"\nArea of triangle =  "<<area(base,ht);
}
int area(int a)
{
    return(a*a);
}
int area(int length,int b)
{
    return(length*b);
}
float area(float radius)
{
    return(3.14*radius*radius);
}
float area(float base,float ht)
{
   return((base*ht)/2);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS