Hi everyone,
I have a problem about inheritance and I can not solve it since Monday. I have two classes (Student_Patient and Emp_Patient) inherited from Patient class. Patient class and Doctor classes are inherited from Person class. The Doctor class has a member functiondouble get_fee_of_doc() const; which returns a double value and Patient class has virtual double billing() const; member function. I am trying to use the double value returned from double get_fee_of_doc() const; in virtual double billing() const; . I tried to do it by two different but I could not do it. Can someone please tell me (by providing an example) what is the possible and best way of using the double value which is returned from Doctor in Patient class. Required codes are below.
By the way, sorry for convenience because it is a very long post.
I appreciate for helps.

Declaration of Doctor and Patient:

class Patient: public Person
{
public:
	Patient();
	Patient(string name_of_patient, int age_of_patient, string address_of_pat, double visit_duration_ofp, string ssn_of_patient);
	Patient(const Patient &p);
	~Patient();
	double get_visit_duration() const;
	string get_ssn() const;	
	void set_ssn_(string ssn_ofp);
	void set_visit_duration(double visit_duration_ofp);
	virtual double billing() const;
	void input(istream &inpa);
	void output(ostream &outpa);
	
protected:
	double visit_duration;
	string ssn;
	//double set_doc_fee;
};
class Doctor: public Person
{
public:
	Doctor();
	Doctor(string name_of_doctor,int age_of_doctor, string add_of_doctor, double hour_fee_of_doc, long reg_number, string specialty);
	Doctor(const Doctor &d);
	~Doctor();
	double get_fee_of_doc() const;
	long get_regnum_of_doc() const;
	string get_spec_of_doc() const;
	void set_spec_of_doc(string specialty);
	void set_fee_of_doc(double hour_fee);
	void set_regnum_of_doc(long reg_num);
	void input(istream &ind);
	void output(ostream &outd);
protected:
	double doctor_hour_fee;
	long doctor_reg_num;
	string spacialty;
};

Definition of Doctor and Patient Classes:

Doctor::Doctor():Person(),doctor_hour_fee(0.0), doctor_reg_num(0), spacialty("0")
{
}
Doctor::Doctor(string name_of_doctor,int age_of_doctor, string add_of_doctor, double hour_fee_of_doc, long reg_number, string specialty):Person(name_of_doctor,age_of_doctor,add_of_doctor),doctor_hour_fee(hour_fee_of_doc),doctor_reg_num(reg_number),spacialty(specialty)
{
}
Doctor::Doctor(const Doctor &d)
{
	name = d.name;
	age = d.age;
	address = d.address;
	doctor_hour_fee = d.doctor_hour_fee;
	doctor_reg_num = d.doctor_reg_num;
	spacialty = d.spacialty;
}
Doctor::~Doctor()
{
}
double Doctor::get_fee_of_doc()const
{
	return doctor_hour_fee;
}
long Doctor::get_regnum_of_doc() const
{
	return doctor_reg_num;
}

string Doctor::get_spec_of_doc() const
{
	return spacialty;
}

void Doctor::set_spec_of_doc(string specialty)
{
	spacialty = specialty;
}
void Doctor::set_fee_of_doc(double hour_fee)
{
	doctor_hour_fee = hour_fee;
}
void Doctor::set_regnum_of_doc(long reg_num)
{
	doctor_reg_num = reg_num;
}
void Doctor::input(istream &ind)
{
	cout << "Please enter information of doctor (name--address--age--1 hour fee--registraiton number--specialty) " << endl;
	ind >> name >> address >> age >> doctor_hour_fee >> doctor_reg_num >> spacialty;
}
void Doctor::output(ostream &outd)
{
	outd << "Name: " << name << "Address:  " << address << "Age: not allowed to see " << " 1 Hour fee of doctor: " <<
		doctor_hour_fee << "Registratioon number of doctor: " << doctor_reg_num << "Specialty of doctor:  " << spacialty; 
}

Patient::Patient():Person(),visit_duration(0.0),ssn("0")
{

}
Patient::Patient(string name_of_patient, int age_of_patient, string address_of_pat, double visit_duration_ofp, string ssn_of_patient):Person(name_of_patient,age_of_patient,address_of_pat),visit_duration(visit_duration_ofp),ssn(ssn_of_patient)
{
}
Patient::Patient(const Patient &p)
{
	name = p.name;
	age = p.age;
	address = p.address;
	visit_duration = p.visit_duration;
	ssn = p.ssn;
	//set_doc_fee = p.set_doc_fee;
}
Patient::~Patient()
{
}
double Patient::get_visit_duration() const
{
	return visit_duration;
}
string Patient::get_ssn() const
{
	return ssn;
}
void Patient::set_ssn_(string ssn_ofp)
{
	ssn = ssn_ofp;
}

void Patient::set_visit_duration(double visit_duration_ofp)
{
	visit_duration = visit_duration_ofp;
}

//THIS IS THE FUNCTION WHERE I WANT TO USE DOUBLE VALUE RETURNED FROM DOCTOR CLASS
//double Patient::billing() const
//{	
//	return (get_fee_odoc()*get_visit_duration());
//}

void Patient::input(istream &inpa)
{
	cout << "Please enter information of patient(name--address--age--visit duration--ssn)" << endl;
	inpa >> name >> address >> age >> visit_duration >> ssn ;
}

void Patient::output(ostream &outpa)
{
	outpa << "Name:  " << get_name() << "Address:  " << get_address()
		<< "Age:  " << get_age() << "Visit Duration:  " << get_visit_duration() << "SSN:  " << get_ssn() << endl;
}

my advice would be to add a member variable to the patient class of type doctor that you assign when you get a doctor. this way you could call the member doctors get fee function.

class Patient
{
public:
// ...
void SetDoctor(Doctor & doc) { doctor = doc; }
// ...
protected:
// ...
Doctor doctor;
};

double Patient::Billing() const
{
return doctor.get_fee_of_doc();
}

Hi NathanOliver,

Thank you very much for your advice. It makes sense. I tried it but I got more that 30 syntax errors. I checked them but does not make sense.
Do you have any idea?
Thanks,

was this the first compile of the program? if it was then you could of just had the errors waiting for you. if not where are the syntax errors? are the related to the doctor or the patient class? if they are can you list them for me

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.