-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDoctor_Task1.cpp
106 lines (88 loc) · 3.14 KB
/
Doctor_Task1.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include "Doctor_Task1.h" // class implemented
using namespace std;
// File scope starts here
/////////////////////////////// PUBLIC ///////////////////////////////////////
//============================= LIFECYCLE ====================================
// Doctor Default+Overloaded Constructor
Doctor::Doctor(char* aName, int aAge, char aGender, char* aDesignation, int aSalary) : Person(aName, aAge, aGender, aDesignation), mSalary(aSalary) {
this->SetDoctor(aSalary);
this->SetDesignation(aDesignation);
}
// end Doctor constructor
// Doctor Copy Constructor
Doctor::Doctor(const Doctor& rhs) : Person(rhs.GetName(), rhs.GetAge(), rhs.GetGender(), rhs.mDesignation), mSalary(rhs.GetSalary()) {
this->SetDoctor(rhs.GetSalary());
this->SetDesignation(rhs.mDesignation);
}
// end Doctor constructor
// Doctor assignment operator.
Doctor& Doctor:: operator =(const Doctor& rhs) {
this->SetDoctor(rhs.GetName(), rhs.GetAge(), rhs.GetGender(), rhs.GetSalary());
this->SetDesignation(rhs.mDesignation);
return *this;
}
// end Doctor assignment operator.
//============================= OPERATIONS ===================================
// function that depicts checking (patients) by Doctor.
void Doctor::CheckUp() {
cout << this->GetName() << " is checking up." << endl;
}
// end function CheckUp
// function that depicts giving prescription by Doctor.
void Doctor::Prescribe() {
cout << this->GetName() << " is giving prescribtion." << endl;
}
// end function Prescribe
//============================= ACESS ===================================
// function that sets salary of Teacher
void Doctor::SetSalary(int aSalary) {
if (aSalary < 0)
cout << "Error: Salary cannot be nagative." << endl;
else
this->mSalary = aSalary;
}
// end function SetSalary
// Pure virtual function that sets designation in (Parent)Person class
void Doctor::SetDesignation(char* aDesignation) {
// freeing the previously alloted memory
if (this->mDesignation)
delete[] this->mDesignation;
// reserving new memory space for updated designation
if (aDesignation != NULL) {
int len = strlen(aDesignation) + 1;
this->mDesignation = new char[len];
strcpy_s(this->mDesignation, len, aDesignation);
}
else {
this->mDesignation = new char;
strcpy_s(this->mDesignation, 1, "\0");
}
}
// end function SetDesignation
// function that sets Doctor
void Doctor::SetDoctor(char* aName, int aAge, char aGender, int aSalary) {
this->SetPerson(aName, aAge, aGender);
this->SetDoctor(aSalary);
}
// end function SetDoctor
// overloaded function that sets the Doctor
void Doctor::SetDoctor(int aSalary) {
this->SetSalary(aSalary);
}
// end function SetDoctor
// overloaded function that sets the Doctor
void Doctor::SetDoctor(const Doctor& aDoctor) {
this->SetPerson(aDoctor.GetPerson());
this->SetDoctor(aDoctor.GetSalary());
}
// end function SetDoctor
// function that gets salary of Doctor
int Doctor::GetSalary()const {
return this->mSalary;
}
// end function GetSalary
// function that gets the Doctor
const Doctor& Doctor::GetDoctor()const {
return *this;
}
// end function GetDoctor