I have to make a function under class record that returns a pointer person class data type. I am assuming that this means setting a person object to equal to the returned pointer person class type but in order to do that It looks like i need to make an overloaded = operator. Here is my code:
-------------------------------------
#include <string>
#include <iostream>
#include <ctime>
#include <fstream>
using namespace std;
class person{
protected:
string firstName, lastName;
int age;
public:
string getFirstname(){return firstName;}
string getLastName(){return lastName;}
int getAge(){return age;}
void setFirstName(string fname){firstName=fname;}
void setLastName(string lname){lastName=lname;}
void setAge(int yo){age=yo;}
virtual void print()const{cout<<lastName<<", "<<firstName<<", age "<<age<<endl;}
void operator=(person);
};
void person::operator=(person p){this->firstName = p.getFirstname();this->lastName = p.getLastName();this->age = p.getAge();}
class patient: public person{
private:
string desease;
int id;
public:
void setDesease(string illness){desease=illness;}
void setID(int ID){id=ID;}
void print()const{cout<<lastName<<", "<<firstName<<"; age "<<age<<"; desease: "<<desease<<"; id: "<<id<<endl;}
};
class doctor: public person{
private:
string specialty;
int ssn;
public:
void setSpecialty(string proffesion){specialty=proffesion;}
void setSSN(int SSN){ssn=SSN;}
void print()const{cout<<lastName<<", "<<firstName<<"; age "<<age<<"; specialty: "<<specialty<<"; ssn: "<<ssn<<endl;}
};
class record{
private:
int id;
person* pPtr;
public:
record(int ID){id=ID;}
void setpPtr(person subject){pPtr=&subject;}
int getID(){return id;}
person getpPtr(){return *pPtr;}
};
int main () {
person theDoctor;
;
doctor myDoctor;
int ssn, age, ID;
ID=999;
record myRecord (ID);
string Fname, Lname, specialty;
cout<<"enter fname:"<<endl;
cin>>Fname;
cout<<"enter lname:"<<endl;
cin>>Lname;
cout<<"enter age:"<<endl;
cin>>age;
cout<<"enter desease:"<<endl;
cin>>specialty;
cout<<"enter ssn:"<<endl;
cin>>ssn;
myRecord.setpPtr(myDoctor);
myDoctor.setFirstName(Fname);
myDoctor.setLastName(Lname);
myDoctor.setAge(age);
myDoctor.setSSN(ssn);
myDoctor.setSpecialty(specialty);
myDoctor.print();
theDoctor = myRecord.getpPtr;
system("pause");
return 0;
}
This specifically What was specifically asked for the HW: "A function to return the value of pPtr"
I have tryed making an overloaded operation....but i can't figure it out.