Question

In: Computer Science

C++ ^ ^ Write a menu driven program to perform following operations using a map container...

C++
^
^
Write a menu driven program to perform following operations using a map container that stores the information about USA Population (In Million).

@@@Menu@@@
1. Add Information
2. Display Information
3. Update Information
4. Erase Information
5. Clear Information

For example, Suppose the map initially contains following information (Use emplace() function to store the information)
2010, 309.33
2011, 311.58
2012, 313.87
2015, 320.74
2016, 323.07

The program should produce the desired output when a valid input is provided, as follows:

1. If the Input is:
1
2018
329.16
The output should be:
Record Added: USA population in 2018 is 329.16 Million.

2. If the Input is:
2
2015
The output should be:
USA population in 2015 is 320.75 Million.

3. If the Input is:
3
2015
321.88

The output should be:
Record Updated: USA population in 2015 is 321.88 Million.

4. If the Input is:
4
2015

The output should be:
Record Deleted: USA population in 2015 was 321.88.

5. If the Input is:
5

The output should be:
All records Deleted.

Solutions

Expert Solution

#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


Related Solutions

C++ 14.11 Lab # Map Write a menu driven program to perform following operations using a...
C++ 14.11 Lab # Map Write a menu driven program to perform following operations using a map container that stores the information about USA Population (In Million). @@@Menu@@@ 1. Add Information 2. Display Information 3. Update Information 4. Erase Information 5. Clear Information For example, Suppose the map initially contains following information (Use emplace() function to store the information) 2010, 309.33 2011, 311.58 2012, 313.87 2015, 320.74 2016, 323.07 The program should produce the desired output when a valid input...
Write a C++ program to run a menu driven program with the following choices: 1) Display...
Write a C++ program to run a menu driven program with the following choices: 1) Display the grades 2) Adjust grade 3) Display Average for each student 4) Display number of student with at least a B 5) Quit requirements: 1. Write a function called getValidGrade that allows a user to enter in an integer and loops until a valid number that is >= 0 and <= 100 is entered. It returns the valid value. 2. Write a function called...
Java Write a menu driven program that implements the following linked list operations : INSERT (at...
Java Write a menu driven program that implements the following linked list operations : INSERT (at the beginning) INSERT_ALPHA (in alphabetical order) DELETE (Identify by contents, i.e. "John", not #3) COUNT CLEAR
Write a menu driven Java program which uses a method for each of the following operations:...
Write a menu driven Java program which uses a method for each of the following operations: (Note : The user should be allowed to repeat the operations as long as he wants to. Use appropriate number of parameters and return type for each method.) A. to find the sum of the following series (up to N terms). The program should    display the terms:              22 + 42 + 62… For example, if N=4, then the program should display the following...
The Menu-driven Program: Write a menu-driven program to implement a roomsboard for a classroom reservations system....
The Menu-driven Program: Write a menu-driven program to implement a roomsboard for a classroom reservations system. The menu includes the following options: Add new room. The program will prompt the user to enter the roomID, courseID and time of the new reserved room, then will call the add() method from the RoomsBoard class. Remove all occurrences of a room. The program will prompt the user to input the room ID to be removed, then call the remove() method from the...
Write a menu driven C++ program that prints the day number of the year , given...
Write a menu driven C++ program that prints the day number of the year , given the date in the form of month-day-year. For example , if the input is 1-1-2006 , then the day number is 1. If the input is 12-25- 2006 , the day number is 359. The program should check for a leap year. A year is leap if it is divisible by 4 but not divisible by 100. For example , 1992 , and 2008...
write a c++ program to perform the following operations on stack of Integers (Array Implementation of...
write a c++ program to perform the following operations on stack of Integers (Array Implementation of Stack with maximum size MAX) (i) Push an Element on to stack (ii) Pop an Element from stack (iii) Demonstrate how stack can be used to check Palindrome (iv) Display the status of stack (v) Exit
Write a menu-driven C++ program with two options: 1) Is it odd or even? 2) End...
Write a menu-driven C++ program with two options: 1) Is it odd or even? 2) End Program.The user can only input a positive integer (0 does not count) and if the input is not a positive integer the program must state "Invalid Input." The program must determine whether the input is even or odd. The program must use functions and can only use the iostream and iomanip libraries. Note: The program must loop until the 2nd menu option is chosen.
No Global variables No goto statement No break outside switch Write a menu driven C program...
No Global variables No goto statement No break outside switch Write a menu driven C program using functions and switch. Feel free to use “Empty Outlines” template from Canvas to design the functions as needed to build the code. Make sure to submit your work through Canvas. You can show me your code running in class when you are done. The program shows following menu to the user repetitively until user selects option 3 to exit. Circle Triangle Exit Based...
Write a  program in c++ using a map to create the following output. Here is the list...
Write a  program in c++ using a map to create the following output. Here is the list of students: 100: Tom Lee 101: Joe Jones 102: Kim Adams 103: Bob Thomas 104: Linda Lee Enter a student an ID to get a student's name: ID:  103 students[103] - Bob Thomas # of students: 5 Delete a student (Y or N)?  Y Enter ID of student to be deleted:  103 Here is the list of students after the delete: 100: Tom Lee 101: Joe Jones...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT