In: Computer Science
When an object is falling because of gravity, the following formula can be use 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.
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
A prime number is a number that is only evenly divided by itself and 1. For example, the number 5 is a prime because it can only be evenly divided by 1 and 5. The number 6, however, is not prime because it can be divided evenly by 1, 2, 3, and 6.
In case of any queries,please comment. I would be very happy to
assist all your queries.Please give a Thumps up if you like the
answer.
C++ Program
#include <iostream>
#include <iomanip>
using namespace std;
const double GRAVITY = 9.8;
// Function prototypes
double fallingDistance(float);
int main()
{
cout <<
"Seconds\t\tMeters"<<endl;
for(float T = 1.0; T <= 10; T++)
{
cout<<
fixed<<setprecision(1) << T <<
"\t\t"<<fallingDistance(T) << endl;
}
cout << endl;
return 0;
}
double fallingDistance(float T)
{
return .5 * GRAVITY * T*T;
}
Output
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.1
8.0 313.6
9.0 396.9
10.0 490.0