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

I have homework for my c++ class. Here is the all information about my homework.

ID: 3674376 • Letter: I

Question

I have homework for my c++ class. Here is the all information about my homework. I need to get this screen that located at very bottom. Please help

HW#5 Functions and Arrays

For HW#5 we will return to the state method of solving the ballistic projectile problem with added twists. The goal will be to hit a target 1000 meters east of your cannon but the wind is blowing from the south. Your initial muzzle velocity is fixed at 110 meters per second, but you can control the elevation and azimuth angles of your aim. Elevation angle is measured up or down. Azimuth angle is measured right or left. Use positive x for east, positive y for north, and positive z for up.

For HW#5 you must use an iterative solution with a time increment of .001 seconds. Even if you could derive an exact solution for the position of the projectile at any instant in time, you may not use it.

You must use arrays to store the x, y, and z components of position, velocity, and acceleration. You must use functions to update the position and velocity arrays and output the current x, y, z position of the projectile after each time increment. You will terminate the iteration when the projectile hits the ground and calculate the horizontal distance from the impact point to the actual target. The closest shot wins bonus points.

Your working variables will be limited to a constant time-increment, aiming inputs and three arrays; position, velocity, and acceleration. Each array will contain 3 elements representing x, y, and z components.

Function prototypes

Void UpdatePosistion(double pos[], double vel[], const double timeInc);

Void UpdateVelocity(double vel[], const double acc[], const double timeInc);

Void OutputPosition(double pos[]);

Variables

const double timeInc = .001 // unit s

const double initialVelocity = 110; // units m/s

const double target[3] = { 1000, 0, 0}; // units m ( x, y, z coordinates) East is positive x

const double acc[3] = { 0, .25, -9.81}; // units m/s2 wind and gravity, North is positive y

double azimuth, elevation, time;

double pos[3], vel[3];

As always you must match the column and precision formatting.

Don’t for get to sign your screens.

HW#5 Ballistics

State Machine Calculation of Trajectories

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, azimuth, and an elevation angle. This produces an initial velocity vector with 3-dimensional 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 hit the target.

You must prompt the user for initial input of azimuth and 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)

C:SchooNCSC11205ProjectsLion1inDebugLion1.exe Time Time Time Time Time Time Time Time Time Time missed bu 1.227 Author Dr. Gray Azimuth -2.900 Elevation angle62.900 19.954s X-Pos 19.955s X-Pos 19.956s X-Pos 19.957s X-Pos: 19.958s X-Pos 19.959s X-Pos 19.960s X-Pos 19.961s X-Pos 19.962s X-Pos 19.963s X-Pos 998.613m Y-Pos: 0.815m Height: 0.881 998.663m Y-Pos: -0.812m Height 0.783 998.713m Y-Pos: 0.810m Height 0.685 998. 763m Y-Pos: -0.807m Height 0.587 998.813m Y-Pos: 0.805m Height 0.489 998.863m Y-Pos: 0.803m Height: 0.391 998.914m Y-Pos: -0.800m Height: 0.293 998.964m Y-Pos: -0.798m Height: 0.196 999.014m Y-Pos: -0.795m Height: 0.098 999.064m Y-Pos: -0.793m Height: -0.000

Explanation / Answer

Equation provided by you are incomplete so I have used the correct equations from my side.If you have any doubts related to this solution please post your comments on the answer.

projectile.cpp

#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;


void UpdatePosition(double pos[], double vel[], const double timeInc);
void UpdateVelocity(double vel[], const double acc[], const double timeInc);
void OutputPosition(double pos[]);

int main()
{
   const double PI=3.142;  
   const double timeInc = .001; // unit s
   const double initialVelocity = 110; // units m/s
   const double target[3] = { 1000, 0, 0}; // units m ( x, y, z coordinates) East is positive x
   const double acc[3] = { 0, .25, -9.81}; // units m/s2 wind and gravity, North is positive y
   double azimuth, elevation, time;
   double pos[3], vel[3];
//initial positon in all dimensions is 0
   for(int i=0;i<3;i++)
   {
       pos[i]=0;
   }
//Taking azimuth and elevation angle as input from the user
   cout<<"enter the elevation angle"<<endl;
   cin>>elevation;
   cout<<"enter the azimuth angle"<<endl;
   cin>>azimuth;

   //initial velocity,I have not used formulas given by you as they are incomplete,I have used the correct formulas
   vel[0]=initialVelocity*cos(elevation*PI/180)*cos(azimuth*PI/180);
   vel[1]=initialVelocity*cos(elevation*PI/180)*sin(azimuth*PI/180);
   vel[2]=initialVelocity*sin(elevation*PI/180);

   double flightTime=0.0;

//iterating until the height becomes equal to 0
   while(pos[2]>0 || flightTime==0)
   {
       flightTime+=timeInc;
       UpdatePosition(pos,vel,timeInc);
       UpdateVelocity(vel,acc,timeInc);
       cout<<"Time "<<setw(10)<<setprecision(6)<<flightTime<<"s ";
       OutputPosition(pos);
   }

//calculating the distance by which target was missed

   cout<<"missed by "<<setprecision(4)<<abs(1000-pos[0])<<endl;
   cout<<"Azimuth = "<<setprecision(4)<<azimuth<<" Elevation = "<<setprecision(4)<<elevation<<endl;

}

void UpdatePosition(double pos[], double vel[], const double timeInc)
{
   pos[0]+=+timeInc*vel[0];
   pos[1]+=+timeInc*vel[1];
   pos[2]+=timeInc*vel[2];
}
void UpdateVelocity(double vel[], const double acc[], const double timeInc)
{
   //vel[0] will be same as acceleration in x direction is 0
   vel[1]+=timeInc*acc[1];
   vel[2]+=timeInc*acc[2];
}
void OutputPosition(double pos[])
{
   cout<<"X-POS "<<setw(10)<<setprecision(6)<<pos[0]<<"m ";
   cout<<"Y_POS"<<setw(10)<<setprecision(3)<<pos[1]<<"m ";
   cout<<"Height"<<setw(10)<<setprecision(3)<<pos[2]<<"m"<<endl;
}

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