Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

) Answer the following (Function Overloading): [1 marks] 1) Write and test a C++

ID: 3568505 • Letter: #

Question

) Answer the following (Function Overloading): [1 marks]
1) Write and test a C++ function (getArea()) that has three double parameters: a, b, and c that
represent the sides of a triangle. Let your function return -1 if the three parameters do not
represent a triangle, and return the area of the triangle otherwise.
Hint: A simple test for that a, b and c represent a triangle is by checking that the sum of any two
numbers is greater than the third.
To calculate the area, use Heron's formula

) Answer the following (Function Overloading): [1 marks] 1) Write and test a C++ function (getArea()) that has three double parameters: a, b, and c that represent the sides of a triangle. Let your function return -1 if the three parameters do not represent a triangle, and return the area of the triangle otherwise. Hint: A simple test for that a, b and c represent a triangle is by checking that the sum of any two numbers is greater than the third. To calculate the area, use Heron's formula If triangle has sides a, b, c and Semiperimeter = a + b + c/2 then Area of triangle ABC: root s(s - a)(s - b)(s - c) 2) Add an overloaded function that returns the area of a right-angled triangle. Hint: getArea() takes only two parameters, the base and height. 3) Add an overloaded function that returns the area of an equilateral triangle. Hint: getArea() takes only one parameter, side.

Explanation / Answer

I give three examples at the end. The output is

I am a beginner in C++.

#include <iostream>

using namespace std;
double getArea(double a,double b,double c)
{ double semip, area;
if ((a+b>c) and (a+c>b) and (b+c>a))
{semip=(a+b+c)/2;
area=sqrt(semip*(semip-a)*(semip-b)*(semip-c));
return area;}
else return -1;
}
double getArea(double a,double b)
{ double area;
area=a*b/2;
return area;
}
double getArea(double a)
{double area;
area=a*a*sqrt(3)/4;
return area;
}
int main()
{double result;
result=getArea(3.1,2.1,5.1);
cout<< "if positive the area is: "<<result<<endl;
result=getArea(2,3);
cout<< "the area of the right triangle is: "<<result<<endl;
result=getArea(6);
cout<< "the area of the equilateral triangle is: "<<result<<endl;
}