CS 10C Programming Concepts and Methodologies 2

Project 31.1

Similarly to what you did with the array-based implementation, you'll start with the LinkedBag code from the links below and make the needed edits to change it to a link-based Set.

The vast majority of your code will be copied directly from the LinkedBag class from the links below. You just need to make minor adjustments to reflect the fact that duplicate elements are not allowed. As with the ArraySet class, insert() should throw an exception if the item to insert already exists in the Set.

Your LinkedSet class must be derived from a "SetInterface" abstract class. You should be able to reuse your SetInterface class from the last assignment.

You must provide the big-3. If you are not familiar with the term "big-3," please take a few minutes to review lesson 17. The LinkedBag from the links below provides a copy constructor but does not provide an overloaded assignment operator, so you will need to add that to your class.

I strongly suggest the following as a review of the function of the copy constructor: Compile and run the LinkedBag code provided below. Then comment out the copy constructor from both LinkedBag.h and LinkedBag.cpp, and observe what happens. Study the copyConstructorTester() function to make sure you understand what is happening.

Here's my suggestion about the big-3. Change the given copy constructor into a function named "copy()". This won't require any changes to the code inside the function. Then create a new copy constructor that does nothing except call the copy() function. Once you have tested that carefully, then you can call copy() from the assignment operator to do the work of making the copy. (The assignment operator will also need to call clear(), check for self-assignment, and return the appropriate object.)

A subtle point about the copy() function I'm suggesting: It should be a private function, because it won't be appropriate for the client to call this function, because a copy() function intended for client use would need to deallocate the already existing LinkedBag object that is being copied into. The copy() function that I am suggesting will only be called on an object that has not previously been initialized.

Here is the source code that you are to use as a starting point:

Important Submission Note

Just a reminder, for submission to zyBooks we will be combining the class declaration and class implementation into a single file.

Documentation

For documentation, you must provide function documentation for any new functions that you are writing (just the big-3). No other documentation is required.