-
Notifications
You must be signed in to change notification settings - Fork 0
/
attM.cpp
729 lines (673 loc) · 17.8 KB
/
attM.cpp
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
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
/* COPYRIGHT INFO */
/*
AUTHOR: RAJJIT LAISHRAM
DATE CREATED: SEPTEMBER 06, 2022
PURPOSE: FOR MANAGING THE ATTENDANCE OF STUDENTS BY THE TEACHERS.
THIS APPLICATION CAN BE USED TO MANAGE ALL THE ACTIVITIES OF THE STUDENTS.
DATE MODIFIED: JANUARY 25, 2023
CHANGES: ADDED INFOR FOR EACH SECTION
*/
// C++ Program on Attendance Management of Students
// INCLUDES THE REQUIRED LIBRARY FILES
#include <iostream>
#include <conio.h>
#include <ctype.h>
#include <cstring>
#include <dirent.h>
#include <fstream>
#include <process.h>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <sstream>
#include <time.h>
#include <typeinfo>
#include <windows.h>
using namespace std;
// USER DEFINED FUNCTIONS
void title(); // TO GIVE THE TITLE
void date(); // TO GIVE THE DATE
int delay(); // TO DELAY THE DISPLAY
void delay(unsigned int mseconds);
int adminLogin(); // LOGIN FUNCTION FOR TEACHERS
int adminView(); // DISPLAY FOR THE TEACHERS
int registerStudent(); // TO REGISTER STUDENTS
int checkListOfStudentsRegistered(); // TO CHECK THE LIST OF STUDENTS
int studentLogin(); // LOGIN FUNCTION FOR STUDENTS
int studentView(); // DISPLAY FOR THE STUDENTS
int checkStudentCredentials(string userName, string password); // CHECK PASSWORD
int markMyAttendance(string username); // MARK THE ATTENDANCE
int countMyAttendance(string username); // COUNT THE ATTENDANCE
int sendLeaveApplication(string username); // TO SEND LEAVE
int deleteAllStudents(); // TO DELETE ALL THE STUDENTS
int getListOFStudentsRegistered(); // GET THE LIST OF STUDENTS
int deleteStudentAllData(); // DELETE STUDENT DATA
using namespace std;
int m = 0;
int total = 100;
void title()
{
cout << "\n";
cout << "\t\t\t\t\t";
cout << "\n";
cout << "\t\t\t\t -----------------------------------\n";
cout << "\t\t\t\t |Attendance Management Of Students|\n";
cout << "\t\t\t\t -----------------------------------\n";
cout << "\n\n";
cout << "\t\t\t\t";
}
void date()
{
time_t T = time(NULL);
struct tm tm = *localtime(&T);
cout << "\n\n\n";
printf("\t\t\t\t\t Date:%02d/%02d/%04d\n", tm.tm_mday, tm.tm_mon + 1, tm.tm_year + 1900);
}
int delay()
{
for (int i = 0; i < 3; i++)
{
cout << "\nSaving Records ...\n";
for (int ii = 0; ii < 20000; ii++)
{
for (int iii = 0; iii < 20000; iii++)
{
}
}
}
cout << "\nExiting Now ...";
for (int i = 0; i < 3; i++)
{
for (int ii = 0; ii < 20000; ii++)
{
for (int iii = 0; iii < 20000; iii++)
{
}
}
}
return 0;
}
void delay(unsigned int mseconds)
{
clock_t goal = mseconds + clock();
while (goal > clock())
;
}
// Login part for Admin
int adminLogin()
{
system("cls");
date();
title();
cout << "\n --------- Admin Login --------- \n\n";
string username;
string password;
cout << "\nEnter username: ";
cin >> username;
cout << "\nEnter password: ";
cin >> password;
if (username == "admin" && password == "admin@2")
{
adminView();
getchar();
delay();
}
else
{
cout << "\n\nError! Invalid Credentials ...";
cout << "\n\nPress any key for main menu ...";
getchar();
getchar();
}
return 0;
}
// Options for Admin
int adminView()
{
int goBack = 0;
while (1)
{
system("cls");
date();
title();
cout << "\n\n\nPlease select an option ...\n";
cout << "---------------------------\n";
cout << "\n1. Register a Student";
cout << "\n2. Check list of Students registered and view Roll No.";
cout << "\n3. Delete all registered Students";
cout << "\n4. Get list of Students registered by Username";
cout << "\n5. Delete Data of Students";
cout << "\n0. Go back <-\n";
int choice;
cout << "\nEnter your choice: ";
cin >> choice;
switch (choice)
{
case 1:
registerStudent();
break;
case 2:
checkListOfStudentsRegistered();
break;
case 3:
deleteAllStudents();
break;
case 4:
getListOFStudentsRegistered();
break;
case 5:
deleteStudentAllData();
break;
case 0:
goBack = 1;
break;
default:
cout << "\nInvalid choice. Please enter again.";
getchar();
}
if (goBack == 1)
{
break; // breaking the loop
}
}
return 0;
}
// Registering Student
int registerStudent()
{
cout << "\n ------ Form to Register Student ------ \n\n";
string name, username, password, rollno, address, fathersname, mothersname;
int total;
cout << "\nEnter Name: ";
cin >> name;
cout << "\nEnter Username: ";
cin >> username;
cout << "\nEnter Password: ";
cin >> password;
cout << "\nEnter Roll No.: ";
cin >> rollno;
getchar();
char add[100];
cout << "\nEnter Address: ";
cin.getline(add, 100);
cout << "\nEnter Father's Name: ";
cin >> fathersname;
cout << "\nEnter Mother's Name: ";
cin >> mothersname;
cout << "\nEnter initial number of atendance: ";
cin >> m;
// check if record already exist ...
ifstream read;
read.open("db.dat");
if (read)
{
int recordFound = 0;
string line;
while (getline(read, line))
{
if (line == username + ".dat")
{
recordFound = 1;
break;
}
}
if (recordFound == 1)
{
cout << "\nUsername already Registered. Please choose another username ...";
getchar();
getchar();
delay();
read.close();
return 0;
}
}
read.close();
ofstream out;
out.open("db.dat", ios::app);
out << username + ".dat"
<< "\n";
out.close();
ofstream out1;
string temp = username + ".dat";
out1.open(temp.c_str());
out1 << name << "\n";
out1 << username << "\n";
out1 << password << "\n";
out1 << rollno << "\n";
out1 << add << "\n";
out1 << fathersname << "\n";
out1 << mothersname << "\n";
out1 << m << "\n";
out1.close();
cout << "\nStudent Registered Successfully!!\n";
cout << "\nPlease press any key to continue ...";
getchar();
getchar();
return 0;
}
// Checking list of Students registered with roll no
int checkListOfStudentsRegistered()
{
cout << "\n --- Check list of Students registered and view Roll No.--- \n\n";
// check if record already exist ...
ifstream read;
read.open("db.dat");
if (read)
{
int recordFound = 0;
string line;
while (getline(read, line))
{
char name[100];
strcpy(name, line.c_str());
string filename = name;
cout << "\n"
<< filename;
int total_lines = 0;
ifstream read1;
read1.open(filename.c_str(), ios::app);
string line;
while (getline(read1, line))
{
++total_lines;
}
read1.close();
ifstream read;
read.open(filename.c_str(), ios::app);
string l;
if (read)
{
int line_no = 0;
while (line_no != total_lines && getline(read, l))
{
++line_no;
}
if (line_no == total_lines)
{
cout << " -> " << l << "\n";
}
read.close();
}
read.close();
}
}
else
{
cout << "\nNo Record found :(";
}
cout << "\nPlease any key to continue..";
getchar();
getchar();
return 0;
}
// Login part for Student
int studentLogin()
{
system("cls");
date();
title();
cout << "\n --------- Student Login --------- \n\n";
studentView();
return 0;
}
// Options for Student
int studentView()
{
string username, password;
cout << "\nEnter username: ";
cin >> username;
cout << "\nEnter password: ";
cin >> password;
int res = checkStudentCredentials(username, password);
if (res == 0)
{
cout << "\n\nInvalid Credentials!!";
cout << "\n\nPress any key for Main Menu ...";
getchar();
getchar();
return 0;
}
int goBack = 0;
while (1)
{
cout << "\n\nPlease select an option ...\n";
cout << "---------------------------\n";
cout << "\n1. Mark Attendance for Today";
cout << "\n2. Count my Attendance";
cout << "\n3. Send a leave application";
cout << "\n0. Go Back <-\n";
int choice;
cout << "\nEnter your choice: ";
cin >> choice;
switch (choice)
{
case 1:
markMyAttendance(username);
break;
case 2:
countMyAttendance(username);
break;
case 3:
sendLeaveApplication(username);
break;
case 0:
goBack = 1;
break;
default:
cout << "\nInvalid choice. Please enter again.";
getchar();
}
delay();
if (goBack == 1)
{
break; // breaking the loop
}
}
return 0;
}
// Checking information/credentials of Student
int checkStudentCredentials(string username, string password)
{
// read file line by line and check if username-password.dat exist?
// if it exist return 1 else 0
ifstream read;
read.open("db.dat");
int recordFound = 0;
if (read)
{
// the file exist, and open for input
string line;
string temp = username + ".dat";
cout << "\nFile name is: " << temp;
while (getline(read, line))
{
if (line == temp)
{
recordFound = 1;
}
}
}
read.close();
cout << "\n\nRecord found " << recordFound << "\n\nusername: " << username << "\n\npassword: " << password;
if (recordFound == 1)
{
ifstream read;
string filename = username + ".dat";
read.open(filename);
int line_number = 0;
string line;
while (line_number != 3 && getline(read, line))
{
cout << "\n\nLine " << line;
++line_number;
}
cout << "\n\n";
cout << "\n\n --- Credentials matched!! --- \n\n";
read.close();
if (password == line)
return 1;
else
return 0;
}
else
return 0;
}
// Marking attendance of Student
int markMyAttendance(string username)
{
cout << "\n\n --- Marking Attendance for today!! --- \n\n";
int total_lines = 0;
string filename = username + ".dat";
ifstream read;
read.open(filename);
string line;
while (getline(read, line))
{
++total_lines;
}
read.close();
ifstream read1;
read1.open(filename);
if (read1)
{
int line_no = 0;
while (line_no != total_lines && getline(read1, line))
{
++line_no;
}
if (line_no == total_lines)
{
cout << "\n\nInitial Attendance: " << line;
cout << "\n\nAttendance marked!!!";
int i;
istringstream(line) >> i;
i++;
cout << "\n\nTotal present: " << i;
cout << "\n\nPercentage of attendance: " << (i * 100 / total) << "%";
}
}
cout << "\n\nPlease press any key to continue ...";
getchar();
getchar();
return 0;
}
// Counting attendance of Student
int countMyAttendance(string username)
{
cout << "\n\n --- Counting attendance for today!! --- \n\n";
int total_lines = 0;
string filename = username + ".dat";
ifstream read;
read.open(filename);
string line;
while (getline(read, line))
{
++total_lines;
}
read.close();
ifstream read1;
read1.open(filename);
if (read1)
{
int line_no = 0;
while (line_no != total_lines && getline(read1, line))
{
++line_no;
}
if (line_no == total_lines)
{
cout << "\n\nInitial attendance: " << line;
int i;
istringstream(line) >> i;
i++;
cout << "\n\nAttendance Report - Total present: " << i;
}
}
cout << "\n\nPlease press any key to continue ...";
getchar();
getchar();
return 0;
}
// Sending leave for absence
int sendLeaveApplication(string username)
{
char add[1000];
cout << "\nWrite your application here: ";
getchar();
cin.getline(add, 1000);
time_t now = time(0);
tm *ltm = localtime(&now);
ofstream out;
out.open("application.dat", ios::app);
out << add << " -> " << ltm->tm_mday << "/" << 1 + ltm->tm_mon << "/" << 1900 + ltm->tm_year << " -> " << username << "\n";
out.close();
cout << "\nApplication successfully sent !!";
cout << "\n\nPlease press any key to continue..";
getchar();
return 0;
}
// Deleting all registered Students
int deleteAllStudents()
{
cout << "\n\n --- Deleting all registered students!! --- \n\n";
cout << "Deleting";
for (int process = 0; process < 25; process++)
{
delay(150);
printf(".");
}
remove("db.dat");
remove("application.dat");
cout << "\n\nAll registered Students deleted successfully...";
cout << "\n\nPlease press any key to continue ...";
getchar();
getchar();
return 0;
}
int getListOFStudentsRegistered()
{
DIR *di;
char *ptr1, *ptr2, name;
int retn, result;
struct dirent *dir;
di = opendir("."); // specify the directory name
if (di)
{
cout << "\n\n --- Lsit of Students registered by Username --- \n\n";
while ((dir = readdir(di)) != NULL)
{
ptr1 = strtok(dir->d_name, ".");
ptr2 = strtok(NULL, ".");
if (ptr2 != NULL)
{
retn = strcmp(ptr2, "dat");
if (retn == 0)
{
cout << "\n\n";
printf("%s\t", ptr1);
cout << "\n\n";
}
}
}
closedir(di);
}
cout << "\n\nPlease press any key to continue ...";
getchar();
getchar();
return 0;
}
// Delete data of Students
int deleteStudentAllData()
{
system("cls");
DIR *di;
char *ptr1, *ptr2;
char name[20];
int retn;
int status;
struct dirent *dir;
di = opendir("."); // specify the directory name
if (di)
{
cout << "\n\n --- Lsit of Students with data --- \n\n";
while ((dir = readdir(di)) != NULL)
{
ptr1 = strtok(dir->d_name, ".");
ptr2 = strtok(NULL, ".");
if (ptr2 != NULL)
{
retn = strcmp(ptr2, "dat");
if (retn == 0)
{
cout << "\n";
printf("%s", ptr1);
cout << ".dat";
cout << "\n\n";
}
}
}
closedir(di);
}
cout << "\n\nEnter the name of the file which is to be deleted: ";
cin >> name;
status = remove(name);
if (status == 0)
cout << "\nFile Deleted Successfully!";
else
{
cout << "\n\nError Occurred!";
cout << "\n\nPlease enter a valid data";
}
cout << "\n\nPlease press any key to continue ...";
getchar();
getchar();
return 0;
}
// Main part of the Program
int main(int argc, char **argv)
{
system("cls");
date();
cout << "\n";
cout << "\t\t\t\t -----------------------------------\n";
cout << "\t\t\t\t |Attendance Management Of Students|\n";
cout << "\t\t\t\t -----------------------------------\n";
cout << "\n\n";
cout << "\t\t\t\t";
cout << "Prepared By : Rajjit Laishram";
cout << "\n\n\t\t\t\tSchool Project : Attendance Management of Students";
cout << "\n\n\t\t\t\tPress Enter to continue......";
getchar();
printf("\n\n\t\t\t\tLoading");
for (int process = 0; process < 25; process++)
{
delay(150);
printf(".");
}
while (1)
{
system("cls");
date();
title();
cout << "\n";
cout << "1. Student Login\n";
cout << "2. Admin Login\n";
cout << "0. Exit\n";
int choice;
cout << "\nEnter your choice: ";
cin >> choice;
switch (choice)
{
case 1:
studentLogin();
break;
case 2:
adminLogin();
break;
case 0:
while (1)
{
system("cls");
cout << "\nAre you sure you want to exit? Y | N or y | n \n";
char ex;
cin >> ex;
if (ex == 'y' || ex == 'Y')
exit(0);
else if (ex == 'n' || 'N')
{
break;
}
else
{
cout << "\nInvalid Choice!!";
getchar();
}
}
break;
default:
cout << "\nInvalid Choice. Please enter again.";
getchar();
}
}
return 0;
}