Homework 3B, Dynamic 2D Array Class.
Short Description:
Update your static array class to use dynamic memory.
Goals
When you finish this homework, you should have:- Demonstrated that you can use dynamic memory in a class.
Formal Description
Change your static 2D array from homework 3A to a class that uses dynamic memory. You should support everything from homework 3a with the following changes.- The default constructor should take two parameters, the number of rows and the number of columns. It should build a dynamic 2d array based on these.
- You should provide default parameters to create a 10x10 array if not values are passed.
- You should supply ALL required methods for a class with dynamic memory.
- You should add a
Resize(size_t rows, size_t columns)function.- Allocate a new array of the given size.
- Copy any data from the previous array to the new array.
- This may involve losing data, but that is OK. If the size was 10x10 and the user asked for a new array 5x5, just copy the first 5x5 portion of the old array over.
- If the array grows, i.e. the old array was 5x5 and the new array is 10x10, initialize the 5x5 portion with the existing data.
I would implement an index function that takes the 2d indexes and returns the valid 1d index. This should be a private member function.
All conditions from the previous assignment apply.
Your library should free all memory allocated. Running this program with valgrind should report " All heap blocks were freed -- no leaks are possible".