-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOOP-8-MAP.cpp
More file actions
37 lines (28 loc) · 1003 Bytes
/
OOP-8-MAP.cpp
File metadata and controls
37 lines (28 loc) · 1003 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main()
{
map<string, int> populationMap;
populationMap.insert(pair<string, int>("MH", 112));
populationMap.insert(pair<string, int>("UP", 199));
populationMap.insert(pair<string, int>("MP", 726));
populationMap.insert(pair<string, int>("AP", 845));
map<string, int>::iterator iter = populationMap.end();
cout << "Size of populationMap:" << populationMap.size() << "\n";
for (iter = populationMap.begin(); iter != populationMap.end(); ++iter)
{
cout << iter->first << ":" << iter->second << "million\n";
}
string state;
cout << "\nEnter the state:";
cin >> state;
iter = populationMap.find(state);
if (iter != populationMap.end())
cout << state << "population is:" << iter->second << "million\n";
else
cout << "Key is not in populationMap";
populationMap.clear();
return 0;
}