Consider the following definition of a C++ class that acts like an array with bounds-checking (i.e. ensuring that a valid array index is used each time an array element is referenced).
class checked_array {
public:
checked_array(int s): size(s) { a = new int[size]; }
int &operator[](int i);
int get_size() { return size; }
private:
int size;
int *a;
};
Complete the definition of the checked_array class by defining its operator[] method, but placing the definition outside of the class. Be sure that operator[] checks that the index is between 0 and size - 1.
Convert the checked_array class to a class template, where the type of the elements of the array is a template parameter.
Declare a class template called comparable_checked_array, derived from checked_array, which implements the < operator for comparing two comparable_checked_array's. Given comparable_checked_array's X and Y, X < Y if the sum of the elements of X is less than the sum of the elements of Y
Finally, create a checked_array A containing elements that are themselves comparable_checked_array's of integers. Then, use your sort template to,
for each element x of A, sort the elements of x, and
sort A itself.
For example, if A is a checked_array of comparable_checked_array's such that:
A[0] = {2,4,1}
A[1] = {5,3,7}
A[2] = {0,3,2}
then after all the sorting, A will look like:
A[0] = {0,2,3}
A[1] = {1,2,4}
A[2] = {3,5,7}
What to turn in:
Turn in a single C++ source file with:
The complete definition of the checked_array class template,
the definition of the comparable_checked_array class template,
the template function sort(), and
the main() procedure which creates the array A described above and calls the necessary procedures for sorting each individual element of A as well as sorting A overall. Your program should print out A before and after sorting.