fork download
  1. //Castulo Jaosn Quintero CSC5 Chapter 6, Pg. 370, #5
  2. //
  3. /**************************************************************************
  4.  *
  5.  * Calculate Falling Distance
  6.  * ________________________________________________________________________
  7.  * This program receives an argument from the loop to calculate
  8.  * how far the an item has fallen in meters within a set amount
  9.  * of seconds.
  10.  *
  11.  * Computation is based on formula:
  12.  * distance = 0.5 * (9.8 * (t * t))
  13.  * ________________________________________________________________________
  14.  * INPUT
  15.  * N/A
  16.  *
  17.  * OUTPUT
  18.  * seconds : The amount of seconds that have passed
  19.  * while the object was falling.
  20.  * distanceFall : The distance in meters the object has fallen.
  21.  *
  22.  *************************************************************************/
  23.  
  24. #include <iostream>
  25. #include <iomanip>
  26. using namespace std;
  27.  
  28. // Prototypes
  29. float fallingDistance(float);
  30.  
  31. // Main function
  32. int main()
  33. {
  34. // Variables
  35. float distanceFall;
  36. float seconds;
  37.  
  38. // Loop and Output
  39. for (int i = 1; i <= 10; i++)
  40. {
  41. seconds = i;
  42. distanceFall = fallingDistance(seconds);
  43.  
  44. cout << "The distance the objest has fallen in " << seconds
  45. << " second(s) is " << distanceFall << " meters\n";
  46. }
  47. return 0;
  48. }
  49. // Value returning function and calculations
  50. float fallingDistance (float time)
  51. {
  52. return 0.5 * (9.8 * (time * time));
  53. }
  54.  
Success #stdin #stdout 0.01s 5304KB
stdin
Standard input is empty
stdout
The distance the objest has fallen in 1 second(s) is 4.9 meters
The distance the objest has fallen in 2 second(s) is 19.6 meters
The distance the objest has fallen in 3 second(s) is 44.1 meters
The distance the objest has fallen in 4 second(s) is 78.4 meters
The distance the objest has fallen in 5 second(s) is 122.5 meters
The distance the objest has fallen in 6 second(s) is 176.4 meters
The distance the objest has fallen in 7 second(s) is 240.1 meters
The distance the objest has fallen in 8 second(s) is 313.6 meters
The distance the objest has fallen in 9 second(s) is 396.9 meters
The distance the objest has fallen in 10 second(s) is 490 meters