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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started