Question: C++ requirements Your program will read in the menu number as an unsigned int value . The menu item must be processed using a if

C++ requirements

Your program will read in the menu number as an unsigned int value .

The menu item must be processed using a if / else / else if statements.

The seconds value and all calculations need to be done using double values.

Failure to follow the C++ requirements could reduce the points received from passing the tests.

General overview

In this program you will be reading in the number of seconds and then calculating how far sound can travel in a specified medium in that many seconds.

The menu will have four items (the mediums will all be gasses at 0 degrees centigrade). Also, you will read in the number of seconds and will then calculate and output the number of meters (not feet) traveled in those seconds. The number of seconds should be in the range 0 to 30 seconds (including both 0 and 30). The seconds are allowed to have a fractional value (example, 2.5).

You may have to create variables to store intermediate values and you may need to set bool values to indicate that you have valid input values. You can then check the bool value or values later in your program.

When we get to functions you will learn a different way to get rid of having to write the same (or very similar) code multiple times.

The gasses you will use all assume the speed of sound (at 0 degrees centigrade). The meters traveled per second for each of these gasses is as follows:

Medium Speed (Meters per second)
Carbon Dioxide 258.0
Air 331.5
Helium 972.0
Hydrogen 1,270.0

So here is your menu. You need to read in one of 4 menu values (for 4 gasses).

Select the medium that sound is traveling through: 1 Carbon Dioxide 2 Air 3 Helium 4 Hydrogen 

Your program will then read in an unsigned int value for the menu item.

Use if / else / else if statements to process the menu value you have just read in. If the value is invalid (0, or greater than 4) display the following error message:

The menu value is invalid. Please run the program again. 

If the menu value is valid, read in the number of seconds that sound will travel in the medium selected. This will look as follows:

Enter time (in seconds) 

If the number of second is less than zero or greater than thirty output the message:

The time must be between 0.00 and 30.00 (inclusive) 

If the number of seconds is valid calculate distance traveled (in meters) in that time (here is some output for Air for 10 seconds)::

Air: 10.00 seconds Traveled 3315.000 meters 

Note that the output value for seconds is two digits of precision and the output for meters traveled is three digits of precision. All calculations must be done using double variables.

Here are two additional sample runs (with input):

Run 1:

1 23.7608 

Here is the output:

Select the medium that sound is traveling through: 1 Carbon Dioxide 2 Air 3 Helium 4 Hydrogen Enter time (in seconds) Carbon Dioxide: 23.76 seconds Traveled 6130.286 meters 

Run 2:

3 30.001 

Here is the output:

Select the medium that sound is traveling through: 1 Carbon Dioxide 2 Air 3 Helium 4 Hydrogen Enter time (in seconds) The time must be between 0.00 and 30.00 (inclusive)

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!