-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathA01_SHIVA.c
199 lines (193 loc) · 6.05 KB
/
A01_SHIVA.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
//MINI PROJECT
//LEAVE MANAGMENT SYSTEM
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
void module1();//function prototype for entering employee detail
void module2();//function prototype for viewing employee detail
void module3();//function prototype for viewing the leave taken and pending
struct detail//structure
{
char u_id[20],name[50],sex[6];
int sick_leave,casual_leave;
};
/*global variables*/
//variable choice -To choose the option for entering or veiwing the leave taken by employee
//variable mm for returning to function main
//variable name_org for entering the name of organization
int choice,mm;
char name_org[30];
void main()
{
printf("\n welcome to ");
printf("\n ******Leave Managment System******");
//main menu starts from here
printf("\n 1.Enter employee detail");
printf("\n Enter the name of organisation\n");
gets(name_org);
puts(name_org);
printf("\n Enter choice\n");
printf("\n Pres 1 to Enter the employee details\n");
printf("\n press 2 to view employee details\n");
printf("\n press 3 to view leave taken or leave pending\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
puts("\nenter employee detail\n");
module1();//module for entering employee detail
printf("\n would you like to go to main menu\n");
printf("\n 1. YES \t\t 0-NO\n\t");
scanf("%d",&mm);
if(mm==1)
{
main();
}
else
{
break;
}
case 2:
printf("\nview employee detail\n");
module2();//module for viewing the entered employee detail
printf(" \nwould you like to goto the main menu\n");
printf(" \n 1 - yes \t\t 0 - no\n\t");
scanf("%d",&mm);
if(mm==1)
{
main();
}
else
{
break;
}
case 3:
printf("\nview leave taken or pending\n");
module3();//module for viewing the leave taken or pending
printf(" \nwould you like to goto the main menu\n");
printf(" \n 1 - yes \t\t 0 - no\n\t");
scanf("%d",&mm);
if(mm==1)
{
main();
}
else
{
break;
}
default ://default is used if none of the given case match
printf("not valid");
printf(" \nwould you like to goto the main menu");
printf(" \n 1 - yes \t\t 0 - no\n\t");
scanf("%d",&mm);
if(mm==1)
{
main
();
}
else
{
break;
}
}
}
void module1()//module for entering the employee details
{
FILE *source;//source is a file pointer
char another='y';
struct detail employee;//variable employee for stucture detail
source=fopen("employee_det.txt","w+");
while(another=='y'||another=='Y')
{
printf("enter employee details---\n");
printf("\n employee ID: ");
fflush(stdin);
gets(employee.u_id);
printf("\nemployee name:");
fflush(stdin);
gets(employee.name);
printf("\n sex");
fflush(stdin);
gets(employee.sex);
printf("\n sick leave\n");
fflush(stdin);
scanf("%d",&employee.sick_leave);
printf("%d \n",employee.sick_leave);
printf("\n casual leave\n");
fflush(stdin);
scanf("%d",&employee.casual_leave);
printf("%d \n",employee.casual_leave);
fwrite(&employee,sizeof(employee),1,source); /// write the record in the file
if(source==NULL)
{
printf("\n cannot open file");
}
else
{
fprintf(source,"%s%s%s%d%d",employee.u_id,employee.name,employee.sex,employee.sick_leave,employee.casual_leave);
fwrite(&employee,sizeof(employee),1,source);
fclose(source);
}
printf("\n Add another record(Y/N):");
another=getche();
}
}
void module2()//module for viewing the details of entered employee
{
FILE *target;//target is another file pointer to read the enterd details
struct detail employee;
//employee =(struct detail*)malloc(sizeof(struct detail));
target=fopen("employee_det.txt","r");
if(target==NULL)//condition for checking the file is existing or not
{
printf("\n cannot open file");
}
else
{
while(fread(&employee,sizeof(struct detail),1,target)==1)
{printf("\nemplyee_uid\temployee_name\temployee_sex\temployee_sick_leave\temployee_sick_leave\t\n");
printf("\n%s\t%s\t%s\t%d\t%d\t\n",employee.u_id,employee.name,employee.sex,employee.sick_leave,employee.casual_leave);
fprintf(target,"\n%s\t%s\t%s\t%d\t%d\t\n",employee.u_id,employee.name,employee.sex,employee.sick_leave,employee.casual_leave);
}
fclose(target);
}
}
void module3()//module for displaying the leave taken or pending
{
int choice_leave,pending_sick,pending_casual;
int l_sick;
int l_casual,total_sick,total_casual;
printf("please select the leave category\n");
printf("\nPress 1 for sick leave");
printf("\nPress 2 for casual leave");
scanf("%d",&choice_leave);
switch(choice_leave)
{
case 1:
printf("enter the total no. of sick leave in a term as entered before in main \n");
scanf("%d ",&total_sick);
printf("%d \n",total_sick);
printf("\n enter the no. of leaves:");
scanf("%d",&l_sick);
printf("%d\n",l_sick);
printf("no. of days leave pending\n");
pending_sick=total_sick-l_sick;
printf("%d\n",pending_sick);
break;
case 2:
printf("enter the total no. of casual leave in a term as entered before in main \n");
scanf("%d ",&total_casual);
printf("%d\n",total_casual);
printf("enter the no. of leaves");
scanf("%d",&l_casual);
printf("%d\n",l_casual);
printf("no. of days leave pending\n");
pending_casual=total_casual-l_casual;
printf("%d\n",pending_casual);
break;
default:
printf("please enter the correct leave category\n");
exit(1);
}
}