Question: Must Be Coded in C++ Problem B: Triangle-tastic (20 points) Say you want to enter a number of triangles and want to find the average

Must Be Coded in C++

Problem B: Triangle-tastic (20 points)

Say you want to enter a number of triangles and want to find the average area of them all. You input a triangle by typing t then entering the base and height of the triangle. When you are done, type q to quit. The program should then display the average area for all triangles entered.

The area of a triangle for base b and height h is:

Area = Must Be Coded in C++ Problem B: Triangle-tastic (20 points) Say you

Your program should check for three special cases:

(1) No triangles input at all. Rather than displaying an average area of 0 (zero), say No triangles.

(2) If you tell it anything other than t or q, ask it to Please repeat that and continue the program normally.

(3) If the triangle is invalid, meaning a non-positive base or height (such as a height 0 triangle is not a triangle, but rather a line). Just like case (2) ask them to repeat the whole command (starting from t or q).

Example 1

(user input is underlined, two valid triangles of areas: 2 and 8):

Please enter a command

t 2 2

Please enter a command

c

Unknown command, try again

Please enter a command

t4 4

Please enter a command

t 0 4

Invalid triangle, try again

Please enter a command

t 4 0

Invalid triangle, try again

Please enter a command

q

Average area:

5

Example 2 (user input is underlined):

Please enter a command:

q

No triangles

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!