| | |
problem is almost solved
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Apr 2009
Posts: 27
Reputation:
Solved Threads: 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.
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:
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.
C++ Syntax (Toggle Plain Text)
void Patient::input(istream &inpa) { cout << endl; cout << "Please enter information of patient(name--visit duration--Doctor)" << endl; inpa >> name >> visit_duration; }
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:
C++ Syntax (Toggle Plain Text)
#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; }
C++ Syntax (Toggle Plain Text)
inpa >>(name)>> (visit_duration) >> doctor;
>> 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.
![]() |
Similar Threads
- How to Insert/Edit data from TAG SELECT HTML Form to MySQL Database? (PHP)
- Dell Dimension 4500 Shuts Off If I move The Case!? (Cases, Fans and Power Supplies)
- MATRIX algebra pracice problem solved (C++)
- How to download a file (Java)
- Windows XP Hangs on Startup (Windows NT / 2000 / XP)
- while loop (C)
- Standby mode in 98 SE (Windows 95 / 98 / Me)
- No cursor in hotmail for reply or compose...any body else have this problem? (Web Browsers)
- Alex Cavnar - rectangle problem not solved (C++)
- Windows XP problem on new computer (Windows NT / 2000 / XP)
Other Threads in the C++ Forum
- Previous Thread: 10049 - wsaeaddrnotavail
- Next Thread: c+ problem
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamic dynamiccharacterarray encryption error file format forms fstream function functions game givemetehcodez graph gui homeworkhelp iamthwee ifstream input int java lib library linkedlist linker list loop looping loops map math matrix memory microsoft newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template templates test text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets





