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# ############

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education