Question: C++ Code Using the listType code from Chapter 13 of your text as a guide, create a template class bagType which may be filled with

C++ Code

Using the listType code from Chapter 13 of your text as a guide, create a template class bagType which may be filled with any one of the standard data types including, as a minimum, integers, floats, characters, and strings. Your class should include function templates to

print the contents of a bag

display the total capacity of a bag

display the number of items currently in the bag

determine if the bag is empty

determine if the bag is full

Write a driver program to test your class and functions. Your driver program should include code to create a bag object that holds each of the types noted above and performs each of the functions for each type of bag.

Your main program should also implement exception handling using try and catch blocks as described in Chapter 14 of your text.

Do not use exception handling to ensure the user input matches the type requested. If you want to include that in your program use the logic that we have used previously to implement it (a while loop). For the purposes of this program, your bag should only accept positive values for the numeric types and only upper case values for the bag of characters. You do not need to write exception handling code for your bag of strings. Your code should include hard-coded input that tests the exception handling as well as code that generates correct input.

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!