-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPartTimeEmployee.cpp
88 lines (75 loc) · 2.29 KB
/
PartTimeEmployee.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
#include "PartTimeEmployee.h"
#include "input_validation.h"
PartTimeEmployee::PartTimeEmployee()
{
set_partime_employee_details();
}
PartTimeEmployee::PartTimeEmployee(const PartTimeEmployee &other) : Employee(other), hourlyRate(other.hourlyRate), hoursWorked(other.hoursWorked)
{
}
PartTimeEmployee::~PartTimeEmployee()
{
}
int PartTimeEmployee::calculateSalary() const
{
return static_cast<int>(hourlyRate * hoursWorked);
}
void PartTimeEmployee::displayInfo() const
{
Employee::displayInfo();
cout << "Hourly Rate: " << hourlyRate << endl;
cout << "Hours Worked: " << hoursWorked << endl;
cout << "Salary: " << calculateSalary() << " $" << endl;
}
void PartTimeEmployee::setHourlyRate()
{
while (true)
{
validate_input_double(hourlyRate, "Enter hourly rate (max range 80 $): ", "Invalid hourly rate, please try again...");
if (hourlyRate >= 0 && hourlyRate <= 80)
break;
}
}
void PartTimeEmployee::setHoursWorked()
{
while (true)
{
validate_input_int(hoursWorked, "Enter the hours worked (max 169 hours): ", "Invalid working hours, please try again...");
if (hoursWorked > 0 && hoursWorked < 160)
break;
}
}
void PartTimeEmployee::set_partime_employee_details()
{
cout << "Setting Part-Time Employee Details: " << endl;
this->setName();
this->setDOB();
this->setPhoneNumber();
this->setAddress();
this->setJobRole();
this->setHourlyRate();
this->setHoursWorked();
this->setAge();
}
double PartTimeEmployee::getHourlyRate() const
{
return hourlyRate;
}
int PartTimeEmployee::getHoursWorked() const
{
return hoursWorked;
}
ostream &operator<<(ostream &out, const PartTimeEmployee &ptEmp)
{
out << "Name: " << ptEmp.name << endl;
out << "ID: " << ptEmp.id << endl;
out << "Job Role: " << ptEmp.jobRole << endl;
out << "Date of Birth: " << ptEmp.dob.getDay() << "/" << ptEmp.dob.getMonth() << "/" << ptEmp.dob.getYear() << endl;
out << "Phone Number: " << ptEmp.phoneNumber << endl;
out << "Address: " << ptEmp.address << endl;
out << "Age: " << ptEmp.age << endl;
out << "Hourly Rate: " << ptEmp.hourlyRate << endl;
out << "Hours Worked: " << ptEmp.hoursWorked << endl;
out << "Salary: " << ptEmp.calculateSalary() << " $" << endl;
return out;
}