Using the class UML diagram given below to implement the Class Subsets in C++. You are...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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. 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.
Expert Answer:
Related Book For
Financial Management for Public Health and Not for Profit Organizations
ISBN: 978-0132805667
4th edition
Authors: Steven A. Finkler, Thad Calabrese
Posted Date:
Students also viewed these algorithms questions
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
On 1/1/22, lmani and Ahmad formed AI Partnership, a limited partnership. lmani will be the general partner and Ahmad will be a limited partner. He will not participate in management of the...
-
The manifesto states the core values of agile. How do you think these core values make agile different from traditional project management, especially in terms of promoting flexibility and change? Do...
-
Two sinusoidal 120 Hz waves, of the same frequency and amplitude, are to be sent in the positive direction of an x axis that is directed along a cord under tension. The waves can be sent in phase, or...
-
Define open, closed and isolated systems. Classify each with example.
-
Kango Corporation owns 180 shares of Shanda Corporation. Kafue, an individual shareholder, owns the remaining 20 shares of Shanda Corporation. In 2018, Kango Corporation decided to liquidate Shanda...
-
In the year to 30 September 2022, an advertising agency declares in interim ordinary dividend of 7.4C per shares and a final ordinary dividend of 8.6C per share. assuming an ex-dividend share price...
-
What is the preffered mode of communication with instructor? if you want quick response what is the best way to reach?
-
Consider the one-line diagram shown below, which depicts an industrial distribution system consisting of a 3-phase system operating at a voltage of Vs = 410 V. The impedance of the distribution lines...
-
The effectiveness of the performance appraisal is often a topic of debate. Read the Forbes article, Eliminating Performance Appraisals. Based on the content of the article, identify three key points...
-
Question 1 Assume the current exchange rate is $1.20 per Euro and the interest rate in the United States is 2% while the interest rate in Europe is 1%. The one-year forward exchange rate is $1.19 per...
-
Briefly discuss THREE factors which will influence the effectiveness of any performance standards selected for the schools new performances measurement system.
-
Assessing the Effectiveness of Intervention Programmes Aimed at Improving Matric Performance in Serial Underperforming Secondary Schools at uMzinyathi District in KwaZulu-Natal" : With regard to...
-
Select a system (or major element) of your choice and complete a functional analysis covering the activities in the retirement phase of the life cycle.
-
Swifty company is a publicly held corporation whose $1 par value stock is actively traded at $30 per share. The company issued 3400 shares of stock to acquire land recently advertised at $93000. When...
-
What are some common causes of variances?
-
What is financial management?
-
Describe the elements of an internal control system.
-
You release three balls simultaneously from the same height above the floor. The balls all carry the same quantity of surplus positive charge, but they have different masses: \(1 \mathrm{~kg}, 2...
-
A proton, a deuteron (a hydrogen nucleus containing one proton and one neutron), and an alpha particle (a helium nucleus consisting of two protons and two neutrons) initially at rest are all...
-
What orientation of an electric dipole in a uniform electric field has the greatest electric potential energy? What orientation has the least? (Let the system comprise both the electric dipole and...
Study smarter with the SolutionInn App