Question: hi.we are using c++, put comments to help me better understand Use of the C++ Template Classes list and vector The goal is to create

hi.we are using c++, put comments to help me better understand

Use of the C++ Template Classes list and vector

The goal is to create a Class named Bag used to contain items of template type Type, in a fixed size, primitive array. The items are added to a Bag object in random order. The class is to be a template class.

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 methods 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 bag1 and bag2 are bags; bag1 contains the strings a, b, and c; and bag2 contains the strings b, b, d, and e. The expression bag1.union(bag2) returns a bag containing the strings a, b, b, b, c, d, and e. Note that union does not affect the contents of bag1 and bag2.

1. Client-test.cpp that has just the method main and any other required support methods

2) Bag.h that declares the Class Bag

3) Bag.cpp that defines all of the class methods listed in the following UML table.

sample output

Example

Given: Bag bag1; Bag bag2;

Bag unionBag; "bag1": [1, 2, 3, 4, 2] "bag2": [5, 3, 7, 1, 9, 5] unionBag = bag1.bagsUnion(bag2); // "bag1" invokes the method Result: Union: [1, 1, 2, 2, 3, 3, 4, 5, 5, 7, 9]

Use the UML diagram to implement the class

-BAG_SIZE: static const int -items: Type[SIZE] -elementsUsed: int +Bag() +Bag(const &Type) +Bag(const Bag&) +~Bag() // Mutator Methods +operator=(const Bag&): const Bag& +addItem(const &Type): bool +removeItem(const Type&): bool +temoveAllItems(const Type&: int +empty(): void // Observer Methods +nmbrItems(): int +capacity(): int +isEmpty(): bool +isFull(): bool +contains(const &Type): bool +itemOccurrences(const Type&: int +bagsUnion(const Nag&): Bag +toString(): string

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!