Final answer:
To modify the Set.cpp file and implement a dynamically allocated version of a Set class, you need to use pointers and dynamic memory allocation. Resize the array by creating a new array with a larger size, copying the existing elements, and deleting the old array.
Step-by-step explanation:
The goal of this assignment is to modify the existing code for a Set class and implement a dynamically allocated version. Currently, the user is limited to a certain maximum number of elements in their Set, but the task is to change it so the number of elements can be set dynamically during the program's execution. To achieve this, you need to modify the Set.cpp file.
To implement a dynamically allocated Set, you would need to use pointers and dynamic memory allocation. So, instead of initializing the array with a fixed size, you would create a dynamic array using the 'new' operator. Here's an example:
int* elements = new int[maxSize];
When the user needs to add more elements than the current size, you would resize the array by creating a new array with a larger size, copying the existing elements to the new array, and deleting the old array. Here's an example:
int* newElements = new int[newSize];
for (int i = 0; i < currentSize; i++) {
newElements[i] = elements[i];
}
delete[] elements;
elements = newElements;