-
Notifications
You must be signed in to change notification settings - Fork 0
/
Employee.h
226 lines (190 loc) · 5.11 KB
/
Employee.h
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
214
215
216
217
218
219
220
221
222
223
224
225
#define Employee_header
#include"person.h"
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
class Employee:public person{
std::string position;
std::string address;
int salary;
int phoneNumber;
public:
Employee(std::string nameX,int IDX,std::string dateX,std::string positionX,int salaryX,int phoneX,std::string AddressX):person(name,ID,d){
position=positionX;
salary=salaryX;
phoneNumber=phoneX;
address=AddressX;
}
Employee(){
ID=0;
name="";
d="";
position="";
salary=0;
phoneNumber=0;
address="";
}
Employee(const Employee& E){
ID=E.ID;
name=E.name;
position=E.position;
salary=E.salary;
phoneNumber=E.phoneNumber;
d=E.d;
address=E.address;
}
~Employee(){}
friend Employee* ExtractEmployees(Employee* Employees);
friend void UpdateEmployeesFile(Employee* Employees, int& Total);
friend void PrintArrayContent(Employee*Employees,int Total);
//ADD employees
Employee* AddEmployee(Employee* Employees,int& Total){
bool flag=SearchEmployeeID(Employees,Total);
if(flag==false){
Employee* newEmployees= new Employee[Total+1];
for(int i=0;i<Total;i++){
newEmployees[i]=Employees[i];
}
newEmployees[Total].ID=ID;
newEmployees[Total].name=name;
newEmployees[Total].d=d;
newEmployees[Total].position=position;
newEmployees[Total].salary=salary;
newEmployees[Total].phoneNumber=salary;
newEmployees[Total].address=address;
delete[] Employees;
Employees=newEmployees;
Total++;
std::cout<<"Employee is successfully added to Database"<<endl;
}
else{
std::cout<<"ERROR ! An employee is already registrated! with this ID"<<endl;
}
return Employees ;
}
//Modify employee data
bool SearchEmployeeID(Employee* employees,int Total){
int i;
bool flag=false;
for (i=0;i<=Total;i++){
if(employees[i].ID == ID){
flag=true;
break;
}
}
return flag;
}
//Data management
void UpdatePosition(Employee* Employees,int Total, std::string newPosition){
int i;
for(i=0;i<Total;i++){
if (SearchEmployeeID(Employees,Total)){
if(Employees[i].ID=ID){
Employees[i].position=newPosition;
std::cout<<"Congratulations on the new position ! Database updated"<<endl;
break;
}
}
}
if(!SearchEmployeeID(Employees,Total)){
std::cout<<"Employee Identification not found in the system"<<endl;
}
}
void UpdateSalary(Employee* Employees, int Total, int newSalary){
int i;
bool flag=SearchEmployeeID(Employees,Total);
for(i=0;i<Total;i++){
if (flag){
if(Employees[i].ID=ID){
Employees[i].salary=newSalary;
std::cout<<"Salary updated in the system"<<endl;
break;
}
}
}
if(!flag){
std::cout<<"Employee Identification not found in the system"<<endl;
}
}
void UpdatePhone(Employee* Employees,int Total,int newPhone){
bool flag=SearchEmployeeID(Employees,Total);
int i;
for(i=0;i<Total;i++){
if (flag){
if(Employees[i].ID=ID){
Employees[i].salary=newPhone;
std::cout<<"Phone number of employee "<<Employees[i].ID<<"has been updated"<<endl;
break;
}
}
}
if(!flag){
std::cout<<"Employee Identification not found in the system"<<endl;
}
}
void UpdateAddress(Employee* Employees,int Total,std::string newAddress){
bool flag=SearchEmployeeID(Employees,Total);
int i;
for(i=0;i<Total;i++){
if (flag){
if(Employees[i].ID=ID){
Employees[i].address=newAddress;
std::cout<<"Employee's address "<<Employees[i].ID<<"has been updated"<<endl;
break;
}
}
}
if(!flag){
std::cout<<"Employee Identification not found in the system"<<endl;
}
}
void DeleteEmployee(Employee* Employees,int &Total){
bool flag=SearchEmployeeID(Employees,Total);
int i;
int j=0;
for(int i=0;i<=Total;i++){
if(flag){
Employee* newEmployees=new Employee[Total-1];
for(i=0,j=0;i<Total;i++){
if(Employees[i].ID!=ID){
newEmployees[j]=Employees[i];
j++;
}
delete[] Employees;
Employees=newEmployees;
Total--;
}
}
}
std::cout<<"Employee has been deleted from the system"<<endl;
}
//overloading of >> and << operators to read/write the employees data
friend ostream& operator << (ostream& os, const Employee & Employees ) {
os <<"The Employee Details "<<endl << "Employee ID :" << Employees.ID<< endl << "name :" << Employees.name << endl << "position :" << Employees.position << endl;
os << "Date of brith :" << Employees.d << endl;
os << "Address :" << Employees.address << endl << "Salary " << Employees.salary<< endl;
os << "phone Number :" << Employees.phoneNumber << endl;
return os;
}
friend istream& operator >> (istream& is, Employee & Employees ) {
cout << endl;
cout << "Employee ID :";
is >> Employees.ID;
cout << "Employee name :";
is >> Employees.name;
cout << "Employee birthdate:";
is >> Employees.d;
cout << "Employee position :";
is >> Employees.position;
cout << "Employee salary :";
is >> Employees.salary;
cout<< "Employee address:";
is >> Employees.address;
cout << "phone number:";
is >> Employees.phoneNumber;
return is;
}
//setter
void SetID(int IDx){ID=IDx;}
};