943,605 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 338
  • C++ RSS
Aug 14th, 2009
0

problem is almost solved

Expand Post »
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.
C++ Syntax (Toggle Plain Text)
  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:
C++ Syntax (Toggle Plain Text)
  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, 7 views)
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
esesili is offline Offline
38 posts
since Apr 2009
Aug 14th, 2009
1

Re: problem is almost solved

C++ Syntax (Toggle Plain Text)
  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.
Reputation Points: 673
Solved Threads: 125
Practically a Posting Shark
Sky Diploma is offline Offline
818 posts
since Mar 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: 10049 - wsaeaddrnotavail
Next Thread in C++ Forum Timeline: c+ problem





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC