Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 = image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_step_2

Step: 3

blur-text-image_step3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DB2 11 The Database For Big Data And Analytics

Authors: Cristian Molaro, Surekha Parekh, Terry Purcell, Julian Stuhler

1st Edition

ISBN: 1583473858, 978-1583473856

More Books

Students also viewed these Databases questions