-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.c
444 lines (408 loc) · 11.6 KB
/
menu.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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "lib/menu.h"
#include "lib/print.h"
#include "lib/sort.h"
#include "lib/array.h"
#include "lib/search-and-filter.h"
#include "lib/add-edit-and-delete.h"
#include "lib/error-checking.h"
void type_entity(Student *temp)
{
printf(">> Type the ID of the student (must be 9 digits)\n");
while (1) {
scanf("%s",&temp->id);
if(!check_id(&temp->id))break;
else
{
printf("Please, type again !\n");
}
}
printf(">> Type the full name of the student as the format (Firstname_Surname)\n");
printf("You should not exceed the maximum limit:59\n");
while (1) {
scanf("%s",&temp->name);
if(!check_name(&temp->name))break;
else
{
printf("Please, type again !\n");
}
}
printf(">> Type the abbrevation of the faculty of the student\n");
printf("You should not exceed the maximum limit:24\n");
while (1) {
scanf("%s",&temp->faculty);
if(!check_faculty(&temp->faculty))break;
else
{
printf("Please, type again !\n");
}
}
printf(">> Type the abbrevation of major of the student\n");
printf("You should not exceed the maximum limit:24\n");
while (1) {
scanf("%s",&temp->major);
if(!check_major(&temp->major))break;
else
{
printf("Please, type again !\n");
}
}
printf(">> Type the class of the student\n");
scanf("%d",&temp->class);
printf(">> Type the contact (mobile number) of the student\n");
printf("You should not exceed the maximum limit:20\n");
while (1) {
scanf("%s",&temp->contact);
if(!check_contact(&temp->contact))break;
else
{
printf("Please, type again !\n");
}
}
printf(">> Type the name of father of the student as the format (Firstname_Surname)\n");
printf("You should not exceed the maximum limit:25\n");
while (1) {
scanf("%s",&temp->parents[0].name);
if(!check_parent(&temp->parents[0].name))break;
else
{
printf("Please, type again !\n");
}
}
printf(">> Type the name of mother of the student as the format (Firstname_Surname)\n");
printf("You should not exceed the maximum limit:25\n");
while (1) {
scanf("%s",&temp->parents[1].name);
if(!check_parent(&temp->parents[1].name))break;
else
{
printf("Please, type again !\n");
}
}
printf(">> Type the GPA of the student as a fractional number (Max GPA is 4.0) \n");
printf("If GPA is unknown , type -1.00!!!\n");
while (1) {
scanf("%lf",&temp->gpa);
if(!check_gpa(temp->gpa))break;
else
{
printf("Please, type again !\n");
}
}
int n;
printf(">> Type the number of studied subjects of the student\n");
printf("You should not exceed the maximum limit:40\n");
while(1)
{
scanf("%d",&temp->number_of_subjects);
if(!check_numsubj(temp->number_of_subjects))break;
else
{
printf("Please, type again !\n");
}
}
n=temp->number_of_subjects;
printf(">> Type the all studied %d subjects of the student in one line (keep one space between subjects)\n",n);
for(int i=0;i<n;i++)
{
scanf("%s",&temp->subjects[i].name);
}
}
void type_entity_1(Student *temp)
{
printf("----------You can filter by using any combination of parameters. Answer on next questions for being able to filter.------------\n\n");
printf(">> Do you want to filter by using the ID of the student?\nType y for yes or any symbol for no\n");
char tmp[2];
scanf("%s",&tmp);
if(tmp[0]=='y')
{
printf("~Type the ID of the student (must be 9 digits)~\n");
while (1) {
scanf("%s",&temp->id);
if(!check_id(&temp->id))break;
else
{
printf("Please, type again !\n");
}
}
}
printf(">> Do you want to filter by using the full name of the student?\nType y for yes or any symbol for no\n");
scanf("%s",&tmp);
if(tmp[0]=='y')
{
printf("~Type the Full Name of the student as format (FirstName_Surname)~\n");
printf("You should not exceed the maximum limit:59\n");
while (1) {
scanf("%s",&temp->name);
if(!check_name(&temp->name))break;
else
{
printf("Please, type again !\n");
}
}
}
printf(">> Do you want to filter by using the Name of Faculty of the student?\nType y for yes or any symbol for no\n");
scanf("%s",&tmp);
if(tmp[0]=='y')
{
printf("~Type the abbrevation of the Faculty of the student~\n");
printf("You should not exceed the maximum limit:24\n");
while (1) {
scanf("%s",&temp->faculty);
if(!check_faculty(&temp->faculty))break;
else
{
printf("Please, type again !\n");
}
}
}
printf(">> Do you want to filter by using the Name of Major of the student?\nType y for yes or any symbol for no\n");
scanf("%s",&tmp);
if(tmp[0]=='y')
{
printf("~Type the abbrevation of the Major of the student~\n");
printf("You should not exceed the maximum limit:24\n");
while (1) {
scanf("%s",&temp->major);
if(!check_major(&temp->major))break;
else
{
printf("Please, type again !\n");
}
}
}
printf(">> Do you want to filter by using the class of the student?\nType y for yes or any symbol for no\n");
scanf("%s",&tmp);
if(tmp[0]=='y')
{
printf("~Type the class of the student~\n");
scanf("%d",&temp->class);
}
printf(">> Do you want to filter by using the GPA of the student?\nType y for yes or any symbol for no\n");
scanf("%s",&tmp);
if(tmp[0]=='y')
{
printf(">> Type the GPA of the student as a fractional number (Max GPA is 4.0) \n");
printf("If GPA is unknown , type -1.00!!!\n");
while (1) {
scanf("%lf",&temp->gpa);
if(!check_gpa(temp->gpa))break;
else
{
printf("Please, type again !\n");
}
}
}
printf(">> Do you want to filter by using the contact(mobile number) of the student?\nType y for yes or any symbol for no\n");
scanf("%s",&tmp);
if(tmp[0]=='y')
{
printf("~Type the mobile number of the student~\n");
printf("You should not exceed the maximum limit:20\n");
while (1) {
scanf("%s",&temp->contact);
if(!check_contact(&temp->contact))break;
else
{
printf("Please, type again !\n");
}
}
}
printf(">> Do you want to filter by using the studied subjects of the student?\nType y for yes or any symbol for no\n");
scanf("%s",&tmp);
if(tmp[0]=='y')
{
printf("~Type the number of the studied subjects~\n");
printf("You should not exceed the maximum limit:40\n");
while(1)
{
scanf("%d",&temp->number_of_subjects);
if(!check_numsubj(temp->number_of_subjects))break;
else
{
printf("Please, type again !\n");
}
}
int n=temp->number_of_subjects;
printf(">> Type the all studied %d subjects of the student in one line (keep one space between subjects)\n",n);
for(int i=0;i<n;i++)
{
scanf("%s",&temp->subjects[i].name);
}
}
else temp->number_of_subjects=0;
}
void add_menu()
{
system("cls");
//Initialize
Student temp;
temp.gpa=-2.0;
////////////
printf("-------------Enter the required parameters for adding the student entity-----------------\n");
type_entity(&temp);
add(&temp);
printf("Succesfully added!\n");
}
void edit_menu(Student *student)
{
printf("-------------Enter the required parameters for editing the entity-----------------\n");
Student temp;
temp.gpa=-2.0;
temp.class=0;
type_entity(&temp);
edit(student,&temp);
printf("------Succesfully edited !----\n");
return ;
}
void delete_menu(Student *student)
{
printf(">> Are you sure that you want to delete this student from the system?\n");
printf("Type y for yes or any symbol for no\n");
char tmp[2];
scanf("%s",&tmp);
if(tmp[0]!='y')return;
else
{
delete(student);
printf("------Succesfully deleted !----\n");
return ;
}
}
void filter_menu()
{
system("cls");
Student temp;
temp.gpa=-2.0;
temp.class=0;
type_entity_1(&temp);
array all_students=input_array();
array required=filter(&all_students,&temp);
if(required.size==0)
{
printf("Not found! There is no such student!\n");
}
else print_array(required.students,required.size);
free(all_students.students);
free(required.students);
}
void search_menu()
{
system("cls");
//Initialize
Student temp;
temp.gpa=-2.0;
temp.class=0;
////////////
type_entity(&temp);
array all_students=input_array();
Student res=search(&all_students,&temp);
if(strcmp(res.name,"Not found! There is no such student!\n")==0)printf("Not found! There is no such student!\n");
else print_student(&res);
free(all_students.students);
if(strcmp(res.name,"Not found! There is no such student!\n")==0)return ;
char tmp[2];
printf(">> Type e for editing this item , type d for deleting the item or something else for backing the menu\n");
scanf("%s",&tmp);
if(tmp[0]=='e')
{
edit_menu(&res);
}
else if(tmp[0]=='d')
{
delete_menu(&res);
}
else return;
}
void sort_menu()
{
system("cls");
printf(">> To sort all students by ID, please type 1\n");
printf(">> To sort all students by Full Name, please type 2\n");
printf(">> To sort all students by Faculty, please type 3\n");
printf(">> To sort all students by Major, please type 4\n");
printf(">> To sort all students by Class, please type 5\n");
printf(">> To sort all students by GPA, please type 6\n");
printf(">> To sort all students by Mobile number, please type 7\n");
printf(">> To exit from the sort menu, please type 8\n");
int x;
scanf("%d",&x);
if(x>=8 || x==0)return ;
system("cls");
printf(">> To sort all students in increasing order, please type 1\n");
printf(">> To sort all students in decreasing order, please type 2\n");
int xx;
scanf("%d",&xx);
array all=input_array();
switch(x){
case 1:
sort_by_string(all.students,xx,all.size,x);
break;
case 2:
sort_by_string(all.students,xx,all.size,x);
break;
case 3:
sort_by_string(all.students,xx,all.size,x);
break;
case 4:
sort_by_string(all.students,xx,all.size,x);
break;
case 5:
sort_by_class(all.students,xx,all.size);
break;
case 6:
sort_by_gpa(all.students,xx,all.size);
break;
case 7:
sort_by_string(all.students,xx,all.size,x);
break;
}
print_array(all.students,all.size);
fprint_students(&all);
free(all.students);
fflush(stdout);
}
void main_menu()
{
while(1) {
system("cls");
printf("============Welcome to the student management system of ADA university!==========\n");
puts("");
printf(">> To list all students, please type 1\n");
printf(">> To add student's information, please type 2\n");
printf(">> To sort students' information, please type 3\n");
printf(">> To search student, please type 4\n");
printf(">> To filter students, please type 5\n");
printf(">> To exit from the program, please type 6\n");
int x;
scanf("%d",&x);
if(x>=7)return ;
switch(x){
case 1:
system("cls");
print_all();
break;
case 2:
add_menu();
break;
case 3:
sort_menu();
break;
case 4:
search_menu();
break;
case 5:
filter_menu();
break;
case 6:
printf("See you!\n");
return;
}
printf("Type something for coming back to menu!\n");
fflush(stdout);
char xx[100];
scanf("%s", &xx);
}
}