problem is almost solved

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Apr 2009
Posts: 27
Reputation: esesili is an unknown quantity at this point 
Solved Threads: 0
esesili esesili is offline Offline
Light Poster

problem is almost solved

 
0
  #1
Aug 14th, 2009
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.
  1. void Patient::input(istream &inpa)
  2. {
  3. cout << endl;
  4. cout << "Please enter information of patient(name--visit duration--Doctor)" << endl;
  5. inpa >> name >> visit_duration;
  6. }
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:
  1. #include <iostream>
  2. #include <string>
  3. #include <cstdlib>
  4. using namespace std;
  5. class Person
  6. {
  7. public:
  8. Person();
  9. Person(string name_of_person);
  10. Person(const Person &p);
  11. ~Person();
  12. string get_name()const;
  13. void set_name(string name_ofp);
  14. void input(istream &inp);
  15. void output(ostream &outp);
  16. protected:
  17. string name;
  18. };
  19. class Doctor: public Person
  20. {
  21. public:
  22. Doctor();
  23. Doctor(string name_of_doctor, double hour_fee_of_doc);
  24. Doctor(const Doctor &d);
  25. ~Doctor();
  26. double get_fee_of_doc() const;
  27. void set_fee_of_doc(double hour_fee);
  28. void input(istream &ind);
  29. void output(ostream &outd);
  30. protected:
  31. double doctor_hour_fee;
  32. };
  33. class Patient: public Person
  34. {
  35. public:
  36. Patient();
  37. Patient(string name_of_patient, double visit_duration_ofp, Doctor &doc);
  38. Patient(const Patient &p);
  39. ~Patient();
  40. double get_visit_duration() const;
  41. void set_visit_duration(double visit_duration_ofp);
  42. void setDoctor(Doctor &doc);
  43. virtual double billing() const;
  44. void input(istream &inpa);
  45. void output(ostream &outpa);
  46. protected:
  47. double visit_duration;
  48. Doctor doctor;
  49. };
  50. int main()
  51. {
  52. Person person1("first last");
  53. person1.output(cout);
  54. Person person2;
  55. person2.input(cin);
  56. person2.output(cout);
  57. Doctor doct1("doctorfirst doctorlast",100);
  58. doct1.output(cout);
  59. Patient patient1("firstpatient",0.1,doct1);
  60. patient1.output(cout);
  61. }
  62. Person::Person()
  63. {
  64. name = "No name yet";
  65. }
  66. Person::Person(string name_of_person)
  67. {
  68. name = name_of_person;
  69. }
  70. Person::Person(const Person &p)
  71. {
  72. name = p.name;
  73. }
  74. Person::~Person()
  75. {}
  76. string Person::get_name() const
  77. {
  78. return name;
  79. }
  80. void Person::set_name(string name_ofp)
  81. {
  82. name = name_ofp;
  83. }
  84. void Person::input(istream &inp)
  85. {
  86. cout << "Please enter information of person (name)" << endl;
  87. inp >> name;
  88. }
  89. void Person::output(ostream &outp)
  90. {
  91. outp << "Name: " << get_name() << endl;
  92. }
  93. Doctor::Doctor():Person(),doctor_hour_fee(0.0)
  94. {}
  95. Doctor::Doctor(string name_of_doctor, double hour_fee_of_doc):Person(name_of_doctor),doctor_hour_fee(hour_fee_of_doc)
  96. {}
  97. Doctor::Doctor(const Doctor &d):Person(d),doctor_hour_fee(d.doctor_hour_fee)
  98. {}
  99. Doctor::~Doctor()
  100. {}
  101. double Doctor::get_fee_of_doc()const
  102. {
  103. return doctor_hour_fee;
  104. }
  105. void Doctor::set_fee_of_doc(double hour_fee)
  106. {
  107. doctor_hour_fee = hour_fee;
  108. }
  109. void Doctor::input(istream &ind)
  110. {
  111. cout << "Please enter information of doctor " << endl << " (name--1 hour fee) " << endl;
  112. ind >> name >> doctor_hour_fee;
  113. }
  114. void Doctor::output(ostream &outd)
  115. {
  116. outd << "Name of Doctor: " << name << " 1 Hour fee of doctor: " << doctor_hour_fee;
  117. }
  118. Patient::Patient():Person(),visit_duration(0.0),doctor(Doctor())
  119. {}
  120. Patient::Patient(string name_of_patient, double visit_duration_ofp, Doctor &doc):Person(name_of_patient),visit_duration(visit_duration_ofp),doctor(doc)
  121. {}
  122. Patient::Patient(const Patient &p):Person(p),visit_duration(p.visit_duration),doctor(doctor)
  123. {}
  124. Patient::~Patient()
  125. {}
  126. double Patient::get_visit_duration() const
  127. {
  128. return visit_duration;
  129. }
  130. void Patient::set_visit_duration(double visit_duration_ofp)
  131. {
  132. visit_duration = visit_duration_ofp;
  133. }
  134. void Patient::setDoctor(Doctor &doc)
  135. {
  136. doctor = doc;
  137. }
  138. double Patient::billing() const
  139. {
  140. /*Doctor *docto_try;
  141. docto_try = new Doctor;*/
  142. return (doctor.get_fee_of_doc()*get_visit_duration());
  143. }
  144. void Patient::input(istream &inpa)
  145. {
  146. cout << endl;
  147. cout << "Please enter information of patient(name--visit duration--Doctor)" << endl;
  148. inpa >> name >> visit_duration >> doctor;
  149. }
  150. void Patient::output(ostream &outpa)
  151. {
  152. outpa << "Name of Patient: " << get_name() << " Visit Duration of Patient: " << get_visit_duration() << endl <<
  153. "Billing of the patient: " << billing() << endl;
  154. }
Attached Files
File Type: cpp begin_fin.cpp (3.7 KB, 0 views)
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 678
Reputation: Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold Sky Diploma is a splendid one to behold 
Solved Threads: 101
Sky Diploma's Avatar
Sky Diploma Sky Diploma is offline Offline
Practically a Master Poster

Re: problem is almost solved

 
1
  #2
Aug 14th, 2009
  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.
1. Please Mark Your Thread as Solved After Getting Your Answers.
2. Please Use CODE TAGS .
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC