Answer to Question #263859 in C++ for Aashi

Question #263859

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



demonstrating the concept of function overloading

1
Expert's answer
2021-11-11T17:38:56-0500
#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 base,ht;
 cout<<"Enter one side of the square";
 cin>>a;
 cout<<"Enter length the rectangle:";
 cin>>length;
 cout<<"Enter  breadth the rectangle:";
 cin>>b;
 cout<<"Enter the height of the triangle:";
 cin>>ht;
 cout<<"Enter the base of the triangle:";
 cin>>base;
 cout<<"Area of square = "<<area(a);
 cout<<"\nArea of rectangle = "<<area(length,b);
 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 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