Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part of lab lesson 5 There are two parts to lab lesson 5. The entire lab will be worth 100 points. Bonus points for lab

Part of lab lesson 5

There are two parts to lab lesson 5. The entire lab will be worth 100 points.

Bonus points for lab lesson 5

There are also 10 bonus points. To earn the bonus points you have to complete the Participation Activities and Challenge Activities for zyBooks/zyLabs unit 4. These have to be completed by the due date for lab lesson 5. For example, if you complete 89% of the activities you will get 8 points (there is no rounding).

Lab lesson 5 part 2 is worth 50 points

For part 2 you will have 40 points if you enter the program and successfully run the program tests. An additional 10 points will be based on the style and formatting of your C++ code.

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

Proper formatting of your code (follow the guidelines in the Gaddis text book, or those used by your CS 1336 professor)

If you have any variables they must have meaningful names.

Development in your IDE

For lab lesson 5 (both parts) you will be developing your solutions using an Integrated Development Environment (IDE) such as Visual Studio, Code::Blocks or Eclipse. You should use whatever IDE you are using for your CS 1336 class. Once you have created and tested your solutions you will be uploading the files to zyBooks/zyLabs. Your uploaded file must match the name specified in the directions for the lab lesson. You will be using an IDE and uploading the appropriate files for this and all future lab lessons.

You will need to develop and test the program in your IDE. Once you are satisfied that it is correct you will need to upload the source file to zyBooks/zyLabs, and submit it for the Submit mode tests. If your program does not pass all of the tests you need to go back to the IDE, and update your program to fix the problems you have with the tests. You must then upload the program from the IDE to zyBooks/zylabs again. You can then run the tests again in Submit mode.

When running your program in Submit mode it is very important that you look at the output from all of the tests. You should then try and fix all of the problems in your IDE and then upload the updated code to zyBooks/zyLabs.

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:

Medium Speed (Meters per second)
Carbon Dioxide 258.0
Air 331.5
Helium 972.0
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 

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) 

Failure to follow the requirements for lab lessons can result in deductions to your points, even if you pass the validation tests. Logic errors, where you are not actually implementing the correct behavior, can result in reductions even if the test cases happen to return valid answers. This will be true for this and all future lab lessons.

Expected output

There are nine tests. Each test will have a new set of input data. You must match, exactly, the expected output.

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: 3

blur-text-image

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

More Books

Students also viewed these Databases questions