In: Computer Science
#include <bits/stdc++.h>
using namespace std;
// display menu
void menu()
{
cout<<"1. Add Information"<<endl;
cout<<" 2. Display Information"<<endl;
cout<<"3. Update Information"<<endl;
cout<<"4. Erase Information"<<endl;
cout<<"5. Clear Information"<<endl;
  
cout<<"0. To end the program"<<endl;
  
}
int main() {
   // your code goes here
   map<int,float>mp;
   menu();
   int n;// to store the user input;
   while(1)
   {
   cin>>n;
   if(n==0)
   break;
   if(n==1)
   {
   // takes the input and stores the information in
map
   int year;
   cin>>year;
   float population;
   cin>>population;
   mp.emplace(year,population);
   cout<<"Record Added: USA population in
"<<year<<" is "<<population<<"
Million"<<endl;
   }
   if(n==2)
   {
   int year;
   cin>>year;
   // take the year and display the population
   cout<<"USA population in "<<year<<"
is "<<mp[year]<<" Million"<<endl;
  
  
   }
   if(n==3)
   {
   // take the year and population to be updated
   int year;
   cin>>year;
   float population;
   cin>>population;
   mp[year]=population;// updatin population
  
   cout<<"Record Updated: USA population in
"<<year<<" is "<<mp[year]<<"
Million"<<endl;
  
   }
   if(n==4)
   {
   // clear the year
   int year;
   cin>>year;
   float temp=mp[year];
   mp.erase(year);
   cout<<"Record Deleted: USA population in
"<<year<<" was "<<temp<<"
Million"<<endl;
  
  
   }
   if(n==5)
   {
   // clear the map
   mp.clear();
   }
   }
   return 0;
}
For input
1
2010 323.4
1
2012 326.9
1
2016 330.9
1
2020 335.8
2
2016
3
2016 333.8
4
2016
5
0
output
1. Add Information
2. Display Information
3. Update Information
4. Erase Information
5. Clear Information
0. To end the program
Record Added: USA population in 2010 is 323.4 Million
Record Added: USA population in 2012 is 326.9 Million
Record Added: USA population in 2016 is 330.9 Million
Record Added: USA population in 2020 is 335.8 Million
USA population in 2016 is 330.9 Million
Record Updated: USA population in 2016 is 333.8 Million
Record Deleted: USA population in 2016 was 333.8 Million