Question

C++ LANGUAGE

The following formula can be used to determine the distance an object falls in a specific time period:

d = 1 2 g t 2

where d is the distance in meters, g is 9.8, and t is the amount of time, in seconds, the object has been falling.

Write a function named fallingDistance that accepts an object's falling time in seconds as an argument. You must define a named constant for g using a meaningful name and use that named constant in the calculation. G will not be an acceptable identifier. The function should return the distance, in meters, that the object has fallen during that time interval.

Check. The function prototype is near the top of the program above the main function.

Check. The function definition is below the main function.

Check. There is a comment box above the function definition that contains the description of the function, a description of the parameter variable, and a description of the return value. You can use the following text:

Name: fallingDistance

Description: This function returns the distance the falling object has traveled during a time interval.

Parameters:

interval - the time interval in seconds the object has traveled.

Return:

The distance in meters the object has traveled in the time interval.

From the main function, demonstrate the function by calling it in a for loop that passes the values 1 through 12 as arguments, and displays the return value.

The output should look exactly as follows (in single space):

Time Traveled (in seconds) Distance Traveled (in meters) Il 1 2 3 4 5 6 4.90 19.60 44.10 78.40 122.50 176.40 240.10 313.60 39

Please pay attention that the formatting output is as close to the given image as possible. This is very important.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Copy pastable code

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#include<iostream>

#include <iomanip> //included for IO manipulations

using namespace std;

#define g 9.8 //define G

float fallingDistance(int time){

float dis = 0;

dis = 0.5*g*time*time; // distance calculation

return dis;

}

int main(){

float distance = 0;

cout<<setw(20)<<left<<"Time Traveled"<<setw(20)<<left<<"Distance Traveled"<<endl;

//setw sets the word length to print and left will align left

cout<<setw(22)<<left<<"(in seconds)"<<setw(20)<<left<<"(in meters)"<<endl;

//printed the time and distance

cout<<setw(40)<<setfill('=')<<""<<endl;

cout<<setfill(' ');

//reset setfilles to spaces

for(int i = 1; i<13; i++){

distance = fallingDistance(i); //calculating distance

cout<<setw(10)<<right<<i; //print time right align 10 word length

cout<<setw(20)<<right<<fixed<<setprecision(2)<<distance<<endl;

// print distance with fixed precision of 2 in right align 20 wordlength

}

return 0; // main return

}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////

Code Snippet:

home > deeplearningcv > Documents > 6 distance_travel.cpp > ... 1 #include<iostream> 2 #include <iomanip> //included for 10 m

OUTPUT of code:

= = = (base) deeplearningcv@deepak-LINUX :-/Documents$ g++ distance_travel.cpp ave (base) deeplearningcv@deepak-LINUX :-/Docu

Add a comment
Know the answer?
Add Answer to:
C++ LANGUAGE The following formula can be used to determine the distance an object falls in...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Do not prompt the user for input during the execution of your program. Do not pause...

    Do not prompt the user for input during the execution of your program. Do not pause at the end of the execution waiting for the user's input. Important notes: from now on, function prototypes should be written before the main function. And function definitions should be written after the main function. 10% will be deducted if this is not observed. Zybooks MODULES: MODULE 6 a.) (Lab4a.cpp) Chapter 6, “Falling Distance." The following formula can be used to determine the distance...

  • PYTHON HOMEWORK When an object is falling because of gravity, the following formula can be used...

    PYTHON HOMEWORK When an object is falling because of gravity, the following formula can be used ot determine the distance the object falls during a specific time period: d=1/2 g t^2 The variables in the formula are as follows: d is the distance in meters(m), g is the acceleration due to gravity, an and its value is 9.8 m/s^2, t is the time duration in seconds(s). Write a function named falling_distance() that accepts an object's falling duration(time) in seconds as...

  • write program in java 5. Falling Distance When an object is falling because of gravity, the...

    write program in java 5. Falling Distance When an object is falling because of gravity, the following formula can be used to determine the distance the object falls in a specific time period: d = 1/2 gta The variables in the formula are as follows: d is the distance in meters, g is 9.8, and t is the amount of time, in seconds, that the object has been falling. Write a method named fallingDistance that accepts an object's falling time...

  • When an object is falling because of gravity, the following formula can be used to determine...

    When an object is falling because of gravity, the following formula can be used to determine the distance the object falls in a specific time period: d=1/2 gt^2 The variables in the formula are as follows: d is the distance, g is 9.8, and t is the amount of time that the objects has been falling. Write a soldier method that accepts an object’s falling time as an argument. The method should return the distance that the object has fallen...

  • Java: Create a main method for your class, and then add another method to your class...

    Java: Create a main method for your class, and then add another method to your class (above the main method) named fallingDistance. This method accepts an integer into its parameter t, which is the amount of time, in seconds, that an object has been falling. This method returns the distance, in meters, that the object has fallen during the time interval. When an object s falling because of gravity, we use the following formula to determine the distance the object...

  • Consider an object moving along a line with the following velocity and initial position. Assume time...

    Consider an object moving along a line with the following velocity and initial position. Assume time t is measured in seconds and velocities have units of​ m/s. Complete parts​ (a) through​ (d) below. Consider an object moving along a line with the following velocity and initial position. Assume time t is measured in seconds and velocities have units of m/s. Complete parts (a) through (d) below. v(t) = -1-2cos for Osts (0) = 0 (**). a. Over the given interval,...

  • Paragraph Styles Problem 5-The following figure represents a traveling wave. The distance the wave has traveled...

    Paragraph Styles Problem 5-The following figure represents a traveling wave. The distance the wave has traveled is 50 meters during a 10 second. w Formulas: F=1/T, V=f1, w = 271, K=27/A, Y= Asin(kx - w t) The wave Y-5 sin (k x-wt) travels in the rope. • "5" in the formula is in cm. a)What is the amplitude (A) of the wave? b)What is the frequency (f) (-in Hertz) of the wave? (see the above figure) c) What is the...

  • c++ program Notes 1. Your program should use named string constant for the file name to open the file. Do not add any pa...

    c++ program Notes 1. Your program should use named string constant for the file name to open the file. Do not add any path to the file name because the path on your computer is not likely to exist on the computer the instructor uses to grade the program. Points may be deducted if you don't follow this instruction. 2. Split statements and comments longer than 80 characters into multiple lines and use proper indentations for the split portions. 3....

  • Using C programming language Question 1 a) through m) Exercise #1: Write a C program that...

    Using C programming language Question 1 a) through m) Exercise #1: Write a C program that contains the following steps (make sure all variables are int). Read carefully each step as they are not only programming steps but also learning topics that explain how functions in C really work. a. Ask the user for a number between 10 and 99. Write an input validation loop to make sure it is within the prescribed range and ask again if not. b....

  • can you please follow all the instructions ? The answers that I got has either missing...

    can you please follow all the instructions ? The answers that I got has either missing range for loop or one funtion . Read the instructions carefully. At least 10% will be deducted if the instructions are not followed. For general lab requirements, see General Lab Requirements. Do not prompt the user for input during the execution of your program. Do not pause at the end of the execution waiting for the user's input. Notes 1. Your program should use...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT