Question: Need answer in C++ Q) Create a class Bag that uses a linked list to store the bag items. The item type must be char.

Need answer in C++

Q) Create a class Bag that uses a linked list to store the bag items. The item type must be char. The class should have the methods listed below. Create a main() that will store in a bag object a fixed number of characters entered by the program user. After the input is completed, the program should modify the bag content so that it does not contain any duplicate characters, if duplicates were entered. For example, if the user entered 'M' 'I' 'S' 'S' 'I' 'S' 'S' 'I' 'P' 'P' 'I', the characters remaining in the bag after the removal of duplicates would be 'M' 'I' 'S' 'P'.

Bag(): default constructor

~Bag(): class destructor

bool isEmpty(): determines whether the bag is empty

void print(): prints the bag elements

int getSize(): returns the number of items in the bag

void clear(): removes all of the items from the bag

void add(char item): adds an item to the bag

void remove(char item): removes an item from the bag; only one occurrence of the item should be removed.

int count(char item): counts the number of occurrences of an item in the bag.

(Note that you can reuse the code in Exercise 1 for the LinkedList class to create your Bag class. It will help you to save development time.)

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!