fork download
  1. //Andrew Alspaugh CS1A Chapter 6. P 370. #6
  2. //
  3. /*********************************************************************
  4.  *Calculate Kinetic Energy
  5.  * ___________________________________________________________________
  6.  * This Program Calculates the Kinetic Energy of an object
  7.  * ___________________________________________________________________
  8.  * Input
  9.  * m Mass
  10.  * v Velocity
  11.  * Output
  12.  * KE Kinetic Energy
  13.  *********************************************************************/
  14. #include <iostream>
  15. using namespace std;
  16.  
  17. //Function Protoype KineticEnergy
  18. double KineticEnergy (double m, double v);
  19.  
  20. int main()
  21. {
  22.  
  23. //DATA DICTIONARY
  24.  
  25. //Inputs
  26. double m; //INPUT MASS KILOGRAMS
  27. double v; //INPUT VELOCITY METERS PER SECOND
  28. //Outputs
  29. double KE; //OUTPUT KINETIC ENERGY
  30.  
  31. //INPUT
  32.  
  33. //Input Mass
  34. cout << "Enter Mass in Kilograms: " << endl;
  35. cin >> m;
  36. while (m <= 0)
  37. {
  38. cout << "Enter Mass greater than 0" << endl;
  39. cin >> m;
  40. }
  41. cout << "Mass is: " << m << endl << endl;
  42.  
  43. //Input Velocity
  44. cout << "Enter Velocity in Meters/Second: " << endl;
  45. cin >> v;
  46. while (v <= 0)
  47. {
  48. cout << "Enter Velocity greater than 0" << endl;
  49. cin >> v;
  50. }
  51. cout << "Velocity is: " << v << endl << endl;
  52.  
  53. //PROCESS
  54.  
  55. KE = KineticEnergy(m, v);
  56.  
  57. //OUTPUT
  58.  
  59. cout << "Kinetic Energy is: " << KE << endl;
  60. return 0;
  61. }
  62.  
  63. // KineticEnergy () Definition
  64. double KineticEnergy(double m, double v)
  65. {
  66. return 0.5*m*(v*v);
  67. }
Success #stdin #stdout 0.01s 5276KB
stdin
-1
37
-1
19
stdout
Enter Mass in Kilograms: 
Enter Mass greater than 0
Mass is: 37

Enter Velocity in Meters/Second: 
Enter Velocity greater than 0
Velocity is: 19

Kinetic Energy is: 6678.5