Starting from:

$30

CS2400-Lab 3 Triangle Area Solved

Step 1: Set up a separate directory for this lab
First log on and open a terminal window to create a separate directory to work on
this lab. Issue the following commands to create a directory:
a. Type cd 2400/Labs
b. Type mkdir lab3
c. Type cd lab3
Step 2: Area of a triangle:
Write a program that calculates the area of a triangle using the lengths of the sides
(Heron’s formula). The program should read (input) the three sides of the triangle
and check if the triangle is valid first. A triangle is valid if the sum of any two sides is
greater than the third. Your program should run continuously until the user enters
a negative number for any of the sides. (Hint: use a sentinel loop)
Display an error message if the triangle is not valid.
Display the area using two decimal places.
The area of the triangle can be calculated using the following formulas:
� = ����1 + ����2 + ����3
2 ���� = -�(� − ����1)(� − ����2)(� − ����3)
Try the following input values:
• 5, 2, 1 (Invalid)
• 1, 1, 3 (invalid)
• 1, 3, 1 (invalid)
• 5, 5, 5 (Valid, 10.83)
• 3, 4, 5 (Valid, 6.00)
• 9, 10, 10 (Valid, 40.19)
• 0, 0, 0 (quits the program)

More products