#include #include #include // using namespace std; int main() { std::map notebook; while (true) { std::cout << "Enter a command:\n" << "1 add/change a telephone of a person,\n" << "2 find a telephone of a person,\n" << "3 print all contacts,\n" << "q quit." << std::endl; std::string line; std::getline(std::cin, line); if (line == "1") { // Add/change telephone std::cout << "Name: "; std::string name; std::getline(std::cin, name); std::cout << "Phone: "; std::string phone; std::getline(std::cin, phone); notebook[name] = phone; } else if (line == "2") { std::cout << "Name: "; std::string name; std::getline(std::cin, name); if (notebook.count(name) == 0) { std::cout << "No such name." << std::endl; } else { std::cout << "Phone: " << notebook[name] << std::endl; } } else if (line == "3") { std::map::const_iterator i = notebook.cbegin(); while (i != notebook.cend()) { std::cout << i->first << " " << i->second << std::endl; ++i; } } else if (line == "q") { break; } } return 0; }