Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.1 kB
4
Indexable
Never
#include <iostream>
#include <map>
#include <string>

class phonebook
{
public:
    void AddEntry(std::string& Name, std::string& number)
	{
        phone_book[Name] = number;
    }

    std::string getnumber(std::string& name)
	{
        return phone_book[name];
    }

    void remove_entry(std::string name)
	{
        phone_book.erase(name);
    }

    void PrintAllEntries()
	{
        for (auto entry : phone_book) {
            std::cout << entry.first << ": " << entry.second << std::endl;
        }
    }

    void updateNumber(std::string& name, std::string number)
	{
        phone_book[name] = number;
    }

private:
    std::map<std::string, std::string> phone_book;
};

int main()
{
    phonebook pb;
    pb.AddEntry("Alice", "123-456-7890");
    pb.AddEntry("Bob", "098-765-4321");
    pb.AddEntry("Eve", "555-555-5555");

    pb.remove_entry("Alice");

    pb.AddEntry("Charlie", "222-333-4444");
    pb.AddEntry("Dave", "111-222-3333");
	
    pb.PrintAllEntries();

    pb.updateNumber("Eve", "999-999-9999");

    pb.PrintAllEntries();

    return 0;
}
Leave a Comment