Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Code Only Missile Game or Calculate the Range of a Projectile Fired at an Angle You can use physics to calculate how far a

C++ Code Only

image text in transcribedimage text in transcribed

image text in transcribed

Missile Game or Calculate the Range of a Projectile Fired at an Angle You can use physics to calculate how far a projectile will travel. When calculating projectile motion, it. is necessary to separate the horizontal and vertical components of the motion. This is because the force of gravity only acts on the projectile in the vertical direction, and the horizontal component of the trajectory's velocity remains uniform.[1] Here's an example: Imagine that you fire a cannonball at an angle, as shown in the preceding figure. Given the initial speed of the cannonball and the angle at which it was shot, can you determine how far it will travel? In physics, assuming a flat Earth with a uniform gravity field, and no air resistance, a projectile launched with specific initial conditions will have a predictable range. This assumption, a.k.a., Ideal projectile motion, simplifies the mathematics and is a close approximation of actual projectile motion in cases where the distances travelled are small [2]. Assuming the projectile is launched from the qround, the ideal project motion formula can be used. The distance to the landing point of a projectile, launched at an angle (in radians) with an initial velocity of velocity (in feet per second). ignoring air resistance, is given by the formula distance=32.2velocityvelocitysin(2angle) Program Assignment: You are to create a game where given the distance to a target, the user is given up to 5 changes to guess a velocity and angle to try to hit the target. If the projectile comes within 0.1% of the distance to the target, the user wins the game. If the projectile doesn't come close enough, the user is told how far off the projectile is and is allowed to try again. Each of the formulas in this problem should be implemented as a C++value-returning function. Suggestions/hints: Consider the following pseudocode and functions to start: - Ask the user to first enters the distance to target. Function: GetTargetDistance (1) - The user then enters the angle and velocity for lunching a projectile. GetLauncherAngle () t DegreesroRadians ( -), GetMissilevelocity (); - Determine if the projectile comes within 0.1% of the distance to the target. If so, then the user wins the game. If the projectile doesn't come close enough, the user is told how far off the projectile is and is allowed to try again. CalcwinningRange ( - ) f calckissileDistance 17 Printsumary l - If there isn't a winning input after five tries, then the user loses the game. DegreesToRadians( ....); To simplify input for the user, your program should allow the anqle to be input in deqrees. The formula for converting degrees to radians is radians=degrees3.14159265/180.0 Output Example:See end of document for more examples The distartea to the target (in feut) must be se bero. Entev target distance: 629 The larencher afgle fin degreas) must be in-betwein auro and ninaty. Enter launchal aingle: 45 The misile volocifr fin feve per second) must be geater thath apre. Enter mivile miocity 45 Shot Namber:1 Target Distance: 62.9 Linuncher Angle: 45 Miseile Velocity. 45 Misile Distance: 62 Rea2 The misole landed 0.0118027 fewt dhert of the target. Hicl rou win tha game! Submissions: - Source code with pseudocode as comments - Loq file demonstrating test - Video explaining your program and test References: 1. Holzner, Steven, "CALCULATE THE RANGE OF A PROJECTILE FIRED AT AN ANGLE" in related book Pyysicis I for Dummies, 2nd edtion, or at httos://www.dummies.com/education/science/phisics/calculate-the-range-of-a-projectilefired-at-an-anglel 2. Wikipedia: https://en-wikipedia.org/wiki/Range_of_a_projectile The dstance to the target (in fevt) mug be > aero. Enter tarpet distatce: 62.4 The launcher anple fin degressf must be is-between zaro and nieety. Coterinuncher angie: 45 The missle velbcity lin feet per second, must be preater than zere. Enter miscie rolocity: 45 Shot Number: 1 Target Distance: 62.9 Launcher Anvle: 45 Miscle velocity. 45 Msole Distance: 62 . 88a2 The miskle landed 0.0118027 fevt hicrt of the tanget. Hinl You win the gaine! or The distance to the target (in feet) mat be > aedo. Eater target distance. 62 The launchar argle (in degees) mugt bat in-betawn 2ero and rincty. Eater launchar angle: 76 The misile wiochy (in feot per secend) must be greater than zero. Enter miasile vilooty: 2 The misile wiocity fin fevt per secend) must be greater than zeero. Enter miale volacity: 23 Shot Number: 1 Targen Diatance 62 Laincher Aegfe. 76 Misile veloeity: 23 Misile Distance: 7.71275 The misile langed 54.2873 fees shot of the terget. 1) Einer tries for thats 24 The launcher augle (in degrees) must be in-betwoen 2ero and rinety. Enter launcher aufle: 35 The misile wiociny lia feet por secend mast be greatee than zeero. Enter misill volacity: 75 Shot Number: 5 Target Ditance: 62 Laincher Aefle: 35 Misile vetocty. 75 Missile Distance: 164.154 Missile Game or Calculate the Range of a Projectile Fired at an Angle You can use physics to calculate how far a projectile will travel. When calculating projectile motion, it. is necessary to separate the horizontal and vertical components of the motion. This is because the force of gravity only acts on the projectile in the vertical direction, and the horizontal component of the trajectory's velocity remains uniform.[1] Here's an example: Imagine that you fire a cannonball at an angle, as shown in the preceding figure. Given the initial speed of the cannonball and the angle at which it was shot, can you determine how far it will travel? In physics, assuming a flat Earth with a uniform gravity field, and no air resistance, a projectile launched with specific initial conditions will have a predictable range. This assumption, a.k.a., Ideal projectile motion, simplifies the mathematics and is a close approximation of actual projectile motion in cases where the distances travelled are small [2]. Assuming the projectile is launched from the qround, the ideal project motion formula can be used. The distance to the landing point of a projectile, launched at an angle (in radians) with an initial velocity of velocity (in feet per second). ignoring air resistance, is given by the formula distance=32.2velocityvelocitysin(2angle) Program Assignment: You are to create a game where given the distance to a target, the user is given up to 5 changes to guess a velocity and angle to try to hit the target. If the projectile comes within 0.1% of the distance to the target, the user wins the game. If the projectile doesn't come close enough, the user is told how far off the projectile is and is allowed to try again. Each of the formulas in this problem should be implemented as a C++value-returning function. Suggestions/hints: Consider the following pseudocode and functions to start: - Ask the user to first enters the distance to target. Function: GetTargetDistance (1) - The user then enters the angle and velocity for lunching a projectile. GetLauncherAngle () t DegreesroRadians ( -), GetMissilevelocity (); - Determine if the projectile comes within 0.1% of the distance to the target. If so, then the user wins the game. If the projectile doesn't come close enough, the user is told how far off the projectile is and is allowed to try again. CalcwinningRange ( - ) f calckissileDistance 17 Printsumary l - If there isn't a winning input after five tries, then the user loses the game. DegreesToRadians( ....); To simplify input for the user, your program should allow the anqle to be input in deqrees. The formula for converting degrees to radians is radians=degrees3.14159265/180.0 Output Example:See end of document for more examples The distartea to the target (in feut) must be se bero. Entev target distance: 629 The larencher afgle fin degreas) must be in-betwein auro and ninaty. Enter launchal aingle: 45 The misile volocifr fin feve per second) must be geater thath apre. Enter mivile miocity 45 Shot Namber:1 Target Distance: 62.9 Linuncher Angle: 45 Miseile Velocity. 45 Misile Distance: 62 Rea2 The misole landed 0.0118027 fewt dhert of the target. Hicl rou win tha game! Submissions: - Source code with pseudocode as comments - Loq file demonstrating test - Video explaining your program and test References: 1. Holzner, Steven, "CALCULATE THE RANGE OF A PROJECTILE FIRED AT AN ANGLE" in related book Pyysicis I for Dummies, 2nd edtion, or at httos://www.dummies.com/education/science/phisics/calculate-the-range-of-a-projectilefired-at-an-anglel 2. Wikipedia: https://en-wikipedia.org/wiki/Range_of_a_projectile The dstance to the target (in fevt) mug be > aero. Enter tarpet distatce: 62.4 The launcher anple fin degressf must be is-between zaro and nieety. Coterinuncher angie: 45 The missle velbcity lin feet per second, must be preater than zere. Enter miscie rolocity: 45 Shot Number: 1 Target Distance: 62.9 Launcher Anvle: 45 Miscle velocity. 45 Msole Distance: 62 . 88a2 The miskle landed 0.0118027 fevt hicrt of the tanget. Hinl You win the gaine! or The distance to the target (in feet) mat be > aedo. Eater target distance. 62 The launchar argle (in degees) mugt bat in-betawn 2ero and rincty. Eater launchar angle: 76 The misile wiochy (in feot per secend) must be greater than zero. Enter miasile vilooty: 2 The misile wiocity fin fevt per secend) must be greater than zeero. Enter miale volacity: 23 Shot Number: 1 Targen Diatance 62 Laincher Aegfe. 76 Misile veloeity: 23 Misile Distance: 7.71275 The misile langed 54.2873 fees shot of the terget. 1) Einer tries for thats 24 The launcher augle (in degrees) must be in-betwoen 2ero and rinety. Enter launcher aufle: 35 The misile wiociny lia feet por secend mast be greatee than zeero. Enter misill volacity: 75 Shot Number: 5 Target Ditance: 62 Laincher Aefle: 35 Misile vetocty. 75 Missile Distance: 164.154

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions