Question: c++ Declares a 2D integer array of size 10*10 that represents the terrain Uses random number generation to populate safe and unsafe locations of the

c++

Declares a 2D integer array of size 10*10 that represents the terrain

Uses random number generation to populate safe and unsafe locations of the terrain

o Each location in the grid has 50% probability to be safe and 50% to be unsafe o Safe locations are represented by the number 1

o Unsafe locations are represented by the number 0

Displays a well-formatted table that visualizes the terrain

Prompts the user to enter the (x, y) coordinates of the desired landing location

Implements and calls a function that attempts to land the lunar lander o bool land(int *location);

If the location is safe, change its value to 3 (using int *location) to indicate the lunar lander has landed successfully

Parameters:

int *location: a pointer to the element in the 2D array that was selected by the user

Return value:

true: if the location is safe

false: if the location is unsafe

If the location is unsafe, displays a message to the user and prompts for another (x, y) coordinates to attempt a landing, until a successful one is entered. You may NOT use any global variables in this program.

Prompting the user to enter one of four directions in which to move: left, right, up, down o Validate the user input for one of the four possibilities

Making sure that the proposed move keeps the rover inside the grid

o For example, do not accept an attempted move to the left from (0, 5)

Implementing a function that simulates the movement of the lunar rover:

o bool move(int *old_location, int *new_location);

If the new location is safe, change its value to 3 and the old location to 1

to indicate a successful move, then return true

If the new location is unsafe, then return false

In a loop, prompt the user to move the rover until it attempts an unsafe mov

sample output:

c++ Declares a 2D integer array of size 10*10 that represents the

EEHW09.pdf Optional Bonus Sample Output | 0 1 2 345 678 9 1 000 0 0 3 10 0 0 4100 0 0 0 0 610 0 0 0 0 Enter (x, y) coordinates: 11 CRASH! Try again! Enter (x, y) coordinates: 4 5 1 0 1 2 345 678 9 1 000 0 0 3 10 0 0 4100 0 300 0 610 0 0 0 0 SUCCESSFUL LANDING! Enter a move (L, R, U, or D) : N Invalid move! Try again! Enter a move (L, R, U, or D) : D 1 0 1 2 345 678 9 1 000 0 0 3 10 0 0 4100 0 0 0 0 5 0 3 0 610 0 0 00

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!