#include #include using namespace std; #include "ordered_pair.h" int main() { map M; map::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[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: 3 (0,0) = 202, (1,0) = 212, (2,0) = 222 Objects indexed by (1,1): (1,0) = 212 Removing (1,1)... Size of M: 2 (0,0) = 202, (2,0) = 222 *****************************************************/