Question: Define a base class called Person. The class should have two data members to hold the first name and last name of a person, both

Define a base class called Person. The class should have two data members to hold the first name and last name of a person, both of type string.

The Person class will have a default constructor to initialize both data members to empty strings, a constructor to accept two string parameters and use them to initialize the first and last name, and a copy constructor. Also include appropriate accessor and mutator member functions. Overload the operators == such that two objects of class Person are considered equal if and only if both first and last names are equal. Overload the assignment operator = such that one object of Person can be copied to another Person object.

Also overload operators >> and <<.

class Person {

private:

string first;

string last;

public:

Person();

Person(string, string);

Person(const Person&); //copy constructor

void setFirst(string);

void setLast(string);

string getFirst() const;

string getLast() const;

bool operator =(const Person&);

const Person& operator =(const Person&); //copy

friend istream& operator >>(istream&, Person&);

friend ostream& operator <<(ostream&, const Person&);

};

I am primarily having troubles with the friend functions and the copy constructor code.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!