74: void ShowMap(const map<T, A>& v); // display map properties
75:
76: typedef map<string, Student> SchoolClass;
77:
78: int main()
79: {
80: Student Harry(“Harry”, 18);
81: Student Sally(“Sally”, 15);
82: Student Bill(“Bill”, 17);
83: Student Peter(“Peter”, 16);
84:
85: SchoolClass MathClass;
86: MathClass[Harry.GetName()] = Harry;
87: MathClass[Sally.GetName()] = Sally;
88: MathClass[Bill.GetName()] = Bill;
89: MathClass[Peter.GetName()] = Peter;
90:
91: cout << “MathClass:” << endl;
92: ShowMap(MathClass);
93:
94: cout << “We know that “ << MathClass[“Bill”].GetName()
95: << “ is “ << MathClass[“Bill”].GetAge()
96: << “ years old” << endl;
97: return 0;
98: }
99:
100: //
101: // Display map properties
102: //
103: template<class T, class A>
104: void ShowMap(const map<T, A>& v)
105: {
106: for (map<T, A>::const_iterator ci = v.begin();
107: ci != v.end(); ++ci)
108: cout << ci->first << “: “ << ci->second << endl;
109:
110: cout << endl;
111: }
MathClass:
Bill: Bill is 17 years old
Harry: Harry is 18 years old
Peter: Peter is 16 years old
Sally: Sally is 15 years old
We know that Bill is 17 years old
OUTPUT
706 Day 19
LISTING19.10 continued