in c++,A container class is a data type that is capable of holding a collection of items…
- User
in c++,A container class is a data type that is capable of holding a collection of items and provides functions to access them. Bag is an example of a container class. It is an unordered collection of items that may have duplicates. In this assignment, you are asked to design and develop an abstract Bag class, called BagInterface, with the following fixed collection of operations: Insert an item of any type into a bag Query the bag contents: two queries Is an item in the bag? How many copies of an item is in the bag? Remove an item from the bag clear the bag Get the size of the bag How many items are there in the bag? Check if the bag is empty Check if the bag is full Assume the bag capacity is 20 In addition to BagInterface, you are asked to implement two classes of bag implementations: PlainBag and MagicChangeBag.
PlainBag is a simple container that holds items of any type using an array implementation.
MagicChangeBag is also very similar to PlainBag, with two exceptions. When an item is inserted into a magic change bag, it’ll magically disappear, and bag looks empty. Whenever a remove operation is invoked, all the items, except the one is removed will appear.
- Assistant
- User
comment the code
- Assistant
- User
how will a UML class diagram look like for the solution
- Assistant
A UML class diagram for the solution would look like this:
_________________________________ | BagInterface | |---------------------------------| | +insertItem(item: int) | | +isInBag(item: int): bool | | +countOfItem(item: int): int | | +removeItem(item: int) | | +clearBag() | | +getSize(): int | | +isEmpty(): bool | | +isFull(): bool | --------------------------------- / \ / \ / \ ---------------- ---------------- | PlainBag | | MagicChangeBag | |-----------------|-----------------| | -capacity: int | | | -size: int | | | -items: int[] | | |-----------------|-----------------| | +insertItem(item: int) | | +isInBag(item: int): bool | | +countOfItem(item: int): int | | +removeItem(item: int) | | +clearBag() | | +getSize(): int | | +isEmpty(): bool | | +isFull(): bool | ---------------------------------