This lab is designed to give you experience with:
Consider an N-by-N grid in which some squares are occupied by circles.
Two occupied squares
belong to the same group if they share a common edge. In the grid shown
below, there is one group of four occupied squares, three groups
of two occupied squares, and two individual occupied squares. Note that
diagonal squares are not considered to share a common edge.
Write a program that does the following:
The program should be named grid and it will accept a minimum of two arguments:
The file catches a number of errors because you may not enter arguments correctly or create a correct grid file. However, because time is short, your program may assume that all arguments are entered correctly and that the grid file is correct.
The input file will have the format:
N grid linesEach grid line represents one line in the grid. A blank will denote an empty square and an X will denote a square with a circle. The above grid would be represented by the following file, named grid1:
10
X
XX X
X X
X X
XX
XX
Because you are only required to handle one option in any execution of the program it is extremely inefficient to represent the grid as a two-dimensional matrix. It is much better to keep the vertices in a list and, if you are asked to count the size of a group containing a square, to save a pointer to the vertex representing that square when the vertex is created. You can compute the edges for each vertex by keeping only the current line and the previous line of the grid when you are reading in the grid. Thus you only need a two row matrix. It is permissable to use a full blown two-dimensional matrix but you will lose the number of points shown in the grading guide if you do so.
You should submit the following files: