This lab will help you practice dynamic memory mixed with classes.
This program will involve implementing a dynamically allocated version of the mathematical concept of a 'set'. First, please examine the provided library and driver for a statically allocated Set class. (You may also want to refresh your mathematical memory of the set concept before proceeding.)
Now that you are familiar with how the Set class works, let's make it work better. Right now the user is limited to a certain maximum number of elements in their Set. You are to make it so that the number of elements can be set dynamically during the program's execution.
Extend the driver to test all the ADT's operations.
What (three) new methods will you need to add to handle the dynamic memory?
Why do all the current methods pass Set objects as constant references?
When is a copy constructor called?
When is a destructor called?
When is an assignment operator called?
How do the assignment operator and copy constructor differ?
How are the assignment operator and the destructor similar?
What auxiliary method(s) might you employ to keep down the duplication of code in your class? (*cough* alloc *cough* destroy)
Will you need to add any code to the existing methods? Why/why not?
This assignment is (Level 2.5).
Add (Level 2.5) to allow the programmer to increase/decrease the set's size or to have it automatically increase/decrease as needed.
Recall that the most common memory allocation schemes allocate same-sized blocks so that all the holes created in the heap are of the same size. (Tip: it would be nice to allow the programmer to tell you this block size at construction time. But also have a reasonable default value...)
What default block size did you choose? Why might we allow the programmer to choose their own block size?
How does your class' array grow when necessary? How do you tell when you need to grow?
What happens when growth fails? Do all previous elements disappear?
Add (Level 2.5) to use a linked list (with all insertion and removal functions implemented) to manage your dynamic growth/shrinkage. (If you make the linked list 'chunked', I'll throw in another (Level 1) due to the complexities of inserting and removing items.)
Add (Level 1) to merge the overload operators from a separate example appropriately for your Set class. In particular, add an appropriate [] to represent set membership. (This will supplement the already present operator^ in that role.)
If you think of any more/other clever operators for a Set to have, let me know and we can negotiate a level adjustment...