The area of an arbitrary triangle can be computed using the formula area =[ s (
ID: 3631049 • Letter: T
Question
The area of an arbitrary triangle can be computed using the formula
area =[s(s - a)(s - b)(s - c)]
where a, b, and c are the lengths of the sides, and s is the semiperimeter.
s = (a + b + c)/2
Write a void function that computes the area and perimeter (not the semiperimeter) of a triangle based on the length of the sides. The function should use five parameters--three value parameters that provide the lengths of the edges and two reference parameters that store the computed area and perimeter. Make your function robust. Note that not all combinations of a, b, and c produce a triangle. Your function should produce correct results for legal data and reasonable results for illegal combinations.
Explanation / Answer
the void keyword specifies that the function does not return a value. When used for a function's parameter list, void specifies that the function takes no parameters. When used in the declaration of a pointer, void specifies that the pointer is "universal." #include #include #include using namespace std; void area(float a, float b, float c ) { float area; float s; s = ((a + b + c)/2); if ((a + b > c) && (b + c > a) && (a + c > b)) { area = sqrt(s*(s-a)*(s-b)*(s-c)); coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.