(The assignment formerly known as Mouse Escape) 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. In C++ language  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.
Chapter5: Repetition Statements
Section: Chapter Questions
Problem 2PP: (Mechanics) The deflection at any point along the centerline of a cantilevered beam, such as the one...
icon
Related questions
Question

(The assignment formerly known as Mouse Escape)

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.

In C++ language  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
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

how do you create a .txt file so that the program will run from it?

Solution
Bartleby Expert
SEE SOLUTION
Follow-up Question

can you write out how the island txt. file is supposed to look to make the code run?

Solution
Bartleby Expert
SEE SOLUTION
Follow-up Question

What is the island.txt file that the code is referring too?

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Fundamentals of Boolean Algebra and Digital Logics
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