-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefine.cpp
1488 lines (1203 loc) · 29.3 KB
/
define.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
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "header.h"
void Exit(mainclass MC)
{
MC.pushDataToFile();
delete []MC.Vbook;
delete []MC.Vstudent;
exit(0);
}
void howToUse(void)
{
int c = 0;
cout << "본 프로그램은 MySQL과 같은 DB를 사용하는 대신 일반적인 text 파일을 DB화시켜 제작한 프로그램입니다." << endl;
cout << "만약 귀하가 본 프로그램을 처음으로 사용하신다면, 프로그램 파일과 동일한 폴더에 \"" << DBFILE << "\"라는 이름의 파일이 생성됩니다." << endl;
cout << "해당 파일은 절대로 삭제하지 마시길 권고드립니다. 본 프로그램에서 사용하는 모든 데이터가 정해진 양식대로 해당 파일에 저장되어 있습니다." << endl;
cout << "또한 본 프로그램을 사용하는 중 콘솔 창의 우측 상단에 있는 X 버튼을 클릭하시거나 프로세스 강제 종료 등 비정상적인 방법으로 프로그램을 종료할 경우, 진행사항이 저장되지 않을 수 있습니다." << endl;
cout << "프로그램의 대부분의 영역에는 \"상위 메뉴로 이동\" 메뉴와 \"프로그램 종료\" 메뉴가 별도로 마련되어 있습니다." << endl;
cout << "프로그램을 종료하실 경우에는 해당 메뉴를 꼭 이용해서 저장 후 종료하시기 바랍니다." << endl;
cout << "본 프로그램을 이용해 주셔서 대단히 감사합니다." << endl;
cout << "본 프로그램을 사용하다가 문제가 생기거나, 프로그램의 기능에 대한 문의가 있을 경우 언제든 아래 연락처로 연락 주시기 바랍니다." << endl;
cout << "제작자 H.P. 010-2374-0484" << endl;
cout << "제작자 E-mail [email protected]" << endl;
getchar();
getchar();
CLS
}
void mainActivity(void)
{
mainclass MC;
MC.getDataFromFile();
cout << "DB 파일 Input 완료." << endl;
cout << "프로그램을 시작합니다." << endl;
// 메뉴 출력
string mainmenu = "========== 도서 관리 시스템 Ver 1.3 ===========\n1. 관리 모드\n2. 학생 모드\n3. 사용 시 주의사항(처음 이용 시 필독)\n0. 프로그램 종료\n";
int c=0;
while(1)
{
c = choice(mainmenu, 1, 2, 3, 0);
switch(c)
{
case 1:
mainmenu_1(MC);
break;
case 2:
mainmenu_2(MC);
break;
case 3:
howToUse();
break;
case 0:
mainmenu_0(MC);
break;
default:
CLS
cout << "ERROR ! (선택 값이 " << c << " 입니다. )" << endl;
Exit(MC);
break;
}
}
return;
}
void mainmenu_1(mainclass &MC)
{
char c[30];
int numberOfTeacher=0;
int select;
while(1)
{
string password;
cout << "관리자의 교직원번호를 입력하세요 : ";
getchar();
cin >> c;
getchar();
int i=0;
while(c[i])
{
numberOfTeacher*=10;
numberOfTeacher+=c[i]-'0';
i++;
}
// cin >> password; // 프로토 타입에서는 관리자 패스워드 기능을 사용하지 않음.
// if(MC.checkAdminPassword(password)
break;
}
CLS
string menu = "1. 학생 추가하기\n2. 도서 추가하기\n3. 학생 제거하기\n4. 도서 제거하기\n5. 전체 학생 정보 열람\n6. 전체 도서 정보 열람\n7. 학생 정보 수정\n9. 상위 메뉴로 돌아가기\n0. 프로그램 종료하기\n";
do
{
select = choice(menu, 1, 2, 3, 4, 5, 6, 7, 9, 0);
switch(select)
{
case 1:
submenu_1_1(MC);
break;
case 2:
submenu_1_2(MC);
break;
case 3:
submenu_1_3(MC);
break;
case 4:
submenu_1_4(MC);
break;
case 5:
submenu_1_5(MC);
break;
case 6:
submenu_1_6(MC);
break;
case 7:
submenu_1_7(MC);
break;
case 9:
submenu_1_9(MC);
return;
break;
case 0:
submenu_1_0(MC);
break;
default:
CLS
cout << "ERROR ! (선택 값이 " << c << " 입니다. )" << endl;
Exit(MC);
break;
}
}while(select!=9);
return;
}
void mainmenu_2(mainclass MC)
{
char c[30];
int indexOfStudent=0;
int i=0;
for(i=0; i<3; i++)
{
int studentNumber=0;
cout << "9. 상위 메뉴로 이동" << endl;
cout << "0. 프로그램 종료" << endl;
cout << "학생의 학번을 입력하세요 : ";
cin >> c;
int j=0;
while(c[j])
{
studentNumber*=10;
studentNumber+=c[j]-'0';
j++;
}
if(studentNumber==9)
return;
if(studentNumber==0)
Exit(MC);
indexOfStudent=MC.searchStudentByStudentNumber(studentNumber);
if(indexOfStudent!=-1)
break;
else
{
CLS
cout << "존재하지 않는 학번이거나 잘못된 값을 입력하셨습니다. 저희 학교의 학번은 8자리의 숫자로 이루어져 있습니다." << endl;
}
}
if(i>=3)
{
cout << "자신의 학번을 분실하셨다면, 관리자에게 문의하시기 바랍니다. 감사합니다." << endl;
return;
}
if(!MC.Vstudent[indexOfStudent].checkPassword())
return;
cout << "로그인에 성공했습니다." << endl;
CLS
MC.studentMode(indexOfStudent);
return;
}
void mainmenu_0(mainclass MC)
{
CLS
cout << "프로그램을 종료합니다." << endl;
Exit(MC);
return;
}
void submenu_1_1(mainclass &MC) // 학생 추가하기
{
CLS
char c[30];
int numberOfStudent;
string studentName;
int i;
int count=3;
while(count)
{
cout << "9. 상위 메뉴로 이동" << endl;
cout << "0. 프로그램 종료" << endl;
cout << "학생의 학번을 입력하세요 : ";
i=0;
numberOfStudent=0;
cin >> c;
CLS
while(c[i])
{
numberOfStudent*=10;
numberOfStudent+=c[i]-'0';
i++;
}
if(numberOfStudent==9)
return;
if(numberOfStudent==0)
Exit(MC);
cout << "학생의 이름을 입력하세요 : ";
cin >> studentName;
if(MC.addStudent(numberOfStudent, studentName))
return;
else
cout << endl;
count--;
}
CLS
cout << "학번을 생성할 수 없습니다." << endl;
return;
}
void submenu_1_2(mainclass &MC)
{
CLS
string bookName;
int bookNumber;
char c[30];
cout << "추가할 도서명을 입력하세요(띄어쓰기 불가) : ";
cin >> bookName;
getchar();
int i;
while(1)
{
bookNumber=0;
CLS
cout << "추가할 도서의 도서번호를 입력하세요. 자동으로 부여되길 원하신다면 \"-1\"을 입력하세요 : ";
cin >> c;
if(!strcmp(c, "-1"))
{
bookNumber=MC.lastNumberOfBook+1;
MC.lastNumberOfBook++;
MC.addBook(bookNumber, bookName);
return;
}
i=0;
bookNumber=0;
while(c[i])
{
bookNumber*=10;
if(c[i]-'0'<0 || c[i]>9)
{
cout << "잘못된 번호입니다." << endl;
strcpy(c, "ERROR");
break;
}
bookNumber+=c[i]-'0';
i++;
}
if(!strcmp(c, "ERROR"))
continue;
if(bookNumber>MC.lastNumberOfBook)
MC.lastNumberOfBook=bookNumber+1;
MC.addBook(bookNumber, bookName);
return;
}
return;
}
void submenu_1_3(mainclass &MC) // 학생 삭제하기
{
CLS
int i=0;
char c[30];
int select;
int t=0;
while(1)
{
t=0;
for(i=0; (i>8 &&i<=MC.totalStudent) || (i>=0 && i<MC.totalStudent); i++)
{
if(i==8)
{
t=1;
cout << "9. ****** 아래 참조 ******" << endl;
continue;
}
cout << i+1 << ". " << MC.Vstudent[i-t].getName() << endl;
cout << " " << MC.Vstudent[i-t].getNumber() << endl;
}
cout << "9. 상위 메뉴로 이동" << endl;
cout << "0. 프로그램 종료" << endl;
cout << "삭제할 학생의 번호를 입력하세요 : ";
cin >> c;
CLS
i=0;
select=0;
while(c[i])
{
select*=10;
select+=c[i]-'0';
i++;
}
if(select==9)
return;
if(select==0)
Exit(MC);
if(select-1>=0 && select-1<MC.totalStudent && select<9)
{
string check="정말로 삭제하시겠습니까 ? \n1. 예\n2. 아니오\n";
getchar();
int selectChoice=choice(check, 1, 2);
if(selectChoice==1)
MC.deleteStudent(select-1);
break;
}
if(select>9 && select-1<=MC.totalStudent)
{
string check="정말로 삭제하시겠습니까 ? \n1. 예\n2. 아니오\n";
getchar();
int selectChoice=choice(check, 1, 2);
if(selectChoice==1)
MC.deleteStudent(select-1-t);
break;
}
cout << "잘못된 선택입니다." << endl;
}
return;
}
void submenu_1_4(mainclass &MC) // 도서 삭제 함수
{
CLS
int i=0;
char c[30];
int select;
int t=0;
while(1)
{
t=0;
for(i=0; (i>8 &&i<=MC.totalBook) || (i>=0 && i<MC.totalBook); i++)
{
if(i==8)
{
t=1;
cout << "9. ****** 아래 참조 ******" << endl;
continue;
}
cout << i+1 << ". " << MC.Vbook[i-t].getName() << endl;
cout << " ";
if(MC.Vbook[i-t].checkBorrowFlag()==-1)
cout << "대출 없음" << endl;
else
cout << MC.Vstudent[MC.Vbook[i-t].checkBorrowFlag()].getName() << "학생이 대출" << endl;
}
cout << "9. 상위 메뉴로 이동" << endl;
cout << "0. 프로그램 종료" << endl;
cout << "삭제할 도서의 번호를 입력하세요 : ";
cin >> c;
CLS
i=0;
select=0;
while(c[i])
{
select*=10;
select+=c[i]-'0';
i++;
}
if(select==9)
return;
if(select==0)
Exit(MC);
if(select-1>=0 && select-1<MC.totalBook && select<9)
{
string check="정말로 삭제하시겠습니까 ? \n1. 예\n2. 아니오\n";
getchar();
int selectChoice=choice(check, 1, 2);
if(selectChoice==1)
MC.deleteBook(select-1);
break;
}
if(select>9 && select-1<=MC.totalBook)
{
string check="정말로 삭제하시겠습니까 ? \n1. 예\n2. 아니오\n";
getchar();
int selectChlice=choice(check, 1, 2);
if(selectChlice==1)
MC.deleteBook(select-1-t);
break;
}
cout << "잘못된 선택입니다." << endl;
}
return;
}
void submenu_1_5(mainclass MC)
{
CLS
cout << "학생 수 : " << MC.totalStudent << endl;
int i=0;
for(i=0; i<MC.totalStudent; i++)
{
cout << "학생명 : " << MC.Vstudent[i].getName() << endl;
cout << "학번 : " << MC.Vstudent[i].getNumber() << endl;
cout << "블럭 여부 : ";
if(MC.Vstudent[i].getBlock()==true)
cout << "BLOCKED" << endl;
else
cout << "UNBLOCKED" << endl;
cout << "빌린 도서 수 : " << MC.Vstudent[i].getNumberOfBorrowedBook() << endl;
for(int j=0; j<MC.Vstudent[i].getNumberOfBorrowedBook(); j++)
cout << "\t" << MC.Vbook[MC.Vstudent[i].indexOfBorrowedBook[j]].getName() << endl;
cout << endl;
}
return;
}
void submenu_1_6(mainclass MC)
{
CLS
cout << "전체 도서 수 : " << MC.totalBook << endl;
int i=0;
for(i=0; i<MC.totalBook; i++)
{
cout << "도서 번호 : " << MC.Vbook[i].getNumber() << endl;
cout << "도서명 : " << MC.Vbook[i].getName() << endl;
cout << "\t";
if(MC.Vbook[i].checkBorrowFlag()==-1)
cout << "대출 없음";
else
cout << MC.Vstudent[MC.Vbook[i].checkBorrowFlag()].getName() << " 학생이 대출";
cout << endl;
cout << endl;
}
return;
}
void submenu_1_7(mainclass &MC)
{
CLS
int t=0;
char c[30];
int i;
int select;
string name;
bool block;
while(1)
{
t=0;
for(i=0; (i>8 &&i<=MC.totalStudent) || (i>=0 && i<MC.totalStudent); i++)
{
if(i==9)
{
t=1;
cout << "9. ****** 아래 참조 ******" << endl;
continue;
}
cout << i+1 << ". " << MC.Vstudent[i-t].getName() << endl;
cout << " " << MC.Vstudent[i-t].getNumber() << endl;
}
cout << "9. 상위 메뉴로 이동" << endl;
cout << "0. 프로그램 종료" << endl;
cout << "정보를 수정할 학생의 번호를 입력하세요 : ";
cin >> c;
CLS
i=0;
select=0;
while(c[i])
{
select*=10;
select+=c[i]-'0';
i++;
}
if(select==9)
return;
if(select==0)
Exit(MC);
if(select-1>=0 && select-1<MC.totalStudent && select<9)
{
select--;
break;
}
if(select>9 && select-1<=MC.totalStudent)
{
select-=1+t;
break;
}
cout << "잘못된 선택입니다." << endl;
}
cout << MC.Vstudent[select].getName() << " 학생의 정보를 수정합니다." << endl;
string modifyMenu = "1. 학생 이름 변경\n2. 학생 블럭 상태 변경\n9. 상위 메뉴로 이동\n0. 프로그램 종료\n";
int selectChoice=choice(modifyMenu, 1, 2, 9, 0);
switch(selectChoice)
{
case 0:
Exit(MC);
break;
case 9:
break;
case 1:
cout << "변경할 이름을 입력하세요 : ";
cin >> name;
CLS
cout << MC.Vstudent[select].getName();
MC.Vstudent[select].setName(name);
cout << " 학생의 이름이 " << MC.Vstudent[select].getName() << " 으로 변경되었습니다." << endl;
break;
case 2:
cout << "현재 " << MC.Vstudent[select].getName() << " 학생은 ";
if(MC.Vstudent[select].getBlock())
{
cout << "블럭 상태입니다. ";
string blockmenu = "블럭을 해제하시겠습니까 ? \n1. 예. 해제합니다.\n9. 상위 메뉴로 돌아가기.\n";
selectChoice = choice(blockmenu, 1, 9);
if(selectChoice==1)
{
MC.Vstudent[select].setBlock(false);
return;
}
return;
}
else
{
cout << "블럭 상태가 아닙니다. ";
string blockmenu = "블럭 상태로 전환하시겠습니까 ? \n1. 예. 블럭 상태로 전환합니다.\n9. 상위 메뉴로 돌아가기.\n";
selectChoice = choice(blockmenu, 1, 9);
if(selectChoice==1)
{
MC.Vstudent[select].setBlock(true);
return;
}
return;
}
}
return;
}
void submenu_1_9(mainclass MC)
{
CLS
cout << "상위 메뉴로 이동하였습니다." << endl;
return;
}
void submenu_1_0(mainclass MC)
{
CLS
cout << "프로그램을 종료합니다." << endl;
Exit(MC);
return;
}
int choice(string menu, int a, int b, int c, int d, int e, int f, int g, int h, int i, int j, int k, int l, int m, int n)
{
int select;
char selectChar[30];
int count;
while(1)
{
select=0;
cout << menu;
cout << "원하는 번호를 선택하세요 : ";
cin >> selectChar;
count=0;
while(selectChar[count])
{
select*=10;
select+=selectChar[count]-'0';
count++;
}
if( select==a || (select==b && b!=-1) || (select==c && c!=-1) || (select==d && d!=-1) || (select==e && e!=-1) || (select==f && f!=-1) || (select==g && g!=-1) || (select==h && h!=-1) || (select==i && i!=-1) || (select==j && j!=-1) || (select==k && k!=-1) || (select==l && l!=-1) || (select==m && m!=-1) || (select==n && n!=-1) )
{
CLS
return select;
}
else
{
CLS
cout << "잘못된 선택입니다." << endl;
}
}
}
ifstream openInputFile(const string fileName)
{
ifstream fin;
cout << "Input 파일 연결 중 . . ." << endl;
fin.open(fileName);
cout << "Input 파일 생성 완료. 파일 명 " << fileName << endl;
return fin;
}
void closeInputFile(ifstream& fin)
{
cout << "Input 파일 닫는 중 . . ." << endl;
fin.close();
cout << "Input 파일 닫기 완료" << endl;
return;
}
ofstream openOutputFile(const string fileName)
{
ofstream fout;
cout << "Output 파일 생성 중 . . ." << endl;
fout.open(fileName);
cout << "Output 파일 생성 완료. 파일 명 " << fileName << endl;
return fout;
}
void closeOutputFile(ofstream& fout)
{
cout << "Output 파일 닫는 중 . . ." << endl;
fout.close();
cout << "Output 파일 닫기 완료" << endl;
return;
}
void pushIntArray(int* arr, const int index, const int arrSize) // (배열, 지점, 배열 크기)를 인자로 받아 배열의 해당 지점에 있는 값을 삭제하고 그 뒤의 모든 값을 한 칸씩 당긴 후 마지막 칸에 -1을 채워넣기
{
int i=0;
for(i=index; i<arrSize-1; i++)
arr[i]=arr[i+1];
arr[arrSize-1] = -1;
}
void mainclass::getDataFromFile()
{
ifstream fin = openInputFile(DBFILE);
int TotalStudent;
int TotalBook;
string tempName;
int tempNumber;
int tempNumberOfBorrowedBook;
int tempIndexOfBorrowedBook;
int tempPassword;
bool tempBlock;
int tempBorrowFlag;
fin >> TotalStudent;
totalStudent=TotalStudent;
lastNumberOfBook=-1;
Vstudent = new student[TotalStudent];
cout << "필요 변수 선언 완료" << endl;
/*
데이터 파일 저장 양식
N(학생 수)
i번째 학생 이름
학번
빌린 책 수
암호화된 비밀번호
블럭 여부(true/false)
빌린 책 인덱스
j번째 책
j+1번째 책
...
M(도서 수)
i번째 도서 이름
도서 번호
대출 플래그
...
*/
for(int i=0; i<TotalStudent; i++)
{
fin >> tempName >> tempNumber >> tempNumberOfBorrowedBook >> tempPassword >> tempBlock;
cout << i+1 << "번째 임시 변수로 파일로부터 입력 완료" << endl;
Vstudent[i].indexOfBorrowedBook = new int[tempNumberOfBorrowedBook];
Vstudent[i].setName(tempName);
Vstudent[i].setNumber(tempNumber);
Vstudent[i].setNumberOfBorrowedBook(tempNumberOfBorrowedBook);
Vstudent[i].setSecurePassword(tempPassword);
Vstudent[i].justSetBlock(tempBlock);
for(int j=0; j<tempNumberOfBorrowedBook; j++)
{
fin >> tempIndexOfBorrowedBook;
Vstudent[i].indexOfBorrowedBook[j] = tempIndexOfBorrowedBook;
}
cout << i+1 << "번째 학생 데이터 입력 완료" << endl;
}
fin >> TotalBook;
totalBook = TotalBook;
Vbook = new book[TotalBook];
for(int i=0; i<TotalBook; i++)
{
fin >> tempName >> tempNumber >> tempBorrowFlag;
if(lastNumberOfBook<tempNumber)
lastNumberOfBook=tempNumber;
cout << i+1 << "번째 임시 변수로 파일로부터 입력 완료" << endl;
Vbook[i].setName(tempName);
Vbook[i].setNumber(tempNumber);
Vbook[i].setBorrowFlag(tempBorrowFlag);
cout << i+1 << "번째 도서 데이터 입력 완료" << endl;
}
closeInputFile(fin);
CLS
}
void mainclass::pushDataToFile()
{
ofstream fout = openOutputFile(DBFILE);
/*
데이터 파일 저장 양식
N(학생 수)
i번째 학생 이름
학번
빌린 책 수
암호화된 비밀번호
블럭 여부(true/false)
빌린 책 인덱스
j번째 책
j+1번째 책
...
M(도서 수)
i번째 도서 이름
도서 번호
대출 플래그
...
*/
fout << totalStudent << endl;
for(int i=0; i<totalStudent; i++)
{
fout << Vstudent[i].getName() << endl;
fout << Vstudent[i].getNumber() << endl;
fout << Vstudent[i].getNumberOfBorrowedBook() << endl;
fout << Vstudent[i].getPassword() << endl;
fout << Vstudent[i].getBlock() << endl;
for(int j=0; j<Vstudent[i].getNumberOfBorrowedBook(); j++)
fout << Vstudent[i].indexOfBorrowedBook[j] << endl;
}
fout << totalBook << endl;
for(int i=0; i<totalBook; i++)
{
fout << Vbook[i].getName() << endl;
fout << Vbook[i].getNumber() << endl;
fout << Vbook[i].checkBorrowFlag() << endl;
}
closeOutputFile(fout);
}
int mainclass::borrowBook(const int indexOfBorrowBook, const int indexOfBorrowStudent) // 미완성*********
{
CLS
if(Vbook[indexOfBorrowBook].checkBorrowFlag()==-1) // 대출 가능
{
Vbook[indexOfBorrowBook].setBorrowFlag(indexOfBorrowStudent);
int* tempArray = new int[Vstudent[indexOfBorrowStudent].getNumberOfBorrowedBook()+1];
for(int i = 0; i < Vstudent[indexOfBorrowStudent].getNumberOfBorrowedBook(); i++)
tempArray[i] = Vstudent[indexOfBorrowStudent].indexOfBorrowedBook[i];
if(Vstudent[indexOfBorrowStudent].getNumberOfBorrowedBook()!=0)
{
// cout << "본 학생의 빌린 책 수가 " << Vstudent[indexOfBorrowStudent].getNumberOfBorrowedBook() << "개이므로 if문 진입 성공" << endl;
delete []Vstudent[indexOfBorrowStudent].indexOfBorrowedBook;
}
Vstudent[indexOfBorrowStudent].setNumberOfBorrowedBook(Vstudent[indexOfBorrowStudent].getNumberOfBorrowedBook()+1);
Vstudent[indexOfBorrowStudent].indexOfBorrowedBook = new int[Vstudent[indexOfBorrowStudent].getNumberOfBorrowedBook()];
for(int i = 0; i < Vstudent[indexOfBorrowStudent].getNumberOfBorrowedBook(); i++)
Vstudent[indexOfBorrowStudent].indexOfBorrowedBook[i] = tempArray[i];
delete []tempArray;
Vstudent[indexOfBorrowStudent].indexOfBorrowedBook[Vstudent[indexOfBorrowStudent].getNumberOfBorrowedBook()-1]=indexOfBorrowBook;
cout << Vbook[indexOfBorrowBook].getName() << " 도서를 성공적으로 대출하였습니다. 반납일은 (미구현)까지입니다." << endl;
return 1;
}
else if(Vbook[indexOfBorrowBook].checkBorrowFlag()==indexOfBorrowStudent)
{
cout << "이미 \"" << Vbook[indexOfBorrowBook].getName() << "\" 도서를 대출하셨습니다. 저희 도서관에서 같은 도서를 두 권 대출하실 수 없습니다." << endl;
return 0;
}
else
{
cout << "\"" <<Vbook[indexOfBorrowBook].getName() << "\" 도서는 다른 회원이 이미 대출하셨습니다. (미구현) 이후에 다시 방문해 주세요." << endl;
return 0;
}
}
void mainclass::borrowMenu(const int indexOfBorrowStudent)
{
CLS
int i=0;
char c[30];
int t=0;
while(1)
{
for(i=0; i<totalBook || (i>8 && i<=totalBook); i++)
{
if(i==8)
{
cout << "9. ****** 아래 참조 ******" << endl;
t=1;
continue;
}
cout << i+1 << ". " << Vbook[i-t].getName() << " - ";
if(Vbook[i-t].checkBorrowFlag()==-1)
cout << "대출 가능" << endl;
else
cout << "대출 불가" << endl;
}
cout << "0. 프로그램 종료\n9. 상위 메뉴로 이동" << endl;
cout << "대출을 원하는 도서의 번호를 입력하세요 : ";
cin >> c;
getchar();
i=0;
int r=0;
while(c[i])
{
r*=10;
r+=c[i]-'0';
i++;
}
CLS
if(r==0)
Exit(*this);
if(r==9)
return;
if(r>0 && r<=8)
{
if(borrowBook(r-1, indexOfBorrowStudent))
break;
t=0;
}
else if(r>8 && r<=totalBook+1)
{
if(borrowBook(r-1-t, indexOfBorrowStudent))
break;
t=0;
}
else
{
cout << "잘못된 선택입니다." << endl;
t=0;
break;
}
}
return;
}
int mainclass::returnBook(const int indexOfBorrowBook, const int indexOfBorrowStudent)
{
if(Vbook[Vstudent[indexOfBorrowStudent].indexOfBorrowedBook[indexOfBorrowBook]].checkBorrowFlag()!=indexOfBorrowStudent)
{
cout << Vstudent[indexOfBorrowStudent].getName() << " 학생은 \"" << Vbook[Vstudent[indexOfBorrowStudent].indexOfBorrowedBook[indexOfBorrowBook]].getName() << "\" 도서를 대출하지 않으셨습니다. 반납할 수 없습니다." << endl;
return 0;
}