Question: Code in C++ Part 1 You are to implement a class template with the default type of int for the type Set. A set is
Code in C++
Part 1 You are to implement a class template with the default type of int for the type Set. A set is a container in which the order of items does not matter and no duplicate values exists. The following is concluded from the sets properties:
1. The methods of the class may reorder the items included in the object with no change in the objects status. For example, {1, 5, 3} and {3, 5, 1} and {5, 3, 1} are all equal and if an object changes its order from one to another, the object is still unchanged.
2. Since the order of items in the set does not matter and the items may change their locations in the set during the execution of their methods, identifying the items through their positions in the container does not make sense.
3. Since a set never includes duplicate values (i.e. each item in the set is unique), calling an insert method to add an item to the set where the item already exists in the set, does not make any modification in the set.
4. A new item can be inserted at any point in the set with no difference because a set is an unordered container. According to the above description, implement the class template Set including the following members and features:
1) Utilize dynamic memory allocation for your set and consider expanding and shrinking your set to use memory efficiently.
2) Implement a parameterized constructor that accepts an input parameter showing the initial capacity of the set with the default argument of 10 to create an empty set with the specified capacity.
3) Overload the constructor with a parameterized constructor with two input parameters: an array of items and the size of the array. This method creates a set with a capacity equal to the size of the array and including the unique values included in the input array. In case the parameter size is not valid, an exception is thrown.
4) Implement a copy constructor if required.
5) Implement a destructor if required.
6) Implement a method to add a single item to the set. If the item already exists, it is not added.
7) Overload the previous method to add a list of items to the set. The method receives an array of items and adds them to the set (if not exist). Use assertions in this method to make sure that the size of the list is not negative. Make sure you are disabling youre the assertions before delivering the final program.
8) Implement a method to remove an item from the set. If the input value does not exist in the set, an exception is thrown.
9) Implement a method to check the membership of an item in the set. This method returns true if the value passed to the method exists in the set and returns false, otherwise.
10)Implement a method to return the size of the set. The size of a set is equal to the number of items included in the set.
11) Implement a method that accepts another set as its input parameter and checks if the current set is a subset of the input set. A set is a subset of another set if all its items are included in the other set.
12)Implement a method that accepts another set as its input parameter and checks if the current set is a superset of the input set. A set is a superset of another set if it includes all the items of the other set.
13)Overload the '|' operator to calculate the union of two sets. The union of two sets is a set including the items of either or both the sets.
14)Overload the '&' operator to calculate the intersection of two sets. The intersection of two sets is a set including the items that both sets have in common.
15)Overload the '-' operator to calculate the difference of two sets. If s1 and s2 are two sets, s1 s2 is a set including all the items included in s1 that are not a member of s2.
16)Overload the '--' operator that randomly selects an item and removes it from the set. This operation throws an exception if it is applied on an empty set.
17)Overload the equality and inequality operators (i.e. == and !=) to compare two sets.
18)Overload the assignment operator.
19)Overload the stream insertion operator (i.e.
Part 2
20)An Ordered Set is a set in which the order of items is important and is preserved during all the set manipulations. Beside the behaviours of a set, an ordered set can be indexed (i.e. items can be identified by their location in the set) and can be sorted. Extend the Set class to implement an OrderedSet class template with the default type of int, and override any method if required. Implement this class and add the following methods to it:
1) Implement a method to convert a general set to an ordered set. 21)Implement a sort method that accepts a Boolean parameter with the default argument of true to sort the set. If the argument passed to the set is true, the set is sorted in an ascending order and if it is false, the set is sorted in a descending order. 2) Implement a method to search and return the index of an item in the set; if the item does not exist in the set, -1 is returned. 3) Overload the offset operator (i.e []) to access the items in the set. This operator throws an exception if an invalid index is received.
According to the description provided in the attached file, you are to submit three separate files:
- "Set.h" file including the implementation of the class template "Set".
- "OrderedSet.h" file including the implementation of the class template "OrderedSet".
- "SetApplication.cpp" file including the application described in Part 3.

Note that all the operations like union and intersection between ordered sets result an ordered set and are asymmetric: The result of sl | s2 is not necessarily equal to s2 | s1. Also, in the subset and superset operators the order of the items matters. For example, as ordered sets, the set {1, 5, 6} is not a subset of the set {1, 6, 4, 5), but it is a subset of {2, 1, 4, 3, 5, 9, 6, 7}. Part 3 Write a program that creates a number of integer sets with the values read from the keyboard. For each set the user decides if they want an ordered or unordered set. Store all the sets in an appropriate array and calculate the union and the intersection of the sets and display the result set on the screen. Note that all the operations like union and intersection between ordered sets result an ordered set and are asymmetric: The result of sl | s2 is not necessarily equal to s2 | s1. Also, in the subset and superset operators the order of the items matters. For example, as ordered sets, the set {1, 5, 6} is not a subset of the set {1, 6, 4, 5), but it is a subset of {2, 1, 4, 3, 5, 9, 6, 7}. Part 3 Write a program that creates a number of integer sets with the values read from the keyboard. For each set the user decides if they want an ordered or unordered set. Store all the sets in an appropriate array and calculate the union and the intersection of the sets and display the result set on the screen
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
