//Dione Torrevillas CS1A Chapter 6, P. 370, #6
//
/****************************************************************
*
* COMPUTE KINETIC ENERGY
*_______________________________________________________________
* This program computes the kinetic energy of a moving object
* based on its mass and velocity. The program uses a function
* to calculate and return the kinetic energy.
*
* Computation is based on the formula:
* Kinetic Energy = 0.5 * Mass * Velocity * Velocity
*_______________________________________________________________
* INPUT
* mass : Mass of the object in kilograms
* velocity : Velocity of the object in meters per second
*
* OUTPUT
* energy : Kinetic energy of the object in joules
*
****************************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
// Function prototype
double kineticEnergy(double, double);
int main()
{
double mass; //INPUT - Mass in kilograms
double velocity; //INPUT - Velocity in meters per second
double energy; //OUTPUT - Kinetic energy in joules
// Get the mass of the object
cout << "Enter the mass in kilograms: ";
cin >> mass;
// Get the velocity of the object
cout << "Enter the velocity in meters per second: ";
cin >> velocity;
// Call the function to calculate kinetic energy
energy = kineticEnergy(mass, velocity);
// Display the kinetic energy
cout << fixed << setprecision(2);
cout << "The kinetic energy is: "
<< energy << " joules" << endl;
return 0;
}
// Function definition
// Calculates and returns the kinetic energy
double kineticEnergy(double mass, double velocity)
{
double energy; // Kinetic energy in joules
// Calculate the kinetic energy
energy = 0.5 * mass * velocity * velocity;
return energy;
}