-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemployees_system_v2.cpp
155 lines (143 loc) · 3.85 KB
/
employees_system_v2.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
#include <iostream>
using namespace std;
const int MAX = 10000; // maximum employees can be entered to the system
string Employees[MAX]; // array has the name of the employees
int Age[MAX]; // array has the ages of employees
float Salary[MAX]; // salary of each employee
char Gender[MAX]; // gender of each employee
int count = 0; // number of employees in the system
// functoins declartion
int menu();
void employeeSystem();
void addNewEmployee();
void printAllEmployees();
void deleteEmployeesByAge();
void updateSalaryByName();
int main()
{
employeeSystem(); // running the employee system
return 0;
}
// menu displayed to the user
int menu()
{
while (true)
{
int num = -1;
cout << "\nEnter a choice from 1 to 4:\n";
cout << "1) Add new employee\n";
cout << "2) Print all employees\n";
cout << "3) Delete by age\n";
cout << "4) Update salary by name\n";
cout << "Enter your choice: \n";
cin >> num;
// check for invalid input
if (num < 1 || num > 4)
{
cout << "\nInvalid choice. Try again\n";
continue;
}
return num;
}
}
// employeeSystem function to execute user request
void employeeSystem()
{
while (true)
{
int choice = menu();
if (choice == 1)
addNewEmployee();
if (choice == 2)
printAllEmployees();
if (choice == 3)
deleteEmployeesByAge();
if (choice == 4)
updateSalaryByName();
}
}
// function to add new employees to the system
void addNewEmployee()
{
string name;
cout << "Enter employee name: ";
cin >> name;
bool flag = false;
// check if the employee exists in the system already
for (int i = 0; i < count; i++)
{
if (Employees[i] == name)
{
cout << "Error: You have added this Employee before";
flag = true;
break;
}
}
if (flag)
return;
// recieving details about the employee
Employees[count] = name;
cout << "Enter employee age: ";
cin >> Age[count];
cout << "Enter employee salary: ";
cin >> Salary[count];
cout << "Enter employee gender(M/F): ";
cin >> Gender[count];
count++;
}
// function to print all employees in the system
void printAllEmployees()
{
for (int i = 0; i < count; i++)
{
// check if the employee has been remove from the system
if (Employees[i] == " ")
continue;
cout << "Employee name: " << Employees[i] << "\tEmployee age: " << Age[i] << "\tEmployee salary: " << Salary[i] << "\tEmployee gender: " << Gender[i] << "\n";
}
}
// function to delete employees between interval of ages
void deleteEmployeesByAge()
{
int start, end;
cout << "Start age: ";
cin >> start;
cout << "End age: ";
cin >> end;
for (int i = 0; i < count; i++)
{
if (Age[i] >= start && Age[i] <= end)
{
// reseting the data of the employee
Age[i] = 0;
Employees[i] = " ";
Salary[i] = 0;
Gender[i] = ' ';
}
}
}
// function to upadate salary by name
void updateSalaryByName()
{
string name;
cout << "Enter the name of the Employee: ";
cin >> name;
bool Flag = false;
// updating the salary of the employee
for (int i = 0; i < count; i++)
{
if (name == Employees[i])
{
Flag = true;
cout << "The current salary of the employee is: " << Salary[i] << "\n";
cout << "Enter the new salary: ";
int salary;
cin >> salary;
Salary[i] = salary;
cout << "Salary have been Updated successfully\n";
}
}
// check if the employee exists in the system
if (!Flag)
cout << "\nNo employees with this name!\n";
}