I need help writing the following c++ code assignment Your program will prompt t
ID: 3541325 • Letter: I
Question
I need help writing the following c++ code assignment
Your program will prompt the user for the initial total velocity and the angle IN DEGREES above the horizontal at which the object is thrown. All the values in your program should be double values. Your program will then verify that the velocity is greater than or equal to zero and the angle is between 0 and 90 degrees inclusive. It will then echo the input back to the user and then call a function to simulate the trajectory. In most senses, you can ignore the physics and just write the code. Your program should covert the angle from degrees to radians (because the built in math functions want radians) and compute horizontal and vertical com- ponents of velocity as per equations (1) and (2) above. You should then run a while loop on time t in seconds, starting with t = 1.0 and continuing until the vertical position is less than zero.
Program should produce:
Enter the initial velocity (feet per second):
100
Enter the initial angle in degrees (from the horizontal):
30 .
enter simulate
Angle in radians: 0.523599
Initial velocity upwards (fps): 50
Initial velocity forward (fps): 86.6025
(x, y) at time 0 is (0, 0)
(x, y) at time 1 is (86.6025, 34)
(x, y) at time 2 is (173.205, 36)
(x, y) at time 3 is (259.808, 6)
(x, y) at time 4 is (346.41, -56)
Explanation / Answer
#include<iostream>
#include<math.h>
#include<conio.h>
using namespace std;
int main(){
int t = 1;
char c;
double v, theta, vx, vy, x, y = 0;
cout << "Enter the initial velocity (feet per second): ";
cin >> v;
cout << "Enter the initial angle in degrees (from the horizontal): ";
cin >> theta;
theta *= 0.01745329;
vx = v * cos(theta);
vy = v * sin(theta);
cout << "enter simulate ";
c = getch();
cout << "Angle in radians: " << theta << endl;
cout << "Initial velocity upwards (fps): " << vy << endl;
cout << "Initial velocity forward (fps): " << vx << endl;
cout << "(x, y) at time 0 is (0, 0) ";
while(y >= 0){
x = vx * t;
y = vy * t - (32 * t * t) / 2;
cout << "(x, y) at time " << t++ << " is (" << x << ", " << y << ") ";
}
return 0;
}