-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRealLibrary.cpp
More file actions
950 lines (918 loc) · 34.5 KB
/
RealLibrary.cpp
File metadata and controls
950 lines (918 loc) · 34.5 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
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
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <string>
using namespace std;
// Class Declaration
class Admin;
class Member;
// Classes
class Book{
private:
string Name, ISBN, Author, PublisedDate, BorrowDate, return_status;
bool isborrowed;
Admin* min;
Member* mem;
public:
Book(){ // default constructor
Name = "NoName";
ISBN = "0";
Author = "NoAuthor";
PublisedDate = "NoDate";
BorrowDate = "NoDate";
return_status = "NOTHING";
isborrowed = false;
min = nullptr;
mem = nullptr;
}
Book(string name, string isbn, string author, string publised_date){
Name = name;
ISBN = isbn;
Author = author;
PublisedDate = publised_date;
BorrowDate = "NoDate";
return_status = "NOTHING";
isborrowed = false;
min = nullptr;
mem = nullptr;
}
Book(string name, string isbn, string borrow_date, string isReturned, Admin* admin, Member* member){
Name = name;
ISBN = isbn;
Author = "GetAuthorInTheList";
PublisedDate = "GetPublisedDateInTheList";
BorrowDate = borrow_date;
return_status = isReturned;
min = admin;
mem = member;
}
Book(const Book& b){
Name = b.Name;
ISBN = b.ISBN;
PublisedDate = b.PublisedDate;
BorrowDate = b.BorrowDate;
return_status = b.return_status;
isborrowed = b.isborrowed;
Author = b.Author;
min = b.min;
mem = b.mem;
}
string name_get()const{
return Name;
}
string borrow_date_get()const{
return BorrowDate;
}
string isbn_get()const{
return ISBN;
}
string author_get()const{
return Author;
}
string date_get()const{
return PublisedDate;
}
string return_status_get()const{
return return_status;
}
Admin* get_admin()const{
return min;
}
Member* get_member()const{
return mem;
}
bool isBorrowed()const{
return isborrowed;
}
void borrow_details(string date, Admin* adMin, Member* memBer){
BorrowDate = date;
min = adMin;
mem = memBer;
return_status = "NO";
}
void reset(){
BorrowDate = "NoDate";
min = nullptr;
mem = nullptr;
return_status = "YES";
}
void borrow(bool istrue){
isborrowed = istrue;
}
void returnBook(){
return_status = "YES";
}
};
class Admin{
private:
string ID, Name, password;
vector<Admin> admins_rack;
public:
Admin(){ // default constructor
Name = "NoName";
ID = "NoID";
password = "NoPassword";
}
Admin(string name_, string id, string password_){
Name = name_;
ID = id;
password = password_;
}
string get_name(){
return Name;
}
void set_name(const string name_){
Name = name_;
}
string get_id(){
return ID;
}
void set_id(const string id_){
ID = id_;
}
string get_password(){
return password;
}
void set_password(const string password_){
password = password_;
}
};
class Member{
private:
string Name, ID, contact;
int no_book_holding, total_no_book;
vector<Book> books_holding, total_books;
public:
Member(){
Name = "noName";
ID = "noID";
no_book_holding = 0;
total_no_book = 0;
}
Member(string member_id, string member_name, int holdingBooks, int totalBooks, string conTact){
Name = member_name;
ID = member_id;
no_book_holding = holdingBooks;
total_no_book = totalBooks;
contact = conTact;
}
string get_Contact(){
return contact;
}
string mem_name(){
return Name;
}
string mem_id(){
return ID;
}
int no_holding(){
return no_book_holding;
}
void holding_increment(int inc){
no_book_holding = no_book_holding + inc;
}
void total_increment(int inc){
total_no_book = total_no_book + inc;
}
int no_total_books(){
return total_no_book;
}
vector<Book> holdingBooks(){
return books_holding;
}
int size_holdingBooks(){
return books_holding.size();
}
int size_total_books(){
return total_books.size();
}
void holding_books_name(){
for(int i = 0; i < no_book_holding; i++){
cout << "-> Name " << i+1 << ": " << books_holding[i].name_get() << endl;
}
}
void total_books_name(){
for(int i = 0; i < total_no_book; i++){
cout << "-> Name " << i+1 << ": " << total_books[i].name_get() << endl;
}
}
void pushback_holding(Book book_){
books_holding.push_back(book_);
}
vector<Book> totalBooks(){
return total_books;
}
void pushback_total(Book book_){
total_books.push_back(book_);
}
bool book_remover(string IsBn){
for(int i = 0; i < this->books_holding.size(); i++){
if(this->books_holding[i].isbn_get() == IsBn){
this->books_holding.erase(books_holding.begin() + i);
this->no_book_holding--;
return true;
}
}
return false;
}
};
class Library{
private:
Member mem;
Admin* adm;
vector<Book> books_rack, borrowed_book_rack;
vector<Member> members_rack;
vector<Admin> admins_rack;
public:
Admin* LogIn(){
string ID, PASSword;
bool isExist = false;
while(!isExist){
bool isCorrectID = false;
Admin* returning_admin;
cout << "Admin ID: ";
cin >> ID;
cout << "Password: ";
cin >> PASSword;
for(int i = 0; i < admins_rack.size(); i++){
if(admins_rack[i].get_id() == ID){
isCorrectID = true;
if(admins_rack[i].get_password() == PASSword){
returning_admin = &admins_rack[i];
cout << "\n\n\nWelcome " << admins_rack[i].get_name() << ", " << endl << endl << endl;
isExist = true;
break;
}
}
}
if(!isExist){
if(!isCorrectID){
cout << "Your ID is wrong. Only admins that are in the database will be allowed to enter..." << endl;
continue;
}
cout << "Your password wrong. Try to Enter again.." << endl;
continue;
}
return returning_admin;
}
}
void set_admin(Admin* min){
adm = min;
}
bool isValidBook(string ISBN){
for(int i = 0; i < books_rack.size(); i++){
if(books_rack[i].isbn_get() == ISBN)
return true;
}
return false;
}
bool isValidMember(string ID){
for(int i = 0; i < members_rack.size(); i++){
if(members_rack[i].mem_id() == ID)
return true;
}
return false;
}
// ADDING DATA INTO VECTOR FROM TEXT FILES
void admin_list(){ // add the admins into the vector
fstream admin_file;
admin_file.open("Admin.txt");
if(!admin_file){
cout << "Admin file doesn't exist" << endl;
exit(EXIT_FAILURE);
}
string line;
getline(admin_file, line);// skip the header
while(getline(admin_file, line)){
stringstream ss(line);
string ID, NAME, PASSWORD;
getline(ss, ID, ',');
getline(ss, NAME, ',');
getline(ss, PASSWORD, ',');
Admin temp_admin = Admin(NAME, ID, PASSWORD);
admins_rack.push_back(temp_admin);
}
admin_file.close();
}
void member_list(){ // add the members into the vector
fstream members_file;
string line;
members_file.open("Members.txt");
if(!members_file){
cout << "Member file doesn't exist" << endl;
exit(EXIT_FAILURE);
}
getline(members_file, line);// skip the header
while(getline(members_file, line)){
string mem_name, mem_id, total_books, holding_books, isbn1, isbn2, word, contact;
stringstream ss(line);
getline(ss, mem_id, ',');
getline(ss, mem_name, ',');
getline(ss, holding_books, ',');
getline(ss, total_books, ',');
getline(ss, isbn1, ',');
getline(ss, isbn2, ',');
getline(ss, contact, ',');
isbn1 = isbn1.substr(1,isbn1.length()-2); // removing the brackets
isbn2 = isbn2.substr(1,isbn2.length()-2);
stringstream ss1(isbn1);
stringstream ss2(isbn2);
int holdBooks = stoi(holding_books), BooksTotal = stoi(total_books);
string holdingBook[holdBooks], totalBooks[BooksTotal];
for(int i = 0; i < holdBooks; i++){
getline(ss1, word, '|');
holdingBook[i] = word;
}
for(int i = 0; i < BooksTotal; i++){
getline(ss2, word, '|');
totalBooks[i] = word;
}
Member temp_mem = Member(mem_id, mem_name, holdBooks, BooksTotal, contact);
for(int i = 0; i < holdBooks; i++){ // add the books that borrowed currently in the vector
for(int j = 0; j < books_rack.size(); j++){
if(books_rack[j].isbn_get() == holdingBook[i]){
books_rack[j].borrow(true);
temp_mem.pushback_holding(books_rack[j]);
break;
}
}
}
for(int i = 0; i < BooksTotal; i++){ // add the books that borrowed totally in the vector
for(int j = 0; j < books_rack.size(); j++){
if(books_rack[j].isbn_get() == totalBooks[i]){
temp_mem.pushback_total(books_rack[j]);
break;
}
}
}
members_rack.push_back(temp_mem);
}
members_file.close();
}
void book_list(){ // add the books into the vector
fstream books_file;
books_file.open("Books.txt");
if(!books_file){
cout << "Book file doesn't exist" << endl;
exit(EXIT_FAILURE);
}
string line;
getline(books_file, line);// skip the header
while(getline(books_file, line)){
stringstream ss(line);
string book_name, isbn, author, publised_date;
getline(ss, book_name, ',');
getline(ss, isbn, ',');
getline(ss, author, ',');
getline(ss, publised_date, ',');
Book temp_book = Book(book_name, isbn, author, publised_date);
books_rack.push_back(temp_book);
}
books_file.close();
}
void borrow_book_list(){// add the borrowed books into the vector
fstream borrow_books_file;
borrow_books_file.open("Books_Borrow.txt");
if(!borrow_books_file){
cout << "Borrow Book file doesn't exist" << endl;
exit(EXIT_FAILURE);
}
string line;
while(getline(borrow_books_file, line)){
stringstream ss(line);
string book_name, isbn, return_date, member_name, member_id, admin_id, return_status;
Member* temp_mem;
Admin* temp_min;
getline(borrow_books_file, line);
getline(ss, book_name, ':');
getline(ss, book_name);
book_name = book_name.substr(1,book_name.length()-1);
stringstream ss1(line);
getline(borrow_books_file, line);
getline(ss1, isbn, ':');
getline(ss1, isbn);
isbn = isbn.substr(1,isbn.length()-1);
stringstream ss2(line);
getline(borrow_books_file, line);
getline(ss2, return_date, ':');
getline(ss2, return_date);
return_date = return_date.substr(1,return_date.length()-1);
stringstream ss3(line);
getline(borrow_books_file, line);
getline(ss3, member_name, ':');
getline(ss3, member_name);
member_name = member_name.substr(1,member_name.length()-1);
stringstream ss4(line);
getline(borrow_books_file, line);
getline(ss4, member_id, ':');
getline(ss4, member_id);
member_id = member_id.substr(1,member_id.length()-1);
stringstream ss5(line);
getline(borrow_books_file, line);
getline(ss5, admin_id, ':');
getline(ss5, admin_id);
admin_id = admin_id.substr(1,admin_id.length()-1);
stringstream ss6(line);
getline(borrow_books_file, line);
getline(ss6, return_status, ':');
getline(ss6, return_status);
return_status = return_status.substr(1,return_status.length()-1);
temp_mem = nullptr;
for(int i = 0; i < members_rack.size(); i++){
if(members_rack[i].mem_id() == member_id){
temp_mem = &members_rack[i];
break;
}
}
temp_min = nullptr;
for(int i = 0; i < admins_rack.size(); i++){
if(admins_rack[i].get_id() == admin_id){
temp_min = &admins_rack[i];
break;
}
}
Book temp_book = Book(book_name, isbn, return_date, return_status, temp_min, temp_mem);
borrowed_book_rack.push_back(temp_book);
}
borrow_books_file.close();
}
// WRITE DATA FROM VECTOR ONTO TEXT FILES
void rack_txt(){ // write all books from vector onto text file
fstream books_file;
books_file.open("Books.txt", ios::out);
if(books_file){
books_file << "Book_name, ISBN, Author, Publised_date";
for(int i = 0; i < books_rack.size(); i++){
books_file << endl << books_rack[i].name_get() << ',' << books_rack[i].isbn_get() << ',' << books_rack[i].author_get() << ',' << books_rack[i].date_get();
}
}else
cout << "Book file doesn't exist to add the new book.." << endl;
books_file.close();
}
void mem_rack_txt(){ // write all books from vector onto text file
fstream member_file;
member_file.open("Members.txt", ios::out);
if(member_file){
member_file << "Member_id, Member_name, no_holding_books, no_of_books, (holding_books), (total_books), Contact_number";
for(int i = 0; i < members_rack.size(); i++){
member_file << endl << members_rack[i].mem_id() << ',' << members_rack[i].mem_name() << ',' << members_rack[i].no_holding() << ',' << members_rack[i].no_total_books() << ",(" ;
for(int j = 0; j < members_rack[i].no_holding(); j++){
member_file << members_rack[i].holdingBooks()[j].isbn_get();
if(j < members_rack[i].no_holding()-1)
member_file << '|';
}
member_file << "),(";
for(int j = 0; j < members_rack[i].no_total_books(); j++){
member_file << members_rack[i].totalBooks()[j].isbn_get();
if(j < members_rack[i].no_total_books()-1)
member_file << '|';
}
member_file << ')';
member_file << ',' << members_rack[i].get_Contact();
}
}else
cout << "Book file doesn't exist to add the new book.." << endl;
member_file.close();
}
void book_borrow_txt(){ // write all borrowed books from vector onto text file
fstream borrow_book_file("Books_Borrow.txt", ios::out);
if (!borrow_book_file.is_open()) {
cerr << "Error opening Books_Borrow.txt file!" << endl;
exit(EXIT_FAILURE);
}
for(int i = 0; i < borrowed_book_rack.size(); i++){
borrow_book_file << "Book Name: " << borrowed_book_rack[i].name_get() << endl;
borrow_book_file << "ISBN: " << borrowed_book_rack[i].isbn_get() << endl;
borrow_book_file << "Date: " << borrowed_book_rack[i].borrow_date_get() << endl;
if(borrowed_book_rack[i].get_member() == nullptr){
cout << "NULLPTR" << endl;
exit(EXIT_FAILURE);
}
borrow_book_file << "Member Name: " << borrowed_book_rack[i].get_member()->mem_name() << endl;
borrow_book_file << "Member ID: " << borrowed_book_rack[i].get_member()->mem_id() << endl;
if(borrowed_book_rack[i].get_admin() == nullptr){
cout << "NULLPTR" << endl;
exit(EXIT_FAILURE);
}
borrow_book_file << "Admin ID: " << borrowed_book_rack[i].get_admin()->get_id() << endl;
borrow_book_file << "Return Status: " << borrowed_book_rack[i].return_status_get() << endl;
borrow_book_file << "---------------------------------" << endl;
}
// store the borrowed books details into a vector
borrow_book_file.close();
}
// PRINTING FUNCTIONS
void print_books_details(string name){
int count = 0;
for(int i = 0; i < books_rack.size(); i++){
size_t clue = books_rack[i].name_get().find(name);
if(clue != string::npos){
cout << "Book #" << ++count << endl;
cout << "Name: " << books_rack[i].name_get() << endl;
cout << "ISBN: " << books_rack[i].isbn_get() << endl;
cout << "Author: " << books_rack[i].author_get() << endl;
cout << "Publised Date: " << books_rack[i].date_get() << endl;
if(books_rack[i].get_member() == nullptr){
cout << "~~AVAIALABLE~~" << endl;
}else
cout << "Borrowed by: " << books_rack[i].get_member()->mem_name() << endl;
}
}
}
void print_members_details(string ID){
for(int i = 0; i < members_rack.size(); i++){
if(members_rack[i].mem_id() == ID){
cout << endl << "Name: " << members_rack[i].mem_name() << endl;
cout << "ID: " << members_rack[i].mem_id() << endl;
cout << "Contact Number: +6" << members_rack[i].get_Contact() << endl;
cout << "Books currently holding: " << members_rack[i].no_holding() << endl;
members_rack[i].holding_books_name();
cout << "Total books borrowed: " << members_rack[i].no_total_books() << endl;
members_rack[i].total_books_name();
cout << endl;
return;
}
}
cout << "Member ID is not matched with anyone in the list..." << endl;
}
void print_borrowed_books_details(string isbn){
int count = 0;
for(int i = 0; i < borrowed_book_rack.size(); i++){
if(borrowed_book_rack[i].isbn_get() == isbn){
cout << "\nBORROWER #" << ++count << endl;
cout << "Member Name: " << borrowed_book_rack[i].get_member()->mem_name() << " (" << borrowed_book_rack[i].get_member()->mem_id() << ')' << endl;
cout << "Book Name: " << borrowed_book_rack[i].name_get() << endl;
cout << "Borrowed Date: " << borrowed_book_rack[i].borrow_date_get() << endl;
cout << "Admin In-Charge: " << borrowed_book_rack[i].get_admin()->get_id() << endl;
cout << "Return Status: " << borrowed_book_rack[i].return_status_get() << endl;
}
}
}
void member_printer(){
string isSearch, ID;
cout << endl;
for(int i = 0; i < members_rack.size(); i++){
cout << "Member #" << i+1;
cout << " Name: " << members_rack[i].mem_name() << " (" << members_rack[i].mem_id() << ')'<< endl;
}
cout << endl;
cout << "Wanna search for the member's details?(y/n): ";
cin >> isSearch;
if(isSearch == "y"){
cout << "Enter the member's ID: ";
cin >> ID;
print_members_details(ID);
}else
return;
}
void book_printer(){
string name, ISBN;
int count = 0, option;
cout << "1. Available Books\n2. All Books\n3. Search\n4. Borrowed History of Books\n\nEnter an option to see the available books in the library: ";
cin >> option;
cin.ignore();
switch (option){
case 1:
cout << endl << "Books that are available in this library currently:- \n";
for(int i = 0; i < books_rack.size(); i++){
if(!books_rack[i].isBorrowed()){
cout << "Book #" << ++count;
cout << " Name: " << books_rack[i].name_get() << " (" << books_rack[i].isbn_get() << ')'<< endl;
}
}
break;
case 2:
cout << endl << "All Books from this Library:- \n";
for(int i = 0; i < books_rack.size(); i++){
cout << "Book #" << ++count;
cout << " Name: " << books_rack[i].name_get() << " (" << books_rack[i].isbn_get() << ')' << " =>> ";
if(books_rack[i].isBorrowed())
cout << "Borrowed" << endl;
else
cout << "Available" << endl;
}
break;
case 3:
cout << "\nEnter the name of the book: ";
getline(cin, name);
cout << endl;
print_books_details(name);
count++;
break;
case 4:
cout << "Enter the book's ISBN: ";
cin >> ISBN;
print_borrowed_books_details(ISBN);
count++;
break;
default:
cout << "\nInvalid Option..." << endl;
break;
}
if(count == 0)
cout << "There's no book available";
cout << endl;
}
// FUNCTIONS
Member* adding_member(string ID){ //ADD NEW MEMBER FUNCTION
Member* temp_mem;
string name, contact;
cin.ignore();
cout << "Name: ";
getline(cin, name);
cout << "Contact number: ";
getline(cin, contact);
members_rack.push_back(Member(ID, name, 0, 0, contact));
temp_mem = &members_rack[members_rack.size()-1];
mem_rack_txt();
return temp_mem;
}
void remove_book(){ // REMOVE BOOKS FUNCTION
string name, isbn, ID;
bool isfound = false;
cout << "Enter ISBN of book that you wanted to remove from the list: " << endl;
cin >> ID;
fstream books_file;
books_file.open("Books.txt");
if(books_file){
stringstream ss;
for(auto it = books_rack.begin(); it != books_rack.end(); it++){
if(ID == it->isbn_get()){
books_rack.erase(it);
isfound = true;
cout << it->name_get() << " is removed from the list.." << endl;
break;
}
}
books_file.close();
if(isfound){
rack_txt();
}else
cout << "ISBN that you inputed is not found..." << endl;
}
}
void borrow_book(){ // BORROW BOOKS FUNCTION
string name, ID, isbn, line, Bdate;
int noBooks;
bool isOld = false, isValid = false;
Member* mmbr;
cout << "\nEnter the Member ID: ";
cin >> ID;
// Finding whether this borrower is in our list already or not
for(int i = 0; i < members_rack.size(); i++){
if(members_rack[i].mem_id() == ID){
mmbr = &members_rack[i];
isOld = true;
break;
}
}
if(!isOld){
mmbr = adding_member(ID);
}else{
cout << "This member is already exist.." << endl;
}
cout << "\nNumber of borrowing books: ";
cin >> noBooks;
cout << "\nBorrowing Date(DD/MM/YYYY): ";
cin >> Bdate;
cout << endl;
if(noBooks >= 1){
if(noBooks != 1){
for(int i = 0; i < noBooks; i++){
isValid = false;
cout << "Please, enter the borrowing book " << i+1 <<" ISBN: " << endl;
cin >> isbn;
for(int j = 0; j < books_rack.size(); j++){
if(books_rack[j].isbn_get() == isbn){
if(!books_rack[j].isBorrowed()){
mmbr->pushback_holding(books_rack[j]);
mmbr->pushback_total(books_rack[j]);
books_rack[j].borrow(1);
books_rack[j].borrow_details(Bdate, adm, mmbr);
borrowed_book_rack.push_back(books_rack[j]);
book_borrow_txt();
cout << books_rack[j].name_get() << " is added in " << mmbr->mem_name() << "'s borrowed list." << endl;
isValid = true;
break;
}else
cout << "This book is not available!!" <<endl;
return;
}
}
if(isValid){
mmbr->holding_increment(1);
mmbr->total_increment(1);
mem_rack_txt();
}else
cout << "ISBN Book is not in the list!!!" << endl;
}
}else{
cout << "Please, enter the borrowing book's ISBN: ";
cin >> isbn;
for(int i = 0; i < books_rack.size(); i++){
if(books_rack[i].isbn_get() == isbn){
if(!books_rack[i].isBorrowed()){
mmbr->pushback_holding(books_rack[i]);
mmbr->pushback_total(books_rack[i]);
books_rack[i].borrow(1);
books_rack[i].borrow_details(Bdate, adm, mmbr);
borrowed_book_rack.push_back(books_rack[i]);
book_borrow_txt();
cout << books_rack[i].name_get() << " is added in the member borrowed list." << endl;
isValid = true;
break;
}else
cout << "This book is not available!!" <<endl;
}
}
if(isValid){
mmbr->holding_increment(1);
mmbr->total_increment(1);
mem_rack_txt();
}else
cout << "ISBN Book is not in the list!!!" << endl;
}
}else{
cout << "Invalid number of books..." << endl;
exit(EXIT_FAILURE);
}
}
void return_book(){ // RETURN BOOKS FUNCTION
string ID, ISBN;
int noBooks;
bool isRemoved, isValid;
cout << "Enter the Member ID: ";
cin.ignore();
cin >> ID;
isValid = isValidMember(ID);
if(!isValid){
cout << "This ID is not match any of the members' id in the list.." << endl;
return;
}
cout << "Number of returning books: ";
cin >> noBooks;
if(noBooks >= 1){
for(int i = 0; i < noBooks; i++){
if(noBooks == 1){
cout << "Book's ISBN: ";
cin >> ISBN;
}else{
cout << "Book #" << i+1 << " ISBN: ";
cin >> ISBN;
}
isValid = isValidBook(ISBN);
if(!isValid){
cout << "This ISBN is not match any of the books' isbn in the list.." << endl;
return;
}
for(int j = 0; j < members_rack.size(); j++){
if(members_rack[j].mem_id() == ID){
isRemoved = members_rack[j].book_remover(ISBN);
if(isRemoved){
cout << "This book is";
mem_rack_txt();
}else
cout << "This book is not borrowed by this member..." << endl;
break;
}
}
for(int j = 0; j < books_rack.size(); j++){
if(books_rack[j].isbn_get() == ISBN){
books_rack[j].borrow(0);
books_rack[j].reset();
cout << " now available and";
break;
}
}
for(int j = 0; j < borrowed_book_rack.size(); j++){
if(borrowed_book_rack[j].isbn_get() == ISBN && borrowed_book_rack[j].get_member()->mem_id() == ID){
borrowed_book_rack[j].returnBook();
cout << " returned..." << endl << endl;
book_borrow_txt();
break;
}
}
}
}else
return;
}
// ADD NEW BOOKS FUNCTIONS
void new_book_getter(){
string name, isbn, author, publised_date;
cout << "Name: ";
cin.ignore();
getline(cin, name);
cout << "ISBN: ";
getline(cin, isbn);
cout << "Author Name: ";
getline(cin, author);
cout << "Publised Date: ";
getline(cin, publised_date);
book_checker(name, isbn, author, publised_date);
}
void book_checker(string name, string isbn, string author, string publised_date){
bool is_exist = false; // add all the book lists already in the text file into vector
for(int i = 0; i < books_rack.size(); i++){
if(books_rack[i].isbn_get() == isbn){
cout << "This book is already exist in the library.." << endl;
is_exist = true;
break;
}
}
if(!is_exist){
adding_book(name, isbn, author, publised_date);
cout << "New Book is Added in the list..." << endl;
}
}
void adding_book(string book_name, string isbn, string author, string published_date){
Book temp_book = Book(book_name, isbn, author, published_date);
books_rack.push_back(temp_book);
rack_txt();
}
};
int main(){
cout<<"+---------------------------------+"<<endl;
cout<<"| |"<<endl;
cout<<"| Welcome to Knowledge Library |"<<endl;
cout<<"| |"<<endl;
cout<<"+---------------------------------+"<<endl;
cout<<endl;
// Object Instantiation
Admin* A1;
Book B1;
Member* m1;
Library L;
// Load all the books, members and admins from the list into the vector
L.book_list();
L.member_list();
L.admin_list();
L.borrow_book_list();
//Functions..
int option1, option2;
bool back_home;
string enter, id;
while(true){
back_home = false;
cout << "0 End the Program\n1 Admin Login\n" << endl;
cout << "Enter your choice: ";
cin >> option1;
switch (option1){
case 0:
cout << "\n\n~~~ReRun to operate this system~~~\n" << endl;
exit(EXIT_SUCCESS);
break;
case 1:
A1 = L.LogIn();
L.set_admin(A1);
while(true){
cout << endl << endl << "Here are the admin functions to manage this Library:- " <<endl;
cout << "0. BACK\n1. ADD NEW BOOKS\n2. REMOVE BOOKS\n3. BORROW BOOKS\n4. RETURN BOOKS\n5. ADD NEW MEMBERS\n6. VIEW MEMBERS\n7. VIEW BOOKS\n" << endl;
cout << "Enter the function that you want.........";
cin >> option2;
switch (option2){
case 0:
back_home = true;
break;
case 1:
L.new_book_getter();
break;
case 2:
L.remove_book();
break;
case 3:
L.borrow_book();
break;
case 4:
L.return_book();
break;
case 5:
cout << "Member ID: ";
cin >> id;
m1 = L.adding_member(id);
cout << (*m1).mem_name() << " became a member.." << endl;
break;
case 6:
L.member_printer();
break;
case 7:
L.book_printer();
break;
default:
cout << "It's an invalid option, " << A1->get_name() <<endl;
break;
}
if(!back_home){
cout << "-->";
cin.get();
}else
break;
}
break;
default:
cout << "Invalid Option..." << endl;
continue;
}
}
return 0;
}