Your job for this program is to count the number of "blobs" in a 2D array. You will be given a text file containing a 2D matrix of 0's and *'s. A blob is connected group of *'s. The *'s are connected if they are von Neumann neighbors (top, bottom, left or right). Follow the guidelines below.

  • Use constants for the number of rows and the number of columns. You will be given a 20 x 20 text file, but it is beneficial to store a border of 0's around the actual blob world to make the search for blobs on the edges much easier; i.e. make your array 22 x 22 and store the blob world in locations 1..20, 1..20.
  • Read in a given text file containing 0's and *'s. Prompt the user for the filename.
  • Scan through the 2D matrix. When you find the beginning of a blob, call a recursive function that will replace all of the *'s in the blob with #'s.
  • Print the original blob world and the mutated blob world as shown in the example. Do not print the border of 0's around the actual world.
  • Count the number of blobs found and print the total count under the worlds as shown in the example.

Example:

*** Your output heading and explanation of program should be here ****

Original world:
0 0 0 * 0 0 * 0 0 0 0 0 * 0 * 0 * 0 * 0
0 0 0 0 0 0 * 0 * * 0 * 0 0 * 0 0 0 0 0
0 0 * 0 0 0 0 0 0 0 * * 0 * 0 0 * * 0 0
* 0 0 0 0 0 0 0 0 0 * 0 * * 0 * 0 * 0 0
0 0 * * * * 0 * * 0 0 * * 0 0 0 0 * 0 0
* * * 0 0 0 0 0 0 0 * 0 0 0 0 0 0 0 0 0
0 * 0 0 0 0 0 0 0 0 0 0 * 0 0 0 0 0 * *
0 0 0 * 0 0 0 * 0 0 0 * 0 0 0 0 0 * 0 0
* * * 0 0 0 0 0 0 0 * 0 * 0 0 * 0 0 * 0
0 0 * 0 * * 0 0 * 0 0 0 0 0 0 0 0 0 0 0
* * 0 0 0 * * 0 * 0 0 0 0 * 0 * * * 0 0
0 0 0 0 0 0 * 0 * 0 * 0 0 0 * 0 0 * * *
* * 0 0 0 * 0 0 0 0 0 0 0 0 0 0 0 * 0 0
* 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 * * 0 0 * 0 0 0 0 0 0 * 0 0 0
0 0 * * 0 * 0 * 0 0 0 * 0 0 0 * 0 * 0 *
* * 0 0 * 0 0 0 0 0 0 0 * * 0 * 0 0 * *
* 0 * * 0 0 0 0 0 0 0 0 * 0 0 * 0 * 0 0
0 * * 0 * 0 * 0 0 0 0 0 * 0 * 0 0 0 * *
0 * 0 0 0 0 0 0 0 * 0 0 * 0 0 0 * * 0 0

World with mutated blobs:
0 0 0 # 0 0 # 0 0 0 0 0 # 0 # 0 # 0 # 0
0 0 0 0 0 0 # 0 # # 0 # 0 0 # 0 0 0 0 0
0 0 # 0 0 0 0 0 0 0 # # 0 # 0 0 # # 0 0
# 0 0 0 0 0 0 0 0 0 # 0 # # 0 # 0 # 0 0
0 0 # # # # 0 # # 0 0 # # 0 0 0 0 # 0 0
# # # 0 0 0 0 0 0 0 # 0 0 0 0 0 0 0 0 0
0 # 0 0 0 0 0 0 0 0 0 0 # 0 0 0 0 0 # #
0 0 0 # 0 0 0 # 0 0 0 # 0 0 0 0 0 # 0 0
# # # 0 0 0 0 0 0 0 # 0 # 0 0 # 0 0 # 0
0 0 # 0 # # 0 0 # 0 0 0 0 0 0 0 0 0 0 0
# # 0 0 0 # # 0 # 0 0 0 0 # 0 # # # 0 0
0 0 0 0 0 0 # 0 # 0 # 0 0 0 # 0 0 # # #
# # 0 0 0 # 0 0 0 0 0 0 0 0 0 0 0 # 0 0
# 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 # # 0 0 # 0 0 0 0 0 0 # 0 0 0
0 0 # # 0 # 0 # 0 0 0 # 0 0 0 # 0 # 0 #
# # 0 0 # 0 0 0 0 0 0 0 # # 0 # 0 0 # #
# 0 # # 0 0 0 0 0 0 0 0 # 0 0 # 0 # 0 0
0 # # 0 # 0 # 0 0 0 0 0 # 0 # 0 0 0 # #
0 # 0 0 0 0 0 0 0 # 0 0 # 0 0 0 # # 0 0

56 blobs were found.
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.