Compute area of a rectangle using overloaded functions. : Function Overloaded « Function « C++






Compute area of a rectangle using overloaded functions.

Compute area of a rectangle using overloaded functions.
 


#include <iostream>
using namespace std;

double rect_area(double length, double width)
{
  return length * width;
}

double rect_area(double length)
{
  return length * length;
}

int main()
{
  cout  << "10 x 5.8 rectangle has area: ";
  cout << rect_area(10.0, 5.8) << '\n';

  cout  << "10 x 10 square has area: ";
  cout << rect_area(10.0) << '\n';
  return 0;
}


           
         
  








Related examples in the same category

1.Functions differ in number of parametersFunctions differ in number of parameters
2.Overload abs() three waysOverload abs() three ways
3.Overload function: int and longOverload function: int and long
4.Create three functions called prompt( ) that perform this task for data of types int, double, and long
5.Overload function to accept integer or char * argumentOverload function to accept integer or char * argument
6.Overload the min() function.Overload the min() function.
7.Overload function: int and floatOverload function: int and float
8.function overloading between int and string type