//Andrew Alspaugh CS1A Chapter 6 P. 370 # 5
//
/**********************************************************************
*
* Calculate Distance Fallen
* ____________________________________________________________________
* This program displays a table of time of travel and distance travled.
*
* The purpose of the program is to showcase the function named
* fallingDistance() Which uses a time input to calculate the distance
* fallen.
*
* NOTE ABOUT PROCESS
* The Process contains the output in this program because the programming
* challenge asks that you display the use of the function by creating
* a loop that uses the function to create the OUTPUT. Therefore, the
* "for loop" contains both the process and output of this program
* ____________________________________________________________________
* INPUT:
* In this program There are no input variables, the number of
* iterations for the loop are fixed and do not need inputs.
*
* In normal computer programming, the only input used would be
* t :Time of Distance Falling
*
* OUTPUT
* d :Calculated Distance Object has Fallen
*
*
*********************************************************************/
#include <iostream>
using namespace std;
//Function Prototype fallingDistance()
double fallingDistance(double t);
int main() {
//Data Dictionary
const float g = 9.8; //Constant Rate of Gravity
double t; //Input Time in Seconds
double d; //Output Distance Fallen in Meters
int Start = 1; //Start Time loop
int End = 10; //End Time loop
//INPUT
// NO CIN: INPUTS ARE FIXED IN LOOP FROM 1-10//
//PROCESS AND OUTPUT
for(t = Start; t <= End; t++)
{
//PROCESS//
double d = fallingDistance(t);
//OUTPUT//
cout << "Time is: " << t << " Distance is " << d << endl;
}
//OUTPUT
//NO COUT: OUTPUTS ARE PART OF PROCESS IN LOOP
return 0;
}
//Function Definition fallingDistance
//takes any time input and uses gravity constant to solve for distance fallen
//In this program the time input "t" is fixed in the "for loop" however this
//function allows for any "t" input as long as it is passed into the function
double fallingDistance(double t)
{
const float g = 9.8;
return 0.5*g*(t*t);
}