Question: For this assignment, you are to write the implementation of a lunar lander class that has been specified in a file called LunarLander.hpp . This

For this assignment, you are to write the implementation of a lunar lander class that has been specified in a file called LunarLander.hppFor this assignment, you are to write the implementation of a lunarlander class that has been specified in a file called LunarLander.hpp. This. This class is designed to model a simple lunar lander that can rotate left or right, and can burn fuel in a rocket engine to provide thrust.

There are three files involved in this assignment:

LunarLander.hppclass is designed to model a simple lunar lander that can rotateleft or right, and can burn fuel in a rocket engine to - the specification file that is given to you

LunarLander.cpp - the implementation file that you must write

LanderSim.cppprovide thrust. There are three files involved in this assignment: LunarLander.hpp -the specification file that is given to you LunarLander.cpp - the implementation - the client file that uses your implementation

Note that in LanderSim.cpp, there is a #include "LunarLander.hpp". You'll do the same for your implementation file, but in that file, you need only define the functions called for in the specification file. Make no modifications to LunarLander.hpp or LanderSim.cpp as you will only upload you implementation file to Jarvis.

To help you get rolling on your lander implementation, here are a few rules that govern how the lander behaves:

rotateLeft(), rotateRight(), and burn() may be called multiple times before updateTime(), allowing you to perform multiple actions in one time interval of the game.

rotateLeft() and rotateRight() both accept a positive rotate angle in radians.

Negative inputs for rotateLeft() and rotateRight() are to be converted to positive values. The sum of all the rotation commands during a given time interval is not allowed to exceed PI/12.0 in either direction.

The sum of all the burn commands in a time interval must not exceed 50. You may not burn negative fuel.

You should use the private member variables rotatedThisTurn and fuelBurnedThisTurn to keep track of the sum of all the commands since the last timeUpdate() call.

The timeUpdate() function is where most of the activity happens. You need to:

Set your new angle and fuel amounts

Figure out your thrust vector (1 unit of fuel burned equals an acceleration of 1 m/s^2).

Figure out your new velocity vector, and then calculate your new position. Do not allow the Y position go below 0.

You need to figure out if you've crashed or landed,

Reset your rotateThisTurn and fuelBurnedThisTurn variables to get ready for the next time interval.

Remember that you can't burn fuel you don't have.

Your lander should crash if the landing angle is not 90 degrees (PI/2 radians) or if the lander touches down at a speed greater than the max touchdown speed. Be careful when comparing floating point numbers for equality - remember that they are approximations!

What to turn in: LunarLander.cpp. Turn in no other files. Do not turn in a .zip archive.

Hints: 1. The exact code I use to calculate the thrust is

thrust.x=cos(angle)*fuelBurnedThisTurn;

thrust.y=sin(angle)*fuelBurnedThisTurn;

2. Because our time update is in 1-second increments...

...your new velocity is your old velocity plus your thrust plus G

...your new position is you old position plus the velocity

3. Remember that the current angle of the spacecraft is stored in radians.

4. MTS stands for Max Touchdown Speed.

5. Go play the game a few times at http://moonlander.seb.ly (Links to an external site.). This will help you figure out what you should be doing.

Your code must compile with zero errors and zero warnings and execute with zero differences from the expected results on Jarvis in order to receive full credit for this assignment.

This is the LunarLander.hpp file

#ifndef _LUNAR_LANDER_HPP #define _LUNAR_LANDER_HPP #define PI 3.14159 using namespace std; //Vector definition struct Vect { double x; double y; }; class Lander{ public: //constructors Lander(); Lander(Vect iG, double iangle, Vect ivelocity, double ifuel, Vect iposition, double imax, bool icrashed, bool ilanded); //accessors double getAngle(); Vect getVelocity(); double getFuel(); Vect getPosition(); double getMTS(); bool getCrashed(); bool getLanded(); //controls void rotateLeft(double rotateAngle); // max rotation per sec is pi/12 // rotateAngle should be a // positive number. This function // affects only the variable // rotatedThisTurn. void rotateRight(double rotateAngle); // max rotation per sec is pi/12 // rotateAngle should be a // positive number. This function // affects only the variable // rotatedThisTurn. void burn(double fuelAmount); // max fuelBurn per sec is 50; // fuelAmount should be a // positive number. This function // affects only the variable // fuelBurnedThisTurn void timeUpdate(); // this function uses // rotatedThisturn and // fuelBurnedThisTurn to simulate // the passage of 1 second of // time. this vunction updates // angle, thrust, velocity, // position, fuel, crashed, and // landed. it also resets // rotatedThisTurn and // fuelBurnedThisTurn private: Vect gravity; // 1.622 m/s^2 on the moon double angle; // radians. 0 radians is positive x direction // straight up is pi/2 radians Vect thrust; // m/s^2 Vect velocity; // m/s double fuel; // 1 unit of fuel equals 1m/s^2 of acceleration Vect position; // meters double maxTouchdownSpeed; // do not exceed at landing bool crashed; // becomes true if position.y bool landed; // becomes true if position.y double rotatedThisTurn; // the sum of all rotation commands since the // last timeUpdate. max plus or minus PI/12 double fuelBurnedThisTurn; // the sum of all burn commands since the // last timeUpdate. max 50 }; #endif 

