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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!