// // phonebook.h - naive, array-based implementation // #ifndef _phonebook_h #define _phonebook_h #include // An entry in a phone book; captures the person's name and number // Number is a string to allow for non-numeric data // All methods are inline to illustrate this. class Entry { public: Entry(std::string name = "", std::string number = "") : _name(name), _number(number) { } std::string name() const { return _name; } std::string number() const { return _number; } void updateNumber(std::string new_number) { _number = new_number; } private: std::string _name, _number; }; // The full phone book with standard container operations to add, // look up, and remove entries. // All methods are defined in a separate .cpp file. class PhoneBook { public: // construct empty phonebook PhoneBook(); // is phonebook empty? bool empty() const; // look up entry by name, returning nullptr if no such entry Entry *lookup(std::string target) const; // add entry; does nothing if already present void add(Entry *new_entry); // remove entry; does nothing if entry not present void remove(std::string name); // list all entries formatted in two columns void list() const; private: int entries; static constexpr int MAX_ENTRIES = 2000, NOT_FOUND = -1; Entry *book[MAX_ENTRIES]; // index of target name, NOT_FOUND if no entry for target int index_of(std::string target) const; }; #endif