-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLibrary Mangement System.cpp
1858 lines (1699 loc) · 54.8 KB
/
Library Mangement System.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<iostream>
#include<fstream>
#include<string>
#include<string.h>
#include<cstdlib> //we use it ( built in function exit)
#include <conio.h>
#include<algorithm>
using namespace std;
void welcome();
void intro(); // switch cases contain function of logging
void ModifyBookInfo();
void Modify_order();
void borrowbook();
void returnbook();
void display_available_books_only();
void display_booklist();
void book_info();
void addbook();
void deletebook();
void sign_up();
void login_student();
void login_admin();
void forgot();
void change_password();
int loading1(); // load data from file to array( students)
void loading2(); // load data from array to file( students)
int loading3(); //load data from file to array (books)
void loading4(); // load data from array to file(books)
void hide_password();
string hide_password_check();
void logging();
void main_student(); //switch cases----> list
void main_admin(); //switch cases for admin features
void myprofile();
void info_stud();
void bookservices();
//-------------------------------------Bouns-------------------------------------------------//
void displaystudentinfo();
int displaystudentinfo_for_admin();
int displayfeedback(int code);
int date();
void search_author();
void search_category();
//-----------------------------------------------------------------------------------------------------------------------------------------------------------//
#define book_limit 50
#define students_number 100
int answer;
int counter = 0;
int counter_logging = 0; // determine numbers of lines in file
int index;
struct library
{
int code;
int edition;
string book_name, author_name, category;
int available = 0; // not available to borrow
string feedback = " No feedback right now ";
}books[book_limit];
//struct for students information
struct student_info
{
int ID;
string student_name, username, password;
string borrowed_books = " No borrowed books"; //name of borrowed book
bool full = 0; //=0 //borrow and return function student borrowed books check
}student[students_number];
int main()
{
system("color 7d");
welcome();
intro();
return 0;
}
void welcome()
{
cout << endl << endl;
cout << "-------------------------------------------------------------------------------------------------------------------------------------" << endl;
cout << " welcome To Our Library " << endl;
cout << "-------------------------------------------------------------------------------------------------------------------------------------" << endl;
cout << endl;
}
//----------------------------------------------logging functions-------------------------------------------//
int loading1()
{
// load data from file to array
ifstream file; // input from file =read from file
file.open("data1.txt");
int sz = 0;
file >> sz;
for (int i = 0; i < sz; i++)
{
file >> student[i].username >> student[i].password >> student[i].student_name >> student[i].borrowed_books >> student[i].ID;
}
file.close();
return sz;
}
void loading2()
{
// from array to file
ofstream file("data1.txt");//input to file=write in file
file << counter_logging << endl;
for (int i = 0; i < counter_logging; i++)
{
file << student[i].username << ' ' << student[i].password << ' ' << student[i].student_name << ' ' << student[i].borrowed_books << ' ' /*<< student[i].wish_list_arr[counter2]<<<<student[i].full<<' ' */ << student[i].ID << endl;
}
file.close();
}
int loading3()
{
// load data from file to array
int size = 0;
ifstream nfile; // input from file
nfile.open("data2.txt");
nfile >> size;
for (int i = 0; i < size; i++)
{
nfile >> books[i].code >> books[i].edition >> books[i].book_name >> books[i].author_name >> books[i].category >> books[i].available; // determine numbers of lines in file
}
nfile.close();
return size;
}
void loading4()
{
// from array to file
ofstream nfile("data2.txt");
nfile << counter << endl;
for (int i = 0; i < counter; i++)
{
nfile << books[i].code << ' ' << books[i].edition << ' ' << books[i].book_name << ' ' << books[i].author_name << ' ' << books[i].category << ' ' << books[i].available << endl;
}
nfile.close();
}
void hide_password() //we use this function to hide passsword only in sign up to take password from uer in first time
{
int count = 0; //counter to check if user enter 8 characters
char ch; // must be char because getch() store only one value with each press on buttons
while ((ch = _getch()) != '\r') //user donot press enter
{
count++;
student[counter_logging].password += ch; // in string: a+b=ab
cout << "*";
}
}
string hide_password_check() //it is okay to take a parameter or not as you like
{
string pass;
char ch; // must be char because getch() store only one value with each press on buttons
while ((ch = _getch()) != '\r') //user donot press enter
{
pass += ch; // in string: a+b=ab
cout << "*";
}
return pass;
}
void sign_up()
{
string username1, p;
bool found = 0;
cout << endl;
cout << "\t>>Enter The Username: ";
cin >> username1;
//cout << ">>" << endl;
for (int i = 0; i < students_number; i++)
{
if (student[i].username == username1)
{
found = 1;
break;
}
}
if (found == 1)
{
cout << endl;
cout << "\t\t ------------------------------" << endl;
cout << "\t\t | Username Exists |" << endl;
cout << "\t\t ------------------------------" << endl;
cout << "\t\t\t<<<< Please Try again >>>>" << endl << endl;
sign_up();
}
else
{
student[counter_logging].username = username1;
cout << "\t>>Enter Your Name: ";
cin.ignore();
getline(cin, student[counter_logging].student_name);// cout << ">>" << endl;
cout << "\t>>Enter Your ID: "; cin >> student[counter_logging].ID; //cout << ">>" << endl;
cout << "\t>>Enter The Password: ";
hide_password(); cout << endl;
while (true) //user enter password correctly in check
{
cout << "\t>>Confirm password: ";
p = hide_password_check(); cout << endl;
if (p == student[counter_logging].password)
{
counter_logging++;
cout << endl;
cout << "\t\t\t\t-----------Registerition is successful!!-----------\t\t\t\t\t\t" << endl << endl;
break;
}
else
{
cout << "Password is Wrong!!Try again\n";
continue;
}
}
}
}
void login_student()
{
bool found = 0, found1 = 0, found2 = 0;
string user, p;
cout << "Please, Enter Your Username : ";
cin >> user;
cout << "Please, Enter Your Password : ";
p = hide_password_check();
for (int i = 0; i < students_number; i++)
{
//--------------------------------check what is wrong/true(username or password)----------------------------------------------------------------//
if ((student[i].username == user) && (student[i].password == p))
{
found = 1;
index = i; // global variable ,we use it to know index of student in array to edit his information recently
cout << "\t\t\t\t\t-------You have logged in successfully!-------\t\t\t\t\t\t" << endl << endl;
main_student();
break;
}
else if ((student[i].username == user) && (student[i].password != p))
{
found1 = 1;
cout << endl;
cout << "\t\t\t\t\t-------Login is not successful!! Your password is wrong-------\t\t\t\t\t\t " << endl << endl;
cout << endl << "Please, try again" << endl << endl;
login_student();
}
}
// if ((student[i].username != user)
if (found == 0 && found1 == 0)
{
cout << "\t\t\t\t-------Please,Sign up your username isnot found in our library-------\t\t\t\t\t\t " << endl << endl;
system("pause");
system("CLS");
logging();
}
}
void login_admin()
{
string identifying_pass = "456123", pass; // password admin
cout << "\t\t < Enter admin's password :";
cin >> pass; cout << ">" << endl;
if (pass == identifying_pass)
{
cout << "\t\t ------------------------------------------------------" << endl;
cout << "\t\t | Hello, you have logged in successfully | " << endl;
cout << "\t\t -------------------------------------------------------" << endl;
system("pause");
system("CLS");
main_admin();
}
else
{
cout << "\t\t --------------------------------------------" << endl;
cout << "\t\t | Your Paasword is Wrong!! |" << endl;
cout << "\t\t --------------------------------------------" << endl;
cout << "\t\t\t<<< Please!! Try again>>>" << endl << endl;
system("pause");
system("CLS");
login_admin();
}
}
void forgot()
{
//loading1();
int count = 0, index;
string f_username, f_pass;
cout << "\t\t---->> Please Enter your username: "; cin >> f_username;
for (int i = 0; i < students_number; i++)
{
if (f_username == student[i].username)
{
count = 1;
index = i;
break;
}
}
if (count == 1)
{
cout << "\t\t ---------------------------------" << endl;
cout << "\t\t | Your password is found |" << endl;
cout << "\t\t ---------------------------------" << endl;
cout << "<< Your password is:" << student[index].password << ">>" << endl << endl;
}
else
{
cout << "\t\t ---------------------------------------------------------------------------------" << endl;
cout << "\t\t\ | !! Sorry your password is not found You have entered invalid username |" << endl;
cout << "\t\t ---------------------------------------------------------------------------------" << endl;
intro();
}
}
void change_password()
{
// student already make login and use system
string user, new_pass;
bool found = 0;
cout << "\t\t<< Enter Your New Password:";
cin >> new_pass; cout << ">>" << endl;
student[index].password = new_pass;
cout << "\t\t\t --------------------------------------------------------- " << endl;// replace old password with new
cout << "\t\t\t | Your password has been edited sucessfully |" << endl;
cout << "\t\t\t --------------------------------------------------------- " << endl;
myprofile();
}
void logging()
{
int c;
while (true)
{
cout << "\t\t * 1.login As Admin.\t\t * 2.Login As Student.\t\t * 3.Sign up.\t\t * 4.Forget password.\t\t * 5.Exit." << endl;
cout << "\n\t\t > Please Enter your choice: ";
cin >> c; cout << endl;
system("CLS");
switch (c)
{
case 1:
login_admin();
break;
case 2:
login_student();
break;
case 3:
sign_up();
logging();
break;
case 4:
forgot();
logging();
break;
case 5:
cout << endl << endl;
cout << "\t\t\t ------------------------------------------" << endl;
cout << " \t\t\t| Thank you for Using Our Library |\t\t\t \n\n";
cout << "\t\t\t ------------------------------------------" << endl;
loading2();
loading4();
exit(1);
break;
default:
cout << "\t\t\t----> Please select from previous options <---- \t\t\t" << endl;
break;
}
}
}
void intro()
{
counter_logging = loading1();
counter = loading3();
logging();
}
//-----------------------------------------------student functions-----------------------------//
void info_stud()
{
int choice, answer;
cout << "****************************************************************************************************************************************************************" << endl;
cout << " Your information " << endl;
cout << "****************************************************************************************************************************************************************" << endl << endl;
cout << "\t\t * Name: " << student[index].student_name << endl;
cout << "\t\t * ID: " << student[index].ID << endl;
cout << "\t\t * Username: " << student[index].username << endl;
cout << "\t\t * Password: " << student[index].password << endl;
cout << "\t\t * Borrowed books: " << student[index].borrowed_books << endl;
cout << "\t\t > Do You Want To Edit it?\n";
cout << "\t\t\t * 1.YES\n";
cout << "\t\t\t * 2.NO\n\n";
cout << "\t\t > Enter your choice : ";
cin >> choice; cout << endl;
switch (choice)
{
case 1: //from here student start edit his information
{
cout << "\t\t * What do You want to edit ? \n";
cout << "\t\t\t * 1. Name \n \t\t\t * 2.ID\n \t\t\t * 3.Username\n\n \t\t\t > Enter a Choice: ";
cin >> answer; cout << endl;
switch (answer)
{
case 1:
cout << "\t\t > Enter Your new name:"; cin >> student[index].student_name;
system("pause");
cout << "\t\t------> Your name has been edited successfully!! <------" << endl;
system("CLS");
myprofile();
break;
case 2:
cout << "\t\t > Enter Your New ID:"; cin >> student[index].ID;
system("pause");
cout << "\t\t------> Your ID has been edited successfully!! <------" << endl;
system("CLS");
myprofile();
break;
case 3:
cout << "\t\t > Enter Your New Username:"; cin >> student[index].username;
system("pause");
cout << "\t\t------> Your username has been edited successfully!! <------" << endl;
system("CLS");
myprofile();
break;
default:
cout << "\t\t\t > Enter valid Choice:";
info_stud();
break;
}
break;
}
case 2:
{
system("CLS");
myprofile();
break;
}
default:
{
cout << "----> Enter a valid choice ,Please. <-----";
break;
}
}
}
void myprofile()
{
int choice;
cout << "****************************************************************************************************************************************************************" << endl;
cout << " My profile " << endl;
cout << "****************************************************************************************************************************************************************" << endl << endl;
cout << "\t\t * 1.Edit my information " << endl << "\t\t * 2.Change my password " << endl << "\t\t * 3.Back " << endl << "\t\t\t > Enter choice: ";
cin >> choice;
//system("pause");
system("CLS");
switch (choice)
{
case 1:
{
info_stud();
break;
}
case 2:
{
change_password();
break;
}
case 3:
{
main_student();
break;
}
default:
{
myprofile();
break;
}
}
}
void bookservices()
{
cout << "****************************************************************************************************************************************************************" << endl;
cout << " Book services " << endl;
cout << "****************************************************************************************************************************************************************" << endl << endl;
int answer;
int answer2;
cout << "\t\t * 1.Display books" << endl;
cout << "\t\t * 2.View information about specific book" << endl;
cout << "\t\t * 3.Borrow " << endl;
cout << "\t\t * 4.Return" << endl;
cout << "\t\t * 5.Modify your order." << endl;
cout << "\t\t * 6.Search about Book. " << endl;
cout << "\t\t * 7.Back" << endl << endl;
cout << "\t\t\t > Enter your choice: ";
cin >> answer;
system("pause");
system("CLS");
switch (answer)
{
case 1:
{
while (true)
{
cout << "\t\t * 1.Display all books." << endl;
cout << "\t\t * 2.Display availaible books." << endl << endl;
cout << "\t\t > Enter your choice:";
cin >> answer2;
system("pause");
system("CLS");
if (answer2 == 1)
{
display_booklist();
bookservices();
break;
}
else if (answer2 == 2)
{
display_available_books_only();
bookservices();
break;
}
else {
cout << "\t\t\t---------------------------------------------" << endl;
cout << "\t\t\t| Invalid choice! |" << endl;
cout << "\t\t\t---------------------------------------------" << endl << endl;
cout << "\t\t Please, try again: \n";
continue;
}
}
break;
}
case 2:
{
book_info();
break;
}
case 3:
{
borrowbook();
break;
}
case 4:
{
returnbook();
break;
}
case 5:
{
Modify_order();
break;
}
case 6:
{
int choice;
while (true)
{
cout << "\t\t * Do you want to search by:\n";
cout << "\t\t\t * 1.Author name";
cout << "\t\t\t * 2.Category\n\n";
cout << "\t\t > Enter choice:";
cin >> choice;
system("pause");
system("CLS");
if (choice == 1)
{
search_author();
bookservices();
break;
}
else if (choice == 2)
{
search_category();
bookservices();
break;
}
else {
cout << "\t\t\t---------------------------------------------" << endl;
cout << "\t\t\t| Invalid choice! |" << endl;
cout << "\t\t\t---------------------------------------------" << endl << endl;
cout << "\t\t Please, try again: \n";
continue;
}
}
break;
}
case 7:
{
main_student();
break;
}
default:
cout << "\t\t\t---------------------------------------------" << endl;
cout << "\t\t\t| Invalid choice! |" << endl;
cout << "\t\t\t---------------------------------------------" << endl << endl;
cout << "\t\t Please, try again: \n";
bookservices();
break;
}
}
void display_booklist()
{
cout << "****************************************************************************************************************************************************************" << endl;
cout << " list of books: " << endl;
cout << "****************************************************************************************************************************************************************" << endl << endl;
cout << "----------------------------------------------------------------------------------------------------------------------------------------------------------------" << endl;
cout << "\t\t" << "Book name" << "\t\t\t" << "Book code" << "\t\t\t" << "Book edition" << "\t\t\t" << "Book category" << "\t\t\t" << "Author name" << endl;
cout << "----------------------------------------------------------------------------------------------------------------------------------------------------------------" << endl;
; for (int i = 0; i < counter; i++)
{
cout << "\t\t|" << books[i].book_name << "\t\t\t|" << books[i].code << "\t\t\t|" << books[i].edition << "\t\t\t|" << books[i].category << "\t\t\t|" << books[i].author_name << endl;
}
system("pause");
system("CLS");
}
void display_available_books_only()
{
bool found = 0;
cout << "****************************************************************************************************************************************************************" << endl;
cout << " list of available books: " << endl;
cout << "****************************************************************************************************************************************************************" << endl << endl;
cout << "----------------------------------------------------------------------------------------------------------------------------------------------------------------" << endl;
cout << "\t\t" << "Book name" << "\t\t\t" << "Book code" << "\t\t\t" << "Book edition" << "\t\t\t" << "Book category" << "\t\t\t" << "Author name" << endl;
cout << "----------------------------------------------------------------------------------------------------------------------------------------------------------------" << endl;
for (int i = 0; i < counter; i++)
{
if (books[i].available == 1)
{
cout << "\t\t|" << books[i].book_name << "\t\t\t|" << books[i].code << "\t\t\t|" << books[i].edition << "\t\t\t|" << books[i].category << "\t\t\t|" << books[i].author_name << endl;
found = 1;
}
}
system("pause");
system("CLS");
if (found == 0)//system does not contain any available books==all books in system have been borrowed
{
cout << "----------------------------------------------------------------------------------------------------------------------------------------------------------------" << endl;
cout << "\t\t\t\tNo Avaliable books right now\n\n";
cout << "----------------------------------------------------------------------------------------------------------------------------------------------------------------" << endl;
system("pause");
system("CLS");
}
}
void book_info()
{
string title;
int found = 0;
cout << "\t\t Please, enter the name of the book: ";
cin.ignore();
getline(cin, title);
for (int i = 0; i < counter; i++) {
if (books[i].book_name == title) {
found = 1;
cout << "****************************************************************************************************************************************************************" << endl;
cout << " Book Information: " << endl;
cout << "****************************************************************************************************************************************************************" << endl << endl;
cout << "----------------------------------------------------------------------------------------------------------------------------------------------------------------" << endl;
cout << "\t\t" << "Book name" << "\t\t\t" << "Book code" << "\t\t\t" << "Book edition" << "\t\t\t" << "Book category" << "\t\t\t" << "Author name" << endl;
cout << "----------------------------------------------------------------------------------------------------------------------------------------------------------------" << endl;
cout << "\t\t|" << books[i].book_name << "\t\t\t\t|" << books[i].code << "\t\t\t|" << books[i].edition << "\t\t\t|" << books[i].category << "\t\t\t|" << books[i].author_name << endl;
system("pause");
system("CLS");
bookservices();
}
}
if (found == 0)
{
cout << "\t\t\t -------------------------------------" << endl;
cout << "\t\t\t |" << " Book does not exist in our library |" << endl;
cout << "\t\t\t -------------------------------------" << endl;
bookservices();
}
}
void borrowbook()
{
int code;
int answer; int ans;
bool found1 = 0;
bool found2 = 0;
bool found3 = 0;
cout << "\t\t > Enter the code of the book you want to borrow: ";
cin >> code;
for (int i = 0; i < counter; i++)
{
//---------------------book is found----------------//
if (code == books[i].code && books[i].available == 1)
{
if (student[index].full == 0) //student has not borrowed any book
{
found1 = 1;
books[i].available = 0; //now book not available
student[index].borrowed_books = books[i].book_name;
student[index].full = 1; //now he can not borrow another book
break;
}
else if (student[index].full == 1) //student already borrow book
{
cout << "\t\t\t * You have a book already in your borrowed book list, you should return it first! *" << endl;
cout << "\t\t\t * Do you want to return it? " << endl;
cout << "\t\t\t * 1.Yes" << endl << "\t\t\t * 2.No";
cout << "\t\t\t > Enter your choice:";
cin >> answer;
if (answer == 1)
returnbook();
else if (answer == 2)
bookservices();
}
}
//--------------the book is not avalaible-------------------//
else if (code == books[i].code && books[i].available == 0)
{
found2 = 1;
}
//---------------------------invaild code---------------------//
else if (code != books[i].code)
{
found3 = 1;
}
}
if (found1 == 1)
{
cout << "\t\t\t---------------------------------------------" << endl;
cout << "\t\t\t| Your book has been borrowed sucessfully! |" << endl;
cout << "\t\t\t---------------------------------------------" << endl;
date();
while (true)
{
cout << "\t\t Do you want to see the feedback about this book?" << endl << endl;
cout << "\t\t\t * 1.YES";
cout << "\t\t\t * 2.NO";
cout << "\t\t\t > Enter Choice : ";
int ans;
cin >> ans;
system("pause");
system("CLS");
if (ans == 1)
{
displayfeedback(code);
bookservices();
break;
}
else if (ans == 2)
{
bookservices();
break;
}
else
{
cout << "\t\t\t---------------------------------------------" << endl;
cout << "\t\t\t| Invalid choice! |" << endl;
cout << "\t\t\t---------------------------------------------" << endl << endl;
cout << "\t\t * Please, try again\n";
//continue;
}
}
}
else if (found2 == 1)
{
cout << "\t\t\t---------------------------------------------" << endl;
cout << "\t\t\t| Book is not available right now! |" << endl;
cout << "\t\t\t---------------------------------------------" << endl << endl;
cout << "\t\t * 1.Try again";
cout << "\t\t * 2.Back.";
cout << "\t\t > Enter Choice : ";
while (cin >> ans)
{
switch (ans)
{
case 1:
borrowbook();
break;
case 2:
bookservices();
break;
default:
cout << "\t\t\t---------------------------------------------" << endl;
cout << "\t\t\t| Invalid choice! |" << endl;
cout << "\t\t\t---------------------------------------------" << endl << endl;
cout << "\t\t * Please, try again\n";
continue;
}
}
}
else if (found3 == 1) {
cout << "\t\t\t---------------------------------------------" << endl;
cout << "\t\t\t| Invalid Code! |" << endl;
cout << "\t\t\t---------------------------------------------" << endl << endl;
cout << "\t\t * Do you want to try again?";
cout << "\t\t * 1.Yes.\n\t\t * 2.No. \n\n \t\t > Enter Choice: ";
cin >> answer; cout << endl;
system("pause");
system("CLS");
if (answer == 1)
borrowbook();
else
bookservices();
}
}
void returnbook()
{
int code;
bool found1 = 0, found2 = 0;
//int answer = 1;
int ans;
cout << "\t\t > Enter the code of the book you want to return: ";
cin >> code;
int i;
for (i = 0; i < counter; i++)
{
if (code == books[i].code && books[i].book_name == student[index].borrowed_books)//user enter correct code and this is the code of his borrowed book
{
found1 = 1;
books[i].available = 1;
student[index].borrowed_books = "You do not have borrowed books"; //put null value in student info (erase==clear)
student[index].full = 0; //user now can borrow book
//----------- return boorowed book !!-----------------//
break;
}
else if (code == books[i].code && books[i].book_name != student[index].borrowed_books)//user enter correct code and this is not the code of his borrowed book
{
found2 = 1;
break;
}
}
if (found1 == 1)
{
cout << "\t\t\t---------------------------------------------" << endl;
cout << "\t\t\t| Your book has been returned sucessfully! |" << endl;
cout << "\t\t\t---------------------------------------------" << endl << endl;
cout << "\t\t * 1.Bookservice." << endl;
cout << "\t\t * 2.Feedback." << endl << "\t\t\t > Enter Choice:";
cin >> ans; cout << endl;
switch (ans)
{
case 1:
system("CLS");
bookservices();
break;
case 2:
cout << "\t\t > Enter your feedback:";
cin.ignore();
getline(cin, books[i].feedback);
cout << "\t\t\t---------------------------------------------" << endl;
cout << "\t\t\t| Your feedback is saved! |" << endl;
cout << "\t\t\t---------------------------------------------" << endl << endl;
system("pause");
system("CLS");
bookservices();
break;
default:
cout << "\t\t\t---------------------------------------------" << endl;
cout << "\t\t\t| Invalid choice! |" << endl;
cout << "\t\t\t---------------------------------------------" << endl << endl;
cout << "\t\t * Please, try again\n";
break;
}
}
else if (found2 == 1)
{
cout << "\t\t\t ----> You have not borrowed this book!! <---- \n\n";
while (true)
{
cout << "\t\t * 1.Try again";
cout << "\t\t * 2.Back." << endl;
cout << "\t\t > Enter a Choice : ";
cin >> ans;
switch (ans)
{
case 1:
returnbook();
break;
case 2:
bookservices();
break;
default:
cout << "\t\t\t---------------------------------------------" << endl;
cout << "\t\t\t| Invalid choice! |" << endl;
cout << "\t\t\t---------------------------------------------" << endl << endl;
cout << "\t\t * Please, try again\n";
}
}
}
else
{
cout << "\t\t\t---------------------------------------------" << endl;
cout << "\t\t\t| Invalid Code! |" << endl;
cout << "\t\t\t---------------------------------------------" << endl << endl;
while (true)
{
cout << "\t\t * 1.Try again";
cout << "\t\t * 2.Back." << endl;
cout << "\t\t > Enter a Choice : ";
cin >> ans;
switch (ans)
{
case 1:
returnbook();
break;
case 2:
bookservices();
break;
default:
cout << "\t\t\t---------------------------------------------" << endl;
cout << "\t\t\t| Invalid choice! |" << endl;
cout << "\t\t\t---------------------------------------------" << endl << endl;
cout << "\t\t * Please, try again\n";
continue;
}
}
}
}
void Modify_order()
{
int ans;
bool exist = 0;
bool found1 = 0;
bool found2 = 0;
bool found3 = 0;
int code;
cout << "Enter the code of the book that you have already borrowed: ";
cin >> code;
for (int i = 0; i < counter; i++)
{
if (books[i].code == code && books[i].book_name == student[index].borrowed_books)
{
books[i].available = 1;
exist = 1;
}
}