Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Lesson 8 has two parts. using c++ Part 1 is worth 50 points (40 points running the tests and 10 for your program formatting, comments,

Lesson 8 has two parts. using c++

Part 1 is worth 50 points (40 points running the tests and 10 for your program formatting, comments, and variable names). You will be developing and testing with an IDE and them uploading the solution to zyBooks/zyLabs. You need to test your program in the IDE to make sure it is working. Once you have completed your testing you will need to upload the source file for the submit mode tests. Failure to meet the requirements could result in loss of points beyond the 10 for the code formatting, variable names, and so on.

You can only run the submit mode tests 20 times (or less). If you find any errors while in submit mode you will have to go back to your IDE and update your program, test to make sure you have fixed the problems and upload a new version to zyBooks/zyLabs.

In part 1 you will be creating multiple functions to calculate the distance an object falls (on earth) in a specified number of seconds.

All of the functions in part 1 will have a specific function signature. For one of the required functions, there will be unit tests at the function call level. The unit tests will call a function with specific values to ensure the function returns back the correct value. If these unit tests fail it is likely all of the other tests will fail as well. This is a new type of test we have not seen before.

Make sure you exactly match any function signatures that are required by the exercise.

You are not allowed to use any global variables. Use of global variables will result in a grade of zero for part 1.

In addition to the main function you have been creating in all the lab lessons so far you will need three (3) additional functions.

One function will be an input function that will read in a double value from cin and return that value back to main.

You will also need an output function that will display both the number of seconds an object has fallen as well as the distance the object has fallen.

The final function will calculate the distance an object falls (on earth) during the specified number of seconds.

Here are the required signatures of the three functions you need (in addition to the main) function:

double readSeconds() void displayResults(double seconds, double distance) double calculateDistance(double seconds) 

Here is a summary of the processing that is required in the various functions:

double readSeconds()

This function reads in a value from cin. If the value is 0 or more the value should be returned to the calling function. If the value is less than zero you should read in a new value.

This function should have a loop that continues to execute until a valid input value has been entered.

You can assume that the input values are always valid numbers.

The prompt from the function should be:

Enter the time (in seconds) 

If the value is negative you should output the following message and then prompt for input again.

The time must be zero or more Enter the time (in seconds) 

double calculateDistance(double seconds)

This function calculates the distance traveled (on earth) during the number of seconds pass in as a parameter. The distance is calculated in meters and is returned to the calling function.

The formula is:

d = g t

Where d is distance (in meters), t is time (in seconds) and g is 9.8 (the acceleration due to gravity on the earth).

Use good variable names and not just d, g and t. Use double values for your calculations.

void displayResults(double seconds, double distance)

The displayResults function takes two parameters of type double. The first is the number of seconds and the second is the distance traveled.

The output is the text:

The object traveled xx.xx meters in yy.y seconds 

Note that the distance is output with two digits to the right of the decimal point while seconds is output with one digit to the right of the decimal point. Both are in fixed format.

Assume that the number of seconds is 10.5 and distance is xx the output would be:

The object traveled 540.23 meters in 10.5 seconds 

int main()

The main function will be the driver for your program.

First you need a loop that will process input values until you get an input value that is equal to 0. You will get this input value by calling the readSeconds function.

If the value is greater than zero the main function needs to call the calculateDistance and displayResults functions.

If the value is zero the loop should end and your program should then end.

Note that all of the non-main functions are called from main.

For the following sample run assume the input is as follows:

-12.5 -3.5 10.5 4.2 0 

Your program should output the following:

Enter the time (in seconds) The time must be zero or more Enter the time (in seconds) The time must be zero or more Enter the time (in seconds) The object traveled 540.23 meters in 10.5 seconds Enter the time (in seconds) The object traveled 86.44 meters in 4.2 seconds Enter the time (in seconds) 

Note that a zero is used to terminate the loop, but a value of zero is actually a valid value for seconds. We just aren't using that value in this program.

Error message "Could not find main function"

Now that we are using functions some of the tests are unit tests. In the unit tests the zyBooks environment will call one or more of your functions directly.

To do this it has to find your main function.

Right now zyBooks has a problem with this when your int main() statement has a comment on it.

For example:

If your main looks as follows:

int main() // main function 

You will get an error message:

Could not find main function 

You need to change your code to:

// main function int main() 

If you do not make this change you will continue to fail the unit tests.

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

Building Database Driven Catalogs

Authors: Sherif Danish

1st Edition

0070153078, 978-0070153073

More Books

Students also viewed these Databases questions

Question

Explain KPIs and their relevance in application of analytics.

Answered: 1 week ago

Question

=+4 Develop and deliver the CCT program.

Answered: 1 week ago

Question

=+5 Evaluate whether the CCT program was effective.

Answered: 1 week ago

Question

=+Identify the type of global assignment for which CCT is needed.

Answered: 1 week ago