//Cameron Pham CS1A Chapter 6, p. 370, #6
//
/******************************************************************************
* CALCULATE KINETIC ENERGY
* ______________________________________________________________________________
* This program accepts floating point values for an object's mass and velocity
* and computes the amount of kinetic energy the object has.
* ______________________________________________________________________________
* INPUT
* Mass // Mass of an object in kilograms
* Velocity // Velocity of an object in meters per second
*
* OUTPUT
* Kinetic Energy // The object's kinetic energy calculated by KE = 1/2 * mv^2
*
*******************************************************************************/
#include <iostream>
using namespace std;
float kineticEnergy(float mass, float velocity);
int main()
{
// Initialize Variables
float mass;
float velocity;
float ke;
// Ask the User for Object Mass and Velocity
cout << "Enter your object's mass in kilograms and velocity in m/s.";
ke = kineticEnergy(mass, velocity);
cout << endl;
// Displaying Calculated Kinetic Energy
cout << "Your object's kinetic energy is: " << ke << ".";
return 0;
}
float kineticEnergy(float mass, float velocity)
{
float kineticEnergy;
// Receiving Input
cin >> mass >> velocity;
if(mass < 0)
{
cout << "Enter a value equal to 0 or greater.";
}
// Computation for Kinetic Energy
kineticEnergy = (mass * (velocity * velocity)) / 2;
return kineticEnergy;
}