#include "Entry.h" #include /* * Class containing typical data fields for a directory * a basic Entry includes a person's first name, last name, and email address * * Implementation File */ /* constructors */ Entry::Entry () : firstName (""), lastName (""), email ("") { } //Entry::Entry (char * first, char * last, char * eAddress) : Entry::Entry (const std::string & first,const std::string & last, const std::string & eAddress) : firstName (first), lastName (last), email (eAddress) { } /* method to allow viewing of an Entry */ string Entry::toString () const { return "\nName: " + firstName + " " + lastName + "\n E-mail Address: " + email + "\n"; } /*methods to allow comparing Entries */ /* ordering of entries considers alphabetical order of last names or, last names match, the ordering of the first names */ bool Entry::operator < (const Entry & ent2) { if (lastName.compare (ent2.lastName) < 0) { return true; } else if (lastName.compare (ent2.lastName) > 0) { return false; } else { // last names match, so check first names return (firstName.compare (ent2.firstName) < 0) ; } } /* two entries are considered equal if both first and last names match */ bool Entry::operator == (const Entry & ent2) { return (lastName.compare (ent2.lastName) == 0) && (firstName.compare (ent2.firstName) == 0); } bool Entry::operator <= (const Entry & ent2) { //Note: compilation errors with return ((this < ent2) || (this == ent2)); if (lastName.compare (ent2.lastName) > 0) { return false; } else if (lastName.compare (ent2.lastName) < 0) { return true; } else { // last names match, so check first names return (firstName.compare (ent2.firstName) <= 0) ; } } bool Entry::operator != (const Entry & ent2) { return (lastName.compare (ent2.lastName) != 0) || (firstName.compare (ent2.firstName) != 0); } bool Entry::operator > (const Entry & ent2) { //Note: compilation errors withreturn (ent2 < this); if (lastName.compare (ent2.lastName) > 0) { return true; } else if (lastName.compare (ent2.lastName) < 0) { return false; } else { // last names match, so check first names return (firstName.compare (ent2.firstName) > 0) ; } } bool Entry::operator >= (const Entry & ent2) { //Note: compilation errors withreturn !(this < ent2); if (lastName.compare (ent2.lastName) < 0) { return false; } else if (lastName.compare (ent2.lastName) > 0) { return true; } else { // last names match, so check first names return (firstName.compare (ent2.firstName) >= 0) ; } } /* overload the cout << operator for printing */ std::ostream &operator<<(std::ostream &os, const Entry &ent) { // send string to coout os << ent.toString (); return os; }