subject
Computers and Technology, 30.07.2021 05:00 Yasin36

Your program will calculate the distance an object travels (in meters) on Earth for a specified number of seconds. You will also calculate the distance traveled on the Moon (in meters) for the specified number of seconds. Your program must have the main function and, at least, the following four additional functions. The signatures for these functions must be as follows:
double readSeconds()
double calculateEarthDistance(double seconds)
double calculateMoonDistance(double seconds)
void displayResults(double seconds, double earthDistance, double moonDistance)
The readSeconds function will be an input function that will read in a double value from cin and return that value back to main.
The calculateEarthDistance function will calculate the distance an object falls (on Earth) during the specified number of seconds.
The calculateMoonDistance function will calculate the distance an object falls (on the Moon) during the specified number of seconds.
The displayResults function that will display the number of seconds an object has fallen as well as the distance the object has fallen on the Earth and on the Moon.
You can have additional function is needed.
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 less than zero the function should output a message.
The value read in (valid or not) should be returned to the calling function.
The prompt from the function should be:
Enter the time (in seconds)
If the value is less than zero you should output the following message.
The time must be zero or more
double calculateEarthDistance(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 = 0.5 * g * pow(t, 2)
Where d is distance (in meters), t is time (in seconds) and g is 9.8 meters / second squared (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.
double calculateMoonDistance(double seconds)
This function calculates the distance traveled (on the Moon) 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 the same as the formula on Earth, but the value of g is different. For the Moon g is 1.6 meters / second squared.
Use good variable names and not just d, g and t. Use double values for your calculations.
void displayResults(double seconds, double earthDistance, double moonDistance)
The displayResults function takes three parameters of type double. The first is the number of seconds and the second is the distance traveled on the Earth, and the third parameter is the distance traveled on the Moon. Note that the displayResults function must be passed the values for seconds, earthDistance, and moonDistance. The displayResults function MUST NOT call readSeconds, calculateEarthDistance, or calculateMoonDistance.
The output is the text:
The object traveled xxx. meters in zz. zz seconds on Earth
The object traveled yy. meters in zz. zz seconds on the Moon
Note that the distance is output with four digits to the right of the decimal point while seconds is output with two digits to the right of the decimal point. Both are in fixed format.
Assume that the number of seconds is 10.5, the output would be:
The object traveled 540.2250 meters in 10.50 seconds on Earth
The object traveled 88.2000 meters in 10.50 seconds on the Moon
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 calculateEarthDistance, calculateMoonDistance, and displayResults functions.
If the value is zero the loop should end and your program should then end.
Note that all of the required 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

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 14:30
The “rule of 72” is used to approximate the time required for prices to double due to inflation. if the inflation rate is r%, then the rule of 72 estimates that prices will double in 72/r years. for instance, at an inflation rate of 6%, prices double in about 72/6 or 12 years. write a program to test the accuracy of this rule. for each interest rate from 1% to 20%, the program should display the rounded value of 72/r and the actual number of years required for prices to double at an r% inflation rate. (assume prices increase at the end of each year.)
Answers: 1
question
Computers and Technology, 22.06.2019 15:00
When designing content as part of your content marketing strategy, what does the "think" stage represent in the "see, think, do, care" framework?
Answers: 3
question
Computers and Technology, 22.06.2019 15:50
The file sales data.xlsx contains monthly sales amounts for 40 sales regions. write a sub that uses a for loop to color the interior of every other row (rows 3, 5, etc.) gray. color only the data area, columns a to m. (check the file colors in excel.xlsm to find a nice color of gray.)
Answers: 2
question
Computers and Technology, 23.06.2019 00:00
How do we use the sumif formula (when dealing with different formats) ?
Answers: 1
You know the right answer?
Your program will calculate the distance an object travels (in meters) on Earth for a specified numb...
Questions
Questions on the website: 13722361