In: Computer Science
C++ When an object is falling because of gravity, the following formula can be used to determine the distance that object falls in a specific time period: d = 1/2 g t*t The variables in the formula are as follows: d is the distance in meters g is 9.8 t is the amount of time, in seconds that the object has been falling. Design a function called fallingDistance() that accepts an object's falling time (in seconds) as an argument. The function should return the distance, in meters, that the object has fallen during that time interval. Design a program that calls the function in a loop that passes the values 1 through 10 as arguments and displays the return value. 5 Falling Distance (5 points) Seconds Meters 1.0 4.9 2.0 19.6 3.0 44.1 4.0 78.4 5.0 122.5 6.0 176.4 7.0 240.10000000000002 8.0 313.6 9.0 396.90000000000003 10.0 490.0
// C++ Code:-
#include<iostream>
using namespace std;
// Function to calculate the falling distance using
formulat 1/2*g*t*t
double fallingDistance(double t)
{
return 0.5*9.8*t*t;
}
int main()
{
cout<<"Time(Seconds) Falling
Distance(Meters)"<<endl;
// calling fallingDistance function repetedly in loop for
value 1 to 10
// Printing the result in desired format.
for(double i=1.0;i<=10.0;i+=1.0)
{
cout<<i<<"
"<<fallingDistance(i)<<endl;
}
return 0;
}