Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Implement a generic (template) class called My. Inay. A generic class is a gener

ID: 3838581 • Letter: I

Question

Implement a generic (template) class called My. Inay. A generic class is a general version of a class; it is a homogenous data structure that handles multiple data types. My lmay 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: myama: the dynamic array siv: the current size of the arra 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 insertHead tem 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 theold array are copied to the new array. void insert tem 10 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 sort Ascending() sorts the elements of the array in ascending order. Use bubbleSort to do that. void sortDesending() sorts the elements of the array in descending order. Use bubbleSort to do that. Item getMax() returns the maximum value in the array. Item getMin() returns the minimum value in the array. C++ allows the overloading of the tor. This feature makes it possible to access an element in a MyAmay object in an array-like behavior. Overload this operator and make sure to have boundary checks using assertions. If the user tries to access 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.

Explanation / Answer


int main{
MyArray<int> arr1;
int arrayLendth=arr1.length();

cout << "number of elements in arr1 :" << arrayLendth<<end1;
arr1.insertHead(12);
arr1.insertTail(21);
arr1.deleteHead();
arr1.deleteTail();


for(int i=0;i<arrayLendth;i++){
cout<<"insert First element:"<<arr1[0];
cout<<"insert Last element:"<<arr1[arrayLendth-1];
cout<<"delete first element:"<<arr1.deleteHead();
cout<<"delete last element:"<<arr1.arr1.deleteTail();
  for(int j=0;j<=arrayLendth-i;j++)
   {
   if(a[j]>a[j+1])
   {
   temp=a[j];
   a[j]=a[j+1];
   a[j+1]=temp;
   }
   }
   }
   cout<<" Data after sorting(Ascending order): ";
   for(int j=0;j<arrayLendth;j++)
   {
   cout<<a[j];
   }
  
  for(int i=0;i<=arrayLendth;i++)
  {
  for(int j=0;j<=arrayLendth-i;j++)
  {
  if(a[j]>a[j+1])
  {
  temp=a[j];
  a[j]=a[j+1];
  a[j+1]=temp;
  }
  }
  }
  cout<<" Data after sorting(Descending Order): ";
  for(j=arrayLendth-1;j>=0 ;j--)
  {
  cout<<a[j];
  }  

int max = a[0];
int min = a[0];


cin >> arrayLendth;

for (int i = 0; i < 10; i++)
    {
      if (a[i] > max)
        {
          max = a[i];
        }
      else if (a[i] < min)
        {
          min = a[i];
        }
    }
cout << max << endl;
cout << min << endl;
}
  

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote