-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOMS.c
365 lines (336 loc) · 7.07 KB
/
OMS.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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define True 1
#define False 0
#define MAX 30
/*
Office Mangement System:
Menu driven functions-done
Read from file-done
Write to file-done
User defined data type-emp-done
array of emp to store data-done
create new employees-done
Overtime hours-done
calculate salary based on working days and role-done
delete employee-done
Attendance logs-per ind, cumulative,reset
Feedback system
Separate functions for CEO(menu driven) access to emp, feedback-done
*/
char name[MAX]="datafile.txt";
char uname[MAX]="passwords.txt";
int salary_array[]={1000000,900000,900000,750000,500000,450000,300000,150000};
char role_array[8][15]={"CEO","COO","CTO","MAN", "AMAN", "SALES", "PEON", "SEC"};
int count_emp=0;
int count_user;
FILE *fp1;
FILE *fp2;
typedef struct Employee_Data
{
char name[MAX];
char role[MAX];
int wd;
int salary;
}emp;
typedef struct up
{
char name[MAX];
char pass[MAX];
}user;
emp emp_array[MAX];
user user_array[MAX];
void login()
{
user user1;
count_user=0;
//printf("Reading data from file: \n");
fp2=fopen(uname,"r+");
if(fp2==NULL)
{
printf("File Not Found");
}
else
{ while(fscanf(fp2,"%s %s",user1.name,user1.pass)!=EOF)
{
user_array[count_user]=user1;
count_user++;
}
}
}
void begin()
{
printf("\n__________________________________________________________\n");
printf("\n____Welcome to our Office Management System______\n");
printf("\n__________________________________________________________\n");
}
void end()
{
printf("\n__________________________________________________________\n");
printf("\n____Thank you for using our Office Management System______\n");
printf("\n__________________________________________________________\n");
}
int calc_salary(int atten, char role[])
{
int flag = True;
int i =0;
while(flag)
{
if(strcmp(role,role_array[i])==0)
{
flag=False;
}
else
{
i++;
}
}
int sal = salary_array[i] - (((25-atten)*salary_array[i])/100);
return sal;
}
void print_emp(emp emp1)
{
printf("Name: %s\n",emp1.name);
printf("Role: %s\n",emp1.role);
printf("Working Days: %d\n",emp1.wd);
printf("Salary: %d\n",emp1.salary);
}
emp create_emp()
{
emp new;
printf("\nEnter Name: ");
scanf(" %[^\n]s ",new.name);
printf("\nEnter Role: ");
scanf(" %[^\n]s ",new.role);
printf("\nEnter working days:");
scanf("\n %d",&new.wd);
new.salary=calc_salary(new.wd,new.role);
return new;
}
void readfile()
{
emp emp1;
count_emp=0;
//printf("Reading data from file: \n");
fp1=fopen(name,"r+");
if(fp1==NULL)
{
printf("File Not Found");
}
else
{ while(fscanf(fp1,"%s %s %d",emp1.name,emp1.role,&emp1.wd)!=EOF)
{
emp1.salary=calc_salary(emp1.wd,emp1.role);
//print_emp(emp1);
emp_array[count_emp]=emp1;
count_emp++;
}
}
}
void writefile()
{
fclose(fp1);
fp1=fopen(name,"w");
for(int i =0;i<count_emp;i++)
{
if(strcmp(emp_array[i].name,"XXX")!=0)
{ //printf("%s\n",emp_array[i].name);
fprintf(fp1, "%s %s %d\n",emp_array[i].name,emp_array[i].role,emp_array[i].wd);
}
}
fclose(fp1);
readfile();
}
void new_emps()
{
int num;
printf("Enter number of new employees: ");
scanf("%d",&num);
for(int i =0;i<num;i++)
{ printf("Employee %d",i+1);
emp_array[count_emp]=create_emp();
count_emp++;
}
}
void del_emp()
{
int flag=0;
fp1=fopen("datafile.txt","w");
for(int i=0;i<count_emp;i++)
{
if(emp_array[i].wd<12)
{
printf("\nEmployee having \nname: %s \nand role:%s \nis now fired for having no commitment as their number of working days is : %d",emp_array[i].name,emp_array[i].role,emp_array[i].wd);
strcpy(emp_array[i].name,"XXX");
flag++;
//printf("%s",emp_array[i].name);
}
}
if(flag==0)
{
printf("All employee's are outstanding, no one has been fired");
}
writefile();
fclose(fp1);
readfile();
}
int check( char u[],char p[])
{
for(int i=0;i<count_user;i++)
{ int uv=strcmp(user_array[i].name,u);
int pv=strcmp(user_array[i].pass,p);
int res=(!uv && !pv);
//printf("%d\n",res );
if(res)
{
if(!strcmp(u,"CEO"))
{
return 1;
}
else
{
return -1;
}
}
}
return 0;
}
void add_up()
{
user u1;
printf("\nEnter username:");
scanf("%s",u1.name);
printf("\nEnter password:");
scanf("%s",u1.pass);
user_array[count_user]=u1;
count_user++;
fclose(fp2);
fp2=fopen(uname,"w");
for (int i = 0; i < count_user; i++)
{
fprintf(fp2, "%s %s\n",user_array[i].name,user_array[i].pass);
}
fclose(fp2);
login();
}
void inc_attendance()
{
for(int i=0;i<count_emp;i++)
{
emp_array[i].wd++;
}
writefile();
}
void dec_attendance()
{
int pv,num;
char pname[100];
printf("\nEnter name:");
scanf("%s",pname);
printf("\nEnter absent days:");
scanf("%d",&num);
int flag=0;
for(int i=0;i<count_emp;i++)
{
pv=!(strcmp(emp_array[i].name,pname));
if(pv)
{
emp_array[i].wd=emp_array[i].wd-num;
flag++;
}
}
if(!flag)
{
printf("Employee DNE");
}
writefile();
}
int main()
{
begin();
int choice;
readfile();
login();
//printf("%d\n",count_user);
char u[10],p[10];
printf("\nEnter username:");
scanf("%s",u);
printf("\nEnter password:");
scanf("%s",p);
int c=check(u,p);
switch(c)
{
case 1:
printf("\nEnter 1 to read employee data \nEnter 2 to add new employees\nEnter 3 to fire underperforming employees\nEnter 4 to enter new employee login\nEnter 5 to update attendance\nEnter 6 to remove attendace for employee\nEnter 0 to quit: ");
scanf("%d",&choice);
while(choice)
{
switch (choice)
{
case 1:
printf("\nCurrent Employees: \n");
for(int i=0;i<count_emp;i++)
{
print_emp(emp_array[i]);
}
break;
case 2:
new_emps();
writefile();
break;
case 3:
printf("Employees having less than 12 working days will be fired\n");
del_emp();
break;
case 4:
add_up();
break;
case 5:
inc_attendance();
break;
case 6:
dec_attendance();
break;
default:
writefile();
break;
}
printf("\n");
printf("\nEnter 1 to read employee data \nEnter 2 to add new employees\nEnter 3 to fire underperforming employees\nEnter 4 to enter new employee login\nEnter 5 to update attendance\nEnter 6 to remove attendace for employee\nEnter 0 to quit: ");
scanf("%d",&choice);
}
break;
case -1:
printf("\nEnter 1 to read employee data \nEnter 2 to add new employees\nEnter 0 to quit: ");
scanf("%d",&choice);
while(choice)
{
switch (choice)
{
case 1:
printf("\nCurrent Employees: \n");
for(int i=0;i<count_emp;i++)
{
print_emp(emp_array[i]);
}
break;
case 2:
new_emps();
writefile();
break;
default:
writefile();
break;
}
printf("\n");
printf("\nEnter 1 to read employee data \nEnter 2 to add new employees\nEnter 0 to quit: ");
scanf("%d",&choice);
}
break;
default:
printf("\nEmployee DNE");
break;
}
end();
}