Question: Need answer in C++ Create a class Bag (multiset) that uses an expandable array to store the bag items. The item type must be int.
Need answer in C++
Create a class Bag (multiset) that uses an expandable array to store the bag items. The item type must be int. The class should have the methods listed below. Create a main class to test your bag class. This main class should fill a bag of integers with 10 random numbers, each in the interval [0, 20], and print how many times each integer in the interval [0, 20] appears in the bag.
Bag(): default constructor
bool isEmpty(): determines whether the bag is empty
void print(): prints the bag elements
int getLength(): returns the number of items in the bag
void clear(): removes all of the items from the bag
void add(int item): adds an item to the bag
void remove(int item): removes item from the bag; only one occurrence of item should be removed.
int count(int item): counts the number of occurrences of item in the bag.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
