Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please solve and explain the following question Your job for this program is to use recursion to count the number of blobs in a 2D

please solve and explain the following question
image text in transcribed
image text in transcribed
image text in transcribed
Your job for this program is to use recursion 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. a a 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 O'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. Prompt the user for a filename to read in a given text file containing O's and *'s. 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 O's around the actual world. Count the number of blobs found and print the total count under the worlds as shown in the example. "punoy sqota 95 ##@@@#@#@@@@@ # # # # @@#@#@@#@@@ @ @ @ @ # # # # # # # # @ @ @ @ @ @ @#@@ # # #@#@#@@@ # OOO ##@# # @ @ eeeeeeeeeeeeeeee # # # ##@@#@@@#@#@#@@@@@@ ###! ## @@#@@@@@#@@@#@@@#@@@ ##@@@@@#@@@ @ @ @ @ @ @ @# 4 + @@#@@@ ##@@ # # # # # # @ @ 0 # # @@ #####@@@@@@#@@ @@#@#@@@ Esqotq p @@..@@@@@@@@@@@@. ..@@@@@@@@@.0.0.0 @ @.@.@@@@@@@@@@... ..@@.0 .@@@@@@@@@ .@.@@@@@@@.@.@..@ eee. eeeeeeee. .. ... 0.000 @. eee @@.... . eeeeeeeee 0 @.@@.@@. eeeeeee 0 0.0 0.0 80. e e @ @ @ @ @ @ @.@ @@@@@@@... @@@@@@..@@ D.... 8@.@. ..@.@@@@@@@@@. e @..@@.@..@@@@@@@@@ 8 OB 0.08 0..@.@@@@@@ @.@.@.@.@@ @ @ @@@@@ : **** 314 99 pmoys urugod jo uonevejdx pue Suspeoy andino inox +++ [d Program 1 Hints: If you are programming in c++, remember to include the following libraries: iostream (for reading file names from keyboard), fstream (for file reading/writing), and string (for string input/output) Either create a border of 0's (character 0, not integer () or check for out-of- bounds before calling recursive function. IMPORTANT: Read in and print out the world before you do anything else. If you use a border of O's, remember that nested loops processing and printing should go from 1 to n-1 (with the exception of initializing the world). Scanning the 2D array is a nested loop; not recursive. This can be in the main or in a function. If an asterisk, *, is encountered, count the blob and call the recursive function, process Blob (or whatever you want to name it). processBlob, should be sent the 2D array and a specific position (row & col value). The base case for the recursive function is implied (do nothing). If an* is found, it should be replaced with # and only if an * is found, make 4 recursive calls, one for each von Neumann neighbor. Start programming soon. This program is somewhat tricky. Ask for help if needed. a a

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Systems

Authors: Ramez Elmasri, Sham Navathe

4th Edition

0321122267, 978-0321122261

More Books

Students also viewed these Databases questions

Question

What is the difference between Needs and GAP Analyses?

Answered: 1 week ago

Question

What are ERP suites? Are HCMSs part of ERPs?

Answered: 1 week ago