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

For this problem, name your source file projectile.cpp. Your task is to write a

ID: 3543299 • Letter: F

Question

For this problem, name your source file projectile.cpp. Your task is to write a program that computes the maximum height of a projectile (neglecting air resistance), given an initial vertical velocity using two different methods.

The formula for the maximum height of a projectile (neglecting air resistance) with initial vertical velocity V0, is:

xmax = V02/(2*g) where g is the acceleration due to gravity: g = 9.81 m/s2

You could also estimate the maximum height by imagining that the projectile moves upward for a time ?t at V0, then upward for another ?t at (V0 + ?t*g), then upward for another ?t at (V0 + 2?t*g) and so on. Thus, the table on the right shows the time, velocity and location for an initial velocity of 62.5 m/s and a ?t of 0.5 second. Each row represents the velocity and height at t = (row number)*?t. Clearly, the projectile has reached its maximum height when the velocity turns negative. This estimation overestimates the height because the velocity is constantly decreasing over the time interval ?t and because of the granularity of our time steps. We could get a closer estimate by using the average velocity during that time interval, but instead, we'll just keep making the time interval smaller until we are satisfied with the accuracy. We can compare our estimate with the theoretically correct value given by the formula above.

Your program should:

1. Read the initial speed and ?t, issuing appropriate prompts to tell the user what to enter.

2. Use a loop (any kind you like) and the algorithm described above to estimate the maximum height.

3. Output the estimated maximum height, the analytically-computed maximum height, and the percent error, along with appropriate messages, in the format shown in the example run below.


Here is an example run (input highlighted):

Enter initial upward speed in m/s: 62.5

Enter time step size: .5

Maximum height computed numerically = 214.955 meters

Maximum height computed analytically = 199.199.095 meters

Estimation error = 7.96588%

Explanation / Answer

#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
double intial_v,step_size;
cout << "Enter initial upward speed in m/s: ";
cin >> intial_v;
cout << endl;
cout <<"Enter time step size: ";
cin >> step_size;
cout << endl;
double max_height = (intial_v*intial_v)/(2*9.81);
double max_h =0;
int count=0;
cout << "Row # Velocity Height "<< endl;
while(true)
{
double velocity = intial_v -(count)*step_size*9.81;
if(velocity<0) break;
max_h = max_h + velocity*step_size;
cout << count << " " << fixed << setprecision(2) << velocity << " " << fixed << setprecision(2) << max_h << endl;
count++;
}
cout << endl;
cout << "Maximum height computed numerically = "<<max_h <<" meters" << endl;
cout <<"Maximum height computed analytically = "<<max_height << " meters " << endl;
double error = (max_h-max_height)/max_height*100;
cout << "Estimation error = " << error << " % " << endl;
system("pause");
return 0;
}



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