// Marvyn Jesse De La Torre Chapter 6, p. 370, #5
//
/*************************************************************************
*
* CALCULATE FALLING DISTANCE
* This program calculates the distance an object falls during each second
* from 1 through 10.
*
* INPUT
* seconds : Time an object has been falling, from 1 through 10
*
* OUTPUT
* distance : Distance fallen in meters
*************************************************************************/
#include <iomanip>
#include <iostream>
using namespace std;
const double GRAVITY = 9.8; // Gravitational acceleration in meters/second^2
// Function Prototype
double fallingDistance(double seconds);
int main()
{
// Declare Variables
int seconds; // Number of seconds the object has fallen
// Display Table Heading
cout << fixed << setprecision(2);
cout << "Time (seconds)\tDistance Fallen (meters)" << endl;
cout << "---------------------------------------" << endl;
// Display the distance for 1 through 10 seconds
for (seconds = 1; seconds <= 10; seconds++)
{
cout << setw(7) << seconds << setw(23)
<< fallingDistance(seconds) << endl;
}
return 0;
}
/*************************************************************************
* fallingDistance
* This function returns the distance, in meters, an object falls in the
* specified number of seconds.
*************************************************************************/
double fallingDistance(double seconds)
{
return 0.5 * GRAVITY * seconds * seconds;
}