-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLibrary Management System.cpp
More file actions
827 lines (785 loc) · 16.6 KB
/
Copy pathLibrary Management System.cpp
File metadata and controls
827 lines (785 loc) · 16.6 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
#include<bits/stdc++.h>
#include<iostream>
#include<fstream>
#include<stdlib.h>
#include<stdio.h>
#include<process.h>
#include<conio.h>
using namespace std;
#define el "\n"
#define sp " "
int res_book(int,int); //To check whether any book a given book no. exists or not
/*Class of books*/
class book
{
protected:
int bno,quant; //book no
char bname[50]; //book name
char aname[50]; //book author's name
char pname[50]; //publication name
public:
void createb();
void showb();
void showlist();
void assignbno(int x) //bno assigned on the basis of no
{ //no. of objects in file
bno=10001;
bno+=x-1;
start1:
bno+=1;
if(res_book(bno,0))
goto start1;
}
void set_q()
{
quant-=1;
}
int quantity()
{
return quant;
}
void reset_q()
{
quant+=1;
}
int retbno()
{
return bno;
}
};
/*End of class book*/
void book::createb() //To enter data in data members of class book
{
int i;
cout<<"\n\t\tEnter the details:-\n";
cout<<"\n\t\tEnter Book's Name: ";
char n[50];
cin.getline(n,50);
cin.getline(bname,50);
for(i=0;bname[i]!='\0';i++)
{
if(bname[i]>='a'&&bname[i]<='z')
bname[i]-=32;
}
cout<<"\n\t\tEnter Author's Name: ";
cin.getline(aname,50);
cout<<"\n\t\tEnter Publication Name: ";
cin.getline(pname,50);
cout<<"\n\t\tEnter Book's quantity: ";
cin>>quant;
}
void book::showb() //To display the details of books
{
cout<<"\n\t\tBook No.: "<<bno<<el;
cout<<"\n\t\tBook Name: "<<bname<<el;
cout<<"\n\t\tBook's Author Name: "<<aname<<el;
cout<<"\n\t\tBook's Publication: "<<pname<<el;
cout<<"\n\t\tBook's Quantity: "<<quant<<el;
}
void book::showlist() //To display book details in list form
{
cout<<"\n\t"<<bno<<"\t\t"<<bname<<"\t\t"<<aname<<"\t\t"<<quant;
}
/*Class of Students*/
class student
{
protected:
char name[25]; //Student name
int bno; //Book no. of book issued
int token; //To veirfy book issued or not
public:
void creates();
void shows();
void showlist();
void settoken(int x) //To set token and assign bno a book no
{
bno=x;
token=1;
}
void resettoken() //To reset token
{
bno=0;
token=0;
}
int retbno()
{
return bno;
}
int admno; //Admission No
};
/*End of class Students*/
bool res_student(int); //To check whether the admission no. already exist or not
void student::creates() //To enter values to all data members of class student
{
int i;
plane:
system("CLS");
cout<<"\n\t\tEnter the details:-\n";
cout<<"\n\t\tEnter student's Admission no: ";
cin>>admno;
if(res_student(admno))
{
cout<<"\n\t\tRecord already exist with this admission no.";
cout<<"\n\t\tEnter a different admission no.\n";
system("PAUSE");
goto plane;
}
cout<<"\n\t\tEnter student's Name: ";
char n[50];
cin.getline(n,50);
cin.getline(name,25);
for(i=0;name[i]!='\0';i++)
{
if(name[i]>='a'&&name[i]<='z')
name[i]-=32;
}
bno=0;
token=0;
}
void student::shows() //Show details of Students
{
cout<<"\n\t\tStudent's Admission No.: "<<admno<<el;
cout<<"\n\t\tStudent's Name: "<<name<<el;
if(token==1)
{
cout<<"\n\t\tBook Issued (Book no): "<<bno;
}
}
void student::showlist() // To display Student details in list form
{
cout<<"\n\t"<<admno<<"\t\t"<<name<<"\t\t"<<bno;
}
/*To Write object of class book in file*/
void write_book()
{
book bk;
ofstream outf("book1.bin",ios::app|ios::binary);
outf.seekp(0,ios::end);
int x=outf.tellp()/sizeof(book);
bk.assignbno(x);
bk.createb();
bk.showb();
outf.write(reinterpret_cast<char *>(&bk),sizeof(book));
cout<<"\n\t\tRecord added successfully";
outf.close();
}
/*To Write object of class student in file*/
void write_student()
{
student st;
ofstream outf("student.bin",ios::app|ios::binary);
outf.seekp(0,ios::end);
st.creates();
st.shows();
outf.write(reinterpret_cast<char *>(&st),sizeof(student));
cout<<"\n\t\tRecord added successfully";
outf.close();
}
/*To display Student records in list form*/
void list_student()
{
system("CLS");
student st;
ifstream intf("student.bin",ios::in|ios::binary);
intf.seekg(0,ios::beg);
if(!intf)
cout<<"\n\t\tFile not found";
else
{
cout<<"\n\t*****Students Details*****\n\n";
cout<<"\n\tAdmission No:\tName: \tBook Issued:";
while(intf.read(reinterpret_cast<char *>(&st),sizeof(student)))
st.showlist();
}
intf.close();
}
/*To display book records in list form*/
void list_book()
{
book bk;
ifstream intf("book1.bin",ios::in|ios::binary);
intf.seekg(0,ios::beg);
if(!intf)
cout<<"\n\t\tFile not found";
else
{
cout<<"\n\t*****Books Details*****\n\n";
cout<<"\n\tBook No:\t\tName: \t\tAuthor's Name: \t\tQuantity: ";
while(intf.read(reinterpret_cast<char *>(&bk),sizeof(book)))
bk.showlist();
}
intf.close();
}
/*To search for a specific student*/
void search_student(int x)
{
student st;
int cnt=0;
ifstream intf("student.bin",ios::in|ios::binary);
intf.seekg(0,ios::beg);
if(!intf)
cout<<"\n\t\tFile not found";
else
{
while(intf.read(reinterpret_cast<char *>(&st),sizeof(student)))
{
if(st.admno==x)
{
cnt++;
cout<<"\n\t\tFILE FOUND!!!!";
st.shows();
break;
}
}
if(cnt==0)
cout<<"\n\t\tNo such record exists";
}
intf.close();
}
/*To search for a specific book*/
void search_book(int x)
{
book bk;
int cnt=0;
ifstream intf("book1.bin",ios::in|ios::binary);
intf.seekg(0,ios::beg);
if(!intf)
cout<<"\n\t\tFile not found";
else
{
while(intf.read(reinterpret_cast<char *>(&bk),sizeof(book)))
{
if(bk.retbno()==x)
{
cnt++;
cout<<"\n\t\tFILE FOUND!!!!";
bk.showb();
break;
}
}
if(cnt==0)
cout<<"\n\t\tNo such record exists";
}
intf.close();
}
/*To modify the book records*/
void modify_book(int x)
{
book bk;
int cnt=0;
fstream intf("book1.bin",ios::in|ios::out|ios::ate|ios::binary);
intf.seekg(0,ios::beg);
if(!intf)
cout<<"\n\t\tFile not found";
else
{
while(intf.read(reinterpret_cast<char *>(&bk),sizeof(book)))
{
if(bk.retbno()==x)
{
cnt++;
bk.createb();
bk.showb();
intf.seekp(intf.tellp()-sizeof(book));
intf.write(reinterpret_cast<char *>(&bk),sizeof(book));
cout<<"\n\t\tRecord Updated";
break;
}
}
if(cnt==0)
cout<<"\n\t\tNo such record exists";
}
intf.close();
}
/*To modify the student records*/
void modify_student(int x)
{
student st;
int cnt=0;
fstream intf("student.bin",ios::in|ios::out|ios::ate|ios::binary);
intf.seekg(0,ios::beg);
if(!intf)
cout<<"\n\t\tFile not found";
else
{
while(intf.read(reinterpret_cast<char *>(&st),sizeof(student)))
{
if(st.admno==x)
{
cnt++;
st.creates();
st.shows();
intf.seekp(intf.tellp()-sizeof(student));
intf.write(reinterpret_cast<char *>(&st),sizeof(student));
cout<<"\n\t\tRecord Updated";
break;
}
}
if(cnt==0)
cout<<"\n\t\tNo such record exists";
}
intf.close();
}
/*To delete a specific student record*/
void delete_student(int x)
{
student st;
int cnt=0;
ifstream intf("student.bin",ios::in|ios::binary);
intf.seekg(0,ios::beg);
if(!intf)
cout<<"\n\t\tFile not found";
else
{
ofstream outf("temp.bin",ios::app|ios::binary);
while(intf.read(reinterpret_cast<char *>(&st),sizeof(student)))
{
if(st.admno==x)
cnt++;
else
outf.write(reinterpret_cast<char *>(&st),sizeof(student));
}
intf.close();
outf.close();
if(cnt==0)
{
remove("temp.bin");
cout<<"\n\t\tNo such record exists";
}
else
{
remove("student.bin");
rename("temp.bin","student.bin");
cout<<"\n\t\tRecord deleted successfully";
}
}
}
/*To delete a specific book record*/
void delete_book(int x)
{
book bk;
int cnt=0;
ifstream intf("book1.bin",ios::in|ios::binary);
intf.seekg(0,ios::beg);
if(!intf)
cout<<"\n\t\tFile not found";
else
{
ofstream outf("temp1.bin",ios::app|ios::binary);
while(intf.read(reinterpret_cast<char *>(&bk),sizeof(book)))
{
if(bk.retbno()==x)
cnt++;
else
outf.write(reinterpret_cast<char *>(&bk),sizeof(book));
}
intf.close();
outf.close();
if(cnt==0)
{
remove("temp1.bin");
cout<<"\n\t\tNo such record exists";
}
else
{
remove("book.bin");
rename("temp1.bin","book.bin");
cout<<"\n\t\tRecord deleted successfully";
}
}
}
//To search whether a specific student record exists or not
bool res_student(int x)
{
student st;
int cnt=0,f=0;
ifstream intf("student.bin",ios::in|ios::binary);
intf.seekg(0,ios::beg);
if(!intf)
f=1;
else
{
while(intf.read(reinterpret_cast<char *>(&st),sizeof(student)))
{
if(st.admno==x)
{
cnt++;
break;
}
}
if(cnt==0)
f=1;
}
intf.close();
if(f)
return 0;
else
return 1;
}
/*To search a specific book and return true or false*/
int res_book(int x,int z)
{
book bk;
int cnt=0,f=1;
fstream intf("book1.bin",ios::in|ios::out|ios::ate|ios::binary);
intf.seekg(0,ios::beg);
if(!intf)
f=0;
else
{
while(intf.read(reinterpret_cast<char *>(&bk),sizeof(book)))
{
if(bk.retbno()==x)
{
cnt++;
if(z==1)
{
bk.showb();
if(bk.quantity()>0)
{
bk.set_q();
intf.seekp(intf.tellp()-sizeof(book));
intf.write(reinterpret_cast<char *>(&bk),sizeof(book));
}
else
f=2;
}
else if(z==2)
{
bk.showb();
bk.reset_q();
intf.seekp(intf.tellp()-sizeof(book));
intf.write(reinterpret_cast<char *>(&bk),sizeof(book));
}
break;
}
}
if(cnt==0)
f=0;
}
intf.close();
return f;
}
/*To issue books*/
void book_issue()
{
int sn,bn;
system("CLS");
cout<<"\n\n\t\t*****BOOK ISSUE******";
cout<<"\n\n\t\tEnter the student's admission no: ";
cin>>sn;
int cnt=0;
student st;
fstream outf("student.bin",ios::in|ios::out|ios::ate|ios::binary);
outf.seekg(0,ios::beg);
if(!outf)
cout<<"\n\t\tFile not found\n";
else
{
while(outf.read(reinterpret_cast<char *>(&st),sizeof(student)))
{
if(st.admno==sn)
{
cnt++;
list_book();
cout<<"\n\n\t\tEnter the book no.:";
cin>>bn;
cout<<"\n";
int flag=res_book(bn,1);
if(flag==1)
{
st.settoken(bn);
outf.seekp(outf.tellp()-sizeof(student));
outf.write(reinterpret_cast<char *>(&st),sizeof(student));
cout<<"\n\t\tBook Issued";
cout<<"\n\t\tNote: Write the current date in backside of the book";
cout<<"\n\t\t Should be submitted within 15 days to avoid fine";
cout<<"\n\t\t The fine is Rs. 1 for each day after 15 days period\n";
break;
}
else if(flag==2)
{
cout<<"\n\t\tTHE BOOK IS OUT OF STOCK!!!";
break;
}
else
{
cout<<"\n\t\tNo such record exists\n";
break;
}
}
}
if(cnt==0)
cout<<"\n\t\tNo such record exists\n";
}
outf.close();
}
/*To deposit books*/
void book_deposit()
{
int sn,bn;
system("CLS");
cout<<"\n\n\t\t*****BOOK DEPOSIT******";
cout<<"\n\n\t\tEnter the student's admission no: ";
cin>>sn;
int cnt=0;
student st;
fstream outf("student.bin",ios::in|ios::out|ios::ate|ios::binary);
outf.seekg(0,ios::beg);
if(!outf)
cout<<"\n\t\tFile not found\n";
else
{
while(outf.read(reinterpret_cast<char *>(&st),sizeof(student)))
{
if(st.admno==sn)
{
cnt++;
bn=st.retbno();
bool flag=res_book(bn,2);
if(flag)
{
st.resettoken();
outf.seekp(outf.tellp()-sizeof(student));
outf.write(reinterpret_cast<char *>(&st),sizeof(student));
int days;
cout<<"\n\t\tBook deposited in no. of days:";
cin>>days;
if(days>15)
{
int fine=(days-15)*1;
cout<<"\n\n\t\tFine: "<<fine<<el;
}
cout<<"\n\t\tBook Deposited Successfully\n";
break;
}
else
{
cout<<"\n\t\tNo such record exists\n";
break;
}
}
}
if(cnt==0)
cout<<"\n\t\tNo such record exists\n";
}
outf.close();
}
/*Function that has features of Admin Menu*/
void admin_menu()
{
fine:
system("PAUSE");
system("CLS");
int opt;
cout<<"\n\n\n\t\t\t******ADMINISTRATOR MENU******";
cout<<"\n\n\t1.\tCREATE STUDENT RECORD";
cout<<"\n\n\t2.\tDISPLAY ALL STUDENTS RECORD";
cout<<"\n\n\t3.\tDISPLAY SPECIFIC STUDENT RECORD ";
cout<<"\n\n\t4.\tMODIFY STUDENT RECORD";
cout<<"\n\n\t5.\tDELETE STUDENT RECORD";
cout<<"\n\n\t6.\tCREATE BOOK ";
cout<<"\n\n\t7.\tDISPLAY ALL BOOKS ";
cout<<"\n\n\t8.\tDISPLAY SPECIFIC BOOK ";
cout<<"\n\n\t9.\tMODIFY BOOK ";
cout<<"\n\n\t10.\tDELETE BOOK ";
cout<<"\n\n\t11.\tBACK TO MAIN MENU";
cout<<"\n\n\tPlease Enter Your Choice (1-11) ";
cin>>opt;
if(opt==1)
{
system("CLS");
write_student();
cout<<el;
goto fine;
}
else if(opt==2)
{
system("CLS");
list_student();
cout<<el;
goto fine;
}
else if(opt==3)
{
system("CLS");
int ad;
cout<<"\n\n\n\t\tEnter the admission no. of the student";
cin>>ad;
search_student(ad);
cout<<el;
goto fine;
}
else if(opt==4)
{
system("CLS");
int ad;
cout<<"\n\n\n\t\tEnter the admission no. of the student";
cin>>ad;
modify_student(ad);
cout<<el;
goto fine;
}
else if(opt==5)
{
system("CLS");
int ad;
cout<<"\n\n\n\t\tEnter the admission no. of the student";
cin>>ad;
delete_student(ad);
cout<<el;
goto fine;
}
else if(opt==6)
{
system("CLS");
write_book();
cout<<el;
goto fine;
}
else if(opt==7)
{
system("CLS");
list_book();
cout<<el;
goto fine;
}
else if(opt==8)
{
system("CLS");
int ad;
cout<<"\n\n\n\t\tEnter the book no. of the book";
cin>>ad;
search_book(ad);
cout<<el;
goto fine;
}
else if(opt==9)
{
system("CLS");
int ad;
cout<<"\n\n\n\t\tEnter the book no. of the book";
cin>>ad;
modify_book(ad);
cout<<el;
goto fine;
}
else if(opt==10)
{
system("CLS");
int ad;
cout<<"\n\n\n\t\tEnter the book no. of the book";
cin>>ad;
delete_book(ad);
cout<<el;
goto fine;
}
else if(opt==11)
return ;
else
{
cout<<"\n\t\tEnter correct option";
cout<<el;
goto fine;
}
}
/*Checks for correct password*/
//The password if predefined and has to be changed through the source code
//of application
bool passwords()
{
int i=0;
char ch,st[21],ch1[21]={"0000"};
cout<<"\n\n\t\tEnter Password : ";
while(1)
{
ch=getch();
if(ch==13)
{
st[i]='\0';
break;
}
else if(ch==8&&i>0)
{
i--;
cout<<"\b \b";
}
else
{
cout<<"*";
st[i]=ch;
i++;
}
}
for(i=0;st[i]==ch1[i]&&st[i]!='\0'&&ch1[i]!='\0';i++);
if(st[i]=='\0'&&ch1[i]=='\0')
return 1;
else
return 0;
}
//Main function
int main()
{
cout<<"\n\n\t\t\t*******************************************";
cout<<"\n\t\t\t------------------------------------------";
cout<<"\n\t\t\t\tLIBRARY MANAGEMENT SYSTEM";
cout<<"\n\t\t\t------------------------------------------";
cout<<"\n\t\t\t*******************************************";
bool a=passwords();
if(!a)
{
for(int i=0;i<2;i++)
{
cout<<"\nWrong password";
cout<<"\nYou have "<<2-i<<"attempts left";
if(passwords())
goto last;
if(i==1)
{
cout<<"\n\n\n\t\t\t All attempts failed........";
cout<<"\n\n\t\t\t Sorry, but you can't login";
exit(0);
}
}
}
last:
cout<<"\n\n";
start:
system("PAUSE");
system("CLS");
int opt;
cout<<"\n\n\t\t\t------------------------------------------";
cout<<"\n\t\t\t\tLIBRARY MANAGEMENT SYSTEM";
cout<<"\n\t\t\t------------------------------------------";
cout<<"\n\n\t\t\tWhat do you want to do?";
cout<<"\n\t\t\t1.\tBOOK ISSUE";
cout<<"\n\t\t\t2.\tBOOK DEPOSIT";
cout<<"\n\t\t\t3.\tADMINISTRATOR MENU";
cout<<"\n\t\t\t4.\tExit";
cout<<"\n\n Choose your option: ";
cin>>opt;
if(opt==1)
{
system("CLS");
book_issue();
goto start;
}
else if(opt==2)
{
system("CLS");
book_deposit();
goto start;
}
else if(opt==3)
{
admin_menu();
goto start;
}
else if(opt==4)
exit(0);
else
{
cout<<"\n\t\tEnter correct option";
goto start;
}
}