-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
237 lines (175 loc) · 6.46 KB
/
main.c
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
226
227
228
229
230
231
232
233
234
235
236
237
//THIS PROGRAM IS AN EMPLOYEE HR SYSTEM
//YOU CAN INSERT EMPLOYEE(FIRST NAME :LAST NAME :AGE :SALARY)
// UPDATE EMPLOYEE INFO
// SORT EMPLOYEE LIST NOT DATABASEFILE BY(FIRST NAME :AGE :SALARY)
// SEARCH ABOUT EMPLOYEE WITH (FIRST NAME : LAST NMAE)
// DELET EMPLOYEE FROM YOUR DATA BASE
//THIS PROGRAM CAN ALSO READ ALL .txt FILES CONTAIN DATABASE WRETIEN WITH THIS FORMAT
//ID:FIRST NAME;LAST NAME;AGE;SALARY\n
//AUTHOR : KHALED MOSTAFA
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#define DB "CREATDATABASE.txt"
#include "helper.h"
#include "linkedList.h"
#include "database.h"
int main()
{
puts("\t\t\t\t\tWELCOME DUDE IN ROBOCORONA_COMPANY.");
if (fopen(DB, "r") != NULL)
{
DBconverter();
}
int press = 0;
do
{
switch (press)
{
char insertfname[20];
char insertlname[20];
int insertage;
float insertsalary;
case 1: //Insert new employee
do
{
puts("\nPress 1-Insert New Emplyee\nPress 2-Exit");
scanf("%d", &press);
} while ((press <= 0) || (press > 2));
switch (press)
{
case 1:
puts("Enter the First Name.");
scanf("%s", &insertfname);
puts("Enter the Last Name.");
scanf("%s", &insertlname);
puts("Enter the Age.");
scanf("%d", &insertage);
puts("Enter the Salary.");
scanf("%f", &insertsalary);
insert_employee(insertfname, insertlname, insertage, insertsalary);
}
break;
case 2: //List linked list
if (startNULLchecker(start) != 0)
{
do
{
puts("\nPress 1-List Linkedlist\nPress 2-Exit");
scanf("%d", &press);
} while ((press <= 0) || (press > 2));
switch (press)
{
case 1:
listLinkedlist(start);
break;
}
break;
case 3: // Sort employee linked list
if (startNULLchecker(start) != 0)
{
do
{
puts("Press 1-Sort By name\npress 2-Sort By age\npress 3-Sort By salary\nPress 4-Exit");
scanf("%d", &press);
} while ((press <= 0) || (press > 4));
switch (press)
{
puts("The Sorted List is");
case 1:
sort_Employees(1); // Sort By First Name
listLinkedlist(start);
sort_Employees(4); // Sort By ID
break;
case 2:
sort_Employees(2); // Sort By Age
listLinkedlist(start);
sort_Employees(4); // Sort By ID
break;
case 3:
sort_Employees(3); // Sort By Salary
listLinkedlist(start);
sort_Employees(4); // Sort By ID
}
}
}
break;
case 4: // Search for spacific employee
if (startNULLchecker(start) != 0)
{
do
{
puts("\nPress 1-Search By First Name\nPress 2-Search By Last Name\nPress 3-Exit");
scanf("%d", &press);
} while ((press <= 0) || (press > 3));
switch (press)
{
case 1:
searchEmployee(1, "First Name");
break;
case 2:
searchEmployee(2, "Last Name");
break;
}
}
break;
case 5: //Update a spacific employee info
if (startNULLchecker(start) != 0)
{
int id = askForID();
if (ID_checker(id))
{
do
{
puts("Press 1-Update First Name\nPress 2-Update Last Name\nPress 3-Update Age\nPress 4-Update Salary\nPress 5-Exit");
scanf("%d", &press);
} while ((press < 1) || (press > 5));
switch (press)
{
case 1:
update_Employee(1, "First Name", id);
updateFile(start);
break;
case 2:
update_Employee(2, "Last Name", id);
updateFile(start);
break;
case 3:
update_Employee(3, "Age", id);
updateFile(start);
break;
case 4:
update_Employee(4, "Salary", id);
updateFile(start);
}
}
}
break;
case 6: // Delete spacific employee
if (startNULLchecker(start) != 0)
{
int id = askForID();
if (ID_checker(id))
{
do
{
puts("Press 1-Delete The Employee\nPress 2-Exit");
scanf("%d", &press);
} while ((press < 1) || (press > 2));
switch (press)
{
case 1:
delete_employee(id);
updateFile(start);
}
}
}
break;
}
puts("Press 1-Insert New Employee\nPress 2-List All Employees\nPress 3-Sort All Employees\nPress 4-Search For An Employee\nPress 5-Update An Employee Information\nPress 6-Delete An Employee\nPress 7-Exit.");
scanf("%d", &press);
} while ((press >= 1) && (press <= 6));
puts("\t\t\t\t\tYou Choose To Exit Thank You.");
return 0;
}