generated from NgdHung31/Course-Registration-System
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSource1_5cpp
606 lines (547 loc) · 12.8 KB
/
Source1_5cpp
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
#include "Header1_5.h"
void register_a_account()
{
string username, password;
cout << "Sign up a username - (username should be a ID Student Number) : ";
cin >> username;
cout << "Sign up a password: ";
cin >> password;
ofstream f;
f.open("D:\\" + username + "txt");
f << username << endl << password;
f.close();
}
bool check_loggin(string username, string password)
{
string ckuser, ckpassword;
ifstream f("D:\\" + username + ".txt");
getline(f, ckuser);
getline(f, ckpassword);
if ((ckuser == username) && (ckpassword == password))
{
return true;
}
else
{
return false;
}
}
void change_password()
{
string username, password, ckuser, ckpassword, chpassword, chpassword1;
cout << "Input username: ";
cin >> username;
cout << "Input the old password: ";
cin >> password;
ifstream f("D:\\" + username + ".txt");
getline(f, ckuser);
getline(f, ckpassword);
if ((ckuser == username) && (ckpassword == password))
{
cout << "Input the password which you want to change: ";
cin >> chpassword;
cout << endl << "Input the password which you want to change again!: ";
cin >> chpassword1;
if (chpassword == chpassword1)
{
ofstream f1;
f1.open("D:\\" + username + ".txt");
f1 << username << endl << chpassword;
f1.close();
}
}
else
{
cout << "Wrong username or password. Please try again!";
}
}
//Kiem tra ten
bool check_name(char* name1, char* name2)
{
char temp1[20], temp2[20];
int i = 0, flag = 1;
strcpy(temp1, name1);
strcpy(temp2, name2);
while (temp1[i] != '\0') {
if (temp1[i] != temp2[i]) {
flag = 0;
break;
}
i++;
}
if (flag == 1)
return true;
else
return false;
}
//Kiểm tra ngày tháng năm sinh
bool check_date_of_birth(string day, string month, string year)
{
if ((stoi(year) % 4 == 0 && stoi(year) % 100 != 0) || stoi(year) % 400 == 0) // nam nhuan
{
if ((stoi(month) == 1 || stoi(month) == 3 || stoi(month) == 5 || stoi(month) == 7 || stoi(month) == 8 || stoi(month) == 10 || stoi(month) == 12) && (stoi(day) > 0 && stoi(day) < 31))
{
return true;
}
if ((stoi(month) == 4 || stoi(month) == 6 || stoi(month) == 9 || stoi(month) == 11) && (stoi(day) > 0 && stoi(day) < 30))
{
return true;
}
if (stoi(month) == 2 && (stoi(day) > 0 || stoi(day) < 29))
{
return true;
}
return false;
}
else // khong phai nam nhuan
{
if ((stoi(month) == 1 || stoi(month) == 3 || stoi(month) == 5 || stoi(month) == 7 || stoi(month) == 8 || stoi(month) == 10 || stoi(month) == 12) && (stoi(day) > 0 && stoi(day) < 32))
{
return true;
}
if ((stoi(month) == 4 || stoi(month) == 6 || stoi(month) == 9 || stoi(month) == 11) && (stoi(day) > 0 && stoi(day) < 31))
{
return true;
}
if (stoi(month) == 2 && (stoi(day) > 0 && stoi(day) < 30))
{
return true;
}
return false;
}
}
void Enter_the_name(char*& name)
{
cin.ignore();
cout << "Enter the name: ";
char temp_name[20];
cin.getline(temp_name, 20, '\n');
name = new char[strlen(temp_name) + 1];
strcpy(name, temp_name);
}
//Tạo sinh viên
Student* info_student()
{
Student* st = new Student;
cout << "\tEnter the NO: ";
cin >> st->no;
cout << "\tEnter the student ID: ";
cin >> st->student_id;
cin.ignore();
cout << "\tEnter the first name: ";
getline(cin, st->first_name);
cout << "\tEnter the last name: ";
getline(cin, st->last_name);
cout << "\tEnter the gender: ";
getline(cin, st->gender);
do {
cout << "\tEnter the date of birth:\n";
cout << "\t\tDay: ";
getline(cin, st->day_of_birth);
cout << "\t\tMonth: ";
getline(cin, st->month_of_birth);
cout << "\t\tYear: ";
getline(cin, st->year_of_birth);
if ((check_date_of_birth(st->day_of_birth, st->month_of_birth, st->year_of_birth) == false))
{
cout << "Fault! Please re-enter!";
}
} while ((check_date_of_birth(st->day_of_birth, st->month_of_birth, st->year_of_birth) == false));
cout << "\tEnter the social ID: ";
getline(cin, st->social_id);
return st;
}
//Tạo một node sinh viên
Node* create_node(Student* data)
{
Node* node = new Node;
if (node == NULL)
{
cout << "Cannot allocate!";
return NULL;
}
node->data = data;
node->next = NULL;
return node;
}
//Tạo một node lớp
Node_class* create_node_class(Class* data)
{
Node_class* node_class = new Node_class;
node_class->data = data;
node_class->next = NULL;
return node_class;
}
//Tạo một năm học
void create_school_year(School_year*& sy)
{
sy->head = sy->tail = NULL;
cout << "Create a school year (2020-2021, for example): \n";
do
{
cout << "\tThe beginning of the school year: ";
cin >> sy->the_beginning_year;
cout << "\tThe end of the school year: ";
cin >> sy->the_end_year;
if (sy->the_beginning_year < 2000 || sy->the_end_year < 2000 || sy->the_beginning_year == sy->the_end_year)
{
cout << "Fault!Please re-enter" << endl;
}
} while (sy->the_beginning_year < 2000 || sy->the_end_year < 2000 || sy->the_beginning_year == sy->the_end_year);
}
//Tạo một lớp học
void create_class(School_year*& school,Class*& classes)
{
classes->head = classes->tail = NULL;
cin.ignore();
cout << "Create several classes for 1st year students: ";
char temp[20];
cin.getline(temp, 20, '\n');
classes->class_name = new char[strlen(temp) + 1];
strcpy(classes->class_name, temp);
}
//Thêm lớp học vào năm học
void Add_class_to_school_year(School_year*& sy, Class* cl)
{
Node_class* node_class = create_node_class(cl);
if (sy->head == NULL)
{
sy->head = node_class;
}
else {
Node_class* temp = sy->head;
while (temp->next != NULL)
{
temp = temp->next;
}
temp->next = node_class;
}
}
//Them sinh vien vao lop
void Add_student_to_class(Class*& cl, Student* st)
{
Node* node = create_node(st);
if (cl->head == NULL)
{
cl->head = node;
}
else {
Node* temp1 = cl->head;
while (temp1->next != NULL)
{
temp1 = temp1->next;
}
temp1->next = node;
}
}
void Input_class(School_year*& sy)
{
Class* classes = new Class;
create_class(sy, classes);
Add_class_to_school_year(sy, classes);
}
//Đọc file csv vào một danh sách
void read_to_file(char* file_name, School_year*& sy, char* name)
{
ifstream file(file_name);
Student* st = new Student[10];
if (!file.is_open())
{
cout << "Cannot read file!";
}
else
{
for(Node_class* temp = sy->head;temp!=NULL;temp=temp->next)
{
if (check_name(temp->data->class_name, name)) {
int i = 0;
while (file.good())
{
getline(file, (st + i)->no, ',');
getline(file, (st + i)->student_id, ',');
getline(file, (st + i)->first_name, ',');
getline(file, (st + i)->last_name, ',');
getline(file, (st + i)->gender, ',');
getline(file, (st + i)->day_of_birth, ',');
getline(file, (st + i)->month_of_birth, ',');
getline(file, (st + i)->year_of_birth, ',');
getline(file, (st + i)->social_id, '\n');
Add_student_to_class(temp->data,(st+i));
i++;
}
cout << "A large number of students have joined the class\n";
}
}
}
file.close();
}
void Input_student_to_class(School_year*& school)
{
char* name;
Enter_the_name(name);
Node_class* temp = school->head;
int k = 0;
while (temp != NULL)
{
if (check_name(temp->data->class_name, name))
{
k = 1;
Student* st = info_student();
Add_student_to_class(temp->data, st);
cout << "The student has become a part of the class.\n";
}
temp = temp->next;
}
if (k == 0)
cout << "Students cannot be added to the class. Classroom does not exist! \n";
}
//Xuất thông tin một sinh viên
void ouput_info_student(Student* st)
{
cout << "\t\tNO: " << st->no << endl;
cout << "\t\tStudent ID: " << st->student_id << endl;
cout << "\t\tThe student name: " << st->first_name << " " << st->last_name << endl;
cout << "\t\tGender: " << st->gender << endl;
cout << "\t\tDate of birth: " << st->day_of_birth << "/" << st->month_of_birth << "/" << st->year_of_birth << endl;
cout << "\t\tSocial ID: " << st->social_id;
}
const char* check_order(int n)
{
if (n == 1)
{
return "st";
}
else if (n == 2)
{
return "nd";
}
else if (n == 3)
{
return "rd";
}
else
{
return "th";
}
}
//xuất thông tin danh sách 1 lớp
void output_info_class(Class* cl)
{
cout << "\tThe name class: " << cl->class_name;
Node* temp = cl->head;
int i = 1;
while (temp != NULL)
{
if (temp->next != NULL)
{
const char* ch = check_order(i);
cout << "\n\t" << i << ch << " student" << endl;
ouput_info_student(temp->data);
temp = temp ->next;
cout << endl;
i++;
}
}
}
//In danh sách 1 lớp theo tên, người dùng nhập vào trước đó
void print_info_1_class(School_year* sy , char* name)
{
int k = 0;
for (Node_class* temp = sy->head; temp != NULL; temp = temp->next)
{
if (check_name(temp->data->class_name, name) == true)
{
k = 1;
cout << "\t\tThe name class: " << temp->data->class_name << endl;
Node* temp1 = temp->data->head;
int j = 1;
while (temp1 != NULL)
{
const char* ch = check_order(j);
cout << "\n\t" << j << ch << " student" << endl;
ouput_info_student(temp1->data);
temp1 = temp1->next;
cout << endl;
j++;
}
}
}
if (k == 0)
{
cout << "Can not see the list student of class to look for. Classroom does not exist!";
}
}
void print_all_class(School_year* sy)
{
int i = 1;
cout << "--------------------THE INFORMATION CLASS OF THE SCHOOL YEAR--------------------\n";
cout << "\tTHE BEGINNING YEAR: " << sy->the_beginning_year << endl;
cout << "\tTHE ENDING YEAR: " << sy->the_end_year << endl<<endl;
for (Node_class* temp = sy->head; temp != NULL; temp = temp->next)
{
cout << "-----------------The class " << i << " -------------------\n";
cout << "\t\tThe name class: " << temp->data->class_name << endl;
Node* temp1 = temp->data->head;
int j = 1;
while (temp1 != NULL)
{
const char* ch = check_order(j);
cout << "\n\t" << j << ch << " student" << endl;
ouput_info_student(temp1->data);
temp1 = temp1->next;
cout << endl;
j++;
}
i++;
}
}
void remove_Head(School_year*& sy)
{
if (sy->head == NULL)
{
return;
}
else
{
Node_class* p = sy->head;
sy->head = sy->head->next;
delete p;
}
}
void remove_Tail(School_year*& sy)
{
if (sy->head == NULL)
{
return;
}
if (sy->head->next == NULL)
{
remove_Head(sy);
}
else
{
for (Node_class* k = sy->head; k != NULL; k = k->next)
{
if (k->next == sy->tail)
{
delete sy->tail;
k->next = NULL;
sy->tail = k;
}
}
}
}
bool remove_class(School_year*& sy)
{
char* name;
Enter_the_name(name);
Node_class* temp1 = new Node_class;
for (Node_class* temp = sy->head; temp != NULL; temp = temp->next)
{
if (check_name(temp->data->class_name, name))
{
if (temp == sy->head)
{
remove_Head(sy);
return true;
}
else if (temp == sy->tail)
{
remove_Tail(sy);
return true;
}
else
{
temp1->next = temp->next;
delete temp;
temp = temp1;
return true;
}
}
temp1 = temp;
}
return false;
}
void remove_Head(Class*& cl)
{
if (cl->head == NULL)
{
return;
}
else
{
Node* p = cl->head;
cl->head = cl->head->next;
delete p;
}
}
void remove_Tail(Class*& cl)
{
if (cl->head == NULL)
{
return;
}
if (cl->head->next == NULL)
{
remove_Head(cl);
}
else
{
for (Node* k = cl->head; k != NULL; k = k->next)
{
if (k->next == cl->tail)
{
delete cl->tail;
k->next = NULL;
cl->tail = k;
}
}
}
}
bool remove_student(School_year*& sy)
{
char* name;
Enter_the_name(name);
for (Node_class* temp = sy->head; temp != NULL; temp = temp->next)
{
if (check_name(temp->data->class_name, name))
{
Class* cl = temp->data;
Node* temp2 = new Node;
char* firstname;
cout << "The first name_";
Enter_the_name(firstname);
char* lastname;
cout << "The last name_";
Enter_the_name(lastname);
for (Node* temp1 = cl->head; temp1 != NULL; temp1 = temp1->next)
{
if (temp1->data->first_name.compare(firstname)==0)
{
if (temp1->data->last_name.compare(lastname)==0)
{
if (temp1 == cl->head)
{
remove_Head(cl);
return true;
}
else if (temp1 == cl->tail)
{
remove_Tail(cl);
return true;
}
else
{
temp2->next = temp1->next;
delete temp1;
temp1 = temp2;
return true;
}
}
}
temp2 = temp1;
}
return false;
}
}
}