Identify Groups on a Board - Step 2

◀ Identify Groups on a Board - Step 1▶ Identify Groups on a Board - Step 3
Amazon Let’s run the 2nd step of the Four-Step Programming Model!

Four Step Programming Model: Step 2
Now let’s figure out what variables we need. First we need two-dimensional arrays of bool to keep track of what square are occupied and which ones are handled. We need to know which squares are handled in the process of finding groups so that we do not examine the same square twice. We also need integers to store the width and height. We need file input and output objects to read from a file and write to a file.

Finally, we need to store the groups somewhere, and this is a perfect time to use a vector because we don’t know the number of groups ahead of time. We need vectors to keep track of locations of the people in a group, and we need vectors to store the groups we have found. Here is the refined skeleton:
void process(int, int);

int main(int argc, char **argv){
- if arguments are not correct, give an error message and quit

bool **occupy, **handled;
int width, height;
vector<int> tempvx, tempvy; char *fileIn, *fileOut; ifstream fin; ofstream fout; vector<vector<int> > groupX, groupY; - receive locations of people in the given file and assign proper values to all squares on the grid - go through each square on the grid, find the groups, and store them into a vector - output results to the output file, specified by the command line } /* precondition: x and y can never go out of the grid’s bounds postcondition: tempvx and tempvy will contain people belonging to a group
*/ void process(int x, int y) { - same }
Alternatively, I could’ve used a vector of a structure that holds 2 int instead of declared 2 vector, one for x coordinates and the other for y coordinates. Both are fine. Note that we may want some of the variables to have global scope so that we won’t need to pass arguments from function calls to functions. This analysis will be done in the next step.

Next let's look at the next step!
◀ Identify Groups on a Board - Step 1▶ Identify Groups on a Board - Step 3

Questions? Let me know!