In C++ use Functions with Pointers and References Your free fall calculator program will calculate the time it takes an object to fall until it hits the ground. This program requires functions. Place the function prototypes in a file named FallFunctions.h. Create a global constant for ACCELERATION in the .h file, too. Use a comment to define the units for acceleration. Place the associated function implementations in FallFunctions.cpp. Call all functions from main, which is located in your Driver.cpp. In main, you will call the Header function first. Then, start a do another loop. Inside the loop, call the AskHeight function using a reference to height to ask the user for the height of the fall in feet. Next, call the TimeToFall function using a pointer to time to calculate the time it takes the object to fall. Pass time and height to the WriteResults function to write the information in a neatly formatted string. The string is then returned to main and written to the screen. Make sure to ask the user to input values in correct units. See table below for functions to write, formulas and units. Prototype Content void DisplayHeader () Write your program header void AskHeight(double &height) Ask the user for the height of the fall void TimeToFall(double *time, double height); Calculate the time to fall using the formula: Where: time = time to fall in seconds. height = distance to fall in feet. acceleration = 32.2 (acceleration due to gravity in feet/second2). In C++, the square root function could be used like this: time = sqrt( 2 * height / acceleration ) string WriteResults(double time, double height) Writes height of fall and time to fall in a neatly formatted string
C++
In C++ use Functions with Pointers and References
Your free fall calculator program will calculate the time it takes an object to fall until it hits the ground.
This program requires functions. Place the function prototypes in a file named FallFunctions.h. Create a global constant for ACCELERATION in the .h file, too. Use a comment to define the units for acceleration. Place the associated function implementations in FallFunctions.cpp. Call all functions from main, which is located in your Driver.cpp.
In main, you will call the Header function first. Then, start a do another loop. Inside the loop, call the AskHeight function using a reference to height to ask the user for the height of the fall in feet. Next, call the TimeToFall function using a pointer to time to calculate the time it takes the object to fall. Pass time and height to the WriteResults function to write the information in a neatly formatted string. The string is then returned to main and written to the screen.
Make sure to ask the user to input values in correct units. See table below for functions to write, formulas and units.
Prototype |
Content |
void DisplayHeader () |
Write your program header |
void AskHeight(double &height) |
Ask the user for the height of the fall |
void TimeToFall(double *time, double height); |
Calculate the time to fall using the formula: Where: time = time to fall in seconds. height = distance to fall in feet. acceleration = 32.2 (acceleration due to gravity in feet/second2).
In C++, the square root function could be used like this: time = sqrt( 2 * height / acceleration ) |
string WriteResults(double time, double height) |
Writes height of fall and time to fall in a neatly formatted string |
Give your user the opportunity to do more calculations, and then when they are finished, write a Good-Bye message.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps