Overload the function find_perimeter() with one, two and three float parameters.
The function with one parameter is used to return the perimeter of the circle. The function with two parameters is used to return the perimeter of the rectangle. The function with three parameters is used to return the perimeter of the triangle. Write the necessary C++ program to test the functionality of above functions.
#include<iostream>
#include<conio.h>
using namespace std;
// The function with one parameter is used to return the perimeter of the circle.
float find_perimeter(float r){
const float PI=3.14;
return 2*PI*r;
}
// The function with two parameters is used to return the perimeter of the rectangle.
float find_perimeter(float l,float b){
return 2*(l+b);
}
// The function with three parameters is used to return the perimeter of the triangle.
float find_perimeter(float side1,float side2,float side3){
return side1+side2+side3;
}
int main()
{
float radius;
float length;
float width;
float side1;
float side2;
float side3;
cout<<"Enter the radius of the circle: ";
cin>>radius;
cout<<"\nPerimeter of the circle: "<<find_perimeter(radius)<<endl;
cout<<"\nEnter the length of the rectangle: ";
cin>>length;
cout<<"Enter the width of the rectangle: ";
cin>>width;
cout<<"\nPerimeter of the rectangle: "<<find_perimeter(length,width)<<endl;
cout<<"\nEnter the side 1 of the triangle:";
cin>>side1;
cout<<"Enter the side 2 of the triangle: ";
cin>>side2;
cout<<"Enter the side 3 of the triangle: ";
cin>>side3;
cout<<"Perimeter of Triangle: "<<find_perimeter(side1,side2,side3)<<endl;
cin>>side1;
return 0;
}
Comments
Leave a comment