-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNVHD.cpp
213 lines (209 loc) · 5.14 KB
/
NVHD.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#include "NVHD.h"
NVHD::NVHD(string ma_nv, string ten_nv, Date ngay_nhan_viec, bool gioi_tinh, double luong, double luong_ngay)
: NhanVien(ma_nv, ten_nv, ngay_nhan_viec, gioi_tinh, luong), luong_ngay(luong_ngay)
{
this->luong = 0;
}
NVHD::~NVHD()
{
}
double NVHD::tinhLuong()
{
int ngay_cuoi_thang = this->ngay_nhan_viec.getDaysOfMonth();
int ngay_hien_tai = this->ngay_nhan_viec.getDateNow();
int thu = this->ngay_nhan_viec.getDayNow();
if (thu == 1)
thu = 8;
int thu_dang_xet = thu;
int count = 0;
for (int i = ngay_hien_tai; i <= ngay_cuoi_thang; i++)
{
if (thu_dang_xet <= 6 && thu_dang_xet >= 2)
{
count++;
this->luong += this->luong_ngay;
thu_dang_xet++;
}
else
{
thu_dang_xet++;
if (thu_dang_xet == 9)
thu_dang_xet = 2;
}
}
thu_dang_xet = thu - 1;
if (thu_dang_xet == 1)
thu_dang_xet = 8;
for (int i = ngay_hien_tai - 1; i >= 1; i--)
{
if (thu_dang_xet <= 6 && thu_dang_xet >= 2)
{
count++;
this->luong += this->luong_ngay;
thu_dang_xet--;
}
else
{
thu_dang_xet--;
if (thu_dang_xet == 0)
{
thu_dang_xet = 7;
}
}
}
return this->luong;
}
void NVHD::update()
{
cout << "Ten nv:";
cin.ignore();
getline(cin, this->ten_nv);
cout << "Ngay nhan viec:" << endl;
bool valid = false;
do
{
try
{
cin >> this->ngay_nhan_viec;
valid = true;
}
catch (string err)
{
if (err == "year ")
{
cout << "Nam khong hop le !" << endl;
}
if (err == "month")
{
cout << " Khong co thang thich hop !" << endl;
}
if (err == "month2")
{
cout << " Khong co ngay thich hop trong thang 2 !" << endl;
}
if (err == "date")
{
cout << " Khong co ngay thich hop trong thang nay !" << endl;
}
}
} while (valid == false);
bool valid_sex = false;
do
{
cout << "Gioi tinh:";
try
{
if (!(cin >> this->gioi_tinh))
{
valid_sex = true;
throw true;
}
else
valid_sex = true;
}
catch (bool e)
{
cin.clear();
cout << "Gioi tinh nam : 0, gioi tinh nu : 1 " << endl
<< "Xin moi nhap lai!" << endl;
}
} while (!valid_sex);
cout << "Luong ngay:";
cin >> this->luong_ngay;
this->tinhLuong();
}
istream &operator>>(istream &i, NVHD &nv)
{
cout << "Ma nv:";
i >> nv.ma_nv;
cout << "Ten nv:";
i.ignore();
getline(i, nv.ten_nv);
cout << "Ngay nhan viec:" << endl;
bool valid = false;
do
{
try
{
i >> nv.ngay_nhan_viec;
valid = true;
}
catch (string err)
{
if (err == "year ")
{
cout << "Nam khong hop le !" << endl;
}
if (err == "month")
{
cout << " Khong co thang thich hop !" << endl;
}
if (err == "month2")
{
cout << " Khong co ngay thich hop trong thang 2 !" << endl;
}
if (err == "date")
{
cout << " Khong co ngay thich hop trong thang nay !" << endl;
}
}
} while (valid == false);
bool valid_sex;
do
{
cout << "Gioi tinh:";
try
{
if (!(cin >> nv.gioi_tinh))
{
valid_sex = false;
throw true;
}
else
valid_sex = true;
}
catch (bool e)
{
cin.clear();
cout << "Gioi tinh nam : 0, gioi tinh nu : 1 " << endl
<< "Xin moi nhap lai!" << endl;
}
} while (!valid_sex);
cout << "Luong ngay:";
cin.ignore();
i >> nv.luong_ngay;
nv.tinhLuong();
return i;
};
ostream &operator<<(ostream &o, const NVHD &nv)
{
o << setw(6) << "Ma nv" << setw(20) << " Ten NV " << setw(17) << "Ngay Nhan Viec " << setw(10) << "Gioi tinh" << setw(17) << "Luong" << setw(15) << "Luong ngay" << endl;
o << setw(6) << nv.ma_nv << setw(19) << nv.ten_nv << setw(10) << nv.ngay_nhan_viec << setw(11);
if (nv.gioi_tinh == 1)
cout << "nu";
else
cout << "nam ";
cout << setw(17) << long(nv.luong) << setw(15) << nv.luong_ngay << endl;
return o;
};
ostream &operator<<(ostream &o, const NVHD *nv)
{
o << setw(6) << "Ma nv" << setw(20) << " Ten NV " << setw(17) << "Ngay Nhan Viec " << setw(10) << "Gioi tinh" << setw(17) << "Luong" << setw(15) << "Luong ngay" << endl;
o << setw(6) << nv->ma_nv << setw(19) << nv->ten_nv << setw(10) << nv->ngay_nhan_viec << setw(11);
if (nv->gioi_tinh == 1)
cout << "nu";
else
cout << "nam ";
cout << setw(17) << long(nv->luong) << setw(15) << nv->luong_ngay << endl;
return o;
};
void NVHD::show()
{
cout << setw(6) << "Ma nv" << setw(20) << " Ten NV " << setw(17) << "Ngay Nhan Viec " << setw(10) << "Gioi tinh" << setw(17) << "Luong" << setw(15) << "Luong ngay" << endl;
cout << setw(6) << this->ma_nv << setw(19) << this->ten_nv << setw(10) << this->ngay_nhan_viec << setw(11);
if (this->gioi_tinh == 1)
cout << "nu";
else
cout << "nam ";
cout << setw(17) << long(this->luong) << setw(15) << this->luong_ngay << endl;
}