Answer to Question #272849 in C++ for saud

Question #272849

A cannon ball is thrown straight into the air with velocity

v0. Position of the cannon ball after t seconds is given by, s = vi t – (1/2) gt.You are required to confirm equation by a simulation. In simulation, you will consider how the ball moves in very short time interval Δt.In a short time interval, the velocity v is nearly constant, and we can compute distance the ball moves using Δs = vΔt. Δt is a constant double with value 0.01. Get updated position using s = s + v * Δt. Velocity changes constantly—in fact, it is reduced by the gravitational force. In a short time interval, Δv = –gΔt, you must keep the velocity updated as v = v - g * Δt; In next iteration, new velocity is used to update distance.You need to run simulation until cannon ball falls back to ground. Take initial velocity as input. Update position and velocity 100 times per second, but print out the position only every full second. Also, printout values from exact formula s = vi t – (1/2) gt2 for comparison. Lastly plot path.


1
Expert's answer
2021-11-29T02:53:32-0500
#include<math.h>


using ​namespace std;




int main()
{
    double t=0.01;
    int v=0;
    cout<<"\nEnter initial position: ";
    double s;
    cin>>s;
    cout<<"\nEnter gravity: ";
    int g;
    cin>>g;
    for(int i=0;i<100;i++){
        s = v*t - (1/2)*g*pow(t,2);
        s = s + v * t;
        v = v - g * t;
        
    }
    cout<<"\nFinal position = "<<s;
    return 0;

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS