Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Please use the starter code provided at the bottom (input files included as well) Grouping.cpp #include #include #include using namespace std; //Represents an occupied

C++

Please use the starter code provided at the bottom

(input files included as well)

image text in transcribed

Grouping.cpp

#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; }

input1.txt

.........X ...XX....X .......... ....X..X.. ...X...X.. .......XX. ....XX.... .......... .......... ..........

input2.txt

....XXXXXX ...XX....X ....X..XXX ...XX..X.. ...X...X.. ...X...XX. ...XXXXX.. .......... .......... ..........

input3.txt

..X.....X. .X.X.XX.XX ..X..X.... .......XX. XXX..XXX.. X.X..XXX.. XXX.XXXX.. ......XX.. X........X XX....XXXX

input4.txt

.......... ...X.X.... ..XXXXX... ...X.X.... ..XXXXX... ...X.X.... .......X.. .XXXXXXXXX ...X.....X ...XXXX...

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. ...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: grid: 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 O, 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

MySQL/PHP Database Applications

Authors: Brad Bulger, Jay Greenspan, David Wall

2nd Edition

0764549634, 9780764549632

More Books

Students also viewed these Databases questions

Question

5. Discuss the role of the Web in career management.

Answered: 1 week ago

Question

4. Design a career management system.

Answered: 1 week ago