BIG C++ Cay Horstmann & Timothy Budd
Laboratory Notebook Chapter 23 – The Standard Template Library - Containers
Your name:
Your email address:
Your student ID number:
Once this form has been customized for your institution, you can use this button to send your lab work. Be sure to read the instructions before starting your work.
To gain experience with
· understanding the purpose and use of the containers in the Standard Template Library
· the fundamental sequential containers—vector, list, and deque
· the adapter containers—stack, queue, and priority queue
· the ordered container—set
· the associative container—map
P1. Introduction to Maps
Maps can be very useful in the proper situation. To illustrate, write a class to represent a list of secret agents. The class should use a map to store operative names and their ID numbers. Store each pair (an integer and a string) within a map such that the ID number serves as the key. The class definition is given below.
class AgentList
{
public:
AgentList()
string getAgentName(int ID);
void addAgent(int ID, string name);
private:
map<int, string> agentList;
};
Submit all of the code for your answer in the space below.
R1. Fundamental Containers
Name the three fundamental containers. Then, re-implement your agent list class using each of these fundamental containers in place of the map. You will find that it is important to choose the right container for the right job as doing so can significantly reduce the complexity of your programming.
P2. Map Interaction
Returning to the implementation in Problem P1, modify your AgentList class to include a map for storing agent names and their native country (both will be string values). The name will be used as a key to determine the country of origin. The class definition is provided below. For the getAgentCountry() function, you should use the ID to retrieve the name from one map. That name should then be used to retrieve the country from the other map.
AgentList();
string getAgentCountry(int ID);
void addAgent(int ID, string name, string country);
map<int, string> agentNameList;
map<string, string> agentCountryList;
R2. Adapters
In addition to the fundamental containers, there are also a number of structures for representing grouped items. These additional structures are called adapters. In this problem, supply implementations for your AgentList class developed in Problem P2 using a stack and queue in place of a map.
P3. Testing
Write a short program to test your AgentList classes. Ensure that your tests guarantee the complete functionality of each implementation.
Insert all code in the space below.
R3. Iterators
Do you remember how to use iterators? The Map class used within your AgentList class supplies such a feature. Modify your AgentList class to include a new member function called print(). This function should use an iterator to traverse the private map and display information contained within the AgentList class to the screen.
Do not forget to send your answers when you are finished.