Starting from:

$30

COP3014-Foundations of Computer Science Assignment #4


COP3014-Foundations of Computer Science Assignment #4
In this assignment, you will write a program called “all_area_semi.cpp” that
computes the area of an arbitrary triangle. Use the following formula:
π‘Žπ‘Žπ‘Žπ‘Žπ‘Žπ‘Žπ‘Žπ‘Ž = √𝑠𝑠(𝑠𝑠 − π‘Žπ‘Ž)(𝑠𝑠 − 𝑏𝑏)(𝑠𝑠 − 𝑐𝑐)
where a, b and c are the lengths of the sides, and s is the semiperimeter.
s = (a + b + c) / 2
Include a void function call “Compute” that computes the area and perimeter of a
triangle based on the length of the sides. The function should use five parameters –
three call by value parameters (a, b, c) that provide the lengths of the edges and two
call by reference parameters (area, semiperimeter) that stores the computed area and
perimeter.
Make your function robust. The function “Compute” should be called from your
main program. You must print the computed area and semiperimeter rounded to the
nearest hundredths. In main you should declare the necessary variables and include a
while loop asking the user if he/she would like to continue computing area and
semiperimeters.
Note that not all combinations of a, b, and c produce a triangle. Remember, the
sum of any two sides of a triangle must be greater than the third side. You must
make sure that the lengths of the sides of the triangle entered by the user are
valid; if not valid lengths, you should let the user know by printing a message
stating that the lengths are invalid, and then prompt the user if he/she would
like to continue computing area and semiperimeters. Your function should
produce correct results for legal data and reasonable results for illegal combinations.
You may implement more functions if you find it necessary. Please start the
assignment ASAP and ask questions to make sure you understand what you must do.
Remember to follow all style rules and to include all necessary documentation
(consistent, indentation, proper variable names, pre/post condition, program header,
function headers, and so forth.)
2
Consider the following skeleton as a hint:
//include necessary libraries
using namespace std;
//include function prototypes
//void Compute (format parameters go here)
//{
//}
int main( )
{
//declare variables a, b, c,area, and semiperimeter
//declare variable for while loop
//while loop
//begin while loop
//call Computer
//end while loop return 0;
}
Sample Calculations:
Side a Side b Side c Semi Area
9 9 9 13.50 35.07
10 20 30 Invalid Invalid
5 7 9 10.50 17.41
2 4 5 5.50 3.80

More products