New Lab Manual

User Manual:

Open the PDF directly: View PDF PDF.
Page Count: 4

DownloadNew Lab Manual
Open PDF In BrowserView PDF
New Style Lab Manual
Prabodh
September 18, 2017

1

1

Program 1

Question goes here
1
2
3
4
5
6
7
8
9

#i n c l u d e 
#i n c l u d e < s t d l i b . h>
#i n c l u d e < s t r i n g . h>
typedef struct {
u n s i g n e d emp id ;
c h a r emp name [ 2 5 ] ;
c h a r emp dept [ 2 5 ] ;
u n s i g n e d e m p s a l a r y , emp age ;
} employee t ;

10
11
12
13
14
15
16

void
void
void
void
void
void

fnAddRecord ( v o i d ) ;
fnSearchEmpID ( i n t ) ;
fnSearchEmpSal ( i n t ) ;
fnSearchEmpDept ( c h a r [ ] ) ;
fnSearchEmpAge ( i n t ) ;
fnDisplayAllRecords ( void ) ;

17
18
19
20
21

i n t main ( )
{
i n t id , s a l , age , i C h o i c e ;
c h a r dept [ 1 0 ] ;

22

for ( ; ; )
{
p r i n t f ( ” \ n1 . Add Record \ n2 . D i s p l a y Records \ n3 . S e a r c h Employee by ID\n” ) ;
p r i n t f ( ” 4 . S e a r c h Employee by Dept \ n5 . S e a r c h Employee by s a l a r y \n” ) ;
p r i n t f ( ” 6 . S e a r c h Employee by Age\ n7 . E x i t ” ) ;
p r i n t f ( ” \ nEnter your c h o i c e : ” ) ;
s c a n f ( ”%d” ,& i C h o i c e ) ;

23
24
25
26
27
28
29
30

switch ( iChoice )
{
case 1:
fnAddRecord ( ) ;
break ;

31
32
33
34
35
36

case 2:

37

p r i n t f ( ” \n Employee D e t a i l s \n” ) ;
fnDisplayAllRecords () ;
break ;

38
39
40
41

case 3:

42

p r i n t f ( ” \ nEnter t h e emp id t h a t you want t o s e a r c h \n” ) ;
s c a n f ( ”%d” ,& i d ) ;
fnSearchEmpID ( i d ) ;
break ;

43
44
45
46
47

case 4:

48

p r i n t f ( ” \ nEnter t h e dept t h a t you want t o s e a r c h \n” ) ;
s c a n f ( ”%s ” , dept ) ;
fnSearchEmpDept ( dept ) ;
break ;

49
50
51
52
53

case 5:

54

p r i n t f ( ” \ nEnter t h e s a l a r y t h a t you want t o s e a r c h \n” ) ;
s c a n f ( ”%d” ,& s a l ) ;
fnSearchEmpSal ( s a l ) ;
break ;

55
56
57
58
59

case 6:

60

p r i n t f ( ” \ nEnter t h e age t h a t you want t o s e a r c h \n” ) ;
s c a n f ( ”%d” ,& age ) ;
fnSearchEmpAge ( age ) ;
break ;
case 7: exit (0) ;

61
62
63
64
65

}
}
return 0;

66
67
68
69

}

70
71
72
73

void fnDisplayAllRecords ( )
{
i n t iCount = 0 ;

2

e m p l o y e e t ep ;
FILE ∗ f p ;

74
75
76

f p = f o p e n ( ”emp . dat ” , ” r ” ) ;
i f ( f p==NULL)
{
p r i n t f ( ” \ n F i l e d o e s not e x i s t \n” ) ;
return ;
}
w h i l e ( f s c a n f ( fp , ”%d%s%s%d%d” ,& ep . emp id , ep . emp name , ep . emp dept , &ep . e m p s a l a r y , &ep .
emp age ) !=EOF)
{
p r i n t f ( ”%d\ t%s \ t%s \ t%d\ t%d\n” , ep . emp id , ep . emp name , ep . emp dept , ep . e m p s a l a r y , ep .
emp age ) ;
iCount++;
}
i f ( 0 == iCount )
p r i n t f ( ” \nNo Records found \n” ) ;
f c l o s e ( fp ) ;

77
78
79
80
81
82
83

84
85

86
87
88
89
90
91

}

92
93
94
95
96

v o i d fnAddRecord ( )
{
FILE ∗ f p ;
e m p l o y e e t emp ;

97

p r i n t f ( ” \ nEnter Employee d e t a i l s \n” ) ;
p r i n t f ( ” \nID : ” ) ;
s c a n f ( ”%d” ,&emp . emp id ) ;
getchar () ;
p r i n t f ( ” \nName : ” ) ;
f g e t s ( emp . emp name , 2 5 , s t d i n ) ;
p r i n t f ( ” \ nDept : ” ) ;
f g e t s ( emp . emp dept , 2 5 , s t d i n ) ;
p r i n t f ( ”\ nSalary : ” ) ;
s c a n f ( ”%d” ,&emp . e m p s a l a r y ) ;
p r i n t f ( ” \nAge : ” ) ;
s c a n f ( ”%d” ,&emp . emp age ) ;

98
99
100
101
102
103
104
105
106
107
108
109

f p = f o p e n ( ”emp . dat ” , ” a ” ) ;
f p r i n t f ( fp , ”%d\ t%s \ t%s \ t%d\ t%d\n” , emp . emp id , emp . emp name , emp . emp dept , emp . e m p s a l a r y ,
emp . emp age ) ;
f c l o s e ( fp ) ;

110
111

112
113

}

