-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathCommEmp.cpp
105 lines (84 loc) · 3.45 KB
/
CommEmp.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
#include "CommEmp.h" // class implemented
using namespace std;
// File scope starts here
/////////////////////////////// PUBLIC ///////////////////////////////////////
//============================= LIFECYCLE ====================================
// CommEmp Default + Overloaded Constructor
CommEmp::CommEmp(const string& aName, const string& aNIC, const Date& aDateOfBirth, const Date& aDateOfHire, const Address& aHomeAddress, double aTaxRate, double aBasicSalary, int aSales, double aCommRate) : Employee(aName, aNIC, aDateOfBirth, aDateOfHire, aHomeAddress, aTaxRate, aBasicSalary), mSales(aSales), mCommRate(aCommRate) {
// base class initilzation using member initlizer list
this->SetCommEmp(aSales, aCommRate);
}
// end CommEmp constructor
//============================= OPERATIONS ===================================
// Overriding function that prints all the details of the Salaried employee.
void CommEmp::PrintEmployee()const {
Employee::PrintEmployee();
cout << "Net Salary: " << this->CalcSalary() << endl;
}
// end function PrintEmployee
// Overriding function that calculates net salary.
double CommEmp::CalcSalary() const {
double basicSalary, taxRate, grossSalary, tax, netSalary;
basicSalary = this->GetBasicSalary();
taxRate = this->GetTaxRate();
grossSalary = basicSalary + (this->GetSales()*this->GetCommRate());
tax = grossSalary * taxRate;
netSalary = grossSalary - tax;
return netSalary;
}
// end function CalcSalary
//============================= ACESS ===================================
// function that sets sales of Commissioned Employee
void CommEmp::SetSales(int aSales) {
if (aSales < 0)
cout << "ERROR: Sales cannot be nagative." << endl;
else
this->mSales = aSales;
}
// end function SetSales
// function that sets commission Rate of Commissioned Employee
void CommEmp::SetCommRate(double aCommRate) {
if (aCommRate < 0.0)
cout << "ERROR: Commission rate cannot be nagative." << endl;
else
this->mCommRate = aCommRate;
}
// end function SetCommRate
// function that sets the CommEmp
void CommEmp::SetCommEmp(const string& aName, const string& aNIC, const Address& aHomeAddress, double aTaxRate, double aBasicSalary, int aSales, double aCommRate) {
this->SetEmployee(aName, aNIC, aHomeAddress, aTaxRate, aBasicSalary);
this->SetCommEmp(aSales, aCommRate);
}
// end function SetCommEmp
// overloaded function that sets the CommEmp
void CommEmp::SetCommEmp(const Employee& aEmployee, int aSales, double aCommRate) {
this->SetEmployee(aEmployee.GetEmployee());
this->SetCommEmp(aSales, aCommRate);
}
// end function SetCommEmp
// overloaded function that sets the CommEmp
void CommEmp::SetCommEmp(int aSales, double aCommRate) {
this->SetSales(aSales);
this->SetCommRate(aCommRate);
}
// end function SetCommEmp
// overloaded function that sets the CommEmp
void CommEmp::SetCommEmp(const CommEmp& aCommEmp) {
this->SetCommEmp(aCommEmp.GetEmployee(), aCommEmp.GetSales(), aCommEmp.GetCommRate());
}
// end function SetCommEmp
// function that gets sales of Commissioned Employee
int CommEmp::GetSales()const {
return this->mSales;
}
// end function GetSales
// function that gets commission Rate of Commissioned Employee
double CommEmp::GetCommRate()const {
return this->mCommRate;
}
// end function GetCommRate
// function that gets the CommEmp
const CommEmp& CommEmp::GetCommEmp()const {
return *this;
}
// end function GetCommEmp