Question: The program uses a map to store and accumulate the keys and values. In this example, we have 2 keys, iluvuic and AAA, and their

The program uses a map to store and accumulate the keys and values. In this example, we have 2 keys, "iluvuic" and "AAA", and their associated values are 80 and 225 respectively. Next the program allows the user to lookup by key, and if found, outputs the associated value in the map:

Enter key to lookup> 007 Not found... Enter key to lookup> iluvuic Found, value: 225 Enter key to lookup> AAA Found, value: 80 Enter key to lookup> aaa Not found... Enter key to lookup> # 

Finally, the program outputs the contents of the map in ascending order by key (which is the default for maps):

Map: (AAA, 80) (iluvuic, 225)

// // using map to store, accumulate and lookup (key, value) pairs: //

#include #include

using namespace std;

int main() { string key; int value;

// // input (key, value) pairs and accumulate into map: // cout << "Enter key or #> "; cin >> key;

while (key != "#") { cout << "Enter value> "; cin >> value;

// // TODO: use map to store / accumulate (key, value) pair: //

cout << "Enter key or #> "; cin >> key; }

// // now allow user to search for key and retrieve value: // cout << endl; cout << "Enter key to lookup, or #> "; cin >> key;

while (key != "#") { // // TODO: use map to lookup key... //

cout << "Enter key to lookup, or #> "; cin >> key; } // // Finally, let's print the map to the console: // // // TODO: //

// // done: // return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!