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
| #include <conio.h>
#include <stdio.h>
#include <string.h>
void main(void)
{
typedef struct spisok
{
char fam[50];
char dol[50];
int age;
int zar;
}spisok;
spisok rab[20], newrab[20];
char newfam[50],newdol[50];
int d,s,a,c,n,i,f,b,k,l,m1,m2,m3,m4;
FILE *f1;
f=0;
l=0;
do
{
puts("\n----------Menu-----------\n");
puts(" 1)Vvod spiska rabotnikov");
puts(" 2)Zapis spiska v fail, vivod na ecran");
puts(" 3)Formirovanie novogo spiska");
puts(" 4)Zapis novogo spiska v fail, vivod spiska");
puts(" 5)Vihod iz programmi");
puts("\n Vvedite punkt menu (ot 1 do 5)\n");
scanf("%d",&d);
switch(d)
{
case 1:
puts("\n-----Vvod dannih------\n");
puts(" 1)S klaviaturi");
puts(" 2)Chtenie iz faila");
puts("\n Vibetite sposob vvoda dannix 1 ili 2\n");
scanf("%d",&s);
switch(s)
{
case 1:
f=1;
do
{
printf("\n Vvedite kolichestvo rabotnikov ot 1 do 20\n");
scanf("%d",&n);
if(n<1||n>20)
puts("\n Oshibka! Povtorite popitku!!!\n");
}
while(n<1||n>20);
for (i=0; i<n; i++)
{
printf("\n Familiya " "%d-ogo sotrudnika\n", i+1);
fflush(stdin);
gets(rab[i].fam);
printf("\n Vvedite dolznost " "%d-ogo sotrudnika\n", i+1);
fflush(stdin);
gets(rab[i].dol);
printf("\n Vozrast " "%d-ogo sotrudnika \n", i+1);
scanf("%d",&rab[i].age);
printf("\n Zarabornaya plata " "%d-ogo sotrudnika v tisyachah rub\n", i+1);
scanf("%d",&rab[i].zar);
}break;
case 2:
f=1;
f1 = fopen("text2.txt","rt");
if( (f1=fopen("text2.txt","rt"))==0 )
{
puts("Fail ne naeden!!!!!");
}
else
{
fscanf(f1,"%d",&n);
for (i=0; i<n; i++)
{
fscanf(f1,"%s",&rab[i].fam);
fscanf(f1,"%s",&rab[i].dol);
fscanf(f1,"%d",&rab[i].age);
fscanf(f1,"%d",&rab[i].zar);
}
puts("chtenie zaversheno!!!!!");
fclose(f1);
}break;
}break;
case 2:
if (f==1)
{
puts(" 1)Zapis v fail");
puts(" 2)Vivod na ecran");
scanf("%d",&a);
switch(a)
{
case 1:
f1 = fopen("text2.txt","wt");
if( (f1=fopen("text2.txt","wt"))==0 )
{
puts("Fail ne naeden!!!!!");
}
else
{
fprintf(f1,"%d",n);
for (i=0; i<n; i++)
fprintf(f1,"\n%s %s %d %d", rab[i].fam, rab[i].dol, rab[i].age, rab[i].zar);
puts("Zapis zavershena!!!!!");
}
fclose(f1);
break;
case 2:
printf("\n*****************Spisok rabotnikov********************\n");
for (i=0; i<n; i++)
printf("\n Familiya:" " %s Dolznost:" " %s Vozrast:" " %d Zarplata:" " %d
tis.rub.\n", rab[i].fam, rab[i].dol, rab[i].age, rab[i].zar);
break;
}
}
else
puts("Vvedite pervi punkt menu!");
break;
case 3:
if (f==1)
{
l=1;
puts("\n-----Poisk sotrudnika------\n");
puts(" 1)Naiti sotrudnika po familii");
puts(" 2)Naiti sotrudnikov, zanimaushih opredelennuy dolznost ");
puts(" 3)Naiti sotrudnikov po vozrastu ");
puts(" 4)Naiti sotrudnikov po zarplate");
puts("\n Vvedite punkt menu (ot 1 do 5)\n");
scanf("%d",&b);
switch(b)
{
case 1:
puts("Vvedite familiu\n");
fflush(stdin);
gets(newfam);
k=0;
for(i=0; i<n; i++)
{
if(strcmp(newfam, rab[i].fam)==0)
{
newrab[k]=rab[i];
k++;
}
}
break;
case 2:
puts("Vvedite dolznost\n");
fflush(stdin);
gets(newdol);
k=0;
for(i=0; i<n; i++)
{
if(strcmp(newdol, rab[i].dol)==0)
{
newrab[k]=rab[i];
k++;
}
}
break;
case 3:
k=0;
printf("Vvedite minimalni vozrast dlya poiska\n");
scanf("%d", &m1);
printf("Vvedite maximalni vozrast dlya poiska\n");
scanf("%d", &m2);
printf("Pois v predelah ot " "%d do " "%d \n", m1, m2);
for(i=0; i<n; i ++)
{
if(rab[i].age>=m1&&rab[i].age<=m2)
{
newrab[k]=rab[i];
k++;
}
}
break;
case 4:
k=0;
printf("Vvedite minimalnuy zarplatu dlya poiska(v tisyachah rub)\n");
scanf("%d", &m3);
printf("Vvedite maximalnuy zarplatu dlya poiska(v tisyachah rub)\n");
scanf("%d", &m4);
printf("Pois v predelah ot " "%d do " "%d tis.rub\n", m3, m4);
for(i=0; i<n; i ++)
{
if(rab[i].zar>=m3&&rab[i].zar<=m4)
{
newrab[k]=rab[i];
k++;
}
}
break;
}
if(k>0)
printf("\n Novi spisok sformirovan.\n");
else
printf("\n Novi spisok ne sformirovan!\n");
}
else
printf("\n Vvedite 1-i punkt menu!\n");
}break;
case 4:
if (f==1)
{
if(l==1)
{
if(k>0)
{
puts("\n-----Vivod dannih------\n");
puts(" 1)Zapis v fail");
puts(" 2)Vivod na ecran");
puts("\n Vibetite sposob vivoda dannih 1 ili 2\n");
scanf("%d",&c);
switch(c)
{
case 1:
f1 = fopen("text2.txt","wt");
if( (f1=fopen("text2.txt","wt"))==0 )
{
puts("Fail ne naeden!!!!!");
}
else
{
fprintf(f1,"%d",k);
for (i=0; i<k; i++)
fprintf(f1,"\n%s %s %d %d", newrab[i].fam, newrab[i].dol,
newrab[i].age, newrab[i].zar);
puts("Zapis zavershena!!!!!");
fclose(f1);
}break;
case 2:
printf("*************Novi spisok*************");
for (i=0; i<k; i++)
printf("\n Familiya:" " %s Dolznost:" " %s Vozrast:" " %d Zarplata:" "
%d tis.rub.\n", newrab[i].fam, newrab[i].dol, newrab[i].age,
newrab[i].zar);
break;
}
}
else
printf("\n Novi spisok ne sformirovan! \n");
}
else
printf("\n Snachala sdelaite obrabotku! \n");
}
else
printf("\n Vvedite 1-i punkt menu!!! \n");
break;
case 5:
puts("\n Zavershenie programi \n");
default:
puts("Vvedite znachenie ot 1 do 5");
}
}
while(d!=5);
} |