Question: C ++ question please only use branches and loops because that's where we are at. Newtons laws of motion predict the (x, y) position of
C ++ question
please only use branches and loops because that's where we are at.
Newtons laws of motion predict the (x, y) position of an object at time T, with an initial velocity V (in ft/sec) and initial angle of movement A(in degrees). Ignoring friction, the equations are
x = cos(A)VT y = sin(A)VT - (1/2)gT^2
where g denotes the acceleration due to gravity; assume the constant g = 32.174 ft/sec^2. For example, an American football thrown at an angle A of 40 degrees, with an initial velocity V of 88 ft/sec, is at position (134.824, 48.7825) when time T = 2 seconds. On an American football field, that's about 45 yards down the field, and 16 yards up in the air.
Write a complete C++ program that inputs three values: the initial velocity V in ft/sec (a real number), the angle A in degrees (a real number), and the timestep (a real number), in this order. The program then computes the (x, y) position of the object at every timestep, starting at 0.0 seconds and stopping after 5.0 seconds. For example, suppose the inputs are the following angle and initial velocity
88.0 40.0 0.5
Your program should output the following values, where each line denotes the time T followed by the object's (x, y) position at T:
0: (0, 0) 0.5: (33.706, 24.2609) 1: (67.4119, 40.4783) 1.5: (101.118, 48.6522) 2: (134.824, 48.7825) 2.5: (168.53, 40.8694) 3: (202.236, 24.9128) 3.5: (235.942, 0.912695) 4: (269.648, -31.1309) 4.5: (303.354, -71.218) 5: (337.06, -119.349)
Note that C++ provides built-in cosine and sine functions, cos(R) and sin(R). However, these functions work in radians (not degrees), so you'll need to convert A to radians using R = A * PI / 180; define PI=3.14159. You'll also need to include the header file to gain access to the cos(R) and sin(R) functions.
Assume all input values are valid, i.e. are positive real numbers.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
