-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGroup_C_02.cpp
More file actions
41 lines (34 loc) · 1.46 KB
/
Copy pathGroup_C_02.cpp
File metadata and controls
41 lines (34 loc) · 1.46 KB
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
38
39
40
41
/*
Write a program in C++ to use map associative container. The keys will be the names of
states, and the values will be the populations of the states. When the program runs, the
user is prompted to type the name of a state. The program then looks in the map, using
the state name as an index, and returns the population of the state.
*/
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main() {
map<string, long long> statePopulations;
// Populate the map with state names and populations
statePopulations["California"] = 39538223; // Example population for California
statePopulations["Texas"] = 29145505; // Example population for Texas
statePopulations["New York"] = 20380482; // Example population for New York
statePopulations["Florida"] = 21538187; // Example population for Florida
// Add more states and populations as needed
string stateName;
// Prompt the user to enter a state name
cout << "Enter the name of a state: ";
getline(cin, stateName);
// Look up the state population in the map
auto it = statePopulations.find(stateName);
if (it != statePopulations.end()) {
// State found, print its population
cout << "The population of " << stateName << " is " << it->second << " people." << endl;
} else {
// State not found in the map
cout << "State not found in the database." << endl;
}
return 0;
}
/*Created by jayesh pandey*/