//Ryan Shahriyarpour CS1A Carl Argila CH6 HW Q:5
//
/*****************************************************************************
*
* Falling Distance
*
*********************
*
* This program displays the distance an object falls because of gravity for
* 1 through 10 seconds. The function fallingDistance is called in a loop.
* The formula is:
* d = (1/2) * g * t^2 (g = 9.8 m/s^2)
*
* INPUT
* None (fixed values 1 through 10)
*
* OUTPUT
* Table showing time in seconds and distance fallen in meters
*
****************************************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
// Function prototype
double fallingDistance(int seconds);
const double GRAVITY = 9.8; // Acceleration due to gravity (m/s^2)
int main()
{
cout << "Time (sec)\t\tDistance Fallen (m)\n";
cout << "---------------------------------------\n";
// Pass the values 1 through 10 to fallingDistance
for (int time = 1; time <= 10; time++)
{
cout << time << "\t\t\t" << fixed << setprecision(2)
<< fallingDistance(time) << endl;
}
return 0;
}
// Accepts the falling time in seconds and returns the distance in meters
double fallingDistance(int seconds)
{
return 0.5 * GRAVITY * seconds * seconds;
}