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
-
Granny's Fried Chicken bought equipment on January 2, 2024, for $42,000. The equipment was expected to remain in service for four years and to operate for 7,200 hours. At the end of the equipment's...
-
4. Similar to characteristics of a bond, preferred stocks pays a fixed dividend of its face value and therefore has no dividend growth rate. On the other hand, similar to stocks preferred stocks have...
-
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...
-
In Problem 19 - 24, find the x and y coordinates of all inflection points. 20. f (x) = x3 - 24x2 22. f (x) = 5 - x4/3 24. f (x) = x3/5 6x + 7
-
Define standardization and name the primary reasons for its use.
-
Tennessee Co. purchases imports that have a price of 400,000 Singapore dollars, and it has to pay for the imports in 90 days. It will use a 90-day forward contract to cover its payables. Assume that...
-
Creek Enterprises' 2014 operations follows: Using the firm's 2015 income statement presented in Problem 3-18, develop the 2015 common-size income statement and compare it with the 2014 statement....
-
The circle graph shows how a family budgets its annual income. If the total annual income is $110,000, what amount is budgeted for Clothing? Savings 8% Insurance 10% Housing 21% Auto 14% Clothing 17%...
-
Bowman Specialists Inc. (BSI) manufactures specialized equipment for polishing optical lenses. There are two modelsone (A25) principally used for fine eyewear and the other (A10) for lenses used in...
-
You have a goal of having $100,000 five years from today. The return on the investment is expected to be 8%and will be compounded semi annually. What is The amount that needs to be invested today?
-
What basic set of factors must a firm consider when selecting a location for a production facility?
-
What basic factors must be addressed when managing international service operations?
-
How do each of the basic business strategies (differentiation, cost leadership, and focus) relate to operations management?
-
How are a firms strategy and operations management interrelated?
-
Why is it important for organizations to control productivity?
-
A pension fund manager is considering three mutual funds. The first is a stock fund, the second is a long-term bond fund, and the third is a money market fund that provides a safe return of 4%. The...
-
Before the 1973 oil embargo and subsequent increases in the price of crude oil, gasoline usage in the United States had grown at a seasonally adjusted rate of 0.57 percent per month, with a standard...
-
What are some common causes of variances?
-
What is financial management?
-
Describe the elements of an internal control system.
-
What is the popular saying on which the cash flow fade method is founded?
-
Should the buyers costs be separated from the target companys costs in the cost savings that come out of a merger of two companies?
-
What is the cost of capital equal to?
Study smarter with the SolutionInn App