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
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