The purpose of this project is to test your ability to use dynamic memory (mixed with classes), operator overloading, and templates effectively in program design.

Create a class for a 3-dimensional array. To make it more general, allow the actual dimensionality to be 0d, 1d, 2d, or 3d. It should support indexing with operator(). If the programmer subscripts with fewer indices than you 'need' (0 for a 1d, 0 or 1 for a 2d, 0 or 1 or 2 for a 3d -- note that you can't under-subscript a 0d array), you should return the appropriately sized sub-array (of your class's type). (Note: This will require multiple overloads of operator() with different numbers of index arguments.)

Since, as a template, math operations don't make sense, you'll have to for-go addition, etc. But you could use + and += for concatenation. Basically aligning the common dimensions of the two arrays and concatenating along the remaining dimension. (There can be only one for this to make sense. If there are none remaining, there are options for those kinds of things!) Make sure to overload it for proper dimensionality:

original dimensions resulting dimension 3x4x2 + 4x2 --> 4x4x2 3x4x2 + 3x2 --> 3x5x2 3x4x2 + 3x4 --> 3x4x3 3x4 + 3 --> 3x5 3x4 + 3x4 --> 3x4x2 (or is it 2x3x4? *shrug* see the options...) 3 + 3 --> 3x2 (or 2x3 or just 6? *hmm* see the options...) 0 + 0 --> 2 (as in a 1d array of 2 elements) 3x4x2 + 5x6 --> nonsense (empty array -- 0x0x0) 3x4x2 + 3 --> nonsense (empty array -- 0x0x0) 3x4x2 + 3x4x2 --> too large -- would be 4d (empty array -- 0x0x0)

Examples of some of the ones that work:

3x4x2 + 4x2 --> 4x4x2 a b a b c d c d e f e f g h g h c d q r c d e f + s t --> e f g h u v g h i j w x i j e f e f g h g h i j i j k l k l q r s t u v w x 3x4x2 + 3x2 --> 3x5x2 a b a b c d c d e f e f g h g h q r c d q r e f + s t --> c d g h u v e f i j g h i j e f s t g h i j e f k l g h i j k l u v 3x4x2 + 3x4 --> 3x4x3 a b a b q c d c d r e f e f s g h g h t c d q r s t c d u e f + u v w x --> e f v g h y z o p g h w i j i j x e f e f y g h g h z i j i j o k l k l p 3x4 + 3 --> 3x5 a b c d a b c d 3 e f g h + 3 4 5 --> e f g h 4 i j k l i j k l 5

Of course, you should also support input (the programmer must set the dimensions ahead of time) and output (make it look nice like those above) and fun operations like transpose (operator~? but what is a 3d transpose...*ick*).

And how do you exactly store a dynamic array of more than one dimension? Well, the easiest way is to create a 1d array of all the items and then map the 3d subscripts into 1d:

actual dimensions: x,y,z 3dX[i][j][k] --> 1dX[i*y*z+j*z+k]

Write a driver to show off your 3d (or less) class' abilities.

This assignment is (Level 7).

- Add (Level 1) to add a reshape method to your class. It will take a new set of dimensions to replace the current ones. If the new dimensions are larger than the originals, increase your dynamic size and add default-constructed elements to the end. If the new dimensions are smaller, you can either simply ignore the 'lost' data or actually reduce your dynamic size and throw them out.
- Add (Level 3) to allow true n-dimensional arrays (not bounded by 3). Note that you can no longer use multiple overloads of operator() for subscripting since you couldn't write an arbitrary number of them ahead of time. You'll have to index with an array argument (since you don't know how many indices they'll be sending you) and this array's length (ditto). Concatenation extends as above. For those interested in some advanced (yet practical) theory here, check out this article from the C/C++ User's Journal: A Class Template for N-Dimensional Generic Resizable Arrays.
- Add (Level 3) to use your template'd 3d class to create a matrix class. Now, though, instead of concatenation, you'll want to have the mathematics operations defined. Also, matrices are generally speaking only 2d. (Interesting question: Should you inherit or compose?)