Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please FULLY follow the instruction and write a code using simple C++. Thank you. Implement a generic (template) class called MArray. A generic class is
Please FULLY follow the instruction and write a code using simple C++. Thank you.
Implement a generic (template) class called MArray. A generic class is a general version of a class; it is a homogenous data structure that handles multiple data types. My will be similar to C++ vectors. The array size will grow dynamically when the user inserts an element to a full array. The class should not use vectors. Instead, you should use dynamic memory allocation (a dynamic array The class should have three member variables: myarray: the dynamic array sike the current size of the array used the number of elements currently used in the array The class should have the following functionalities: A default constructor that initializes the size of the array to 5 elements A default destructor that frees the dynamic memory that was allocated. int length() a method that returns an integer value indicating the number of elements currently used in the array. void insert Headltem a method that inserts a new item making it the first element in the array. If the array is full, then a new dynamic array of double the size should replace the existing array and the items in the old array are copied to the new array. void insert Tail tem i a method that inserts a new item making it the last element in the array. If the array is full, then a new dynamic array of double the size should replace the existing array. void delete Head() deletes the first element in the array. void delete Tail() deletes the last element in the array. void sortAscending() sorts the elements of the array in ascending order. Use bubblesort to o that. void sortDescending() sorts the elements of the array in descending order Use bubblesort to do that. Item getMax() returns the maximum value in the array. Item get Min() returns the minimum value in the array. C++ allows the overloading of the [J operator. This feature makes it possible to access an element in a MLAnay object in an array-like behavior. Overload this operator and make sure to have boundary checks using assertions. Ifthe user tries toaccess an element outside the range of the array or at a location that is not used yet then an error message should be displayed on the screen
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started