C ++ - Create a program that calculates the distance an object travels in meters on Earth for a specific number of seconds. Also calculate the distance  traveled on the moon, also in meters, for a specific number of seconds.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

C ++ - Create a program that calculates the distance an object travels in meters on Earth for a specific number of seconds. Also calculate the distance  traveled on the moon, also in meters, for a specific number of seconds.

Do not include any global variables

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.

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). Formula for the moon is the same but g is 1.6 meters / second squared. Use double for calculations.

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.xxxx meters in zz.zz seconds on Earth The object traveled yy.yyyy meters in zz.zz seconds on the Moon

int main()

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 less than zero the loop should end and your program should then end.

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

Note that a zero is used to terminate the loop, but a value of zero is actually a valid value for seconds.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Types of Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education