in c++  using 2D Arrays The following diagram represents an island with dry land (represented by “-“) surrounded by water ((represented by “#“). ##-########## #-----------# #-----------# #------------ # -----------# #------X----# #-----------# ############# Two bridges lead off the island. A mouse (represented by “X”) is placed on the indicated square. Write a program to make the mouse take a walk across the island. The mouse is allowed to travel one square at a time, either horizontally or vertically. A random number from 1 to 4 should be used to decide which direction the mouse is to take; for the sake of uniformity assume that 1 = up, 2 = down, 3 = left, and 4 = right.  Since the mouse is wearing cement mouse galoshes, the mouse drowns when he hits the water. He escapes when he steps on a bridge. You may generate a random number up to 100 times allowing the mouse to take 100 steps. If the mouse does not find a bridge by the 100th try, he will wither away and die of starvation.  Restart the mouse in a reinitialized array and repeat the entire process five times. Count the number of times he escapes, drowns, and starves. I have provided 2 example islands that can be used.  The island input is contained in a .txt file (the program must be setup to run the provided island files. First input line: Two integers N and M indicating an NxM array of char that will represent the island including border of water and bridges. Once you have read in n, you can dynamically create an nxm array (e.g., char island = new char[n,n]). The next N input lines are the rows of the two-dimensional array, where the positions “#” represent water, the positions in the edge containing a “-“ represent the bridges, the position containing a “X” represents the starting position of the mouse, and all other positions contain “-“.  Output: the coordinates of bridge 1, the coordinates of bridge 2, the starting position of the mouse, a line stating how many times the mouse escaped, drowned, or starved for that island for the 5 random trials. For each trial, print a map of the island that indicates the frequency count of how many times the mouse visited any given array position up to a max of 9. It will look something like this: ########1### #8113211221# #5########## #1145876231# ############

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter7: Arrays
Section: Chapter Questions
Problem 14PP: (Data processing) Construct a three-dimensional weather array for a two-week time period. Include...
icon
Related questions
Question

in c++  using 2D Arrays

The following diagram represents an island with dry land (represented by “-“) surrounded by water ((represented by “#“).

##-##########

#-----------#

#-----------#

#------------ #

-----------#

#------X----#

#-----------#

#############

Two bridges lead off the island. A mouse (represented by “X”) is placed on the indicated square. Write a program to make the mouse take a walk across the island. The mouse is allowed to travel one square at a time, either horizontally or vertically. A random number from 1 to 4 should be used to decide which direction the mouse is to take; for the sake of uniformity assume that 1 = up, 2 = down, 3 = left, and 4 = right.  Since the mouse is wearing cement mouse galoshes, the mouse drowns when he hits the water. He escapes when he steps on a bridge. You may generate a random number up to 100 times allowing the mouse to take 100 steps. If the mouse does not find a bridge by the 100th try, he will wither away and die of starvation.

 Restart the mouse in a reinitialized array and repeat the entire process five times. Count the number of times he escapes, drowns, and starves. I have provided 2 example islands that can be used.  The island input is contained in a .txt file (the program must be setup to run the provided island files.

  1. First input line: Two integers N and M indicating an NxM array of char that will represent the island including border of water and bridges. Once you have read in n, you can dynamically create an nxm array (e.g., char island = new char[n,n]).
  2. The next N input lines are the rows of the two-dimensional array, where the positions “#” represent water, the positions in the edge containing a “-“ represent the bridges, the position containing a “X” represents the starting position of the mouse, and all other positions contain “-“.

 Output:

  • the coordinates of bridge 1,
  • the coordinates of bridge 2,
  • the starting position of the mouse,
  • a line stating how many times the mouse escaped, drowned, or starved for that island for the 5 random trials.
  • For each trial, print a map of the island that indicates the frequency count of how many times the mouse visited any given array position up to a max of 9. It will look something like this:

########1###
#8113211221#
#5##########
#1145876231#
############

 

Expert Solution
steps

Step by step

Solved in 5 steps with 5 images

Blurred answer
Knowledge Booster
Concept of pointer parameter
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
New Perspectives on HTML5, CSS3, and JavaScript
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:
9781305503922
Author:
Patrick M. Carey
Publisher:
Cengage Learning