The simplest c++ code you can come up with. Potential versus Kinetic Energy The
ID: 3863090 • Letter: T
Question
The simplest c++ code you can come up with. Potential versus Kinetic Energy The potential energy of a ball due to its height above the ground is given by the equation PE = mgh where m is the mass of the ball in kilograms, g is the acceleration due to gravity in m/s^2 and h is the height of the ball above the surface of the earth in meters. The kinetic energy of a ball due to its speed is given by the equation KE = 1/2mv^2 where m is the mass of the ball in kilograms and v is the velocity of the ball in m/s. Assume that a ball, with a mass of 1 kg, is initially stationary at a height of 100 m. When this ball is released, it will start to fall. Calculate the potential energy and kinetic energy of the ball at 10-m increments as it falls from the initial height of 100 m to the ground, and create a table containing height, PE, KE and the total energy (PE+ KE) of the ball at each step and record the table to an output stream. The program should properly label each of the columns in the table. Suggestions: Think of the appropriate data type(s) to use. Declare g as a constant of value 9.81 m/s^2 Name the output stream totalEnergy.txt.Explanation / Answer
#include <iostream>
#include<math.h>
using namespace std;
int main() {
int PE, KE, m = 1, g = 9.8, h = 100, v, deltaH = 0, TE;
clrscr();
cout << "ENTER THE Velocity:/n";
cin >>v ;
PE = m * g * h;
KE = 1/2 * (m*v*v);
TE = PE + KE;
cout<<"Total Energy:"<<TE;
cout<<"Potential Energy:"<<PE;
cout<<"Kinetic Energy:"<<KE;
for(h=100;h>=0;h = h - 10){
deltaH = h - deltaH;
v = sqrt(2 * g * deltaH);
cout<<"Velocity:"<<v;
}
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.