-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLibrary_Management.cpp
1254 lines (972 loc) · 34.9 KB
/
Library_Management.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
/* This is a mini project devloped to manage the Library operations including the book records as well as student records*/
#include<iostream>
#include<cstdlib>
#include<fstream>
#include<iomanip>
#include<utility>
#include<stdexcept>
#include<ctime>
#include<regex>
#include<cstdio>
using namespace std;
//Forward Class declaration
class Library;
class LibraryRecords;
class Student;
//Date class for Handeling the dates in standard format
class Date{
private:
int dd,mm,yr;
public:
Date(){
this->dd = 0;
this->mm = 0;
this->yr = 0;
}
Date(int dd,int mm ,int yr){
this->dd=dd;
this->mm=mm;
this->yr=yr;
}
bool operator==(Date&);
int operator-(Date&);
friend istream& operator >>(istream &,Date &);
friend ostream& operator <<(ostream &,const Date &);
friend class LibraryRecords;
friend class Student;
};
//overloaded == operator to compare Dates
bool Date ::operator==(Date& dt){
if(dd==dt.dd && mm==dt.mm && yr==dt.yr){
return true;
}
return false;
}
//overloaded - operator to calculate the difference between two dates
int Date :: operator-(Date& dt){
int tempdd, tempmm, tempyy;
tempyy=yr-dt.yr;
tempmm=mm-dt.mm;
tempmm<0?tempyy-=1:tempyy;
tempdd=dd-dt.dd;
return abs((tempyy*365)-((tempmm<0)?(tempmm+11)*30:(tempmm*30))-((tempdd<0)?(tempdd+30):tempdd));
}
//overloaded << operator to work with variables of Date class
ostream& operator <<(ostream &out ,const Date &dt){
out<<dt.dd<<" "<<dt.mm<<" "<<dt.yr;
return out;
}
//overloaded >> operator to work with variables of Date class
istream& operator >>(istream &in, Date &dt){
in>>dt.dd>>dt.mm>>dt.yr;
return in;
}
//abstract class containing genral attributes for different type of books
class Book{
protected:
int bookCode;
string bookName;
string bookAuthor;
string bookPublication;
string bookUniqueCode;
public:
Book(){
this->bookCode = 0;
this->bookName = " ";
this->bookAuthor = " ";
this->bookPublication = " ";
}
Book(string bookName,int bookCode,string bookAuthor, string bookPublication){
this->bookCode = bookCode;
this->bookName = bookName;
this->bookAuthor = bookAuthor;
this->bookPublication = bookPublication;
}
//pure virtual function
virtual void showBookDetails(int)=0;
};
//EngineeringBooks class derived from Book class to deal with books for engineering course only
class EngineeringBooks : public Book{
public:
EngineeringBooks(){}
EngineeringBooks(string bookName,int bookCode,string bookAuthor, string bookPublication) : Book(bookName,bookCode,bookAuthor,bookPublication){
this->bookUniqueCode = "ENGG"+ to_string(bookCode);
}
void showBookDetails(int);
void storeBookRecords(int);
int retrieveBookRecords(EngineeringBooks&);
void retrieveAllBooks();
void updateBookRecords(EngineeringBooks&,int);
bool searchBook(EngineeringBooks&);
bool operator ==(EngineeringBooks&);
friend Library;
friend LibraryRecords;
friend ostream& operator<<(ostream& , const EngineeringBooks& );
friend istream& operator>>(istream& , EngineeringBooks& );
};
//overloading == operator to compare books of same type
bool EngineeringBooks::operator==(EngineeringBooks& bk){
if(bookCode==bk.bookCode && bookName==bk.bookName && bookAuthor==bk.bookAuthor && bookPublication==bk.bookPublication && bookUniqueCode==bk.bookUniqueCode){
return true;
}
return false;
}
//overloading << operator to work with variables of EngineeringBooks
ostream& operator<<(ostream& os, const EngineeringBooks& bk){
os<<bk.bookCode<<" "<<bk.bookName<<" "<<bk.bookAuthor<<" "<<bk.bookPublication<<" "<<bk.bookUniqueCode<<endl;
return os;
}
//overloading >> operator to work with variables of EngineeringBooks
istream& operator>>(istream& in, EngineeringBooks& bk){
in>>bk.bookCode>>bk.bookName>>bk.bookAuthor>>bk.bookPublication>>bk.bookUniqueCode;
return in;
}
//Function to store the details of engineering book in file
void EngineeringBooks :: storeBookRecords(int bookCount){
ofstream fout("EngineeringBookRecords.txt",ios::app);
fout<<bookCode<<" "<<bookName<<" "<<bookAuthor<<" "<<bookPublication<<" "<<bookUniqueCode<<" "<<bookCount<<endl;
fout.close();
}
//Function to fetch the details of engineering book from the file
int EngineeringBooks :: retrieveBookRecords(EngineeringBooks& book){
int bookCount=0;
ifstream fin("EngineeringBookRecords.txt",ios::in);
if(fin){
fin>>bookCode>>bookName>>bookAuthor>>bookPublication>>bookUniqueCode>>bookCount;
while(!fin.eof()){
if(*this==book){
cout<<left<<setw(35)<<" Book Available "<<endl;
return bookCount;
}
fin>>bookCode>>bookName>>bookAuthor>>bookPublication>>bookUniqueCode>>bookCount;
}
}
else{
cout<<left<<setw(35)<<" No Record Found"<<endl;
}
return bookCount;
}
//Function to update the records in file whenever a book is issued or returned by a student
void EngineeringBooks :: updateBookRecords(EngineeringBooks& book,int updatedBookCount){
int bookCount=0;
ofstream fout("EngineeringBookRecords1.txt",ios :: out);
ifstream fin("EngineeringBookRecords.txt",ios :: in);
if(fin){
fin>>bookCode>>bookName>>bookAuthor>>bookPublication>>bookUniqueCode>>bookCount;
while(!fin.eof()){
if(book==*this){
fout<<bookCode<<" "<<bookName<<" "<<bookAuthor<<" "<<bookPublication<<" "<<bookUniqueCode<<" "<<updatedBookCount<<endl;
}
else{
fout<<bookCode<<" "<<bookName<<" "<<bookAuthor<<" "<<bookPublication<<" "<<bookUniqueCode<<" "<<bookCount<<endl;
}
fin>>bookCode>>bookName>>bookAuthor>>bookPublication>>bookUniqueCode>>bookCount;
}
fout.close();
fin.close();
remove("EngineeringBookRecords.txt");
rename("EngineeringBookRecords1.txt","EngineeringBookRecords.txt");
}
else{
cout<<left<<setw(35)<<" No Record Found"<<endl;
}
}
//Function to check if a book entered by a student exists in our files or not
bool EngineeringBooks :: searchBook(EngineeringBooks& book){
int bookCount=0;
ifstream fin("EngineeringBookRecords.txt",ios::in);
if(fin){
fin>>bookCode>>bookName>>bookAuthor>>bookPublication>>bookUniqueCode>>bookCount;
while(!fin.eof()){
if(*this==book){
return true;
}
fin>>bookCode>>bookName>>bookAuthor>>bookPublication>>bookUniqueCode>>bookCount;
}
}
else{
cout<<left<<setw(35)<<" No Record Found"<<endl;
}
return false;
}
//Function to retrieve all book details from file
void EngineeringBooks :: retrieveAllBooks(){
int bookCount;
ifstream fin("EngineeringBookRecords.txt",ios::in);
if(fin){
fin>>bookCode>>bookName>>bookAuthor>>bookPublication>>bookUniqueCode>>bookCount;
while(!fin.eof()){
showBookDetails(bookCount);
fin>>bookCode>>bookName>>bookAuthor>>bookPublication>>bookUniqueCode>>bookCount;
}
}
else{
cout<<left<<setw(35)<<" No Record Found"<<endl;
}
}
//Function to show the books and its details
void EngineeringBooks::showBookDetails(int bookCount){
cout<<left<<setw(5)<<bookCode<<left<<setw(15)<<bookName<<left<<setw(15)<<bookAuthor<<left<<setw(15)<<bookPublication<<left<<setw(10)<<bookUniqueCode<<left<<setw(10)<<bookCount<<endl;
}
//ManagementBooks class derived from Book class to deal with books for management course only
class ManagementBooks : public Book{
private:
string bookCategory;
public:
ManagementBooks(){}
ManagementBooks(string bookName,int bookCode,string bookAuthor, string bookPublication):Book(bookName,bookCode,bookAuthor,bookPublication){
this->bookUniqueCode = "MGMT" + to_string(bookCode);
}
void showBookDetails(int);
void storeBookRecords(int);
int retrieveBookRecords(ManagementBooks&);
void retrieveAllBooks();
void updateBookRecords(ManagementBooks&,int);
bool searchBook(ManagementBooks&);
bool operator ==(ManagementBooks&);
// bool operator ==(Book &book);
friend Library;
friend LibraryRecords;
friend ostream& operator<<(ostream& , const ManagementBooks& );
friend istream& operator>>(istream& , ManagementBooks& );
};
//overloading == operator to compare books of same type
bool ManagementBooks::operator==(ManagementBooks& bk){
if(bookCode==bk.bookCode && bookName==bk.bookName && bookAuthor==bk.bookAuthor && bookPublication==bk.bookPublication && bookUniqueCode==bk.bookUniqueCode){
return true;
}
return false;
}
//overloading << operator to work with variables of ManagementBooks
ostream& operator<<(ostream& os, const ManagementBooks& bk){
os<<bk.bookCode<<" "<<bk.bookName<<" "<<bk.bookAuthor<<" "<<bk.bookPublication<<" "<<bk.bookUniqueCode<<endl;
return os;
}
//overloading >> operator to work with variables of ManagementBooks
istream& operator>>(istream& in, ManagementBooks& bk){
in>>bk.bookCode>>bk.bookName>>bk.bookAuthor>>bk.bookPublication>>bk.bookUniqueCode;
return in;
}
//Function to store the details of management book in file
void ManagementBooks :: storeBookRecords(int bookCount){
ofstream fout("ManagementBookRecords.txt",ios::app);
fout<<bookCode<<" "<<bookName<<" "<<bookAuthor<<" "<<bookPublication<<" "<<bookUniqueCode<<" "<<bookCount<<endl;
fout.close();
}
//Function to fetch the details of management book from the file
int ManagementBooks :: retrieveBookRecords(ManagementBooks& book){
int bookCount=0;
ifstream fin("ManagementBookRecords.txt",ios::in);
if(fin){
fin>>bookCode>>bookName>>bookAuthor>>bookPublication>>bookUniqueCode>>bookCount;
while(!fin.eof()){
if(*this==book){
cout<<left<<setw(35)<<" Book Available "<<endl;
return bookCount;
}
fin>>bookCode>>bookName>>bookAuthor>>bookPublication>>bookUniqueCode>>bookCount;
}
}
else{
cout<<left<<setw(35)<<" No Record Found"<<endl;
}
return bookCount;
}
//Function to update the records in file whenever a book is issued or returned by a student
void ManagementBooks :: updateBookRecords(ManagementBooks& book,int updatedBookCount){
int bookCount=0;
ofstream fout("ManagementBookRecords1.txt",ios :: out);
ifstream fin("ManagementBookRecords.txt",ios :: in);
if(fin){
fin>>bookCode>>bookName>>bookAuthor>>bookPublication>>bookUniqueCode>>bookCount;
while(!fin.eof()){
if(book==*this){
fout<<bookCode<<" "<<bookName<<" "<<bookAuthor<<" "<<bookPublication<<" "<<bookUniqueCode<<" "<<updatedBookCount<<endl;
}
else{
fout<<bookCode<<" "<<bookName<<" "<<bookAuthor<<" "<<bookPublication<<" "<<bookUniqueCode<<" "<<bookCount<<endl;
}
fin>>bookCode>>bookName>>bookAuthor>>bookPublication>>bookUniqueCode>>bookCount;
}
fout.close();
fin.close();
remove("ManagementBookRecords.txt");
rename("ManagementBookRecords1.txt","ManagementBookRecords.txt");
}
else{
cout<<left<<setw(35)<<" No Record Found"<<endl;
}
}
//Function to check if a book entered by a student exists in our files or not
bool ManagementBooks :: searchBook(ManagementBooks& book){
int bookCount=0;
ifstream fin("ManagementBookRecords.txt",ios::in);
if(fin){
fin>>bookCode>>bookName>>bookAuthor>>bookPublication>>bookUniqueCode>>bookCount;
while(!fin.eof()){
if(*this==book){
return true;
}
fin>>bookCode>>bookName>>bookAuthor>>bookPublication>>bookUniqueCode>>bookCount;
}
}
else{
cout<<left<<setw(35)<<" No Record Found"<<endl;
}
return false;
}
//Function to retrieve all book details from file
void ManagementBooks :: retrieveAllBooks(){
int bookCount;
ifstream fin("ManagementBookRecords.txt",ios::in);
if(fin){
fin>>bookCode>>bookName>>bookAuthor>>bookPublication>>bookUniqueCode>>bookCount;
while(!fin.eof()){
showBookDetails(bookCount);
fin>>bookCode>>bookName>>bookAuthor>>bookPublication>>bookUniqueCode>>bookCount;
}
}
else{
cout<<left<<setw(35)<<" No Record Found"<<endl;
}
}
//Function to show the books and its details
void ManagementBooks::showBookDetails(int bookCount){
cout<<left<<setw(5)<<bookCode<<left<<setw(15)<<bookName<<left<<setw(15)<<bookAuthor<<left<<setw(15)<<bookPublication<<left<<setw(10)<<bookUniqueCode<<left<<setw(10)<<bookCount<<endl;
}
//Student class to handle the record of a student
class Student{
private:
string stuName;
string stuCourse;
int enrollNo;
public:
Student(){}
Student(string stuName, string stuCourse, int enrollNo){
this->stuName = stuName;
this->stuCourse = stuCourse;
this->enrollNo = enrollNo;
}
bool operator ==(Student&);
friend ostream& operator<<(ostream& , const Student&);
friend istream& operator>>(istream& , Student& );
friend LibraryRecords;
};
//overloading == operator to match the student type variable
bool Student :: operator ==(Student& st){
if(stuName==st.stuName && stuCourse==st.stuCourse && enrollNo== st.enrollNo){
return true;
}
return false;
}
//overloading << operator to work with variables of student class
ostream& operator<<(ostream& out, const Student& st){
out<<st.stuName<<" "<<st.stuCourse<<" "<<st.enrollNo<<endl;
return out;
}
//overloading >> operator to work with variables of student class
istream& operator>>(istream& in, Student& st){
in>>st.stuName>>st.stuCourse>>st.enrollNo;
return in;
}
//LibraryRecords class to manage the Library Records
class LibraryRecords{
private:
ManagementBooks mBook;
EngineeringBooks eBook;
Student student;
Date dt;
float fine;
public:
LibraryRecords(){}
LibraryRecords(EngineeringBooks eBook, ManagementBooks mBook, Student student, Date dt){
this->eBook = eBook;
this->mBook = mBook;
this->student = student;
this->dt = dt;
this->fine = 0;
}
void storeLibraryRecords(int );
bool searchRecord(LibraryRecords&,int);
bool operator==(LibraryRecords&);
void showRecord();
void updateLibraryRecord(LibraryRecords&,int);
void retrieveAllLibraryRecords();
int calculateFine(int, int);
friend ostream& operator <<(ostream &, LibraryRecords&);
friend istream& operator >>(istream &, LibraryRecords&);
friend Library;
};
//overloading == operator to match library records
bool LibraryRecords :: operator==(LibraryRecords& libRec){
if(eBook==libRec.eBook && student==libRec.student && dt==libRec.dt){
return true;
}
else if(mBook==libRec.mBook && student==libRec.student && dt==libRec.dt){
return true;
}
return false;
}
//overloading << operator to work with variables of library records
ostream& operator <<(ostream &out, LibraryRecords &libRec){
out<<libRec.eBook<<endl<<libRec.mBook<<endl<<libRec.student<<endl<<libRec.dt<<endl<<libRec.fine;
return out;
}
//overloading >> operator to work with variables of library records
istream& operator >>(istream &in, LibraryRecords &libRec){
in>>libRec.eBook>>libRec.mBook>>libRec.student>>libRec.dt>>libRec.fine;
return in;
}
//Function to show the library records
void LibraryRecords::showRecord(){
cout<<mBook<<" "<<eBook<<" "<<student<<" "<<dt<<" "<<fine<<endl;
}
//Function to store the library records in a file
void LibraryRecords::storeLibraryRecords(int bookChoice){
ofstream fout("LibraryRecords.txt",ios::app);
if(bookChoice==1){
fout<<eBook<<student<<dt<<endl<<fine<<endl;
}
else{
fout<<mBook<<student<<dt<<endl<<fine<<endl;
}
fout<<endl;
}
//Function to search if a record of a particular student and book exist in library records or not
bool LibraryRecords :: searchRecord(LibraryRecords& libRec, int bookChoice){
ifstream fin("LibraryRecords.txt",ios::in);
if(fin){
if(bookChoice==1){
fin>>eBook>>student>>dt>>fine;
while(!fin.eof()){
if(libRec==*this){
showRecord();
return true;
}
fin>>eBook>>student>>dt>>fine;
}
}
else if(bookChoice==2){
fin>>mBook>>student>>dt>>fine;
while(!fin.eof()){
if(libRec==*this){
showRecord();
return true;
}
fin>>mBook>>student>>dt>>fine;
}
}
}
else{
cout<<left<<setw(35)<<" No Record Found"<<endl;
}
return false;
}
//Function to update library records whenever a student issues or returns a book
void LibraryRecords :: updateLibraryRecord(LibraryRecords& libRec, int bookChoice){
ofstream fout("LibraryRecords1.txt",ios::out);
ifstream fin("LibraryRecords.txt",ios::in);
if(fin){
if(bookChoice==1){
fin>>eBook>>student>>dt>>fine;
while(!fin.eof()){
if(!(libRec==*this)){
fout<<eBook<<" "<<student<<" "<<dt<<" "<<fine<<endl;
}
fin>>eBook>>student>>dt>>fine;
}
}
else if(bookChoice==2){
fin>>mBook>>student>>dt>>fine;
while(!fin.eof()){
if(!(libRec==*this)){
fout<<mBook<<" "<<student<<" "<<dt<<" "<<fine<<endl;
}
fin>>mBook>>student>>dt>>fine;
}
}
fout.close();
fin.close();
remove("LibraryRecords.txt");
rename("LibraryRecords1.txt","LibraryRecords.txt");
}
else{
cout<<left<<setw(35)<<" No Record Found"<<endl;
}
}
//Function to retrieve all library records from a file
void LibraryRecords :: retrieveAllLibraryRecords(){
ifstream fin("LibraryRecords.txt",ios::in);
if(fin){
fin>>eBook>>student>>dt>>fine;
while(!fin.eof()){
showRecord();
fin>>eBook>>student>>dt>>fine;
}
fin>>mBook>>student>>dt>>fine;
while(!fin.eof()){
showRecord();
fin>>mBook>>student>>dt>>fine;
}
fin.close();
}
else{
cout<<left<<setw(35)<<" No Record Found"<<endl;
}
}
//Function to calculate the fine on a student when he returns book
int LibraryRecords :: calculateFine(int dayDiff, int bookChoice){
if(dayDiff > 7){
fine =(dayDiff-7)*10;
cout<<fine<<endl;
return fine;
}
else{
fine=0;
}
return fine;
}
//Library class to handle all the library operations
class Library{
private:
ManagementBooks mBook;
EngineeringBooks eBook;
Student student;
LibraryRecords libRec;
int maxBookCount;
public:
Library(){
maxBookCount=10;
}
void libraryMenu();
void addBook();
void issueBook();
void returnBook();
Date returnValidDate();
void storeBookDetails();
friend ostream& operator<<(ostream& os, Library& lib);
};
//function to display all the options available to a user
void Library::libraryMenu(){
string str;
int choice;
do{
fflush(stdin);
system("CLS");
cout<<left<<setw(35)<<"1. Add Book "<<endl;
cout<<left<<setw(35)<<"2. Issue Book "<<endl;
cout<<left<<setw(35)<<"3. Return Book "<<endl;
cout<<left<<setw(35)<<"4. Available Books "<<endl;
cout<<left<<setw(35)<<"5. Show Library Records "<<endl;
cout<<left<<setw(35)<<"6. Exit "<<endl;
cout<<left<<setw(40)<<" Enter Your Choice ";
cin>>choice;
switch(choice){
case 1 : addBook();
cout<<left<<setw(35)<<" Press Enter"<<endl;
cin.get();
cin.get();
break;
case 2 : issueBook();
cout<<left<<setw(35)<<" Press Enter"<<endl;
cin.get();
cin.get();
break;
case 3 : returnBook();
cout<<left<<setw(35)<<" Press Enter"<<endl;
cin.get();
cin.get();
break;
case 4 : cout<<left<<setw(5)<<"Code"<<left<<setw(15)<<"Book Name"<<left<<setw(15)<<"Author"<<left<<setw(15)<<"Publisher"<<left<<setw(10)<<"UCode"<<left<<setw(10)<<"Quantity"<<endl;
mBook.retrieveAllBooks();
eBook.retrieveAllBooks();
cout<<left<<setw(35)<<" Press Enter"<<endl;
cin.get();
cin.get();
break;
case 5 : libRec.retrieveAllLibraryRecords();
cout<<left<<setw(35)<<" Press Enter"<<endl;
cin.get();
cin.get();
break;
case 6 : exit(0);
break;
default: cout<<"Invalid Option!"<<endl;
}
}while(1);
}
//function to check if a date entered by a user is valid or not
Date Library :: returnValidDate(){
int dd,mm,yy;
int currYear;
time_t now = time(0);
tm *localTime = localtime(&now);
currYear = 1900 +(localTime->tm_year);
try{
cout<<left<<setw(35)<<" Enter Issue Date (dd/mm/yy) "<<left<<setw(4)<<" : ";
cin>>dd>>mm>>yy;
if((dd>29 || dd<=0) && (mm==2)){
throw runtime_error("Invalid Date !");
}
else if(((dd>31 || dd<=0) && (mm>6 || mm%2==0)) || ((dd>31 || dd<=0) && (mm<6 || mm%2!=0))){
throw runtime_error("Invalid Date !");
}
else if(((dd>30 || dd<=0) && (mm==4 || mm==6)) || ((dd>30 || dd<=0) && (mm==9 || mm==11))){
throw runtime_error("Invalid Date !");
}
if((yy>currYear || yy<2000)){
throw runtime_error("Invalid Date !");
}
}catch(runtime_error &error){
cout<<left<<setw(35)<<" Exception Occured !"<<endl;
libraryMenu();
}
Date tempDate(dd,mm,yy);
return tempDate;
}
//function to add book in library
void Library :: addBook(){
string bookName;
int bookCode;
string bookAuthor;
string bookPublication;
int bookChoice;
string input;
regex stringExpr("[A-Z_a-z]+");
cout<<left<<setw(35)<<" 1 Engineering "<<endl;
cout<<left<<setw(35)<<" 2 Management"<<endl;
cout<<left<<setw(40)<<" Enter Book Category ";
cin>>bookChoice;
while(true){
cout<<left<<setw(35)<<" Enter Book Name "<<left<<setw(4)<<" : ";
cin>>input;
if(regex_match(input,stringExpr)){
bookName=input;
break;
}
else{
cout<<left<<setw(35)<<" Invalid Input"<<endl;
}
}
while(true){
cout<<left<<setw(35)<<" Enter Book Author "<<left<<setw(4)<<" : ";
cin>>input;
if(regex_match(input,stringExpr)){
bookAuthor=input;
break;
}
else{
cout<<left<<setw(35)<<" Invalid Input"<<endl;
}
}
while(true){
cout<<left<<setw(35)<<" Enter Publisher of Book "<<left<<setw(4)<<" : ";
cin>>input;
if(regex_match(input,stringExpr)){
bookPublication=input;
break;
}
else{
cout<<left<<setw(35)<<" Invalid Input"<<endl;
}
}
cout<<left<<setw(35)<<" Enter Book Code "<<left<<setw(4)<<" : ";
cin>>bookCode;
if(bookChoice==1){
EngineeringBooks tempBook(bookName,bookCode,bookAuthor,bookPublication);
eBook = tempBook;
eBook.storeBookRecords(maxBookCount);
cout<<left<<setw(35)<<" Book Added Successfully "<<endl;
cout<<left<<setw(5)<<"Code"<<left<<setw(15)<<"Book Name"<<left<<setw(15)<<"Author"<<left<<setw(15)<<"Publisher"<<left<<setw(10)<<"UCode"<<left<<setw(10)<<"Quantity"<<endl;
eBook.retrieveAllBooks();
}
else{
ManagementBooks tempBook(bookName,bookCode,bookAuthor,bookPublication);
mBook = tempBook;
mBook.storeBookRecords(maxBookCount);
cout<<left<<setw(35)<<" Book Added Successfully "<<endl;
cout<<left<<setw(5)<<"Code"<<left<<setw(15)<<"Book Name"<<left<<setw(15)<<"Author"<<left<<setw(15)<<"Publisher"<<left<<setw(10)<<"UCode"<<left<<setw(10)<<"Quantity"<<endl;
mBook.retrieveAllBooks();
}
}
//function to issue a book from the library
void Library :: issueBook(){
string stuName;
string stuCourse;
int enrollNo;
regex stringExpr("[A-Z_a-z]+");
string input;
cout<<left<<setw(35)<<" Enter Your Enrollment Number "<<left<<setw(4)<<" : ";
cin>>enrollNo;
while(true){
cout<<left<<setw(35)<<" Enter Your Name "<<left<<setw(4)<<" : ";
cin>>input;
if(regex_match(input,stringExpr)){
stuName=input;
break;
}
else{
cout<<left<<setw(35)<<" Invalid Input"<<endl;
}
}
while(true){
cout<<left<<setw(35)<<" Enter Your Course "<<left<<setw(4)<<" : ";
cin>>input;
if(regex_match(input,stringExpr)){
stuCourse=input;
break;
}
else{
cout<<left<<setw(35)<<" Invalid Input"<<endl;
}
}
string bookName;
int bookCode;
string bookAuthor;
string bookPublication;
int bookChoice;
cout<<left<<setw(35)<<" 1 Engineering "<<endl;
cout<<left<<setw(35)<<" 2 Management"<<endl;
cout<<left<<setw(40)<<" Enter Book Category ";
cin>>bookChoice;
while(true){
cout<<left<<setw(35)<<" Enter Book Name "<<left<<setw(4)<<" : ";
cin>>input;
if(regex_match(input,stringExpr)){
bookName=input;
break;
}
else{
cout<<left<<setw(35)<<" Invalid Input"<<endl;
}
}
while(true){
cout<<left<<setw(35)<<" Enter Book Author "<<left<<setw(4)<<" : ";
cin>>input;
if(regex_match(input,stringExpr)){
bookAuthor=input;
break;
}
else{
cout<<left<<setw(35)<<" Invalid Input"<<endl;
}
}
while(true){
cout<<left<<setw(35)<<" Enter Publisher of Book "<<left<<setw(4)<<" : ";
cin>>input;
if(regex_match(input,stringExpr)){
bookPublication=input;
break;
}
else{
cout<<left<<setw(35)<<" Invalid Input"<<endl;
}
}
cout<<left<<setw(35)<<" Enter Book Code "<<left<<setw(4)<<" : ";
cin>>bookCode;