-
Notifications
You must be signed in to change notification settings - Fork 2
/
doctor.cpp
80 lines (61 loc) · 1.52 KB
/
doctor.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Doctor;
class Patient{
private:
string m_name;
vector<Doctor*> m_doctors;
void add_doctor(Doctor* doc);
public:
Patient(const string& name):m_name{name}{};
string get_name(void)const{ return m_name;}
friend ostream& operator<<(ostream& out, const Patient& pat);
friend Doctor;
};
class Doctor{
private:
string m_name;
vector<Patient*> m_patients;
public:
Doctor(const string& name):m_name{name}{};
void add_patient(Patient* pat){
m_patients.push_back(pat);
pat->add_doctor(this);
}
string get_name(void)const{ return m_name;}
friend ostream& operator<<(ostream& out, const Doctor& doc){
out << "Doctor " << doc.get_name() << " is seeing patients: " << endl;
for(int i=0; i<doc.m_patients.size(); ++i){
out << doc.m_patients[i]->get_name() << endl;
}
return out;
}
};
void Patient::add_doctor(Doctor* doc){
m_doctors.push_back(doc);
}
ostream& operator<<(ostream& out, const Patient& pat){
out << "Patient " << pat.get_name() << " is seeing doctors: " << endl;
for(int i=0; i<pat.m_doctors.size(); ++i){
out << pat.m_doctors[i]->get_name() << endl;
}
return out;
}
int main(int argc, char const *argv[]){
Doctor* d1 = new Doctor("Sam");
Doctor* d2 = new Doctor("Binny");
Patient* p1 = new Patient("Jinny");
Patient* p2 = new Patient("Honey");
d1->add_patient(p1);
d1->add_patient(p2);
d2->add_patient(p1);
cout << *d1 << endl;
cout << *p1 << endl;
delete d1;
delete d2;
delete p1;
delete p2;
return 0;
}