write a method named area with one double parameter named radius. The method needs to return a double value that represents the area of a circle. If the parameter radius is negative, Then return -1.0 to represent an invalid value
write another overloaded method with 2 parameters side1 and side2 (both doubles) where side1 and side2 represent the sides of a rectangle. The method needs to return an area of a rectangle. If either or both parameters is /are a negative return -1.0 to indicate an invalid value
#include<iostream>
using namespace std;
double area(double);
double area(double,double);
int main()
{
double circle = area(10.0);
cout<<"Area of circle is " << circle<<endl;
double rectangle = area(5.0,7.0);
cout<<"Area of rectangle is "<<rectangle<<endl;
return 0;
}
double area(double radius)
{
if (radius<0)
return -1.0;
else
return 3.14*radius*radius;
}
double area(double side1,double side2)
{
if (side1<0 || side2<0)
return -1;
else
return side1*side2;
}
Get Answers For Free
Most questions answered within 1 hours.