Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Output should be: a a b b c c d e c e e a d d Microsoft Word - A2_ArrayBag.doc 1 / 1 90%

image text in transcribed

Output should be:

a a b b c c d e

c e e

a d d

Microsoft Word - A2_ArrayBag.doc 1 / 1 90% Assignment #2 ArrayBag Methods Credit: 10 pts, DUE: Friday 2/26/21 For the template ArrayBag class introduced in the recent lectures, add these member functions: union, intersection, and difference. They are described as follows: Union: 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 ADT bag 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 one argument. Include sufficient comments to fully specify the method. 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. Specifically, suppose that bagl and bag2 are bags; bagl contains the strings a, b, and c; and bag2 contains the strings b, b, d, and e. The expression bagl union(bag) returns a bag containing the strings a, b, b, b, c, d, and e. Note that union does not affect the contents of bagl and bag2 Intersection: The intersection of two bags is a new bag containing the entries that occur in both of the original two bags. Design and specify a method intersection for the ADT bag 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 one argument. Include sufficient comments to fully specify the method. 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. Specifically, suppose that bagl and bag2 are bags, bagl contains the strings a, b, and c; and bag2 contains the strings b, b, d, and e. The expression bagl.intersection(bag) returns a bag containing only the string b. Note that intersection does not affect the contents of bagl and bag2. Difference: 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 ADT bag 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 one argument. Include sufficient comments to fully specify the method. 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. Specifically, suppose that bagl and bag2 are bags, bagl contains the strings a, b, and c; and bag2 contains the strings b, b, d, and e. The expression bagl.difference(bag) returns a bag containing only the strings a and c. Note that difference does not affect the contents of bagl and bag2. Important Note: Before submission, please thoroughly test these new functions in a driver code to make sure they work correctly! Submission: YOU MUST FOLLOW THE FOLLOWING INSTRUCTIONS. Please comment your code as needed. Put everything into a single file, name it as LastNameFirstInitial_a2.cpp (if your name is John Doe, it will be doeJ_a2.cpp), and then upload it to your blackboard account by the due day

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Management Databases And Organizations

Authors: Richard T. Watson

3rd Edition

0471418455, 978-0471418450

More Books

Students also viewed these Databases questions

Question

=+3. How does an abstract word differ from a concrete word? [LO-4]

Answered: 1 week ago