(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# ############
(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#
############
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images
how do you create a .txt file so that the
can you write out how the island txt. file is supposed to look to make the code run?
What is the island.txt file that the code is referring too?