Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The distance of the landing of a projectile, launched at an angle angle (in radi

ID: 3690642 • Letter: T

Question

The distance of the landing of a projectile, launched at an angle angle (in radians) with the initial velocity of velocity (in feet per second) is given by the formula distance = 0.031056* [velocity^2* sin (2 * angle)] Write a C++ program that implements a game in which the user first enters the distance to a target. The user then enters the angle and velocity for launching a projectile. If the projectile comes within 0.01 % of the distance to the target, the user wins the game. If the projectile does not come close enough, the user is told how far off the projectile is and is allowed to If there is not a winning input after five tries then the user loses the game. To simplify input for the user, your program should have the angle to input in degrees. The formula for converting degrees to radians is radians = 0.0174533 * degrees Each of the formulas in this problem should be implemented as a C++ value-returning function Your program should prompt the user for input appropriately, label the output values and have proper programming style. Use proper indentation, appropriate comments, and meaningful identifiers thought the program.

Explanation / Answer

Solution.cpp

#include <iostream>//input output function header file
#include <math.h>//header file for mathematical operations


using namespace std;//it tells the compiler t link the std name space
// function declarations
void play(float d);

// function for function convertRadians
float con_Rad(float& radians);

// function calculateDistance
double cal_Dist(float d);
float velocity, angle, totaldistance;// Declare objects in global scope to be used by all functions

// main function which returns integer
int main()
{

// uDistance variable for user defined distance
double d;
char display='Y';

  
while(display== 'Y')
{

  
  
cout << "Lets Play Projectile game! "<<endl;
cout <<"Please enter a distance--"<<endl;
// keyboard inputting using cpp
cin >> d;


// Play the game, use function play
play(d);

  
cout << "Would you like to play again? Enter Y for yes " << endl;
cin >> display;
if(display!='Y')
exit (EXIT_FAILURE);// EXIT_FAILURE, an unsuccessful termination status is returned to the host environment.

cout << endl;
}


cin.get();
return 0;
}

void play(float d)
{
// Begin for
for (int attempts = 0; attempts <= 4;attempts++)
{
// Ask user for angle input
cout << " enter angle ";
cin >> angle;

// Convert angle value to radians
con_Rad(angle);

cout << " enter velocity ";
cin >> velocity;

// Call upon calculateDistance to find if user wins or not
cal_Dist(d);

if (totaldistance <= 0.1)
{
cout << "You won the game!" << endl;
cout << "You are at " << totaldistance << " of the target!" << endl;
break; // Break out of the for loop
}
  
else
{
cout << " please try again." << endl;
cout << "You are at " << totaldistance << " of the target." << endl;
cout << endl;
}

// End if
}


}
//function definition
float con_Rad(float& rad)
{
rad = ((angle*3.14159)/180);

return rad;
}
//function definition
double cal_Dist(float d)
{
double dist;
double sinvalue = (2 * angle);
dist = (((velocity*velocity) * sin(sinvalue)/32.2));
totaldistance = dist/d;

return totaldistance;
}

output

Lets Play Projectile game!

Please enter a distance-- 100

enter angle 60

enter velocity 100

please try again.

You are at 2.68952 of the target.

enter angle 50

enter velocity 190

please try again. You are at 11.0409 of the target.

enter angle 10

enter velocity 100

please try again.

You are at 1.06217 of the target.

enter angle 10

enter velocity 100

please try again.

You are at 1.06217 of the target.

enter angle 0

enter velocity 100

You won the game!

You are at 0 of the target!

Would you like to play again?

Enter Y for yes

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote