Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using the class UML diagram given below to implement the Class Subsets in C++. You are to have three files, 1) Client-Project1.cpp, supplied, that


 image

Using the class UML diagram given below to implement the Class Subsets in C++. You are to have three files, 1) Client-Project1.cpp, supplied, that has just the method main and other required support methods, and 2) Bag.h that declares the Class Bag and defines all of the class methods listed in the following UML table. Bag -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 +removeltem(const Type&): bool +temoveAllOccurrences(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 Bag&): Bag +toString(): string The class is to be implemented as a template class, supporting elements of type: All Observer methods must be declared as const methods. Initialize "static const" value "BAG_SIZE" to 30. All class methods are to be declared only, i.e., not implemented, within the Class declaration, in file Bag.h, then defined externally immediately following the Class declaration. All class methods are to be declared only, i.e., not implemented, within the Class declaration, in file Bag.h, then defined externally immediately following the Class declaration. Methods: Bag(): Creates an object with no array elements utilized. Bag(const & Type): Conversion Constructor that creates object with the first item of type ; Bag(const &Bag): Copy Constructor: Creates an object as a copy of another object; ~Bag(): Class Destructor: Nothing to do. Page 1 operator=( const &Bag): Assigns another Bag object to this object addItem(const & Type): Adds the specified item to the end of the utilized array elements. Returns "true" if successful; otherwise "false" if the "items" array is already full. removeltem(const &Type): Removes just the first occurrence, if one exists, of the target item in the array. The remaining array elements must be collapsed to fill the removed element. Returns true if the item was removed, false otherwise removeAllOccurrences(const & Type): Removes all occurrences, if at least one exists, of the target item in the array. The remaining array elements must be collapsed to fill any removed element(s). Returns the number of items removed, 0: target item was not found empty(): Logically clears the Bag object of all utilized elements nmbritems(): Returns the current number of elements utilized capacity(): Returns the number of elements in the fixed size array (BAG_SIZE) isEmpty(): Returns true if the Bag object is empty, false otherwise isFull(): Returns true if the Bag's array is fully utilized, false otherwise contains(const & Type): Returns true if the target item occurs at least once in the array, false if the target item does not exist in the array itemOccurrences(const & Type): Returns the number occurrences of the target item in the array. If the item does not exist in the array, 0 is returned Hint: bagsUnion(const &Bag): Returns a Bag object consisting of the union of this object and the other specified Bag object. See below for the definition of the Union of two Bag objects. Consider using class method item Occurrences in your solution for method bags Union. Union Definition The union of two Bag objects, bag1 and bag2, is another, new Bag object that contains of all items of the two source objects. The new Bag object may contain more than one copy of an item if, 1) both objects contain the item once, and 2) if either object contains multiple copies of an item. For example, if bag1 contains 5 occurrences of item 2 and bag2 contains 3 copies of 2, the new Bag object will contain 8 occurrences of 2.

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

Financial Management for Public Health and Not for Profit Organizations

Authors: Steven A. Finkler, Thad Calabrese

4th edition

133060411, 132805669, 9780133060416, 978-0132805667

More Books

Students also viewed these Algorithms questions

Question

What are some common causes of variances?

Answered: 1 week ago

Question

What is financial management?

Answered: 1 week ago

Question

Describe the elements of an internal control system.

Answered: 1 week ago