Question: Develop a C++ program to implement the following: Implement a new class called a keyedBag. This new class is similar to the ordinary bag, but
Develop a C++ program to implement the following:
Implement a new class called a keyedBag. This new class is similar to the ordinary bag, but whenever an item is added, the programmer using the bag also provides an integer called key. Each item added to the keyed bag must have a unique key; two items cannot have the same key. So the insertion function has the specification shown here:
void keyed_bag::insert(const value_type& entry, int key); //Precondition: size() < CAPACITY //the bag does not contain any item with the given key. //Postcondition: A new copy of entry //has been added to the bag, with the given key.
These are the actions performed by the programs driver: 1. Create a keyedBag class. 2. Inserts 5 items in the keyed bag with the key provided by the user using the overloaded operator >>. Do not use the value 3A as a key. 3. Print the content of the keyed bag using the overloaded operator <<. 4. Remove the items by using their key. 5. Print the content of the keyed bag again. 6. Add one more item to the keyed bag 7. Print again the content of the keyed bag. 8. Remove the items with key 3A and verify that this is illegal. 9. Print again the content of the bag with receipts. 10. Now add the item with the key 3A 11. Print again the content of the keyed bag.
Thank you so much in advance!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