This is the LanderSim.cpp

#include  #include  #include  #include "LunarLander.hpp" #include  #include  #include  #include  #define INTERACTIVE 1 // Set to 1 for text-based coolness, otherwise set it to 0. #define SROWS 32 // how tall the screen is #define SCOLS 80 // how wide the screen is using namespace std; // did the client type any l's or L's? Let's count. int ells(string input) { int l = 0; for (int i = 0; i if (input[i] == 'l') { l++; } if (input[i] == 'L') { l += 10; } } return l; } // did the client type any r's or R's? Let's count. int arrs(string input) { int r = 0; for (int i = 0; i if (input[i] == 'r') { r++; } if (input[i] == 'R') { r += 10; } } return r; } // did the client type any b's or B's? Let's count. int bees(string input) { int b = 0; for (int i = 0; i if (input[i] == 'b') { b++; } if (input[i] == 'B') { b += 10; } } return b; } // have the user type in a possibly empty command line // and make the lander do what the user says void getCommands(Lander& l) { string input; if (INTERACTIVE) { // if INTERACTIVE mode is set, get some commands getline(cin, input); l.burn(bees(input)); l.rotateLeft(ells(input) * PI / 180.0); l.rotateRight(arrs(input) * PI / 180.0); } else  { // put your autopilot software here if you feel up to the challenge // otherwise don't bother return; } } // print out information about the lander's status void dashboard(Lander l, int frame) { int r,c; int cc; Vect p,v; double a; double f; static bool rock[SCOLS]; static bool rockset = false; int landerLine = 0; int rockLine = 0; // make some rocks if (!rockset) { rockset = true; for (int j = 0;j false; } for (int j = 0; j true; } } // get the lander status p = l.getPosition(); v = l.getVelocity(); a = l.getAngle(); f = l.getFuel(); // make a character array that looks like what we want on the screen static char screen[SROWS][SCOLS]; for (int i = 0; i for (int j = 0; j for (int j = 0; j for (int j = 0; j if (rock[j]) { screen[SROWS-1][j] = '^'; } } // figure out where the lander is and 'draw' it into the array r = SROWS - (int)(p.y / 10.0); if (r >= SROWS) { r = SROWS - 1; } c = (int)(p.x / 10.0); if (r >= 0 && r = 0 && c if (a >= (1.875 * PI) || a if(c if (a >= (0.125 * PI) && a if (c  0) { screen[r - 1][c + 1] = '/'; } } if (a >= (0.375 * PI) && a if(r > 0) { screen[r - 1][c] = '|'; } } if (a >= (0.625 * PI) && a if(c > 0 && r > 0) { screen[r - 1][c - 1] = '\\'; } } if (a >= (0.875 * PI) && a if(c > 0) { screen[r][c - 1] = '-'; } } if (a >= (1.125 * PI) && a if(c > 0 && r if(a >= (1.375 * PI) && a if(r if(a >= (1.625 * PI) && a if(c if (r else if (r = SCOLS) { screen[0][SCOLS - 1] = '^'; screen[1][SCOLS - 1] = '>'; } else if (r else if (c else if (c >= SCOLS) { screen[r][SCOLS - 1] = '>'; } cc = c; // handle crashes and landings in an interesting way if(l.getCrashed()) { if (c if (r >= 0 && r = 0 && c if (c if (c if (c if (c if (c if (c if (c if(l.getLanded() && rock[c]) { if (c if (c if (c if (c if (c if (c if (c else if(l.getLanded()) { if (c if (c if (c if (c if (c if (c if (c if(INTERACTIVE) { //if INTERACTIVE mode is set, print out the screen //otherwise don't bother for(int i = 0; i bool containsChars = false; for(int j = 0; j if (screen[i][j] != ' ') { containsChars = true; } } if (containsChars) { for(int j = 0; j if (l.getCrashed()) { cout else if (l.getLanded() && rock[cc]) { cout else if (l.getLanded()) { cout else if (l.getFuel() else if (l.getFuel() else  { cout void printInstructions() { // print out the instruction for INTERACTIVE mode char q[3]; cout  to begin) "; cout int main() { #ifdef JARVIS srand(0); #else srand(time(NULL)); #endif int frame = 0; double a = PI; double f = 200.0; double MTV = 5.0; bool crashed = false; bool landed = false; //set up the parameters for a lander Vect G,v,p; G.x = 0.0; G.y = -1.622; v.x = 20; v.y = 0.0; p.x = 100.0; p.y = 300.0; //create an instance of the lander using the above parameters Lander l(G, a, v, f, p, MTV, crashed, landed); //throw out some instructions if we are in INTERACTIVE mode if (INTERACTIVE) { printInstructions(); } //loop once for each second of flight while (!l.getCrashed() && !l.getLanded()) { dashboard(l, frame); getCommands(l); l.timeUpdate(); frame++; } dashboard(l, frame); //all done return 0; } 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!