Write, test, and debug a program that prompts the user for 3 sides of two triangles. Your program will be written using a Triangle class and will have 2 Triangle objects (variables/instances of the class).
You will need to write a method (member function) that saves those sides to private object variables, write another method(s) to return the side(s), write another method to return the perimeter, write another method to return the area. This means you will have a minimum of 4 methods in your program, you might have more depending on how you write the methods that save/return the sides.
Perimeter: a + b + c // triangle sides are a, b, c
Area:
#include // you will need to include this for the square root function
sqrt(((a+b+c)/2)*(((a+b+c)/2)-a)*(((a+b+c)/2)-b)*(((a+b+c)/2)-c)); // Heron's Formula
Example program run:
This program will take the 3 sides of two triangles and calculate the perimeter and area
Please enter 3 sides of triangle 1: 16 14 10.5
Please enter 3 sides of triangle 2: 6 7.5 9
The triangle 1
with sides of 16, 14, 10.5
has a perimeter of 40.5
and has an area of 72.4185
The triangle 2
with sides of 6, 7.5, 9
has a perimeter of 22.5
and has an area of 22.3235