The 4th problem mimics the situation where eagles flying in the sky can be spotted and counted. FindEagles: a recursive function that examines and counts the number of objects (eagles) in a photograph. The data is in a two-dimensional grid of cells, each of which may be empty (value 0) or filled (value 1 to 9). Maximum grid size is 50 x 50. The filled cells that are connected form an object (eagle). Two cells are connected if they are vertically, horizontally, or diagonally adjacent. The following figure shows 3 x 4 grids with 3 eagles. 0 0 1 2 1 0 0 0 1 0 3 1 FindEagle function takes as parameters the 2-D array and the x-y coordinates of a cell that is a part of an eagle (non-zero value) and erases (change to 0) the image of an eagle. The function FindEagle should return an integer value that counts how many cells has been counted as part of an eagle and have been erased. The following sample data has two pictures, the first one is 3 x 4, and the second one is 5 x 5 grids. Note that your program should be able to handle any number of pictures that are contained in the data file. Print out the picture of the photograph, the highest value in the photograph, and number of eagles found in each picture. As the program discovers each eagle, it should also print the size of the eagle just found. Process all the pictures in the file. Sample data file: 3 4 0 0 1 2 1 0 0 0 1 0 5 1 5 5 0 0 0 1 1 0 1 8 1 9 0 0 0 0 0 1 0 0 2 1 1 3 1 9 1 Sample output: 0 0 1 2 1 0 0 0 1 0 5 1 An eagle size 2 is found. An eagle size 2 is found. An eagle size 2 is found. 3 eagle(s) found in the picture. 0 0 0 1 1 0 1 8 1 9 0 0 0 0 0 1 0 0 2 1 1 3 1 9 1 An eagle size 6 is found. An eagle size 8 is found. 2 eagle(s) found in the picture. For the 4th problem, write a while loop to read and process each photograph in the data file one by one.
The 4th problem mimics the situation where eagles flying in the sky can be spotted and counted.
FindEagles: a recursive function that examines and counts the number of objects (eagles) in a
photograph. The data is in a two-dimensional grid of cells, each of which may be empty (value 0) or
filled (value 1 to 9). Maximum grid size is 50 x 50. The filled cells that are connected form an object
(eagle). Two cells are connected if they are vertically, horizontally, or diagonally adjacent. The
following figure shows 3 x 4 grids with 3 eagles.
0 0 1 2
1 0 0 0
1 0 3 1
FindEagle function takes as parameters the 2-D array and the x-y coordinates of a cell that is a part of
an eagle (non-zero value) and erases (change to 0) the image of an eagle. The function FindEagle
should return an integer value that counts how many cells has been counted as part of an eagle and have
been erased.
The following sample data has two pictures, the first one is 3 x 4, and the second one is 5 x 5 grids. Note
that your program should be able to handle any number of pictures that are contained in the data file.
Print out the picture of the photograph, the highest value in the photograph, and number of eagles found
in each picture. As the program discovers each eagle, it should also print the size of the eagle just
found. Process all the pictures in the file.
Sample data file:
3 4
0 0 1 2
1 0 0 0
1 0 5 1
5 5
0 0 0 1 1
0 1 8 1 9
0 0 0 0 0
1 0 0 2 1
1 3 1 9 1
Sample output:
0 0 1 2
1 0 0 0
1 0 5 1
An eagle size 2 is found.
An eagle size 2 is found.
An eagle size 2 is found.
3 eagle(s) found in the picture.
0 0 0 1 1
0 1 8 1 9
0 0 0 0 0
1 0 0 2 1
1 3 1 9 1
An eagle size 6 is found.
An eagle size 8 is found.
2 eagle(s) found in the picture.
For the 4th problem, write a while loop to read and process each photograph in the data file one
by one.
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 4 images