fork download
  1. //Ryan Shahriyarpour CS1A Carl Argila CH6 HW Q:6
  2. //
  3. /*****************************************************************************
  4.  *
  5.  * Kinetic Energy
  6.  *
  7.  *********************
  8.  *
  9.  * This program calculates the kinetic energy of a moving object using the
  10.  * function kineticEnergy. The \formula is:
  11.  * KE = (1/2) * m * v^2
  12.  *
  13.  * INPUT
  14.  * mass - the object's mass in kilograms
  15.  * velocity - the object's velocity in meters per second
  16.  *
  17.  * OUTPUT
  18.  * The object's kinetic energy in joules
  19.  *
  20.  ****************************************************************************/
  21.  
  22. #include <iostream>
  23. using namespace std;
  24.  
  25. // Function prototype
  26. double kineticEnergy(double mass, double velocity);
  27.  
  28. int main()
  29. {
  30. double mass; // Mass in kilograms
  31. double velocity; // Velocity in meters per second
  32.  
  33. cout << "Enter the object's mass (kg): ";
  34. cin >> mass;
  35. cout << "Enter the object's velocity (m/s): ";
  36. cin >> velocity;
  37.  
  38. cout << "The object's kinetic energy is "
  39. << kineticEnergy(mass, velocity) << " joules.\n";
  40.  
  41. return 0;
  42. }
  43.  
  44. // Accepts mass and velocity and returns the kinetic energy in joules
  45. double kineticEnergy(double mass, double velocity)
  46. {
  47. return 0.5 * mass * velocity * velocity;
  48. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
Enter the object's mass (kg): Enter the object's velocity (m/s): The object's kinetic energy is 0 joules.