Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

So I had a code to begin with but still the code has math error where it doesnt

ID: 3863239 • Letter: S

Question

So I had a code to begin with but still the code has math error where it doesnt store the g as a decimal and the math logic is wrong can you please fix this?

#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 Velocity:" << endl;
cin >> v;
PE = m * g * h;
KE = 1/2*(m*v*v);
TE = PE+KE;
cout<<"Total Energy:"<< TE<<endl;
cout<<"Potential Energy:"<< PE<<endl;
cout<<"Kinetic Energy:"<< KE<< endl;
deltaH = h - deltaH;
v = sqrt(2* g * deltaH);
cout<< "Velocity:"<<v<<endl;

return 0;
}

Lab 06 Problem Statement 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 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 mv where m is the mass of the ball in kilograms and vis 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. Note: use the following equation to calculate the velocity at a given height, and then use that velocity to calculate the KE 2gAh where 4h is the distance that the ball has fallen Source: Chapman, Stephen J. Fortran 95/2003 for Scientists and Engineers. 3rd. Boston: McGraw-Hill, 2004. Print. Suggestions: 1. 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

PROGRAM :

#include <iostream>
#include<math.h>
using namespace std;
int main(){
float m =1 , h = 100,h1=0;
float PE=0,KE=0,g =9.81,v,TE=0;
for(h1=0;h1<=100;h1=h1+10)
{
PE = (m*g*(h-h1));
v = sqrt(2*g*h1);
KE = (0.5)*(m*v*v);
TE = PE+KE;
cout<<"HEIGHT: "<< h1;
cout<<" Total Energy: "<< TE;
cout<<" Potential Energy: "<< PE;
cout<<" Kinetic Energy: "<< KE;
cout<<" Velocity: "<<v<<endl;
cout<<"----------------------------------------------------------------------------------------------------"<<endl;
}
return 0;
}

OUTPUT;

HEIGHT: 0 Total Energy: 981 Potential Energy: 981 Kinetic Energy: 0 Velocity: 0
----------------------------------------------------------------------------------------------------
HEIGHT: 10 Total Energy: 981 Potential Energy: 882.9 Kinetic Energy: 98.1 Velocity: 14.0071
----------------------------------------------------------------------------------------------------
HEIGHT: 20 Total Energy: 981 Potential Energy: 784.8 Kinetic Energy: 196.2 Velocity: 19.8091
----------------------------------------------------------------------------------------------------
HEIGHT: 30 Total Energy: 981 Potential Energy: 686.7 Kinetic Energy: 294.3 Velocity: 24.2611
----------------------------------------------------------------------------------------------------
HEIGHT: 40 Total Energy: 981 Potential Energy: 588.6 Kinetic Energy: 392.4 Velocity: 28.0143
----------------------------------------------------------------------------------------------------
HEIGHT: 50 Total Energy: 981 Potential Energy: 490.5 Kinetic Energy: 490.5 Velocity: 31.3209
----------------------------------------------------------------------------------------------------
HEIGHT: 60 Total Energy: 981 Potential Energy: 392.4 Kinetic Energy: 588.6 Velocity: 34.3103
----------------------------------------------------------------------------------------------------
HEIGHT: 70 Total Energy: 981 Potential Energy: 294.3 Kinetic Energy: 686.7 Velocity: 37.0594
----------------------------------------------------------------------------------------------------
HEIGHT: 80 Total Energy: 981 Potential Energy: 196.2 Kinetic Energy: 784.8 Velocity: 39.6182
----------------------------------------------------------------------------------------------------
HEIGHT: 90 Total Energy: 981 Potential Energy: 98.1 Kinetic Energy: 882.9 Velocity: 42.0214
----------------------------------------------------------------------------------------------------
HEIGHT: 100 Total Energy: 981 Potential Energy: 0 Kinetic Energy: 981 Velocity: 44.2945
----------------------------------------------------------------------------------------------------

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote