WAP to calculate and display the perimeter of triangle, rectangle and square
demonstrating the concept of function overloading
#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);
}
Comments
Leave a comment