Question: In C++ In main, declare an array of doubles or floats to hold the coordinates of the location of a bullet as time passes. Use
In C++
In main, declare an array of doubles or floats to hold the coordinates of the location of a bullet as time passes. Use a 2D array for this. Size the array(const int SIZE{100} for 100 rows, and 2 columns(double axiPosition[SIZE][2]).
Open a do-while or while loop. Call AskUser to ask the user for the angle from which the bullet is shot. This angle is measured in degrees. Remember to convert the degreed to radians, as this is what c++ uses with its trig functions. The function AskUser also asks the user for the velocity, of the bullet in m/s.
Take into account gravity, which should be declared as const grav{9.81}. You will also need to assign the constant for PI. (3.14159).
We will need the velocity in the y-axis and in the x-axis. Call the function, Fire, which will calculate the velocity in both x and y planes. Fire will then call Trajectory, which will calculate the x and y positions of the bullet in intervals of 1 second.
Stop the calculations and filling of the array when the y axis becomes negative, as this is ground level. Fire will assign the positions into the array that tracks the position of the bullet. These intervals will fill the created array with the x and y positions of the bullet. Fire recalculates the y axis velocity and calls Trajectory again.
From main, display the initial velocity and angle of the bullet, then the x and y positions for each second. Then call a WriteFile function to write your position data to an excel file of any type.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
