(a-b) Two n x n squares of black and white cells and (c) an (n + 2) × (n + 2) array implementing square (b).

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

write this program in c++

3. An nxn square consists of black and white cells arranged in a certain way. The
problem is to determine the number of white areas and the number of white cells in
each area. For example, a regular 8 x 8 chessboard has 32 one-cell white areas; the
square in Figure 5.22a consists of 10 areas, 2 of them of 10 cells, and 8 of 2 cells; the
square in Figure 5.22b has 5 white areas of 1, 3, 21, 10, and 2 cells.
Write a program that, for a given n Xn square, outputs the number of white areas
and their sizes. Use an (n + 2) x (n + 2) array with properly marked cells. Two ad-
ditional rows and columns constitute a frame of black cells surrounding the entered
square to simplify your implementation. For instance, the square in Figure 5.22b is
stored as the square in Figure 5.22c.
FIGURE 5.22 (a-b) Two n x n squares of black and white cells and (c) an (n + 2) x (n + 2) array
implementing square (b).
b bbbb b
b bb
bw b b w w b w wb
b bbbb w b
b w ww bbw
b w b w b ww
b w b w w wb
b w bb b bw w wb
b w b w bbw wwb
b w b w b bw w wb
b bbb b b bbbb
(a)
(b)
(c)
Copyright 2012 Cangage Leaming. All Righta Reserved. May not be copied, canned, or duplicated, in whole or in purt. Dac to clectronic rights, some thied party content may be suppreed from the eBook andior oChupierfa).
Editorial revion han docmed tat any approed content do not materially affect the overall leaming caparime. Cngage Leaming reserves the right to nemove additinal content at any time if ahuoquent rights restrictions raquire i
212 1 Chapter 5 Recursion
Traverse the square row by row and, for the first unvisited cell encountered, in-
voke a function that processes one area. The secret is in using four recursive calls in this
function for each unvisited white cell and marking it with a special symbol as visited
(counted).
Transcribed Image Text:3. An nxn square consists of black and white cells arranged in a certain way. The problem is to determine the number of white areas and the number of white cells in each area. For example, a regular 8 x 8 chessboard has 32 one-cell white areas; the square in Figure 5.22a consists of 10 areas, 2 of them of 10 cells, and 8 of 2 cells; the square in Figure 5.22b has 5 white areas of 1, 3, 21, 10, and 2 cells. Write a program that, for a given n Xn square, outputs the number of white areas and their sizes. Use an (n + 2) x (n + 2) array with properly marked cells. Two ad- ditional rows and columns constitute a frame of black cells surrounding the entered square to simplify your implementation. For instance, the square in Figure 5.22b is stored as the square in Figure 5.22c. FIGURE 5.22 (a-b) Two n x n squares of black and white cells and (c) an (n + 2) x (n + 2) array implementing square (b). b bbbb b b bb bw b b w w b w wb b bbbb w b b w ww bbw b w b w b ww b w b w w wb b w bb b bw w wb b w b w bbw wwb b w b w b bw w wb b bbb b b bbbb (a) (b) (c) Copyright 2012 Cangage Leaming. All Righta Reserved. May not be copied, canned, or duplicated, in whole or in purt. Dac to clectronic rights, some thied party content may be suppreed from the eBook andior oChupierfa). Editorial revion han docmed tat any approed content do not materially affect the overall leaming caparime. Cngage Leaming reserves the right to nemove additinal content at any time if ahuoquent rights restrictions raquire i 212 1 Chapter 5 Recursion Traverse the square row by row and, for the first unvisited cell encountered, in- voke a function that processes one area. The secret is in using four recursive calls in this function for each unvisited white cell and marking it with a special symbol as visited (counted).
Expert Solution
steps

Step by step

Solved in 8 steps with 8 images

Blurred answer
Knowledge Booster
Structured English
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