//Zachary Abdollahi CS1A Chapter 6, P. 370, #6
//
/*******************************************************************************
*
* COMPUTE KINETIC ENERGY
*
* This program computes the kinetic energy of an object based on its mass
* (in kilograms) and velocity (in meters per second).
*
* Computation is based on the formula:
* KE = 0.5 x mass x velocity^2
*
* INPUT
* mass : Object's mass in kilograms
* velocity : Object's velocity in meters per second
*
* OUTPUT
* kineticEnergy : Amount of kinetic energy in Joules
*
******************************************************************************/
#include <iostream>
#include <iomanip>
#include <cmath> // Needed for pow function
using namespace std;
// Function Prototypes
double kineticEnergy(double mass, double velocity);
int main()
{
float mass; // To hold the object's mass
float velocity; // To hold the object's velocity
float ke; // To hold the kinetic energy result
// Get input from the user
cout << "Enter the object's mass (in kilograms): ";
cin >> mass;
cout << "Enter the object's velocity (in meters per second): ";
cin >> velocity;
// Call the function to calculate kinetic energy
ke = kineticEnergy(mass, velocity);
// Display the formatted result
cout << fixed << showpoint << setprecision(2);
cout << "\nThe object's kinetic energy is " << ke << " Joules. " << endl;
return 0;
}
/******************************************************************************
* kineticEnergy *
* Accepts mass (kg) and velocity (m/s) as arguments and calculates *
* and returns kinetic energy using KE = 0.5 * m * v^2. *
*****************************************************************************/
double kineticEnergy(double mass, double velocity)
{
return 0.5 * mass * pow(velocity, 2.0);
}