We win be developing a simulation of landing a lunar module
We win be developing a simulation of landing a lunar module on the surface of the moon. It\'s a lunar lander game. Let\'s start with the motion of our lender simply falling to the moon\'s surface. All we need to know to simulate this free fall is the rate of acceleration due to gravity. Because the gravity of the moon is only 1/6 that here on Earth, an object falling on the moon will accelerate at the rate of -1.63 m/s2. Your first task for this is to write a program (from scratch) that prompts the user for an initial altitude and an initial velocity. It then updates the altitude and the velocity after a second has passed, and prints out the new values with two decimal values after the decimal place. To do this, we start with an altitude of a meters and a velocity of v meter per second. One second later, the altitude will be a+v. Similarly, if we start with a velocity of v meters per second and an acceleration due to gravity of g meters per second squared, one second later the velocity will be v+g. Landing Once you are confident in your calculations, extend your code to run until the lander either lands or crashes. If the speed at which your lander hits the ground is faster than -2m/s it has crashed. When the lander reaches the ground, tell the user if it was safe or crashed. Use the Rockets to slow down Our next step is to allow us to bum fuel to slow our descent. At the end of each iteration (actually before adding the gravity to the velocity), ask the user for a number of fuel units to bum during that second. If we burn f units of fuel, our acceleration during that second will be -1-63+0.1f (as opposed to our normal -1.63). Make sure the user can\'t cheat by burning negative fuel. Finite Fuel A real lander can\'t have unlimited fuel. Ask the user for the amount of fuel on board and make use the user can\'t burn more than they have. Example Run Enter an initial altitude: 10 Enter an initial velocity: 1 Enter the initial fuel amount: 0 After 1 seconds Altitude is 11.00 meters, velocity is 1.00m/s How much fuel do you want to burn? 0 After 2 seconds Altitude is 10.37 meters, velocity is -0.63m/s How much fuel do you want to burn? 0 After 3 seconds Altitude is 8.11 meters, velocity is -2.26m/s How much fuel do you want to burn? 0 After 4 seconds Altitude is 4.22 meters, velocity is -3.89m/s How much fuel do you want to burn? 0 After 5 seconds Altitude is 0.00 meters, velocity is -5.52m/s
Solution
#include <iostream>
#include <string>
using namespace std;
int main ()
{
/**declaration variables altitude as alt, velocity as vel and
*fuel amount as f_amount
*/
float altitude,velocity;
int fuel_amount;
/***intital time t=0 and gravity g=-1.63*/
int t=0;
float g=-1.63f;
cout << \"Enter an intital altitude:\";
cin >> alt;
cout << \"Enter an intital velocity:\";
cin >> vel;
cout << \"Enter the intital fuel amount\";
cin >> f_amount;
while(alt>=0)
{ t=t+1;
alt=alt+vel;
cout<<\"After \"<< t <<\" seconds Altitude is \"<< alt <<\"meters, velocity is \"<<vel<<\"m/s\"<<endl;
cout<<\"How much fuel do u want to burn?\";
cin>>f_amount;
vel=vel+gravity;
}
if(abs(vel)>2)
{
cout<<\"we crashed :(\";
}
else
{
cout<<\" we lands:\";
}
return 0;
}

