#include #include using namespace std; #include "ordered_pair.h" int main() { multimap M; multimap::iterator itr, lower, upper; // Insert the ordered pairs (0,0), (0,1), (0,2), (1,0), ..., (2,2) // into the container. for ( int n = 1; n <= 2; ++n ) { for ( int i = 0; i < 3; ++i ) { for ( int j = 0; j < 3; ++j ) { M.insert( pair( ordered_pair( i, j ), 100*n + 10*i + j ) ); } } } // Print the number of objects in the container cout << "Size of M: " << M.size() << endl; // List the objects in the container for ( itr = M.begin(); itr != M.end(); ++itr ) { if ( itr != M.begin() ) { cout << ", "; } cout << itr->first << " = " << itr->second; } cout << endl; // List all objects indexed by the ordered pair (1, 1) cout << "Objects indexed by (1,1):" << endl; lower = M.lower_bound( ordered_pair( 1, 1 ) ); upper = M.upper_bound( ordered_pair( 1, 1 ) ); for ( itr = lower; itr != upper; ++itr ) { if ( itr != lower ) { cout << ", "; } cout << itr->first << " = " << itr->second; } cout << endl; // Remove the ordered pair (1,1) cout << "Removing (1,1)..." << endl; M.erase( ordered_pair( 1, 1 ) ); cout << "Size of M: " << M.size() << endl; // List the objects in the container for ( itr = M.begin(); itr != M.end(); ++itr ) { if ( itr != M.begin() ) { cout << ", "; } cout << itr->first << " = " << itr->second; } cout << endl; return 0; } /**************************************************** OUTPUT Size of M: 18 (0,0) = 100, (0,1) = 101, (0,2) = 102, (0,0) = 200, (0,1) = 201, (0,2) = 202, (1,0) = 110, (1,1) = 111, (1,2) = 112, (1,0) = 210, (1,1) = 211, (1,2) = 212, (2,0) = 120, (2,1) = 121, (2,2) = 122, (2,0) = 220, (2,1) = 221, (2,2) = 222 Objects indexed by (1,1): (1,0) = 110, (1,1) = 111, (1,2) = 112, (1,0) = 210, (1,1) = 211, (1,2) = 212 Removing (1,1)... Size of M: 12 (0,0) = 100, (0,1) = 101, (0,2) = 102, (0,0) = 200, (0,1) = 201, (0,2) = 202, (2,0) = 120, (2,1) = 121, (2,2) = 122, (2,0) = 220, (2,1) = 221, (2,2) = 222 *****************************************************/