Write two generic functions (overloaded) named area(). Create function template for the first area() function that it is able to receive the radius of a circle as its parameter and returns half of the calculated area of circle as of same data type. Similarly, create function template for the second area() function that it is able to receive two parameters as length and width of a rectangle and returns the triple of the calculated area of rectangle as of same data type.
/******************************************************************************
Write two generic functions (overloaded) named area().
Create function template for the first area() function that it is able to
receive the radius of a circle as its parameter and returns half of the calculated
area of circle as of same data type. Similarly, create function template for the second
area() function that it is able to receive two parameters as length and width of a rectangle
and returns the triple of the calculated area of rectangle as of same data type.
*******************************************************************************/
#include <iostream>
using namespace std;
template <class T>
T area (T a, T b)
{
return (3*(a*b));
}
double area (double r)
{
return (0.5*(3.142*r*r));
}
int main()
{
cout<<area<int>(15,7)<<endl;
cout<<area(14);
return 0;
}
Comments
Leave a comment