Does anybody know how to write this program? For HW#7 we will return to the stat
ID: 655365 • Letter: D
Question
Does anybody know how to write this program?
For HW#7 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#7 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
const double acc[3] = { 0, .5, -9.81}; // units m/s2
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.
Explanation / Answer
#include<iostream.h>
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 timeInc = .001 // unit s
const double initialVelocity = 110; // units m/s
const double target[3] = { 1000, 0, 0}; // units m
const double acc[3] = { 0, .5, -9.81}; // units m/s2
double azimuth, elevation, time;
double pos[3], vel[3];
UpdatePosition(pos,vel,timeInc);
UpdateVelocity(vel,acc,timeInc);
OutputPosition(pos);
}
void UpdatePosition(double pos[], double vel[], const double timeInc){
for(int i=0;i<10;i++){
vel[i]=pos[i]/timeInc;
}
}
Void UpdateVelocity(double vel[], const double acc[], const double timeInc){
for(int i=0;i<10;i++){
acc[i]=vel[i]/timeInc;
}
}
void OutputPosition(double pos[]){
for(int i=0;i<10;i++){
cout<<pos[i];
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.