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).