Question

In: Computer Science

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

102: Kim Adams

104: Linda Lee

*/

Solutions

Expert Solution

#include<iostream>
#include<iterator>
#include<string.h>
#include<map>
using namespace std;
int main()
{
int temp,count=0;
char ch;
map<int,string> students;
students.insert(pair<int,string>(100,"Tom Lee"));
  
students.insert(pair<int,string>(101,"Joe Jones"));
students.insert(pair<int,string>(102,"Kim Adams"));
students.insert(pair<int,string>(103,"Bob Thomas"));
students.insert(pair<int,string>(104,"Linda Lee"));
  
map<int,string>::iterator itr;
cout<<"\n The list of students is:\n";
for(itr=students.begin();itr!=students.end();++itr){
cout<<"\t"<<itr->first<<"\t"<<itr->second<<"\n";
count+=1;
}
cout<<"Enter the student id to get the student name"<<endl;
cout<<"ID :";
cin>>temp;
cout<<"students["<<temp<<"]- "<<students.lower_bound(temp)->second<<endl;
cout<<"# of students: "<<count<<endl;
cout<<"delete a student (Y or N)? ";
cin>>ch;
if(ch=='Y')
{
cout<<"Enter the ID of student to be deleted : ";
cin>>temp;
students.erase(temp);
cout<<"\n Here is the list of students after the delete:\n";
for(itr=students.begin();itr!=students.end();++itr){
cout<<"\t"<<itr->first<<"\t"<<itr->second<<"\n";
}
}
}

Output:


Related Solutions

1. Write a python program to create a list of integers using random function. Use map...
1. Write a python program to create a list of integers using random function. Use map function to process the list on the expression: 3x2+4x+5 and store the mapped elements in another list. Now use filter to do sum of all the elements in another list. 2. Write a function that takes n as input and creates a list of n lists such that ith list contains first 10 multiples of i. 3. Write a function that takes a number...
Write a  program in C++ using a vector to create the following output. Declare a vector named  numbers    -  Don’t...
Write a  program in C++ using a vector to create the following output. Declare a vector named  numbers    -  Don’t specify a size and don’t initialize with values. Starting with 2, pushing these into the back of the vector:   2, 4, 6, 8, 10 vector capacity (array size) changes and is dependent on the compiler. The size of the list is now 5. The vector capacity (array size) is 6. The back element is: 10 The front element is: 2 Now deleting the value at...
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,...
write a Program in C++ Using a structure (struct) for a timeType, create a program to...
write a Program in C++ Using a structure (struct) for a timeType, create a program to read in 2 times into structures, and call the method addTime, in the format: t3 = addTime(t1, t2); Make sure to use add the code to reset and carry, when adding 2 times. Also, display the resultant time using a function: display(t3);
Create the following java program with class list that outputs: //output List Empty List Empty List...
Create the following java program with class list that outputs: //output List Empty List Empty List Empty Item not found Item not found Item not found Original list Do or do not. There is no try. Sorted Original List Do There do is no not. or try. Front is Do Rear is try. Count is 8 Is There present? true Is Dog present? false List with junk junk Do or moremorejunk do not. There is no try. morejunk Count is...
USING PYTHON Write a program to create a number list. It will call a function to...
USING PYTHON Write a program to create a number list. It will call a function to calculate the average values in the list. Define main ():                        Declare variables and initialize them                        Create a list containing numbers (int/float)                        Call get_avg function that will return the calculated average values in the list.                                       Use a for loop to loop through the values in the list and calculate avg                        End main()
1) a. Write down a C++ program which will create a list (simple linear linked list)...
1) a. Write down a C++ program which will create a list (simple linear linked list) of nodes. Each node consists of two fields. The first field is a pointer to a structure that contains a student id (integer) and a gradepoint average (float). The second field is a link. The data are to be read from a text file. Your program should read a file of 10 students (with student id and grade point average) and test the function...
Create a schematic of a circuit using and write C program to run on a PIC...
Create a schematic of a circuit using and write C program to run on a PIC 16F88 that will flash between a red and green LED at 5Hz with the green on 75% of the time and the red on 25% of the time.
Using C++, write a code that this program always stores text file output into a text...
Using C++, write a code that this program always stores text file output into a text file named "clean.txt". -The program should read one character at a time from "someNumbers.txt", and do the following. -If it is a letter, print that letter to the screen, AND also store it in the text file. All letters should be converted to lowercase beforehand. -If it is a number, print that number to screen, but do NOT store it in the text file....
Write a program that produces the following output using nested for loop in Java. ****** ////////////...
Write a program that produces the following output using nested for loop in Java. ****** //////////// ****** ***** //////////\\ ***** **** ////////\\\\ **** *** //////\\\\\\ *** ** ////\\\\\\\\ ** * //\\\\\\\\\\ * \\\\\\\\\\\\
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT