//Nicolas Ruano CS1A Chapter 6, P. 370, #6
/**************************************************************
* FUNCTION COMPUTE THE MOVING OBJECT’S KINETIC ENERGY.
* _____________________________________________________________
* The program uses user-inputted mass and velocity to calculate
* kinetic energy functions “kineticEnergy”, then displays the result.
*
* Computation is based on the formula:
*
* KE = 1/2 * m * v^2
* Where:
* KE = Kinetic energy in Joules
* m = Mass in kilograms
* v = Velocity in meters per second
* ____________________________________________________________
* INPUT
* mass double Mass of the object in kilograms
* velocity double of the object in m/s
*
* OUTPUT
* mass double Mass of the object in kilograms
* velocity double of the object in m/s
* KE double Calculated kinetic energy in Joules
*
**************************************************************/
#include <iostream>
using namespace std;
// Function to calculate kinetic energy
double kineticEnergy(double mass, double velocity) {
double KE = 0.5 * mass * velocity * velocity; // KE = 1/2 * m * v^2
return KE;
}
int main() {
double mass, velocity;
// Ask the user for mass and velocity
cout << "Enter the mass of the object (in kilograms): ";
cin >> mass;
cout << "Enter the velocity of the object (in meters per second): ";
cin >> velocity;
// Call the function and display the kinetic energy
double KE = kineticEnergy(mass, velocity);
cout << "The kinetic energy of the object is: " << KE << " Joules" << endl;
return 0;
}