In: Computer Science
Using C++, write a program to calculate the height and velocity of a ball thrown upward at a user-specified height and speed in 10 seconds. Position (h) and velocity (v) of the ball as a function of time are given by the equations: h(t) =(1/2)gt2 + v0t + h0 v(t) = gt + v0
#include<iostream>
using namespace std;
int main()
{
int t=10;
float height,velocity,f_height,f_velocity,g=9.8;
cout<<"Enter the height(in meters): ";
cin>>height;
cout<<"Enter the velocity: ";
cin>>velocity;
f_height=(0.5)*g*(t*t)+velocity*t+height;
f_velocity=g*t+velocity;
cout<<"The height and the velocity of the ball thrown upwards "<<height<<"m high and with a speed of "<<velocity<<"m/s is "<<f_height<<"m and "<<f_velocity<<"m/s";
}
The program in c++ will asks the suer to enter the height and then enter the velocity and then as we know gravitational accreleration is 9.8 and time is given as 10seconds and then we calculathe the f_height and f_velocity as per the following formuale and then we print the message with the calculated height and velocity.
SCREENSHOT OF THE OUTPUT :