Question: Overview In this assignment, you are to write a program to calculate the perimeter and area of a triangle, given the lengths of the three

Overview

In this assignment, you are to write a program to calculate the perimeter and area of a triangle, given the lengths of the three sides. The user will be prompted to enter the three lengths.

Processing Requirements

First display a simple title and figure for the user to see. (See below.) Then prompt the user to enter each of the three numbers and accept them from the keyboard (three prompts and three inputs).

The area of a triangle whose three sides are given is equal to

 the square root of (p times (p - s1) times (p - s2) times (p - s3)) 

where

p is one-half of the perimeter, and

s1, s2, and s3 are the lengths of the three sides.

There is a C library function called sqrt() that will calculate the square root of a number. Suppose x is a variable with a (positive) value. Then the value of sqrt(x) is the square root of that value. So, for example, to print the square root of 5:

 cout << sqrt(5); 

Or to store the value of the square root of x into (a double variable) y:

 y = sqrt(x); 

In order to use the sqrt() function in your program, you must #include .

It is possible for the user to enter lengths that cannot form a triangle - for example, 6, 2, and 2 cannot form a closed triangle. If the expression (p times (p - s1) times (p - s2) times (p - s3)) is negative, then you do not have a triangle. So your program should first calculate this expression and then test it to see if it is zero or negative (do this before you use the sqrt()function). If it is zero or negative, display a message to the user to the effect that the three lengths given do not form a closed triangle. Do not calculate a perimeter or area. If the expression is positive, go ahead and calculate and display the perimeter and area.

Finally, allow the user to enter additional sets of values for additional triangles. Use a bottom-driven do...while loop. At the bottom of the loop, prompt the user to enter "y" or "n" according to whether additional examples are to be done.

Sample Output

A single run of the program (with valid values) should resemble the following:

Triangle Calculator * *** ***** ******* Enter the first side: 3 Enter the second side: 4 Enter the third side: 5 The perimeter is 12.00 The area is 6.00 Another (y/n)? n 

Other Notes

At the top of your C++ source code, include a documentation box similar to the one for Assignment 1.

Submit your source code (.cpp) file on Blackboard.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!