// PhoneBookEntry.h #ifndef _PhoneBookEntry_h_ #define _PhoneBookEntry_h_ #include #include class PhoneBookEntry { friend std::istream & operator>>(std::istream& in, PhoneBookEntry& e); friend std::ostream & operator<<(std::ostream& out, const PhoneBookEntry& e); public: const std::string& name() const { return name_; } void read_from_user(); void update(const PhoneBookEntry & new_data); private: std::string name_; std::string phone_; std::string email_; }; inline void PhoneBookEntry::read_from_user() { using namespace std; cout << "name: "; getline(cin, name_); cout << "phone number: "; getline(cin, phone_); cout << "email address: "; getline(cin, email_); } inline void PhoneBookEntry::update(const PhoneBookEntry& new_data) { if (!new_data.name_.empty()) name_ = new_data.name_; if (!new_data.phone_.empty()) phone_ = new_data.phone_; if (!new_data.email_.empty()) email_ = new_data.email_; } inline std::istream & operator>>(std::istream& in, PhoneBookEntry& e) { getline(in, e.name_); getline(in, e.phone_); getline(in, e.email_); return in; } inline std::ostream & operator<<(std::ostream& out, const PhoneBookEntry& e) { out << e.name_ << std::endl << e.phone_ << std::endl << e.email_ << std::endl; return out; } #endif