-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlms.cpp
More file actions
702 lines (657 loc) · 12.9 KB
/
lms.cpp
File metadata and controls
702 lines (657 loc) · 12.9 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
#include <iostream>
#include <bits/stdc++.h>
#include <windows.h>
#include <conio.h>
#include <stdlib.h>
#include <iomanip> //for using setw()
#include <string.h>
using namespace std;
class book
{
char bno[6];
char bname[50];
char aname[20];
public:
void createbook()
{
cout << endl
<< "New Book Entry" << endl;
cout << endl
<< "Enter the Book No.";
cin >> bno;
cout << endl
<< "Enter the Book Name" << endl;
gets(bname);
cout << endl<< "Enter the Book Author Name" << endl;
gets(aname);
cout << endl
<< endl
<< endl
<< "Book created";
}
void showbook()
{
cout << endl
<< "Book Number : " << bno;
cout << endl
<< "Book Name :";
puts(bname);
cout << endl
<< "Author Name :";
cout << aname;
}
void modifybook()
{
cout << endl
<< "Enter Number : " << bno;
cout << endl
<< "Modify Book Name :";
gets(bname);
cout << endl
<< "Modify Author's Name :";
gets(aname);
}
char *retbno()
{
return bno;
}
void report()
{
cout << bno << setw(30) << bname << setw(30) << aname << endl;
}
};
class student
{
char admno[6];
char name[20];
char stbno[6]; //which book student has issued
int token; //total no. of books issued by students
public:
void createstudent()
{
system("cls");
cout << endl
<< "New Student Entry" << endl;
cout << endl<< "Enter the Admission number";
cin >> admno;
cout << endl<< "Enter the Student Name";
cin.ignore();
gets(name);
token = 0;
stbno[0] = '\0';
cout << endl
<< endl
<< "Student Record Created";
}
void showstudent()
{
cout << endl
<< "Admission Number :" << admno;
cout << endl
<< "Student Name : ";
puts(name);
cout << endl
<< "No of Book Issued :" << token;
if (token == 1) // only one book issued by the student
{
cout << endl
<< "Book number " << stbno;
}
}
void modifystudent()
{
cout << endl
<< "Admission No." << admno;
cout << endl
<< "Modify Student Name :";
gets(name);
}
char *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 << "\t" << admno << setw(20) << name << setw(10) << token << endl;
}
};
fstream fp, fp1;
book bk;
student st;
void writebook() //function to write on a book using file handling..
{
char ch;
fp.open("book.txt", ios ::out | ios ::app);
do
{
system("cls");
bk.createbook();
fp.write((char *)&bk, sizeof(book));
cout << endl
<< endl
<< "Do you want to add more record (y/n)?";
cin >> ch;
} while (ch == 'y' || ch == 'Y');
fp.close();
}
void writestudent() //function to write on a student using file handling..
{
char ch;
fp.open("student.txt", ios ::out | ios ::app);
do
{
system("cls");
st.createstudent();
fp.write((char *)&st, sizeof(student));
cout << endl
<< endl
<< "Do you want to add more record (y/n)?";
cin >> ch;
} while (ch == 'y' || ch == 'Y');
fp.close();
}
void displayspb(char n[]) //searching book
{
cout << endl
<< "Book Details" << endl;
int flag = 0;
fp.open("book.txt", ios::in);
while (fp.read((char *)&bk, sizeof(book)))
{
if (strcmpi(bk.retbno(), n) == 0) //strcmpi ignores casesenstive
{
bk.showbook();
flag = 1;
}
}
fp.close();
if (flag == 0)
{
cout << endl
<< endl
<< "Book does not exist";
getch();
}
}
void displaysps(char n[]) //searching student
{
cout << endl
<< "Student Details" << endl;
int flag = 0;
fp.open("student.txt", ios::in);
while (fp.read((char *)&st, sizeof(student)))
{
if (strcmpi(st.retadmno(), n) == 0) //strcmpi ignores casesenstive
{
st.showstudent();
flag = 1;
}
}
fp.close();
if (flag == 0)
{
cout << endl
<< endl
<< "Student does not exist";
getch();
}
}
void modifybook() //updating book
{
char n[6];
int found = 0;
system("cls");
cout << endl<< endl<< "Modify Book Record ";
cout << endl<< endl<< "Enter the Book Number ";
cin >> n;
fp.open("book.txt", ios::in | ios::out);
while (fp.read((char *)&bk, sizeof(book)) && found == 0)
{
if (strcmpi(bk.retbno(), n) == 0)
{
bk.showbook();
cout<<endl<<"Enter the new details of the book "<<endl;
bk.modifybook();
int pos = -1*sizeof(bk);
fp.write((char*)&bk,sizeof(book));
fp.seekp(pos,ios::cur);
cout<<endl<<endl<<"Record Updated";
found=1;
}
}
fp.close();
if(found == 0)
{
cout<<endl<<endl<<"Record not found";
}
getch();
}
void modifystudent() //updating student
{
char n[6];
int found = 0;
system("cls");
cout << endl<< endl<< "Modify Student Record ";
cout << endl<< endl<< "Enter Admission Number ";
cin >> n;
fp.open("student.txt", ios::in | ios::out);
while (fp.read((char *)&st, sizeof(student)) && found == 0)
{
if (strcmpi(st.retadmno(), n) == 0)
{
st.showstudent();
cout<<endl<<"Enter the new details of the Student "<<endl;
st.modifystudent();
int pos = -1*sizeof(st );
fp.write((char*)&st,sizeof(student));
fp.seekp(pos,ios::cur);
cout<<endl<<endl<<"Record Updated";
found=1;
}
}
fp.close();
if(found == 0)
{
cout<<endl<<endl<<"Record not found";
}
getch();
}
void deletestudent()
{
char n[6];
int flag=0;
system("cls");
cout<<endl<<endl<<endl<<"Delete Student";
cout<<endl<<"Enter the Admission Number";
cin>>n;
fp.open("student.txt",ios::in|ios::out);
fstream fp2;
fp2.open("temp.txt",ios::out);
fp.seekg(0,ios::beg);
while(fp.read((char*)&st,sizeof(student)))
{
if(strcmpi(st.retadmno(),n)!=0)
{
fp2.write((char*)&st,sizeof(student));
}
else
{
flag=1;
}
}
fp.close();
fp2.close();
remove("student.txt");
rename("temp.txt","student.txt");
if(flag==1)
{
cout<<endl<<endl<<"Record deleted";
}
else
{
cout<<endl<<endl<<"Record not found";
}
getch();
}
void deletebook()
{
char n[6];
int flag=0;
system("cls");
cout<<endl<<endl<<endl<<"Delete Book";
cout<<endl<<"Enter the Book Number";
cin>>n;
fp.open("book.txt",ios::in|ios::out);
fstream fp2;
fp2.open("Temp.txt",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
{
flag=1;
}
}
fp.close();
fp2.close();
remove("book.txt");
rename("Temp.txt","book.txt");
if(flag==1)
{
cout<<endl<<endl<<"Record deleted";
}
else
{
cout<<endl<<endl<<"Record not found";
}
getch();
}
void displayalls()
{
system("cls");
fp.open("student.txt",ios::in);
if(!fp) //return true
{
cout<<"File not found";
getch();
return;
}
cout<<endl<<endl<<"\t Student List"<<endl<<endl;
cout<<"=========================================="<<endl;
cout<<"\t Admission Number"<<setw(10)<<"Name"<<setw(20)<<"Book Issued"<<endl;
cout<<"================================================="<<endl;
while(fp.read((char*)&st,sizeof(student)))
{
st.report();
}
fp.close();
getch();
}
void displayllb()
{
system("cls");
fp.open("book.txt",ios::in);
if(!fp)
{
cout<<"File could not be opened";
getch();
return;
}
cout<<endl<<endl<<"\t Book List"<<endl<<endl;
cout<<"======================================================================="<<endl;
cout<<"Book Number"<<setw(20)<<"Book Name"<<setw(25)<<"Author"<<endl;
cout<<"=================================================";
while(fp.read((char*)&bk,sizeof(book)))
{
bk.report();
}
fp.close();
getch();
}
void bookissue()
{
char sn[6],bn[6];
int found=0,flag=0;
system("cls");
cout<<endl<<endl<<"Book Issue";
cout<<endl<<endl<<"Enter Admission Number of Student";
cin>>sn;
fp.open("student.txt",ios::in|ios::out);
fp1.open("book.txt",ios::in|ios::out);
while(fp.read((char*)&st,sizeof(student)) && found==0)
{
if(strcmpi(st.retadmno(),sn)==0)
{
found=1;
if(st.rettoken()==0)
{
cout<<endl<<endl<<"Enter the book number";
cin>>bn;
while(fp1.read((char*)&bk,sizeof(book) && flag==0))
{
if(strcmpi(bk.retbno(),bn)==0)
{
flag=1;
st.addtoken();
st.getstbno(bk.retbno());
int pos= -1 * sizeof(st);
fp.seekg(pos,ios::cur);
fp.write((char*)&st,sizeof(student));
cout<<endl<<endl<<"Book issued Successfully "<<endl<<endl<<"Note : Write the Book issue Date inn backside of Your Book and return book within 15 days,Fine Rs.1 for each day after 15 days Perios";
}
}
if(flag==0)
{
cout<<"Book Number does not exist";
}
}
else
{
cout<<"You have not returned the last book";
}
}
if(found==0)
{
cout<<"Student Record does not exist";
}
getch();
fp.close();
fp1.close();
}
}
void bookdeposit()
{
char sn[6],bn[6];
int found=0,flag=0,day,fine;
system("cls");
cout<<endl<<endl<<"Book Deposit";
cout<<endl<<endl<<"Enter Admission Number of Student";
cin>>sn;
fp.open("student.txt",ios::in|ios::out);
fp1.open("book.txt",ios::in|ios::out);
while(fp.read((char*)&st,sizeof(student)) && found==0)
{
if(strcmpi(st.retadmno(),sn)==0)
{
found=1;
if(st.rettoken()==1)
{
while(fp1.read((char*)&bk,sizeof(book) && flag==0))
{
if(strcmpi(bk.retbno(),st.retstbno())==0)
{
flag=1;
bk.showbook();
cout<<endl<<endl<<"Book Deposited in no. of days";
cin>>day;
if(day>15)
{
fine=(day-15)*1;
cout<<endl<<endl<<"Fine has to be deposited Rs."<<fine;
}
st.resettoken();
int pos= -1 * sizeof(st);
fp.seekg(pos,ios::cur);
fp.write((char*)&st,sizeof(student));
cout<<endl<<endl<<"Book deposited Successfully "<<endl<<endl;
}
}
if(flag==0)
{
cout<<"Book Number does not exist";
}
}
else
{
cout<<"No book is issued";
}
}
if(found==0)
{
cout<<"Student Record does not exist";
}
getch();
fp.close();
fp1.close();
}
}
void gotoxy(int x, int y)
{
COORD c;
c.X = x;
c.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), c);
}
void start()
{
gotoxy(35, 11);
cout << "LIBRARY MANAGEMENT SYSYTEM" << endl
<< endl;
gotoxy(35, 13);
cout << "Developer : Nitesh Prasad";
getch();
}
void adminmenu()
{
system("cls");
int ch2;
cout << endl
<< endl
<< endl
<< "\tAdminstrator Menu";
cout << endl
<< endl
<< endl
<< "\t1.Create Student Record";
cout << endl
<< endl
<< endl
<< "\t2.Display All Student Record";
cout << endl
<< endl
<< endl
<< "\t3.Display Specific Student Record";
cout << endl
<< endl
<< endl
<< "\t4.Modify Student Record";
cout << endl
<< endl
<< endl
<< "\t5.Delete Student Record";
cout << endl
<< endl
<< endl
<< "\t6.Create Book";
cout << endl
<< endl
<< endl
<< "\t7.Display ALL Book";
cout << endl
<< endl
<< endl
<< "\t8.Display Specific Book";
cout << endl
<< endl
<< endl
<< "\t9.Modify Book Record";
cout << endl
<< endl
<< endl
<< "\t10.Delete Book Record";
cout << endl
<< endl
<< endl
<< "\t11.Back to Main Menu";
cout << endl
<< endl
<< endl
<< "\tPlease Enter Your Choice(1-11)";
cin >> ch2;
switch (ch2)
{
case 1:
writestudent();
break;
case 2:
displayalls();
break;
case 3:
{
char num[6];
system("cls");
cout << endl<< endl<< "\t Please Enter the Admission No.";
cin >> num;
displaysps(num);
}
break;
case 4:
modifystudent();
break;
case 5:
deletestudent();
break;
case 6:
writebook();
break;
case 7:
displayllb();
break;
case 8:
{
char num[6];
cin >> num;
cout<<endl<<endl<<"Please Enter the book no.";
cin>>num;
displayspb(num);
}
break;
case 9:
modifybook();
break;
case 10:
deletebook();
break;
case 11:
return;
default:
cout << "Invalid Choice, try again";
}
adminmenu();
}
int main()
{
start();
char ch;
do
{
system("cls");
cout << endl<< endl<< "\tMAIN MENU";
cout << endl<< endl<< "\t1.Book Issue";
cout << endl<< endl<< "\t2.Book Deposit";
cout << endl<< endl<< "\t3.Admnistrator Menu";
cout << endl<< endl<< "\t4.EXIT";
cout << endl<< endl << "\tPlease Select Your Option between 1-4";
ch = getche();
switch (ch)
{
case '1':
bookissue();
case '2':
bookdeposit();
break;
case '3':
adminmenu();
break;
case '4':
exit(0);
break;
default:
cout << "Invalid choice, Choose valid option";
}
} while (ch != 4);
}