Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, I cannot figure out this recursion lab and I need some help. I've attached a picture of the instructions and copy/pasted the starter code.

Hello, I cannot figure out this recursion lab and I need some help. I've attached a picture of the instructions and copy/pasted the starter code.

image text in transcribed

STARTER CODE:

#include #include #include

using namespace std;

//Represents an occupied square in the grid //Do not modify the GridSquare class or its member functions class GridSquare { private: int row, col; public: GridSquare() : row(0), col(0) {} //Default constructor, (0,0) square GridSquare(int r, int c) : row(r), col(c) {} //(r,c) square //Compare with == operator, used in test cases bool operator== (const GridSquare r) const { if ((row == r.row) && (col == r.col)) { return true; } return false; } int getRow() { return row; } //return row value int getCol() { return col; } //return column value //Output using

//Function definition for ostream& operator

/* Groups squares in 10x10 grid upon construction Additional private helper functions may be added Need to implement the constructor that takes a file name as well as findGroup The findGroup function's parameter list may be changed based on how the function is implemented */ class Grouping { private: int grid[10][10]; vector> groups; public: Grouping() : grid{},groups() {} //Default constructor, no groups Grouping(string fileName); //Implement this function void findGroup(int r, int c); //Implement this function (recursive) void printGroups() //Displays grid's groups of squares { for(int g=0; g> getGroups() //Needed in unit tests { return groups; } };

//Implement the (parameterized) constructor and findGroup functions below

//Simple main function to test Grouping int main() { Grouping input1("input1.txt"); input1.printGroups(); return 0; }

DESCRIPTION Consider an NxN grid in which some squares are occupied. Two squares belong to the same group if they share a common edge (not just a corner). In the figure there is one group of four occupied squares, three groups of two occupied squares, and two individual occupied squares. .X ...XX....X ..X..X.. .X...X.. ..XX. .XX. In this lab, in the Grouping.cpp file from the starter code, you are to implement the constructor for a C++ class called Grouping along with a recursive member function findGroup that contains the following: . grld: a 2D int array with 10 rows and 10 columns. groups: a vector containing vectors of the locations of occupied squares (vector vector>] for each group a constructor that reads a file into the array and then processes this array using findGroup to populate each element in groups with the locations of occupied squares in that group. Each line of the file is a row of the array. The character should be converted to 0, and any other character converted to 1 a recursive method findGroup. (Your choice of parameter list, but mine is just: int row, int col.) This function should probably update the array as it goes. the printGroups function which displays each group's occupied squares (already implemented) The Grouping.cpp file also includes the definition for the GridSquare class which contains the row and column value for any occupied square on the grid. This class is fully implemented and does not need to be modified. In addition to the constructors (the parameterized constructor is the one to be used), there are two methods for accessing the row and column values (getRow / getCol), an operator== function to check if two GridSquare objects have the same row/column values by using the == operator, and an operator

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

How To Build A Million Dollar Database

Authors: Michelle Bergquist

1st Edition

0615246842, 978-0615246840

Students also viewed these Databases questions

Question

=+ f. instituting laws against driving while intoxicated

Answered: 1 week ago