-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLibraryManagementProject.cpp
More file actions
838 lines (806 loc) · 15.8 KB
/
LibraryManagementProject.cpp
File metadata and controls
838 lines (806 loc) · 15.8 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
//****************************************************************
// HEADER FILE USED IN PROJECT
//****************************************************************
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
#include<string.h>
#include<iomanip.h>
//****************************************************************
// CLASS USED IN PROJECT
//****************************************************************
void box();
void intro();
class book
{
char bno[6];
char aname[50];
protected:
char bname[50];
public:
void create_book()
{
box();
gotoxy(30,3);
cout<<"...NEW BOOK ENTRY...";
gotoxy(3,4);
cout<<"Enter The book number(10**): ";
cin>>bno;
gotoxy(3,5);
cout<<"Enter The Name of The Book: ";
gets(bname);
gotoxy(3,6);
cout<<"Enter The Author's Name: ";
gets(aname);
gotoxy(3,7);
cout<<"Book Created...";
}
void show_book(int n)
{
gotoxy(3,n);
n++;
cout<<"Book Number(10**) : "<<bno;
gotoxy(3,n);
n++;
cout<<"Book Name : ";
puts(bname);
gotoxy(3,n);
cout<<"Author Name : ";
puts(aname);
}
void modify_book(int i)
{
gotoxy(3,i);
i++;
cout<<"Book Number(10**) : "<<bno;
gotoxy(3,i);
i++;
cout<<"Modify Book Name : ";
gets(bname);
gotoxy(3,i);
cout<<"Modify Author's Name of Book : ";
gets(aname);
}
char* retbno()
{
return bno;
}
/* void report()
{
cout<<bno<<setw(30)<<bname<<setw(30)<<aname<<endl;
}*/
void report(int y)
{
gotoxy(3,y);
cout<<setw(6)<<bno<<setw(35)<<bname<<setw(30)<<aname<<endl;
}
}bk; //class book ends here
class student
{
int admno;
char name[20];
char stbno[6];
int token;
public:
void create_student(int ano)
{
clrscr();
box();
admno=ano;
gotoxy(29,3);
cout<<"...NEW STUDENT ENTRY...";
gotoxy(3,4);
cout<<"Enter The Admission number(50**): "<<admno;
gotoxy(3,5);
cout<<"Enter The Name of The Student: ";
gets(name);
token=0;
stbno[0]='\0';
gotoxy(3,7);
cout<<"Student Record Created..";
}
void show_student(int j)
{
gotoxy(3,j);
j++;
cout<<"Admission Number(50**): "<<admno;
gotoxy(3,j);
j++;
cout<<"Student Name: ";
puts(name);
gotoxy(3,j);
j++;
cout<<"Number of Book issue: "<<token;
if(token==1)
{
gotoxy(3,j);
cout<<"Book Number(10**): "<<stbno;
}
}
void modify_student(int k)
{
gotoxy(3,k);
k++;
cout<<"Admission number(50**) : "<<admno;
gotoxy(3,k);
cout<<"Modify Student Name : ";
gets(name);
}
int retadmno()
{
return admno;
}
char* retstbno()
{
return stbno;
}
int rettoken()
{
return token;
}
void addtoken()
{
token=1;
}
void resettoken()
{
token=0;
}
void getstbno(char t[])
{
strcpy(stbno,t);
}
void report()
{
cout<<setw(8)<<admno<<setw(20)<<name<<setw(10)<<token<<endl;
}
void rep()
{
cout<<setw(8)<<admno<<setw(35)<<name<<setw(27)<<token<<endl;
}
}st; //class Student ends here
//****************************************************************
// global declaration for stream objects
//****************************************************************
fstream fp,fp1;
//****************************************************************
// functions to write in file
//****************************************************************
void write_book()
{
box();
char ch;
fp.open("book.dat",ios::out|ios::app|ios::binary);
do
{
clrscr();
bk.create_book();
fp.write((char*)&bk,sizeof(book));
gotoxy(3,22);
cout<<"Do you want to add more record...(y/n?)";
cin>>ch;
}while(ch=='y'||ch=='Y');
fp.close();
}
void write_student()
{
clrscr();
box();
char ch;
int an;
ifstream f;
f.open("student.dat",ios::in|ios::binary);
if(f.good())
{
while(!f.eof())
{
f.read((char*)&st,sizeof(student));
st.retadmno();
}
an=st.retadmno();
an++;
f.close();
fp.open("student.dat",ios::out|ios::app|ios::binary);
st.create_student(an);
fp.write((char*)&st,sizeof(student));
fp.close();
}
else
{
fp.open("student.dat",ios::out|ios::app|ios::binary);
st.create_student(5000);
fp.write((char*)&st,sizeof(student));
fp.close();
}
fp.close();
}
//***************************************************************
// FUNCTION TO READ SPECIFIC RECORD FROM FILE
//****************************************************************
void display_spb()
{
char n[10];
clrscr();
box();
gotoxy(30,3);
cout<<"... BOOK DETAILS ...";
gotoxy(3,5);
cout<<"Enter The book Number(10**): ";
cin>>n;
int flag=0;
fp.open("book.dat",ios::in);
while(fp.read((char*)&bk,sizeof(book)))
{
if(strcmpi(bk.retbno(),n)==0)
{
bk.show_book(6);
flag=1;
}
}
fp.close();
if(flag==0)
{
gotoxy(3,23);
cout<<"Book does not exist!!!";
}
getch();
}
void display_sps()
{
int n;
clrscr();
box();
gotoxy(3,5);
cout<<"Enter The Admission Number(50**): ";
cin>>n;
gotoxy(30,3);
cout<<"...STUDENT DETAILS...";
int flag=0;
fp.open("student.dat",ios::in);
while(fp.read((char*)&st,sizeof(student)))
{
if(st.retadmno()==n)
{
st.show_student(6);
flag=1;
}
}
fp.close();
if(flag==0)
{
gotoxy(3,23);
cout<<"Student does not exist!!!";
}
getch();
}
//****************************************************************
// FUNCTION TO DELETE RECORD FILE
//****************************************************************
void modify_book()
{
clrscr();
box();
char n[6];
int found=0;
gotoxy(28,3);
cout<<"... MODIFY BOOK RECORD ...";
gotoxy(3,5);
cout<<"Enter The book number of The book(10**):";
cin>>n;
fp.open("book.dat",ios::in|ios::out);
while(fp.read((char*)&bk,sizeof(book)) && found==0)
{
if(strcmpi(bk.retbno(),n)==0)
{
bk.show_book(6);
gotoxy(3,10);
cout<<"Enter The New Details of book:";
bk.modify_book(11);
int pos=-1*sizeof(bk);
fp.seekp(pos,ios::cur);
fp.write((char*)&bk,sizeof(book));
gotoxy(3,23);
cout<<"Record Updated";
found=1;
}
}
fp.close();
if(found==0)
{
gotoxy(3,23);
cout<<"Record Not Found!!! ";
}
getch();
}
void modify_student()
{
clrscr();
box();
int n;
int found=0;
gotoxy(26,3);
cout<<"... MODIFY STUDENT RECORD ...";
gotoxy(3,5);
cout<<"Enter The admission number of The student(50**):";
cin>>n;
fp.open("student.dat",ios::in|ios::out);
while(fp.read((char*)&st,sizeof(student)) && found==0)
{
if(st.retadmno()==n)
{
st.show_student(7);
getch();
gotoxy(3,11);
st.modify_student(12);
int pos=-1*sizeof(st);
fp.seekp(pos,ios::cur);
fp.write((char*)&st,sizeof(student));
gotoxy(3,23);
cout<<"Record Updated!!!";
found=1;
}
}
fp.close();
if(found==0)
{
gotoxy(3,23);
cout<<"Record Not Found!!! ";
}
getch();
}
//***************************************************************
// FUNCTION TO DELETE RECORD FILE
//****************************************************************
void delete_student()
{
clrscr();
box();
int n;
int flag=0;
gotoxy(30,3);
cout<<"... DELETE STUDENT ...";
gotoxy(3,5);
cout<<"Enter The Admission number of the Student You Want To Delete(50**): ";
cin>>n;
fp.open("student.dat",ios::in|ios::out);
fstream fp2;
fp2.open("Temp.dat",ios::out);
fp.seekg(0,ios::beg);
while(fp.read((char*)&st,sizeof(student)))
{
if(st.retadmno()!=n)
{
fp2.write((char*)&st,sizeof(student));
}
else
{
st.show_student(7);
flag=1;
}
}
fp2.close();
fp.close();
remove("student.dat");
rename("Temp.dat","student.dat");
if(flag==1)
{
gotoxy(3,23);
cout<<"Record Deleted ...";
}
else
{
gotoxy(3,23);
cout<<"Record not found!!!";
}
getch();
}
void delete_book()
{
clrscr();
box();
char n[6];
gotoxy(33,3);
cout<<"... DELETE BOOK ...";
gotoxy(3,5);
cout<<"Enter The Book number of the Book You Want To Delete(10**): ";
cin>>n;
fp.open("book.dat",ios::in|ios::out);
fstream fp2;
fp2.open("Temp.dat",ios::out);
fp.seekg(0,ios::beg);
while(fp.read((char*)&bk,sizeof(book)))
{
if(strcmpi(bk.retbno(),n)!=0)
{
fp2.write((char*)&bk,sizeof(book));
}
else
{
bk.show_book(7);
}
}
fp2.close();
fp.close();
remove("book.dat");
rename("Temp.dat","book.dat");
gotoxy(3,23);
cout<<"Record Deleted ...";
getch();
}
//****************************************************************
// FUNCTION TO DISPLAY STUDENT LIST
//****************************************************************
void display_alls()
{
clrscr();
box();
int cnt=7;
fp.open("student.dat",ios::in);
if(!fp)
{
cout<<"ERROR!!! FILE COULD NOT BE OPEN ";
getch();
return;
}
gotoxy(30,3);
cout<<"... STUDENT LIST ...";
gotoxy(2,4);
cout<<"==============================================================================";
gotoxy(3,5);
cout<<"Admission Number"<<setw(30)<<"Student's Name"<<setw(27)<<"Book Issued";
gotoxy(2,6);
cout<<"==============================================================================";
while(fp.read((char*)&st,sizeof(student)))
{
gotoxy(3,cnt);
st.rep();
cnt++;
}
fp.close();
getch();
}
//****************************************************************
// FUNCTION TO DISPLAY BOOK LIST
//****************************************************************
void display_allb()
{
clrscr();
box();
fp.open("book.dat",ios::in|ios::binary);
if(!fp)
{
gotoxy(3,22);
cout<<"ERROR!!! FILE COULD NOT BE OPEN ";
getch();
return;
}
int y=7;
gotoxy(32,3);
cout<<"... BOOK LIST ...";
gotoxy(2,4);
cout<<"==============================================================================";
gotoxy(2,5);
cout<<setw(8)<<" Book Number"<<setw(30)<<"Book Name"<<setw(27)<<"Author";
gotoxy(2,6);
cout<<"==============================================================================\n";
while(fp.read((char*)&bk,sizeof(book)))
{
bk.report(y);
y++;
}
fp.close();
getch();
}
//****************************************************************
// FUNCTION TO ISSUE BOOK
//****************************************************************
void book_issue()
{
clrscr();
box();
char bn[6];
int sn;
int found=0,flag=0;
gotoxy(31,3);
cout<<"... BOOK ISSUE ...";
gotoxy(3,5);
cout<<"Enter The student's admission number(50**):";
cin>>sn;
fp.open("student.dat",ios::in|ios::out);
fp1.open("book.dat",ios::in|ios::out);
while(fp.read((char*)&st,sizeof(student)) && found==0)
{
if(st.retadmno()==sn)
{
found=1;
if(st.rettoken()==0)
{
gotoxy(3,6);
cout<<"Enter the book number(10**): ";
cin>>bn;
while(fp1.read((char*)&bk,sizeof(book))&& flag==0)
{
if(strcmpi(bk.retbno(),bn)==0)
{
bk.show_book(7);
flag=1;
st.addtoken();
st.getstbno(bk.retbno());
int pos=-1*sizeof(st);
fp.seekp(pos,ios::cur);
fp.write((char*)&st,sizeof(student));
gotoxy(3,21);
cout<<"Book issued successfully!!!";
gotoxy(3,22);
cout<<"Note: Write current date in backside of book and submit within 15 days";
gotoxy(3,23);
cout<<"(Fine Rs. 1 for each day after 15 days period)";
getch();
}
}
if(flag==0)
{
gotoxy(3,19);
cout<<"Book no does not exist!!!";
}
}
else
cout<<"You have not returned the last book... ";
}
}
if(found==0)
{
gotoxy(3,23);
cout<<"Student record not exist...";
}
getch();
fp.close();
fp1.close();
}
//***************************************************************
// FUNCTION TO DEPOSIT BOOK
//***************************************************************
void book_deposit()
{
clrscr();
box();
char bn[6];
int sn;
int found=0,flag=0,day,fine;
gotoxy(30,3);
cout<<"... BOOK DEPOSIT ...";
gotoxy(3,5);
cout<<"Enter the student admission number(50**):";
cin>>sn;
fp.open("student.dat",ios::in|ios::out);
fp1.open("book.dat",ios::in|ios::out);
while(fp.read((char*)&st,sizeof(student)) && found==0)
{
if(st.retadmno()==sn)
{
found=1;
if(st.rettoken()==1)
{
while(fp1.read((char*)&bk,sizeof(book))&& flag==0)
{
if(strcmpi(bk.retbno(),st.retstbno())==0)
{
st.show_student(6);
bk.show_book(9);
flag=1;
gotoxy(3,13);
cout<<"Book deposited in number of days:";
cin>>day;
if(day>15)
{
fine=(day-15)*1;
gotoxy(3,15);
cout<<"Fine has to deposited Rs.: "<<fine;
}
st.resettoken();
int pos=-1*sizeof(st);
fp.seekp(pos,ios::cur);
fp.write((char*)&st,sizeof(student));
gotoxy(3,22);
cout<<" Book deposited successfully!!!";
}
}
if(flag==0)
{
gotoxy(3,22);
cout<<"Book number does not exist...";
}
}
else
{
gotoxy(3,22);
cout<<"No book is issued..please check!!!";
}
}
}
if(found==0)
{
gotoxy(3,22);
cout<<"Student record not exist...";
}
fp.close();
fp1.close();
getch();
}
//****************************************************************
// FUNCTION TO MAKE BOX
//****************************************************************
void box()
{
int x,y;
cout<<(char)201;
for(int i=1;i<=78;i++)
{
cout<<(char)205;
}
cout<<(char)187;
y=2;
for(i=1;i<23;i++)
{
gotoxy(1,y);
cout<<(char)186;
gotoxy(80,y);
cout<<(char)186;
y++;
}
cout<<(char)200;
for(i=1;i<=78;i++)
{
cout<<(char)205;
}
cout<<(char)188;
}
//****************************************************************
// INTRODUCTION PAGE FUNCTION
//****************************************************************
void intro()
{
gotoxy(24,11);
cout<<" L I B R A R Y M A N A G E M E N T";
gotoxy(35,13);
cout<<" S Y S T E M";
getch();
clrscr();
box();
gotoxy(28,7);
cout<<"D E V E L O P E D B Y :";
gotoxy(27,9);
cout<<"V A N S H S O N A V A N E";
gotoxy(31,11);
cout<<"C L A S S XII - B";
gotoxy(33,14);
cout<<"( 2019 - 2020 )";
getch();
}
//****************************************************************
// ADMINISTRATOR MENU FUNCTION
//****************************************************************
void admin_menu()
{
clrscr();
box();
int ch2;
gotoxy(28,2);
cout<<"... ADMINISTRATOR MENU ...";
gotoxy(3,5);
cout<<"1.CREATE STUDENT RECORD";
gotoxy(3,6);
cout<<"2.DISPLAY ALL STUDENTS RECORD";
gotoxy(3,7);
cout<<"3.DISPLAY SPECIFIC STUDENT RECORD ";
gotoxy(3,8);
cout<<"4.MODIFY STUDENT RECORD";
gotoxy(3,9);
cout<<"5.DELETE STUDENT RECORD";
gotoxy(3,10);
cout<<"6.CREATE BOOK ";
gotoxy(3,11);
cout<<"7.DISPLAY ALL BOOKS ";
gotoxy(3,12);
cout<<"8.DISPLAY SPECIFIC BOOK ";
gotoxy(3,13);
cout<<"9.MODIFY BOOK ";
gotoxy(3,14);
cout<<"10.DELETE BOOK ";
gotoxy(3,15);
cout<<"11.BACK TO MAIN MENU";
gotoxy(3,17);
cout<<"Please Enter Your Choice (1-11):";
cin>>ch2;
switch(ch2)
{
case 1:
clrscr();
write_student();
break;
case 2:
display_alls();
break;
case 3:
display_sps();
break;
case 4:
modify_student();
break;
case 5:
delete_student();
break;
case 6:
clrscr();
write_book();
break;
case 7:
display_allb();
break;
case 8:
display_spb();
break;
case 9:
modify_book();
break;
case 10:
delete_book();
break;
case 11:
return;
default:
exit(0);
}
admin_menu();
}
//****************************************************************
// THE MAIN FUNCTION OF PROGRAM
//****************************************************************
void main()
{
char ch;
clrscr();
intro();
do
{
clrscr();
box();
gotoxy(32,3);
cout<<"*** MAIN MENU ***";
gotoxy(3,4);
cout<<"01. BOOK ISSUE";
gotoxy(3,5);
cout<<"02. BOOK DEPOSIT";
gotoxy(3,6);
cout<<"03. ADMINISTRATOR MENU";
gotoxy(3,7);
cout<<"04. EXIT";
gotoxy(3,9);
cout<<"Please Select Your Option (1-4): ";
ch=getche();
switch(ch)
{
case '1':
getch();
book_issue();
break;
case '2':
getch();
book_deposit();
break;
case '3':
getch();
admin_menu();
break;
case '4':
getch();
exit(0);
default :
exit(1);
}
}while(ch!='4');
}
//***************************************************************
// END OF PROJECT
//***************************************************************