Answer to Question #270598 in C++ for Hamda khan

Question #270598

cannon ball thrown straight into air with starting velocity v0. position of cannon ball after t seconds is given by equation s = vi t – (1/2)gt^2. You are required to confirm equation by simulation. In simulation, you consider how ball moves in very short time interval Δt. In short time interval the velocity v is constant, we can compute distance ball moves using Δs = vΔt. You assume Δt is constant with value of 0.01. You get updated position using s = s + v *Δt. In short time interval, Δv = –gΔt, you must keep velocity updated as v = v - g×Δt; In next iteration, new velocity used to update distance. You need to run simulation until cannon falls back to ground. Your program take initial velocity as input. Update position and velocity 100 times per second but print out position only every full second. printout values from exact formula s =vi t – (1/2) gt^2 for comparison.plot the path that cannon ball

1
Expert's answer
2021-11-24T00:40:50-0500
#include <iostream>
#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