Q. Write a program in c++ using function overloading to find perimeter of square and perimeter of rectangle.
pls type the full program
Answers
Answered by
0
Function Overloading
Explanation:
//set the header file
#include <iostream>
//using namespace
using namespace std;
//overload the function
//define a function that print perimeter of the rectangle
void perimeter(int l, int b)
{
cout << "Perimeter of the rectangle: " << 2*(l+b) << endl;
}
//define a function that print perimeter of the square
void perimeter(int side)
{
cout << "Perimeter of the square: " << side*4;
}
//define the main method
int main()
{
//call the function by passing the arguments
perimeter(24, 22);
//call the function by passing an argument
perimeter(23);
return 0;
}
The following are the description of the program.
- Firstly, define the required header file and using the namespace.
- Then, define a function 'perimeter()' and pass two integer data type arguments 'l' for length and 'b' for the breadth of the rectangle, it prints the perimeter of the rectangle.
- Then, overloading the function 'perimeter()' and pass an integer data type argument 'side' for the sides of the square, it prints the perimeter of the square.
- Finally, define the main method that calls the following functions by passing arguments in it.
Learn More:
https://brainly.in/question/5985607
Similar questions