Question: Write a program that simulates a bag. Implement this program in a file called bag.cpp . The program should work as follows: a . This

Write a program that simulates a bag. Implement this program in a file called bag.cpp. The program should
work as follows:
a. This bag holds a certain number of characters.
b. When the program begins, the user should be prompted for the size of the bag. (Hint: use dynamic
allocation to create an array of exactly this size)
c. The program should display three menu options: 1) Add to Bag, 2) Remove from Bag, 3) Quit.
i. When adding to the bag, the user should be prompted for a character. If the bag has space, the
character should be added to the bag. Otherwise, the message The bag is full! should
be displayed. Afterwards, the current contents of the bag should be output.
ii. When removing from the bag, the user should be prompted for a character. If the character is
not present in the bag, a message should be displayed in the format {char} is not in
the bag. Otherwise, all occurrences of the character should be removed; a message should
be displayed detailing how many of the characters were removed. Afterwards, the current
contents of the bag should be output.
iii. If the user chooses to quit, the program should end

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 Programming Questions!