0

Hi all,

I have a simple question. I am working on it for a long time and I feel that I am almost done except for a small problem.
As seen below there is a member function of patient class. It takes variables name and visit_duration. In addition to these variables I want user to be able to enter doctor. This version works but user can not enter doctor.

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

When I define this function as below it gives me the error message " error C2679:"

My all code is shown as below and I attached it also. Can you tell me please how can I include doctor object to input member function?
I appreciate for helps

Code listing:

#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
class Person
{
public:
	Person();
	Person(string name_of_person);
	Person(const Person &p);
	~Person();
	string get_name()const;	
	void set_name(string name_ofp);	
	void input(istream &inp);
	void output(ostream &outp);
protected:
	string name;	
};
class Doctor: public Person
{
public:
	Doctor();
	Doctor(string name_of_doctor, double hour_fee_of_doc);
	Doctor(const Doctor &d);
	~Doctor();
	double get_fee_of_doc() const;	
	void set_fee_of_doc(double hour_fee);	
	void input(istream &ind);
	void output(ostream &outd);
protected:
	double doctor_hour_fee;	
};
class Patient: public Person
{
public:
	Patient();
	Patient(string name_of_patient, double visit_duration_ofp, Doctor &doc);
	Patient(const Patient &p);
	~Patient();
	double get_visit_duration() const;	
	void set_visit_duration(double visit_duration_ofp);
	void setDoctor(Doctor &doc);
	virtual double billing() const;
	void input(istream &inpa);
	void output(ostream &outpa);	
protected:
	double visit_duration;
	Doctor doctor;
};
int main()
{
	Person person1("first last");
	person1.output(cout);
	Person person2;
	person2.input(cin);
	person2.output(cout);
	Doctor doct1("doctorfirst doctorlast",100);
	doct1.output(cout);
	Patient patient1("firstpatient",0.1,doct1);
	patient1.output(cout);
}
Person::Person()
{
	name  = "No name yet";	
}
Person::Person(string name_of_person)
{
	name = name_of_person;	
}
Person::Person(const Person &p)
{
	name = p.name;	
}
Person::~Person()
{}
string Person::get_name() const
{
	return name;
}
void Person::set_name(string name_ofp)
{
	name = name_ofp;
}
void Person::input(istream &inp)
{
	cout << "Please enter information of person (name)" << endl;
	inp >> name;
}
void Person::output(ostream &outp)
{
	outp << "Name:  " << get_name() << endl;
}
Doctor::Doctor():Person(),doctor_hour_fee(0.0)
{}
Doctor::Doctor(string name_of_doctor, double hour_fee_of_doc):Person(name_of_doctor),doctor_hour_fee(hour_fee_of_doc)
{}
Doctor::Doctor(const Doctor &d):Person(d),doctor_hour_fee(d.doctor_hour_fee)
{}
Doctor::~Doctor()
{}
double Doctor::get_fee_of_doc()const
{
	return doctor_hour_fee;
}
void Doctor::set_fee_of_doc(double hour_fee)
{
	doctor_hour_fee = hour_fee;
}
void Doctor::input(istream &ind)
{
	cout << "Please enter information of doctor  " << endl << " (name--1 hour fee) " << endl;
	ind >> name >> doctor_hour_fee;
}
void Doctor::output(ostream &outd)
{
	outd << "Name of Doctor: " << name << "  1 Hour fee of doctor: " << doctor_hour_fee; 
}
Patient::Patient():Person(),visit_duration(0.0),doctor(Doctor())
{}
Patient::Patient(string name_of_patient, double visit_duration_ofp, Doctor &doc):Person(name_of_patient),visit_duration(visit_duration_ofp),doctor(doc)
{}
Patient::Patient(const Patient &p):Person(p),visit_duration(p.visit_duration),doctor(doctor)
{}
Patient::~Patient()
{}
double Patient::get_visit_duration() const
{
	return visit_duration;
}
void Patient::set_visit_duration(double visit_duration_ofp)
{
	visit_duration = visit_duration_ofp;
}
void Patient::setDoctor(Doctor &doc)
{
	doctor = doc;
}
double Patient::billing() const
{	
	/*Doctor *docto_try;
	docto_try = new Doctor;*/	
	return (doctor.get_fee_of_doc()*get_visit_duration());
}
void Patient::input(istream &inpa)
{
	cout << endl;
	cout << "Please enter information of patient(name--visit duration--Doctor)" << endl;
	inpa >> name >> visit_duration >> doctor;
}
void Patient::output(ostream &outpa)
{
	outpa << "Name of Patient:  " << get_name() << "  Visit Duration of Patient:  " <<  get_visit_duration() << endl <<
		"Billing of the patient:  " << billing() << endl;
}
Attachments
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
class Person
{
public:
	Person();
	Person(string name_of_person);
	Person(const Person &p);
	~Person();
	string get_name()const;	
	void set_name(string name_ofp);	
	void input(istream &inp);
	void output(ostream &outp);
protected:
	string name;	
};
class Doctor: public Person
{
public:
	Doctor();
	Doctor(string name_of_doctor, double hour_fee_of_doc);
	Doctor(const Doctor &d);
	~Doctor();
	double get_fee_of_doc() const;	
	void set_fee_of_doc(double hour_fee);	
	void input(istream &ind);
	void output(ostream &outd);
protected:
	double doctor_hour_fee;	
};
class Patient: public Person
{
public:
	Patient();
	Patient(string name_of_patient, double visit_duration_ofp, Doctor &doc);
	Patient(const Patient &p);
	~Patient();
	double get_visit_duration() const;	
	void set_visit_duration(double visit_duration_ofp);
	void setDoctor(Doctor &doc);
	virtual double billing() const;
	void input(istream &inpa);
	void output(ostream &outpa);	
protected:
	double visit_duration;
	Doctor doctor;
};
int main()
{
	Person person1("first last");
	person1.output(cout);
	Person person2;
	person2.input(cin);
	person2.output(cout);
	Doctor doct1("doctorfirst doctorlast",100);
	doct1.output(cout);
	Patient patient1("firstpatient",0.1,doct1);
	patient1.output(cout);
}
Person::Person()
{
	name  = "No name yet";	
}
Person::Person(string name_of_person)
{
	name = name_of_person;	
}
Person::Person(const Person &p)
{
	name = p.name;	
}
Person::~Person()
{}
string Person::get_name() const
{
	return name;
}
void Person::set_name(string name_ofp)
{
	name = name_ofp;
}
void Person::input(istream &inp)
{
	cout << "Please enter information of person (name)" << endl;
	inp >> name;
}
void Person::output(ostream &outp)
{
	outp << "Name:  " << get_name() << endl;
}
Doctor::Doctor():Person(),doctor_hour_fee(0.0)
{}
Doctor::Doctor(string name_of_doctor, double hour_fee_of_doc):Person(name_of_doctor),doctor_hour_fee(hour_fee_of_doc)
{}
Doctor::Doctor(const Doctor &d):Person(d),doctor_hour_fee(d.doctor_hour_fee)
{}
Doctor::~Doctor()
{}
double Doctor::get_fee_of_doc()const
{
	return doctor_hour_fee;
}
void Doctor::set_fee_of_doc(double hour_fee)
{
	doctor_hour_fee = hour_fee;
}
void Doctor::input(istream &ind)
{
	cout << "Please enter information of doctor  " << endl << " (name--1 hour fee) " << endl;
	ind >> name >> doctor_hour_fee;
}
void Doctor::output(ostream &outd)
{
	outd << "Name of Doctor: " << name << "  1 Hour fee of doctor: " << doctor_hour_fee; 
}
Patient::Patient():Person(),visit_duration(0.0),doctor(Doctor())
{}
Patient::Patient(string name_of_patient, double visit_duration_ofp, Doctor &doc):Person(name_of_patient),visit_duration(visit_duration_ofp),doctor(doc)
{}
Patient::Patient(const Patient &p):Person(p),visit_duration(p.visit_duration),doctor(doctor)
{}
Patient::~Patient()
{}
double Patient::get_visit_duration() const
{
	return visit_duration;
}
void Patient::set_visit_duration(double visit_duration_ofp)
{
	visit_duration = visit_duration_ofp;
}
void Patient::setDoctor(Doctor &doc)
{
	doctor = doc;
}
double Patient::billing() const
{	
	/*Doctor *docto_try;
	docto_try = new Doctor;*/	
	return (doctor.get_fee_of_doc()*get_visit_duration());
}
void Patient::input(istream &inpa)
{
	cout << endl;
	cout << "Please enter information of patient(name--visit duration--Doctor)" << endl;
	inpa >> name >> visit_duration >> doctor;
}
void Patient::output(ostream &outpa)
{
	outpa << "Name of Patient:  " << get_name() << "  Visit Duration of Patient:  " <<  get_visit_duration() << endl <<
		"Billing of the patient:  " << billing() << endl;
}
2
Contributors
1
Reply
3
Views
7 Years
Discussion Span
Last Post by Sky Diploma
1
inpa >>(name)>> (visit_duration) >> doctor;

your doctor class does not have a >> operator overloaded, hence the compiler places that error.

You can either define the operator, or change the value of doctor through temporary objects and the doctor classes functions.

Votes + Comments
you are great
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.