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 itemOccurrences 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 itemOccurrences 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.
-
Because Natalie has been so successful operating Cookie Creations, Katy would like to have Natalie become her partner. Katy believes that together they will create a thriving cookie-making business....
-
What would be a good thesis statement about the causes that have increased childhood obesity
-
Figure shows transverse acceleration ay versus time t of the point on a string at x = 0, as a wave written in the form y(x, t) = ym sin (kx ?? wt + ?) passes through that point. The scale of the...
-
Differentiate among heat, work and internal energy.
-
The owner of a comer lot wants to find a use that will yield a desirable return on his investment. After much study and calculation, the owner decides that the two best alternatives are: If the owner...
-
Find the derivative of the function f(x) = {3x^2 + 2x - 5}/{x^2 +1}
-
1.Alkylating agents act against microbes through what mechanism? Explain 2.What method is commonly used in lab animal rooms to limit the number of microorganisms present in the air?
-
Analyze an organization's leadership effectiveness in up to five of James and Wooten's crisis phases, identifying leadership capacities, competencies, and behaviors (or lack thereof) in response to...
-
9. Frontier Inc. is the only producer of video games in Manbari Country. The market demand for video games is given by P 40-20d, where P is the price per video game and Q is the number of video games...
-
"Leadership effectiveness depends on the appropriate matching of leadership behavior to the follower's level of maturity". Using the Hersey-Blanchard Situational Leadership Theory, explain the...
-
Describe a scenario in your career where organizational effectiveness was positively or negatively influenced by the leadership.
-
Using theories and academic research critically evaluate the effectiveness of leadership exhibited by Mark Parker (Nike).
-
Drs. Glenn Feltham and David Ambrose began operations of their physical therapy clinic, called Northland Physical Therapy, on January 1, 2017. The annual reporting period ends December 31. The trial...
-
Consider the discrete group G of order 8 that has the following Cayley diagram e If we have the sequence of operations: fcagec, which of the options represents the reduction of the sequence to a...
-
SECTION A: Denison Specialty Hospital is planning its master budget for the coming year. The budget will include operating, capital, cash, and flexible budgets. The hospital is noted for its three...
-
You are given the following information about We-Save-Um Animal Rescue (WSU): Number of dogs rescued and placed by WSU600 Average length of stay for a dog10 days Daily cost of feeding one dog$. 90...
-
The Abby Arboretum (AA) has several programs, each of which has its own fund. AA also has several other important funds such as a Debt Service Fund and an Operating Fund (which handles all...
-
Determine whether each of the following statements is true or false: Management accountants should be proficient in Excel.
-
Determine whether each of the following statements is true or false: The Association of International Certified Professional Accountants (AICPA) issues the Certified Management Accountant (CMA)...
-
Determine whether each of the following statements is true or false: Critical thinking can be improved by asking yourself a series of questions about any issue or problem you encounter. These...
Study smarter with the SolutionInn App