114
115
116
117
118
119

v o i d fnSearchEmpID ( i n t i d )
{
i n t iCount = 0 ;
e m p l o y e e t ep ;
FILE ∗ f p ;

120

f p = f o p e n ( ”emp . dat ” , ” r ” ) ;
i f ( f p==NULL)
{
p r i n t f ( ” \ n F i l e d o e s not e x i s t \n” ) ;
return ;
}
w h i l e ( f s c a n f ( fp , ”%d%s%s%d%d” ,& ep . emp id , ep . emp name , ep . emp dept , &ep . e m p s a l a r y , &ep .
emp age ) !=EOF)
{
i f ( ep . emp id == i d )
{
p r i n t f ( ”%d\ t%s \ t%s \ t%d\ t%d\n” , ep . emp id , ep . emp name , ep . emp dept , ep . e m p s a l a r y ,
ep . emp age ) ;
iCount++;
}
}
i f ( 0 == iCount )
p r i n t f ( ” \nNo Records found \n” ) ;
f c l o s e ( fp ) ;

121
122
123
124
125
126
127

128
129
130
131

132
133
134
135
136
137
138

}

139
140
141
142
143
144

v o i d fnSearchEmpSal ( i n t s a l )
{
i n t iCount = 0 ;
e m p l o y e e t ep ;
FILE ∗ f p ;

3

145

f p = f o p e n ( ”emp . dat ” , ” r ” ) ;
i f ( f p==NULL)
{
p r i n t f ( ” \ n F i l e d o e s not e x i s t \n” ) ;
return ;
}
w h i l e ( f s c a n f ( fp , ”%d%s%s%d%d” ,& ep . emp id , ep . emp name , ep . emp dept , &ep . e m p s a l a r y , &ep .
emp age ) !=EOF)
{
i f ( ep . e m p s a l a r y == s a l )
{
p r i n t f ( ”%d\ t%s \ t%s \ t%d\ t%d\n” , ep . emp id , ep . emp name , ep . emp dept , ep . e m p s a l a r y ,
ep . emp age ) ;
iCount++;
}
}
i f ( 0 == iCount )
p r i n t f ( ” \nNo Records found \n” ) ;
f c l o s e ( fp ) ;

146
147
148
149
150
151
152

153
154
155
156

157
158
159
160
161
162
163

}

164
165
166
167
168
169

v o i d fnSearchEmpDept ( c h a r dept [ ] )
{
i n t iCount = 0 ;
e m p l o y e e t ep ;
FILE ∗ f p ;

170
171

f p = f o p e n ( ”emp . dat ” , ” r ” ) ;
i f ( f p==NULL)
{
p r i n t f ( ” \ n F i l e d o e s not e x i s t \n” ) ;
return ;
}
w h i l e ( f s c a n f ( fp , ”%d%s%s%d%d” ,& ep . emp id , ep . emp name , ep . emp dept , &ep . e m p s a l a r y , &ep .
emp age ) !=EOF)
{
i f ( ! strcmp ( ep . emp dept , dept ) )
{
p r i n t f ( ”%d\ t%s \ t%s \ t%d\ t%d\n” , ep . emp id , ep . emp name , ep . emp dept , ep . e m p s a l a r y ,
ep . emp age ) ;
iCount++;
}
}
i f ( 0 == iCount )
p r i n t f ( ” \nNo Records found \n” ) ;

172
173
174
175
176
177
178

179
180
181
182

183
184
185
186
187
188

}

189
190
191
192
193
194

v o i d fnSearchEmpAge ( i n t age )
{
i n t iCount = 0 ;
e m p l o y e e t ep ;
FILE ∗ f p ;

195

f p = f o p e n ( ”emp . dat ” , ” r ” ) ;
i f ( f p==NULL)
{
p r i n t f ( ” \ n F i l e d o e s not e x i s t \n” ) ;
return ;
}
w h i l e ( f s c a n f ( fp , ”%d%s%s%d%d” ,& ep . emp id , ep . emp name , ep . emp dept , &ep . e m p s a l a r y , &ep .
emp age ) !=EOF)
{
i f ( ep . emp age == age )
{
p r i n t f ( ”%d\ t%s \ t%s \ t%d\ t%d\n” , ep . emp id , ep . emp name , ep . emp dept , ep . e m p s a l a r y ,
ep . emp age ) ;
iCount++;
}
}
i f ( 0 == iCount )
p r i n t f ( ” \nNo Records found \n” ) ;

196
197
198
199
200
201
202

203
204
205
206

207
208
209
210
211
212

}

Programs/01EmployeeDB.c

4



Source Exif Data:
File Type                       : PDF
File Type Extension             : pdf
MIME Type                       : application/pdf
PDF Version                     : 1.5
Linearized                      : No
Page Count                      : 4
Producer                        : pdfTeX-1.40.14
Creator                         : TeX
Create Date                     : 2017:09:18 11:25:36+05:30
Modify Date                     : 2017:09:18 11:25:36+05:30
Trapped                         : False
PTEX Fullbanner                 : This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013/Debian) kpathsea version 6.1.1
EXIF Metadata provided by EXIF.tools

Navigation menu