Welcome! Today, we will explore creating a simple address book application using C++ and its std::unordered_map
class. This task will help you understand how to manipulate unordered maps in C++, focusing on adding, retrieving, and deleting entries. By the end of this lesson, you'll have a solid grasp of these fundamental operations.
In this task, we will implement three methods to manage our address book:
bool add_contact(const std::string& name, const std::string& phone_number)
: Adds a new contact. Returnsfalse
if the contact already exists; otherwise, adds the contact and returnstrue
. In this task, let's assume phone numbers do not change, so it's not allowed to overwrite the existing contact's number.std::string get_contact(const std::string& name)
: Retrieves the phone number for a givenname
. Returns an empty string if the contact does not exist.bool delete_contact(const std::string& name)
: Deletes a contact with the givenname
. Returnstrue
if the contact exists and is deleted,false
otherwise.
