-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmployee.cpp
More file actions
89 lines (84 loc) · 2.72 KB
/
Employee.cpp
File metadata and controls
89 lines (84 loc) · 2.72 KB
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
#include<iostream>
#include<iomanip>
#include "Employee.h"
using namespace std;
unsigned int Employee::totalEmployee = 0;
Employee::Employee(unsigned int _id, double _basicsalary, double _price, Employee* _bandemployee) {
id = _id;
bs = _basicsalary;
price = _price;
band = _bandemployee;
totalEmployee++;
}
double Employee::getPrice() {
return price;
}
unsigned int Employee::getID() const {
return id;
}
void Employee::setBandEmployee(Employee* employee) {
band = employee;
}
Employee& Employee::operator+=(int salemoney) {
if (salemoney <= 5000 && salemoney >= 0) {
price += 0.02 * salemoney;
return *this;
}
price += 0.02 * 5000;
salemoney -= 5000;
if (salemoney <= 5000) {
price += salemoney * 0.04;
return *this;
}
price += 5000 * 0.04;
salemoney -= 5000;
price += salemoney * 0.08;
return *this;
}
double Employee::computeSalary() {
if (!band)
return price + bs;
return price + bs + 0.1 * band->price;
}
void Employee::showStatus() {
if (!band) {
cout << "ID:" << id << ", basicSalary:" << fixed << setprecision(1) << bs << ", price:" << price << ", bandID:" << -1 << endl;
return;
}
cout << "ID:" << id << ", basicSalary:" << fixed << setprecision(1) << bs << ", price:" << price << ", bandID:" << band->id << endl;
}
SuperEmployee::SuperEmployee(unsigned int id, double basicsalary, double price,Employee* bandemployee, int level):\
Employee(id, basicsalary, price, bandemployee) {
this->level = level;
}
double SuperEmployee::computeSalary() {
if (!band) {
return bs + price + price * level * 0.1;
}
return bs + price + 0.1 * band->price + price * level * 0.1;
}
void SuperEmployee::showStatus() {
std::cout << setiosflags(ios::fixed) << setprecision(1);
if (!band) {
cout << "ID:" << id << ", basicSalary:"<< bs << ", price:" << price << ", bandID:" << -1 << ", level:" << level << endl;
return;
}
cout << "ID:" << id << ", basicSalary:" << bs << ", price:" << price << ", bandID:" << band->id << ", level:" << level << endl;
}
Manager::Manager(int id, double basicsalary, double price, Employee* bandemployee, int workyear):\
Employee(id, basicsalary, price, bandemployee) {
this->workyear = workyear;
}
double Manager::computeSalary() {
if(!band)
return bs + price + workyear*300;
return bs + price + 0.1 * band->price + workyear * 300;
}
void Manager::showStatus() {
std::cout << setiosflags(ios::fixed) << setprecision(1);
if (!band) {
cout << "ID:" << id << ", basicSalary:" << bs << ", price:" << price << ", bandID:" << -1 << ", workYear:" << workyear << endl;
return;
}
cout << "ID:" << id << ", basicSalary:" << bs << ", price:" << price << ", bandID:" << band->id << ", workYear:" << workyear << endl;
}