// FILE: FreeFall.cpp // DISPLAY HEIGHT OF A DROPPED OBJECT AT EQUAL INTERVALS // Displays the height of an object dropped from a tower // at user specified intervals, until it hits the ground. #include #include #include // Function prototypes ... // GENERATE TABLE void generate_table (double, // INPUT: height of tower from which object dropped double); // INPUT: time interval int main () { // Local data ... double tower_height; // height of tower (meters) double delta_t; // time interval // Enter tower height and time interval. cout << "Enter tower height in meters: "; cin >> tower_height; cout << "Enter time in seconds between table lines: "; cin >> delta_t; cout << endl; // Display object height until it hits the ground. generate_table (tower_height, delta_t); return 0; } // GENERATE TABLE void generate_table (double tower_height, // INPUT: height of tower from which object dropped double delta_t) // INPUT: time interval { // Local data ... const double g = 9.80655; // gravitational pull in meters per second squared double object_height; // height of object at any time t double t; // total elapsed time // Display table header. cout << setw (10) << "Time" << setw (9) << "Height" << endl; t = 0.0; object_height = tower_height; // Display table. cout.precision (2); cout.setf (ios::fixed); while (object_height > 0.0) { cout << setw(10) << t << setw(9) << object_height << endl; t += delta_t; object_height = tower_height - 0.5 * g * pow (t, 2); } // end while // Object hits the ground. cout << endl; cout << "SPLAT!!!" << endl << endl; }