-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentManagementSystem.c
More file actions
578 lines (497 loc) · 11.2 KB
/
StudentManagementSystem.c
File metadata and controls
578 lines (497 loc) · 11.2 KB
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
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
/// Header File
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include <conio.h>
// Color Function to change text color.
void red() {
printf("\033[1;31m");
}
void yellow() {
printf("\033[1;33m");
}
void green() {
printf("\033[0;32m");
}
void blue() {
printf("\033[0;34m");
}
void purple() {
printf("\033[0;35m");
}
void cyan() {
printf("\033[0;36m");
}
void white() {
printf("\033[0;37m");
}
void reset () {
printf("\033[0m");
}
// Gotoxy Function
void gotoxy(int x, int y)
{
printf("\033[%d;%dH",y,x);
}
// Drawing a line
void drawline(int x1, int y1, int x2,int y2,char ch,char c)
{
int i;
if(x1==x2){
for(i=y1;i<y2;i++){
gotoxy(x1,i);
printf("%c",c);
}
}
else{
for(i=x1;i<x2;i++)
{
gotoxy(i,y1);
printf("%c",ch);
}
}
}
// Rectangle Drawing
void drawrect(int x1, int y1, int x2, int y2,char ch,char c)
{
drawline(x1, y1, x2, y1,ch,c);
drawline(x2, y1, x2, y2,ch,c);
drawline(x1, y1, x1, y2,ch,c);
drawline(x1, y2, x2, y2,ch,c);
}
// Structure of Students
struct Student{
char name[200], ID[20],email[60], password[50];
int semester;
char mobile[30];
double cgpa[10];
};
typedef struct Student STD;
// use your file path, where program read input data
char filePath[100] = "input.txt";
// Get All records from file ...
int getRecords(STD stdList[],int x)
{
int i, n = 0;
if(x==0){
FILE *fp = fopen(filePath, "r");
if(fp == 0) {
red();
printf("Cannt open file\n");
return -1;
}
STD aStd;
/// Showing all records
while(fgets(aStd.name, sizeof aStd.name, fp) != NULL)
{
fscanf(fp, "%s%s%s%d", aStd.ID,aStd.email,aStd.mobile, &aStd.semester);
for(int i=1; i<=8; i++)
{
fscanf(fp,"%lf",&aStd.cgpa[i]);
}
fscanf(fp,"\n");
strcpy(stdList[n].name, aStd.name);
strcpy(stdList[n].ID, aStd.ID);
strcpy(stdList[n].email,aStd.email);
strcpy(stdList[n].mobile,aStd.mobile);
stdList[n].semester = aStd.semester;
for(i=1; i<=8; i++)
{
stdList[n].cgpa[i] = aStd.cgpa[i];
}
n++;
}
fclose(fp);
return n;
}
else
{
FILE *fp = fopen("RecycleBin.txt","r");
STD aStd;
/// Showing all records
while(fgets(aStd.name, sizeof aStd.name, fp) != NULL)
{
fscanf(fp, "%s%s%s%d", aStd.ID,aStd.email,aStd.mobile, &aStd.semester);
for(int i=1; i<=8; i++)
{
fscanf(fp,"%lf",&aStd.cgpa[i]);
}
fscanf(fp,"\n");
strcpy(stdList[n].name, aStd.name);
strcpy(stdList[n].ID, aStd.ID);
strcpy(stdList[n].email,aStd.email);
strcpy(stdList[n].mobile,aStd.mobile);
stdList[n].semester = aStd.semester;
for(i=1; i<=8; i++)
{
stdList[n].cgpa[i] = aStd.cgpa[i];
}
n++;
}
fclose(fp);
return n;
}
}
// ShowRecords function to show all records from file
void showRecords()
{
STD stdList[100];
int i, j,n = getRecords(stdList,0);
if(n==0){
printf("There is no record. Please, add record.\n");
return;
}
gotoxy(12, 2);
cyan();
printf("Student Record");
printf("\n\n");
reset();
for(i = 0; i < n; i++) {
if(i%3==0) green();
else if(i%3==1)cyan();
else white();
printf("Name : %s", stdList[i].name);
printf("ID : %s\n", stdList[i].ID);
printf("E-mail : %s\n",stdList[i].email);
printf("Mobile : %s\n",stdList[i].mobile);
printf("Semester: %d\n",stdList[i].semester);
printf("CGPA : ");
for(j=1; j<=8; j++)
{
printf("%.2lf ",stdList[i].cgpa[j]);
}
reset();
printf("\n\n");
}
}
//=====Add Record Function start===//
void addRecord()
{
white();
gotoxy(12, 2);
printf("Add Record");
printf("\n\n");
reset();
STD stdList[100];
int n = getRecords(stdList,0);
FILE *fp = fopen(filePath, "a");
STD add;
int i,flag=0;
printf("\nEnter your Id: ");
scanf("%s",add.ID);
for(i=0; i<n; i++)
{
if(strcmp(add.ID,stdList[i].ID)==0)
{
printf("\n\n\tDuplicate Matric Id\nEnter another info\n");
flag=1;
}
}
if(flag==0)
{
printf("\nEnter your name: ");
scanf(" %[^\n]",add.name);
printf("\nEnter your email:");
scanf("%s",add.email);
printf("\nEnter your mobile no :");
scanf("%s",add.mobile);
printf("\nEnter your Semester no: ");
scanf(" %d",&add.semester);
for(int i=1; i<add.semester; i++)
{
printf("\nEnter your %d semester CGPA: ",i);
scanf("%lf",&add.cgpa[i]);
}
fprintf(fp,"\n%s\n", add.name);
fprintf(fp,"%s\n", add.ID);
fprintf(fp,"%s\n",add.email);
fprintf(fp,"%s\n",add.mobile);
fprintf(fp,"%d\n", add.semester);
for(i=add.semester;i<=8;i++)
{
add.cgpa[i]=0.00;
}
for(i=1; i<=8; i++)
{
fprintf(fp,"%.2lf ",add.cgpa[i]);
}
purple();
printf("\n\n\t\t===Successfully Added===\n\n");
reset();
}
fclose(fp);
}
//=====Delete Record By ID======//
void deleteRecord()
{
white();
gotoxy(12, 2);
printf("Delete Record");
printf("\n\n");
reset();
printf("\nPlease, Enter your Id: ");
char ID[100];
scanf("%s",ID);
STD stdList[100];
int i,j, n = getRecords(stdList,0);
double max=-1;
FILE *fp = fopen(filePath, "w");
FILE *Rc = fopen("RecycleBin.txt","a");
//===i. delete record ===//
for(int i = 0; i < n; i++)
{
if(strcmp(stdList[i].ID, ID) != 0) {
fprintf(fp, "%s%s\n%s\n%s\n%d\n",
stdList[i].name, stdList[i].ID, stdList[i].email,stdList[i].mobile, stdList[i].semester);
for(j=1; j<=8; j++)
{
fprintf(fp,"%.2f ",stdList[i].cgpa[j]);
}
fprintf(fp,"\n");
}
else
{
fprintf(Rc, "%s%s\n%s\n%s\n%d\n", stdList[i].name, stdList[i].ID, stdList[i].email,stdList[i].mobile, stdList[i].semester);
for(j=1; j<=8; j++)
{
fprintf(Rc,"%.2f ",stdList[i].cgpa[j]);
}
fprintf(Rc,"\n");
}
}
//===ii=====
for(i=0; i<n; i++)
{
if(strcmp(stdList[i].ID,ID)==0)
{
printf(" Name: %s\n",stdList[i].name);
for(j=1; j<=8; j++)
{
if(max<stdList[i].cgpa[j])
{
max = stdList[i].cgpa[j];
}
}
printf("\n\nHighest CGPA : %.2lf\n",max);
printf("Semester : ");
for(j=1; j<=8; j++)
{
if(max==stdList[i].cgpa[j])
{
printf("%d, ",j);
}
}
printf("\n");
}
}
fclose(fp);
fclose(Rc);
}
/// Update Record
void update()
{
white();
gotoxy(12, 2);
printf("Update Record");
printf("\n\n");
reset();
printf("\nPlease Enter your Id: ");
char id[100];
scanf("%s",id);
STD stdList[100];
int i,j,n=getRecords(stdList,0);
double newCGPA;
int updatesem;
char newMail[50],ch[50];
printf("\nEnter GPA OR EMAIL TO UPDATE: ");
scanf("%s",ch);
if(strcmp(ch,"EMAIL")==0)
{
printf("\nEnter your updated E-mail: ");
scanf("%s",newMail);
for(i=0; i<n; i++)
{
if(strcmp(stdList[i].ID,id)==0)
{
strcpy(stdList[i].email,newMail);
}
}
}
else
{
printf("\nEnter your semester to update CGPA: ");
scanf("%d",&updatesem);
printf("\nEnter updated CGPA: ");
scanf("%lf",&newCGPA);
for(i=0; i<n; i++)
{
if(strcmp(stdList[i].ID,id)==0)
{
stdList[i].cgpa[updatesem] = newCGPA;
}
}
}
FILE *fp = fopen(filePath,"w");
for(i=0; i<n; i++)
{
fprintf(fp,"%s",stdList[i].name);
fprintf(fp,"%s\n",stdList[i].ID);
fprintf(fp,"%s\n",stdList[i].email);
fprintf(fp,"%s\n",stdList[i].mobile);
fprintf(fp,"%d\n",stdList[i].semester);
for(j=1;j<=8; j++)
{
fprintf(fp,"%.2lf ",stdList[i].cgpa[j]);
}
fprintf(fp,"\n");
}
fclose(fp);
}
// This function save a text file of any id
void SaveAsTextFile()
{
printf("Enter your id : ");
char id [50];
scanf("%s",id);
STD stdList[100];
int i,j,flag=0,n=getRecords(stdList,0);
char txt[100];
strcpy(txt,id);
strcat(txt,".txt");
FILE *tx = fopen(txt,"w");
if(tx==0){
printf("Cann't open file\n");
exit(1);
}
for(i=0;i<n;i++)
{
if(strcmp(stdList[i].ID,id)==0)
{
flag=1;
red();
fprintf(tx, "Name : %s",stdList[i].name);
fprintf(tx, "ID : %s\n",stdList[i].ID);
fprintf(tx, "Email : %s\n",stdList[i].email);
fprintf(tx, "Mobile : %s\n",stdList[i].mobile);
fprintf(tx, "Semester : %d\n",stdList[i].semester);
fprintf(tx, "CGPA : ");
for(j=1;j<=8;j++)
{
fprintf(tx, " %.2lf ",stdList[i].cgpa[j]);
}
}
}
if(flag==0) printf("Id Not Found\n");
fclose(tx);
}
// sorting Record
void sort()
{
STD stds[1000];
int n = getRecords(stds,0), i, f, j, k;
char temp[100];
for(i = 0; i < n; i++) {
for(j = i + 1; j < n; j++)
if(strcmp(stds[i].ID, stds[j].ID) < 1) {
strcpy(temp, stds[i].ID);
strcpy(stds[i].ID, stds[j].ID);
strcpy(stds[j].ID, temp);
}
}
for(i = 0; i < n; i++) {
printf("%s\n", stds[i].ID);
}
}
// Show deleted records from recycle Bin.
void showRecycle()
{
STD stdList[100];
int i, j,n = getRecords(stdList,1);
if(n==0){
printf("Empty Recyle Bin \n");
return;
}
gotoxy(12, 2);
cyan();
printf("Recycle Bin");
printf("\n\n");
reset();
for(i = 0; i < n; i++) {
if(i%3==0) green();
else if(i%3==1)cyan();
else white();
printf("Name : %s", stdList[i].name);
printf("ID : %s\n", stdList[i].ID);
printf("E-mail : %s\n",stdList[i].email);
printf("Mobile : %s\n",stdList[i].mobile);
printf("Semester: %d\n",stdList[i].semester);
printf("CGPA : ");
for(j=1; j<=8; j++)
{
printf("%.2lf ",stdList[i].cgpa[j]);
}
reset();
printf("\n\n");
}
}
///Main Function
int main()
{
cyan();
drawrect(1, 0, 46, 4, '~','+');
yellow();
gotoxy(5, 1);
printf("Welcome To Student Management Solution");
gotoxy(7, 2);
printf("Developed By: Emdadul Islam");
gotoxy(15, 5);
yellow();
printf("\n╭╮╭╮╭╮╱╱╭╮\n");
printf("┃┃┃┃┃┃╱╱┃┃\n");
printf("┃┃┃┃┃┣━━┫┃╭━━┳━━┳╮╭┳━━╮\n");
printf("┃╰╯╰╯┃┃━┫┃┃╭━┫╭╮┃╰╯┃┃━┫\n");
printf("╰╮╭╮╭┫┃━┫╰┫╰━┫╰╯┃┃┃┃┃━┫\n");
printf("╱╰╯╰╯╰━━┻━┻━━┻━━┻┻┻┻━━╯\n");
drawrect(15, 13,35,15, '+','!');
gotoxy(23, 14);
green();
printf("Menu");
gotoxy(1, 17);
printf("Please Enter a number upto 4 to choose option\n\n\n");
int choice;
while(1)
{
cyan();
printf("\t\t1. Show info.\n\t\t2. Add record\n\t\t3. Delete Record\n\t\t4. Update Record\n\t\t5. Sort Record\n\t\t6. Save As Txt file\n\t\t7. Recycle Bin\n\t\t8. Exit\n");
scanf("%d",&choice);
system("cls");
switch(choice)
{
case 1:
showRecords();
break;
case 2:
addRecord();
break;
case 3:
deleteRecord();
break;
case 4:
update();
break;
case 5:
sort();
break;
case 6:
SaveAsTextFile();
break;
case 7:
showRecycle();
break;
case 8:
exit(1);
break;
}
}
return 0;
}