Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Marketing The New Profit Frontier

Authors: Ed Burnett

1st Edition

0964535629, 978-0964535626

More Books

Students also viewed these Databases questions