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.

This part of lesson 5 is going to start a little bit differently. In part two you will be creating a program that looks a lot like lesson 5 part 1. 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).

This next one is important. Unlike part one, in part two you MUST use if / else statements to check your menu values (in part one you used a switch statement). We are making you change the menu processing so you can see the way it would be done with a switchstatement (part 1) and with if statements (part 2).

Finally, you should look at part one and see if you are duplicating code. If you are, try and reduce the duplicated code. 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:

C++ requirements Your program will read in the menu number as an

unsigned int value . The menu item must be processed using a

Style points

The 10 points for coding style will be based on the following guidelines:

Comments at the start of your programming with a brief description of the purpose of the program.

Comments throughout your program

If you have any variables they must have meaningful names.

Medium Speed (Meters per second) Carbon Dioxide 258.0 331.5 972.0 Air Helium Hydrogen 1,270.0 If you look at part 1 you will see that the speed for Air is different. Why is that? The answer is next, so formulate your answer before you go to the next paragraph. The speeds in part 1 are in feet per second. The speeds in part 2 are in meters per second. You really need to read the instructions to make sure your program is correct. 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

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!