Need help with c++ homework. The objective of homework 5 is to calculate and dis
ID: 3759857 • Letter: N
Question
Need help with c++ homework.
The objective of homework 5 is to calculate and display the ballistic flight trajectory of a projectile. The problem is simple, an artillery shell is fired from a cannon with an initial velocity and an elevation angle. This produces an initial velocity vector with vertical and horizontal components. Over time the force of gravity causes the initial upward velocity to decrease and eventually become downward. From that point on the projectile accelerates downward until it strikes the ground. The time it takes to hit the ground is called the flight time. During the flight time the projectile also has a horizontal component of velocity which cause it to travel downrange. In homework 5 there is also a variable headwind in the horizontal direction which slows the horizontal velocity over time.
In a simple problem there are no horizontal forces acting on the projectile and the entire problem could easily be solved by a simple kinematic equation which could yield exact height and range positions at any instant of time. The addition of a variable headwind significantly complicates the problem and makes ballistic equations difficult to use and certainly beyond the scope of a freshmen class. Fortunately there is another option called a “state machine”.
At any instant of time the projectile has a range and height position, vertical and horizontal components of velocity and vertical and horizontal components of acceleration. Its’ state is completely described by 6 variables. In any small interval of time the change from one state to the next state can be calculated by simple equations. If the time interval between states is small enough the accuracy of this approximate method is quite high.
Equations
newXpos = oldXpos + timeInterval * oldXVel
newYpos = oldYpos + timeInterval * oldYVel
newXvel = oldXvel + timeInterval * Xacceleration
newYvel = oldYvel + timeInterval * Yacceleration
Yacceleration = -9.81 + time
X acceleration = -time // it changes with time
muzzleVelocity = 50;
InitialXVel = muzzleVelocity * cos(elevationAngle)
InitialYvel = muzzleVelocity * sin(elevationAngle)
timeInterval = .001 seconds
Units
Seconds
Meters
Course objectives
You must use functions to update position, velocity, and acceleration.
You must use arrays for the position, velocity, and acceleration vectors.
Bonus points for students who can find the maximum range of the system.
You must prompt the user for initial input of elevation angle.
You must output the time, the height, and the downrange distance at each increment of time. (instantaneous states)
You program must terminate when the projectile strikes the ground.
You must use the “+=” operator.
All data must be output with three decimal places. (use setprecision)
All columns must be aligned. (use setw)
Explanation / Answer
newXpos = oldXpos + timeInterval * oldXVel
newYpos = oldYpos + timeInterval * oldYVel
newXvel = oldXvel + timeInterval * Xacceleration
newYvel = oldYvel + timeInterval * Yacceleration
Yacceleration = -9.81 + time
X acceleration = -time // it changes with time
muzzleVelocity = 50;
InitialXVel = muzzleVelocity * cos(elevationAngle)
InitialYvel = muzzleVelocity * sin(elevationAngle)