Question: Part I. In-Lab Exercise (10 points) Submit the solution files of Exercises online before the due date/time. Upload your assignment using a file named List.cpp
Part I. In-Lab Exercise (10 points) Submit the solution files of Exercises online before the due date/time. Upload your assignment using a file named List.cpp and List.h. The objective of this assignment is to extend the List class. Read the code for the List class implemented using the dynamic array we discussed in class: List.h and List.cpp. Try to review how the List class works. Your Programming Task: You are asked to extend the List class, by adding a constructor to it and adding a member function that allows us to expand the capacity: (1) A constructor that allows initializing a new List from an array. Declaration: List(ElementType * array, int arraySize, int capacity); The constructor should initialize a newly declared List with capacity set to be the "capacity" parameter. The size of the list should be "arraySize and should contain the first arraySize elements in array "array". Example: int A[] = {1,4,2,5,4}; // This should create a List with a capacity of 20, and stores 5 elements: 1, 4, 2, 5, 4 List mylist(A,5,20); (2) A new member function to the List class: void ChangeCapacity(int); This member function should allow us to change the capacity of a List object. It should not change the elements of the List. For example, if list2 is a List object which stores 5 elements 1, 2, 3, 4, and 5, with capacity 5. Now list2 is full, but we can call list2.ChangeCapacity(50) to change the capacity to 50. Note that list2 is still holding 5 elements 1, 2, 3, 4, and 5, but we are now able to insert more elements into it. Important note: In C++, once an array is created, there is no way to modify its length afterward. So, the trick here is you will need to create a new dynamic array with the new capacity, then switch to this new array for the storage (by changing the myArrayPtr field to the address to this array). Also, since the elements of the List object are supposedly preserved after the expansion, you need to copy the elements from the old array to the new array. Finally, since the old array is no longer needed, we need to delete it. A main program to test your extended List class: InLab6ListDriver.cpp. Submit your modified List.cpp and List.h.
Code:
_______________________________________________
List.h
#include
____________________________________________
List.cpp
#include
_____________________________________
Driver code:
#include
_________________________________
please provide the code im supposed to put
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
