Question

use C++ std:: map. Use necessary methods from the library. First Name Last Name “Jane” “Smith”...

use C++ std:: map.

Use necessary methods from the library.

First Name

Last Name

“Jane”

“Smith”

“John”

“Do”

“Susan”

“Collins”

“Bill”

“Rodgers”

“Eric”

“Jones”

“Bill”

“Wright”

“Mike”

“Bader”

Use Conventional Method Names Insert, Remove, Search:

insert(key, value)

insert(“First”, “Last”)

Search(“First”) → Method will return value

Remove(“First”) → Method will delete key and value

0 0
Add a comment Improve this question Transcribed image text
Answer #1

/*
 *  C++ Program to perform basic operations on STL MAP
 */

#include <iostream>
#include <string>
#include <map>
#include <iterator>

using namespace std;

map <string, string> names;

void insert(string key, string value)
{
  names.insert(pair<string, string>(key, value));
}

string search(string key)
{
  return names[key];
}

void remove(string key)
{
  names.erase(key);
}

void display()
{
  map <string, string>::iterator it;

  for (it = names.begin(); it != names.end(); ++it)
  {
    cout << it->first << ' ' << it->second << endl;
  }
}

int main()
{
  insert("Jane", "Smith");
  insert("John","Do");
  insert("Susan","Collins");
  insert("Bill","Rodgers");
  insert("Eric","Jones");
  insert("Billy","Wright");
  insert("Mike","Bader");

  cout << "Results after insertion -" << endl;
  display();
  cout << endl;

  string toSearch = "John";
  cout << "Search Results for " << toSearch << ": " << search(toSearch) << endl << endl;

  string toRemove = "Mike";
  remove(toRemove);
  cout << "Result after removing " << toRemove <<" -"<< endl;
  display();

  return 0;
}
/*  Program ends here */

Note: For queries, drop comment.

Add a comment
Know the answer?
Add Answer to:
use C++ std:: map. Use necessary methods from the library. First Name Last Name “Jane” “Smith”...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ I need a program that will read a list of names from a data file and store them in an array. You will then sort the array by last name using a quicksort, and display the results, one name per line...

    C++ I need a program that will read a list of names from a data file and store them in an array. You will then sort the array by last name using a quicksort, and display the results, one name per line.Each line has a first name and a last name.The file has 40 names in it right now, but the array should be able to accommodate up to 50 names.txt***************************************************** Barbara Wright Ian Chesterton Steven Taylor Sara Kingdom Dodo...

  • SQL - create statement for query For each patient, display his or her last name, first...

    SQL - create statement for query For each patient, display his or her last name, first name, and the name of his or her doctor. For each pediatrics patient, display his or her ID and his or her doctor's ID and name. For each doctor, display the name and the name of the doctor's supervisor in alphabetic order of supervisor's name. Include column aliases for clarity. Note: Check for accuracy. For each doctor in one of the two areas entered...

  • SQL: CREATE STATEMENT For patients whose last name matches the name entered by the user, display...

    SQL: CREATE STATEMENT For patients whose last name matches the name entered by the user, display their first name, phone number, and doctor's name. Note: Try Davis. (TEXT FOR DATABASE BELOW) DROP TABLE PATIENT; DROP TABLE BILLING; DROP TABLE DOCTOR; CREATE TABLE DOCTOR( DOC_ID VARCHAR2(10) NOT NULL, DOC_NAME VARCHAR2(20), DATEHIRED DATE, SALPERMON NUMBER(8), AREA VARCHAR2(20), SUPERVISOR_ID NUMBER(8), CHGPERAPPT NUMBER(8), ANNUAL_BONUS NUMBER(8), PRIMARY KEY (DOC_ID) ); INSERT INTO DOCTOR VALUES('432', 'Harrison', to_date('05-DEC-1994','dd-mon-yyyy'), 12000, 'Pediatrics', 100, 75, 4500); INSERT INTO DOCTOR VALUES('509',...

  • How to write the insert, search, and remove functions for this hash table program? I'm stuck......

    How to write the insert, search, and remove functions for this hash table program? I'm stuck... This program is written in C++ Hash Tables Hash Table Header File Copy and paste the following code into a header file named HashTable.h Please do not alter this file in any way or you may not receive credit for this lab For this lab, you will implement each of the hash table functions whose prototypes are in HashTable.h. Write these functions in a...

  • // C code // If you modify any of the given code, the return types, or...

    // C code // If you modify any of the given code, the return types, or the parameters, you risk getting compile error. // Yyou are not allowed to modify main (). // You can use string library functions. #include <stdio.h> #include <stdlib.h> #include <string.h> #pragma warning(disable: 4996) // for Visual Studio #define MAX_NAME 30 // global linked list 'list' contains the list of patients struct patientList {    struct patient *patient;    struct patientList *next; } *list = NULL;  ...

  • ***JAVA: Please make "Thing" movies. Objective In this assignment, you are asked to implement a bag...

    ***JAVA: Please make "Thing" movies. Objective In this assignment, you are asked to implement a bag collection using a linked list and, in order to focus on the linked list implementation details, we will implement the collection to store only one type of object of your choice (i.e., not generic). You can use the object you created for program #2 IMPORTANT: You may not use the LinkedList class from the java library. Instead, you must implement your own linked list...

  • C++ Create an application that searches a file of male and female first names. A link...

    C++ Create an application that searches a file of male and female first names. A link to the file is provided on the class webpage. "FirstNames2015.txt" is a list of the most popular baby names in the United States and was provided by the Social Security Administration. Each line in the file contains a boy's name and a girl's name. The file is space-delimited, meaning that the space character is used to separate the boy name from the girl name....

  • First, read the article on "The Delphi Method for Graduate Research." ------ Article is posted below...

    First, read the article on "The Delphi Method for Graduate Research." ------ Article is posted below Include each of the following in your answer (if applicable – explain in a paragraph) Research problem: what do you want to solve using Delphi? Sample: who will participate and why? (answer in 5 -10 sentences) Round one questionnaire: include 5 hypothetical questions you would like to ask Discuss: what are possible outcomes of the findings from your study? Hint: this is the conclusion....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT