Question: In this homework you will be building an extensible array class. IE a class which acts like an array but will grow bigger as you
In this homework you will be building an extensible array class. IE a class which acts like an array but will grow bigger as you add elements. For this assignment you will: Create a class to hold an array of integers. As you add elements to the array, the underlying data structures will grow invisibly to the user. When testing your homework we will compile and link your class with a test driver written by the instructor. Therefore, there are some naming conventions and functions which must be followed. Name of header file: x_Array.h Name of cpp file x_Array.cpp Class name X_Array X_Array(); Constructor bool operator == ( const X_Array & const) Test for equality. bool operator !=(const X_Array & const) Test for inequality int add( int) adds an integer to the array. Returns the index where added void removeLast(); Delete the last element in the array. ( resetting currentNumber elements) int getSize() const returns current number of elements in the array int getAt( int index) const returns the value at index. Returns 0 if out of bounds setAt( int index, int value) sets the value at the index. If out of bounds does nothing You may ( and likely should) have additional methods. I have provided a test program for testing / development The actual program used to test your class may be different, but it will be similar. Implemtation. ( This is easier on a white board) You will store the values in a 2 dimensional array that will grow as more elements are added. You will need at least three variables These can be named however you wish ( the names below are only to make the description clearer) int currLength; // The current num elements in the array int maxLength; // the max num elements the array can hold without resizing int ** dataArray; // Holds the actual data elements. When you create the X_Array object, you will set the dataArray to be an array of length 1. You will also allocate an integer array from the heap of length 10. You wills et the address in the [0] element in dataArray to the address of the 10 integer array. Note that the arrays dataArray point to should hold 10 values. No more no less. As you fill the array, ultimately you will have to get more memory. What you do is to allocate another integer array of size 10. Create a new dataArray with one more member. Copy the pointers from the old dataArray to the new dataArray, and set the last element in the dataArray to the new data you allocated. Assume you have 20 elements in the array. dataArray When you need to add a new item you will 1 create a new dataArray one element larger 2 Copy the address of the extant data rows into the new dataArray 3 Allocate a new data row and point the last element in dataArray to the new data Update currLength and maxLength as appropriate Submitting your answer You will have to create two files. Zip them up into a single file and submit that zip file.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
