Create a Person class to represent a person's contact information. Your Person class must consist of the following:
PRIVATE members:
string firstName,lastName;
birthDate //you get to choose the data type, but the type you choose must be able to maintain a
// 1 day resolution
PUBLIC members:
1. Default constructor that sets the first name to "", last name to "", and the date of birth to January 1st, 2000.
2. Copy constructor
3. Initialization constructor that takes 3 arguments - 1 const string for each first name and last name, and a third argument of the type you use for your Person's age.
4. Three Accessor methods that each return one of the private data members - the first name, last name, and date of birth as strings (i.e. string type). In other words, you must implement these methods:
string getFirstName() const;
string getLastName() const;
string getBirthDate() const;
5. A method that compares the age of this person with another person's age, returning the number of days old this person is to the others. This method must have the following prototype:
int ageDifference(const Person& p); // returns #days older this person is than Person p
FRIEND FUNCTIONS:
ostream& operator<<(ostream& o, const Person& p); bool operator==(const Person& p1, const Person& p2); //returns true if p1 and p2 have same //first and last names AND the same birthdate. bool operator<(const Person& p1, const Person& p2); // returns true if p1 comes first alphabetically // look at last names first, then first names if // the last names are the same bool operator>(const Person& p1, const Person& p2); //returns true if p2 comes first alphabetically
I have no problems with steps 1 through 4. When it came down to step 5, I have no clue what to do. My problem is constructing ageDiffference and other methods that can support it. I am stuck with a string. (ex "01/01/2001") How can I do subtraction with strings?
Person() : fN(""), lN(""),BD(()){}
Person(const string& fn,const string& ln,const string& dob):
fN(fn), lN(ln), bD(dob) {}
int ageDifference(const Person& p);
For example I want my output for this case to be Micheal is 365 days older.
Assume every month is 30 days. No leap years.
int main{
Person a("Michael", "", "7/25/1980");
Person b("Marius", "", "6/25/1981");
cout << a.getFirstName() << " is " << a.ageDifference(b) << " days older than " << b.getFirstName() << endl;
}
I've been thinking about using tt_time but I have no clue how that works.