CSCI-15 Assignment #7 – a 2-Dimensional Array class and problem... Your job is to write a class TwoDArray implementing an...

advertisement
CSCI-15 Assignment #7 – a 2-Dimensional Array class and problem (100 points), due 5/11/16
Your job is to write a class TwoDArray implementing an abstract data type (in a class) of a 2dimensional array of ints. You may use the MyArray class example from my web site
(essentially as is) to implement the one-dimensional arrays of integers needed for the rows of
your 2-dimensional array. You will implement this ADT as a type of ragged array (using an
array of pointers to MyArray objects).
Your TwoDArray class will allocate an array of pointers to MyArray class objects, which it
creates using the new[] operator, of an arbitrary size provided to the constructor (default to 10 as
per the 1-dimensional Array class). It will then loop down that array of pointers to MyArrays,
creating the rows of the array as MyArray objects using the new operator, assigning the pointers
returned from the new operator to the elements of the TwoDArray's array of pointers to Arrays. I
know this is confusing: I'll explain in class.
Implement (at least) the following class methods on your 2-dimensional array class:



Member operator[] method. This will return a reference to the row so the row’s
MyArray::operator[] method can return a reference to an int as needed.
Default and normal constructors that create arrays of nRows and nCols as supplied by the
user, with 10×10 the default size.
A destructor to call delete on each of the rows, thus destructing the rows also, then to
delete the table of MyArray pointers.
You may decide you need other methods or friend functions, you are free to add and use these as
needed. You must be able to access the elements of your array using array[row][column] (e.g.,
normal indexing) notation, and you must use that notation in your program.
Use the TwoDArray class to solve the mouse on an island problem, as specified before. Write
your program as a multi-file program with appropriate headers and source files. Except for being
able to construct a TwoDArray after it knows the size of the structure it needs, the client program
should not need to know anything about the internals of the 2-d array implementation
(remember, encapsulate!). To declare the 2-dimensional arrays and construct them to the right
size, move the declarations of the two TwoDArray objects to after you have read the number of
rows and columns of the map, and pass these sizes into the constructors for your map and count
arrays. The high level design for this program, and most of the client code, will be the same as
for the original problem. The only real changes to it involve use of the TwoDArray class for the
map and count arrays instead of the original arrays.
This program is not difficult, but will require approximately 5-6 pages of code, and it has a few
tricky points (constructing the rows of the 2-d array and returning a row from a[i] to allow a[i][j]
to work, for example) so START EARLY and DESIGN first, and only then write code.
Download