Question
C++ ADT Bag Union Help. I need to write the following program but I'm having trouble with implementation files methods and calling these methods from
C++ ADT Bag Union Help. I need to write the following program but I'm having trouble with implementation files methods and calling these methods from main().
The following 3 methods are to be added to the Linked-based implementation of a Bag ADT. Methods must compose a new Bag object by accessing the elements of the underlying linked list of the Bag objects. You may not convert the Bags to vectors. The main method must also be updated to thoroughly test the newly added methods. The algorithms are the same as in the previous lab. However, the syntax will change due to the implementation.
1) bagUnion: The union of two bags is a new bag containing the combined contents of the original two bags. Design and specify a method union for the ArrayBag that returns as a new bag the union of the bag receiving the call to the method and the bag that is the method's parameter. Note that the union of two bags might contain duplicate items. For example, if object x occurs five times in one bag and twice in another, the union of these bags contains x seven times. The union does not affect the contents of the original bags.
2) bagIntersection: The intersection of two bags is a new bag containing the entries that occur in both of the original bags. Design and specify a method intersection for the ArrayBag that returns as a new bag the intersection of the bag receiving the call to the method and the bag that is the method's parameter. Note that the intersection of two bags might contain duplicate items. For example, if object x occurs five times in one bag and twice in another, the intersection of these bags contains x two times. The intersection does not affect the contents of the original bags.
3) bagDifference: The difference of two bags is a new bag containing the entries that would be left in one bag after removing those that also occur in the second. Design and specify a method difference for the ArrayBag that returns as a new bag the difference of the bag receiving the call to the method and the bag that is the method's parameter. Note that the difference of two bags might contain duplicate items. For example, if object x occurs five times in one bag and twice in another, the difference of these bags contains x three times.
My current method headers in the implementation file are:
template
// needs to union bag1 and bag2 and put it in a unionBag to return to main() }
template
//finds the intersection of unionBag }
template
//finds the difference of unionBag }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started