Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2014 Administration

Authors: Adam Jorgensen, Bradley Ball

1st Edition

111885926X, 9781118859261

More Books

Students also viewed these Databases questions

Question

=+ Have they changed the way employers view IP?

Answered: 1 week ago