Library Management System In C++ With Source Code
The Library Management System In C++ is written in C++ programming language, This project is based on a concept of recording owned books, issued books, returned books, students who have borrowed and many more. Before stepping into the main system a user has to pass through a login system to get access, there are two types of login i.e Student and Librarian Login. To get access to the Librarian’s account, a password should be provided for the Librarian only. There are many features in this system. The user can also change the password from the system for their own security.
A Library Management System C++ features is after logging in as a student he/she can only view booklists. All the system is controlled by the librarian as he/she can view, search, modify, add, delete books, and Issue books. The other main feature contains re-issue books and returns book.
This Project also includes a downloadable Project In C++ Free Download, just find the downloadable source code below and click to start downloading.
Watch here the full running Library Management System in C++ with Source Code.
To start creating a Library Management System In C++, make sure that you have code blocks or any platform of C/C++ language installed in your computer.
Steps on how to create a Library Management System In C++
Library Management System In C++ With Source Code
- Step 1: Create a new project.
First open the code blocks IDE and click “create a new project“.
- Step 2: Choose console application.
Second click the “console application” and after that click “next“.
- Step 3: Choose C++ language.
Third choose “C++ language” and click “next“.
- Step 4: Name Your Project.
Fourth name the project you’ve created and click “next” after that click “finish“.
- Step 5: The actual code.
You are free to copy the given source code below or download the downloadable source code given.
The Code Given Below Is For The Issuing Module
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 |
void Lib::issue() { char st[50],st1[20]; int b,i,j,d,m,y,dd,mm,yy,cont=0; system("cls"); cout<<"\n\t\t->Please Choose one option :-\n"; cout<<"\n\t\t1.Issue Book\n\n\t\t2.View Issued Book\n\n\t\t3.Search student who isuued books\n\n\t\t4.Reissue Book\n\n\t\t5.Return Book\n\n\t\t6.Go back to menu\n\n\t\tEnter Your Choice : "; cin>>i; fflush(stdin); if(i==1) { system("cls"); b=branch(2); system("cls"); fflush(stdin); cout<<"\n\t\t->Please Enter Details :-\n"; cout<<"\n\t\tEnter Book Name : "; cin.getline(bookname,100); cout<<"\n\t\tEnter Book's ID : "; cin.getline(sc,20); //strcpy(st,sc); der(sc,b,1); cout<<"\n\t\tEnter Student Name : "; cin.getline(auname,100); cout<<"\n\t\tEnter Student's ID : "; cin.getline(sc1,20); cout<<"\n\t\tEnter date : "; cin>>q>>B>>p; ofstream outf("student.txt",ios::binary|ios::app); outf.write((char*)this,sizeof(*this)); outf.close(); cout<<"\n\n\t\tIssue Successfully.\n"; } else if(i==2) { ifstream intf("student.txt",ios::binary); system("cls"); cout<<"\n\t\t->The Details are :-\n"; intf.read((char*)this,sizeof(*this)); i=0; while(!intf.eof()) { i++; cout<<"\n\t\t********** "<<i<<". ********** \n"; cout<<"\n\t\tStudent Name : "<<auname<<"\n\t\t"<<"Student's ID : "<<sc1<<"\n\t\t"<<"Book Name : "<<bookname<<"\n\t\t"<<"Book's ID : "<<sc<<"\n\t\t"<<"Date : "<<q<<"/"<<B<<"/"<<p<<"\n"; intf.read((char*)this,sizeof(*this)); } intf.close(); } else if(i==3) { system("cls"); fflush(stdin); cout<<"\n\t\t->Please Enter Details :-\n"; cout<<"\n\n\t\tEnter Student Name : "; cin.getline(st,50); cout<<"\n\n\t\tEnter Student's ID : "; cin.getline(st1,20); system("cls"); ifstream intf("student.txt",ios::binary); intf.read((char*)this,sizeof(*this)); cont=0; while(!intf.eof()) { for(i=0;sc1[i]!='\0'&&st1[i]!='\0'&&st1[i]==sc1[i];i++); if(sc1[i]=='\0'&&st1[i]=='\0') { cont++; if(cont==1) { cout<<"\n\t\t->The Details are :-\n"; cout<<"\n\t\tStudent Name : "<<auname; cout<<"\n\t\tStudent's ID : "<<sc1; } cout<<"\n\n\t\t******* "<<cont<<". Book details *******\n"; cout<<"\n\t\tBook Name : "<<bookname; cout<<"\n\t\tBook's ID : "<<sc; cout<<"\n\t\tDate : "<<q<<"/"<<B<<"/"<<p<<"\n"; } intf.read((char*)this,sizeof(*this)); } intf.close(); if(cont==0) cout<<"\n\t\tNo record found."; } else if(i==4) { system("cls"); fflush(stdin); cout<<"\n\t\t->Please Enter Details :-\n"; cout<<"\n\n\t\tEnter Student's ID : "; cin.getline(st,50); cout<<"\n\t\tEnter Book's ID : "; cin.getline(st1,20); fstream intf("student.txt",ios::in|ios::out|ios::ate|ios::binary); intf.seekg(0); intf.read((char*)this,sizeof(*this)); while(!intf.eof()) { for(i=0;sc[i]!='\0'&&st1[i]!='\0'&&st1[i]==sc[i];i++); for(j=0;sc1[j]!='\0'&&st[j]!='\0'&&st[j]==sc1[j];j++); if(sc[i]=='\0'&&sc1[j]=='\0'&&st[j]=='\0'&&st1[i]=='\0') { d=q; m=B; y=p; cout<<"\n\t\tEnter New Date : "; cin>>q>>B>>p; fine(d,m,y,q,B,p); //fn1 intf.seekp(intf.tellp()-sizeof(*this)); //fn3 intf.write((char*)this,sizeof(*this)); //fn5 cout<<"\n\n\t\tReissue successfully."; //fn3 break; } intf.read((char*)this,sizeof(*this)); } intf.close(); } else if(i==5) { system("cls"); b=branch(2); system("cls"); fflush(stdin); cout<<"\n\t\t->Please Enter Details :-\n"; cout<<"\n\t\tEnter Book's ID : "; cin.getline(st1,20); der(st1,b,2); cout<<"\n\n\t\tEnter Student's ID : "; cin.getline(st,20); cout<<"\n\t\tEnter Present date : "; cin>>d>>m>>y; ofstream outf("temp.txt",ios::app|ios::binary); ifstream intf("student.txt",ios::binary); intf.read((char*)this,sizeof(*this)); while(!intf.eof()) { for(i=0;sc[i]!='\0'&&st1[i]!='\0'&&st1[i]==sc[i];i++); for(j=0;sc1[j]!='\0'&&st[j]!='\0'&&st[j]==sc1[j];j++); if(sc[i]=='\0'&&sc1[j]=='\0'&&st[j]=='\0'&&st1[i]=='\0'&&cont==0) { cont++; intf.read((char*)this,sizeof(*this)); fine(q,B,p,d,m,y); cout<<"\n\t\tReturned successfully."; } else { outf.write((char*)this,sizeof(*this)); intf.read((char*)this,sizeof(*this)); } } intf.close(); outf.close(); getch(); remove("student.txt"); rename("temp.txt","student.txt"); } else if(i==6) { system("cls"); librarian(); } else cout<<"\n\t\tWrong Input.\n"; cout<<"\n\n\t\tPress any key to continue....."; getch(); system("cls"); librarian(); } |
In this module which is the issuing of the book module.
The Code Given Below Is For The Librarian Account Module
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 |
void Lib::librarian() { int i; cout<<"\n\t************ WELCOME LIBRARIAN ************\n"; cout<<"\n\t\t>>Please Choose One Option:\n"; cout<<"\n\t\t1.View BookList\n\n\t\t2.Search for a Book\n\n\t\t3.Modify/Add Book\n\n\t\t4.Issue Book\n\n\t\t5.Go to main menu\n\n\t\t6.Change Password\n\n\t\t7.Close Application\n"; cout<<"\n\t\tEnter your choice : "; cin>>i; switch(i) { case 1:booklist(2); break; case 2:see(2); break; case 3:modify(); break; case 4:issue(); break; case 5:system("cls"); get(); break; case 6:password(); break; case 7:exit(0); default:cout<<"\n\t\tPlease enter correct option :("; getch(); system("cls"); librarian(); } } void Lib::password() { int i=0,j=0; char ch,st[21],ch1[21]={"pass"}; system("cls"); cout<<"\n\n\t\tEnter Old 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++; } } ifstream intf("password.txt"); intf>>ch1; intf.close(); for(i=0;st[i]==ch1[i]&&st[i]!='\0'&&ch1[i]!='\0';i++); if(st[i]=='\0'&&ch1[i]=='\0') { system("cls"); cout<<"\n\t**The Password Should be less than 20 characters & don't use spaces**\n\n"; cout<<"\n\t\tEnter New Password : "; fflush(stdin); i=0; while(1) { j++; ch=getch(); if(ch==13) { for(i=0;st[i]!=' '&&st[i]!='\0';i++); if(j>20 || st[i]==' ') { cout<<"\n\n\t\tYou did't follow the instruction \n\n\t\tPress any key for try again....."; getch(); system("cls"); password(); librarian(); } st[i]='\0'; break; } else if(ch==8&&i>0) { i--; cout<<"\b \b"; } else { cout<<"*"; st[i]=ch; i++; } } ofstream outf("password.txt"); outf<<st; outf.close(); cout<<"\n\n\t\tYour Password has been changed Successfully."; cout<<"\n\t\tPress any key to continue......"; getch(); system("cls"); librarian(); } else { cout<<"\n\n\t\tPassword is incorrect.....\n"; cout<<"\n\t\tEnter 1 for retry or 2 for menu"; cin>>i; if(i==1) { system("cls"); password(); } else { system("cls"); librarian(); } } } |
In this module which is the librarian account that can manage all information inside the library.
The Code Given Below Is For The Student Account Module
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 |
void Lib::student() { int i; cout<<"\n\t************ WELCOME STUDENT ************\n"; cout<<"\n\t\t>>Please Choose One Option:\n"; cout<<"\n\t\t1.View BookList\n\n\t\t2.Search for a Book\n\n\t\t3.Go to main menu\n\n\t\t4.Close Application\n"; cout<<"\n\t\tEnter your choice : "; cin>>i; if(i==1) booklist(1); else if(i==2) see(1); else if(i==3) { system("cls"); get(); } else if(i==4) exit(0); else { cout<<"\n\t\tPlease enter correct option :("; getch(); system("cls"); student(); } } void Lib::pass() { int i=0; char ch,st[21],ch1[21]={"pass"}; cout<<"\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++; } } ifstream inf("password.txt"); inf>>ch1; inf.close(); for(i=0;st[i]==ch1[i]&&st[i]!='\0'&&ch1[i]!='\0';i++); if(st[i]=='\0'&&ch1[i]=='\0') { system("cls"); librarian(); } else { cout<<"\n\n\t\tWrong Password.\n\n\t\ttry again.....\n"; getch(); system("cls"); get(); } } |
In this module which is the student account.
Complete Source Code
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 |
#include<iostream> #include<stdio.h> #include<stdlib.h> #include<fstream> #include<string.h> #include<conio.h> using namespace std; class Lib { public: char bookname[100],auname[50],sc[20],sc1[50]; int q,B,p; Lib() { strcpy(bookname,"NO Book Name"); strcpy(auname,"No Author Name"); strcpy(sc,"No Book ID"); strcpy(sc1,"No Book ID"); q=0; B=0; p=0; } void get(); void student(); void pass(); void librarian(); void password(); void getdata(); void show(int); void booklist(int); void modify(); void see(int); int branch(int); void issue(); void der(char[],int,int); void fine(int,int,int,int,int,int); }; void Lib::getdata() { int i; fflush(stdin); cout<<"\n\t\tEnter the details :-\n"; cout<<"\n\t\tEnter Book's Name : "; cin.getline(bookname,100); for(i=0;bookname[i]!='\0';i++) { if(bookname[i]>='a'&&bookname[i]<='z') bookname[i]-=32; } cout<<"\n\t\tEnter Author's Name : "; cin.getline(auname,50); cout<<"\n\t\tEnter Publication name : "; cin.getline(sc1,50); cout<<"\n\t\tEnter Book's ID : "; cin.getline(sc,20); cout<<"\n\t\tEnter Book's Price : "; cin>>p; cout<<"\n\t\tEnter Book's Quantity : "; cin>>q; } void Lib::show(int i) { cout<<"\n\t\tBook Name : "<<bookname<<endl; cout<<"\n\t\tBook's Author Name : "<<auname<<endl; cout<<"\n\t\tBook's ID : "<<sc<<endl; cout<<"\n\t\tBook's Publication : "<<sc1<<endl; if(i==2) { cout<<"\n\t\tBook's Price : "<<p<<endl; cout<<"\n\t\tBook's Quantity : "<<q<<endl; } } void Lib::booklist(int i) { int b,r=0; system("cls"); b=branch(i); system("cls"); ifstream intf("Booksdata.txt",ios::binary); if(!intf) cout<<"\n\t\tFile Not Found."; else { cout<<"\n\t ************ Book List ************ \n\n"; intf.read((char*)this,sizeof(*this)); while(!intf.eof()) { if(b==B) { if(q==0 && i==1) { } else { r++; cout<<"\n\t\t********** "<<r<<". ********** \n"; show(i); } } intf.read((char*)this,sizeof(*this)); } } cout<<"\n\t\tPress any key to continue....."; getch(); system("cls"); if(i==1) student(); else librarian(); } void Lib::modify() { char ch,st1[100]; int i=0,b,cont=0; system("cls"); cout<<"\n\t\t>>Please Choose one option :-\n"; cout<<"\n\t\t1.Modification In Current Books\n\n\t\t2.Add New Book\n\n\t\t3.Delete A Book\n\n\t\t4.Go back\n"; cout<<"\n\n\t\tEnter your choice : "; cin>>i; if(i==1) { system("cls"); b=branch(2); ifstream intf1("Booksdata.txt",ios::binary); if(!intf1) { cout<<"\n\t\tFile Not Found\n"; cout<<"\n\t\tPress any key to continue....."; getch(); system("cls"); librarian(); } intf1.close(); system("cls"); cout<<"\n\t\tPlease Choose One Option :-\n"; cout<<"\n\t\t1.Search By Book Name\n\n\t\t2.Search By Book's ID\n"; cout<<"\n\t\tEnter Your Choice : "; cin>>i; fflush(stdin); if(i==1) { system("cls"); cout<<"\n\t\tEnter Book Name : "; cin.getline(st1,100); system("cls"); fstream intf("Booksdata.txt",ios::in|ios::out|ios::ate|ios::binary); intf.seekg(0); intf.read((char*)this,sizeof(*this)); while(!intf.eof()) { for(i=0;b==B&&bookname[i]!='\0'&&st1[i]!='\0'&&(st1[i]==bookname[i]||st1[i]==bookname[i]+32);i++); if(bookname[i]=='\0'&&st1[i]=='\0') { cont++; getdata(); intf.seekp(intf.tellp()-sizeof(*this)); intf.write((char*)this,sizeof(*this)); break; } intf.read((char*)this,sizeof(*this)); } intf.close(); } else if(i==2) { cout<<"\n\t\tEnter Book's ID : "; cin.getline(st1,100); system("cls"); fstream intf("Booksdata.txt",ios::in|ios::out|ios::ate|ios::binary); intf.seekg(0); intf.read((char*)this,sizeof(*this)); while(!intf.eof()) { for(i=0;b==B&&sc[i]!='\0'&&st1[i]!='\0'&&st1[i]==sc[i];i++); if(sc[i]=='\0'&&st1[i]=='\0') { cont++; getdata(); intf.seekp(intf.tellp()-sizeof(*this)); intf.write((char*)this,sizeof(*this)); break; } intf.read((char*)this,sizeof(*this)); } intf.close(); } else { cout<<"\n\t\tIncorrect Input.....:(\n"; cout<<"\n\t\tPress any key to continue....."; getch(); system("cls"); modify(); } if(cont==0) { cout<<"\n\t\tBook Not Found.\n"; cout<<"\n\t\tPress any key to continue....."; getch(); system("cls"); modify(); } else cout<<"\n\t\tUpdate Successful.\n"; } else if(i==2) { system("cls"); B=branch(2); system("cls"); getdata(); ofstream outf("Booksdata.txt",ios::app|ios::binary); outf.write((char*)this,sizeof(*this)); outf.close(); cout<<"\n\t\tBook added Successfully.\n"; } else if(i==3) { system("cls"); b=branch(2); ifstream intf1("Booksdata.txt",ios::binary); if(!intf1) { cout<<"\n\t\tFile Not Found\n"; cout<<"\n\t\tPress any key to continue....."; getch(); intf1.close(); system("cls"); librarian(); } intf1.close(); system("cls"); cout<<"\n\t\tPlease Choose One Option for deletion:-\n"; cout<<"\n\t\t1.By Book Name\n\n\t\t2.By Book's ID\n"; cout<<"\n\t\tEnter Your Choice : "; cin>>i; fflush(stdin); if(i==1) { system("cls"); cout<<"\n\t\tEnter Book Name : "; cin.getline(st1,100); ofstream outf("temp.txt",ios::app|ios::binary); ifstream intf("Booksdata.txt",ios::binary); intf.read((char*)this,sizeof(*this)); while(!intf.eof()) { for(i=0;b==B&&bookname[i]!='\0'&&st1[i]!='\0'&&(st1[i]==bookname[i]||st1[i]==bookname[i]+32);i++); if(bookname[i]=='\0'&&st1[i]=='\0') { cont++; intf.read((char*)this,sizeof(*this)); } else { outf.write((char*)this,sizeof(*this)); intf.read((char*)this,sizeof(*this)); } } intf.close(); outf.close(); remove("Booksdata.txt"); rename("temp.txt","Booksdata.txt"); } else if(i==2) { cout<<"\n\t\tEnter Book's ID : "; cin.getline(st1,100); ofstream outf("temp.txt",ios::app|ios::binary); ifstream intf("Booksdata.txt",ios::binary); intf.read((char*)this,sizeof(*this)); while(!intf.eof()) { for(i=0;b==B&&sc[i]!='\0'&&st1[i]!='\0'&&st1[i]==sc[i];i++); if(sc[i]=='\0'&&st1[i]=='\0') { cont++; intf.read((char*)this,sizeof(*this)); } else { outf.write((char*)this,sizeof(*this)); intf.read((char*)this,sizeof(*this)); } } outf.close(); intf.close(); remove("Booksdata.txt"); rename("temp.txt","Booksdata.txt"); } else { cout<<"\n\t\tIncorrect Input.....:(\n"; cout<<"\n\t\tPress any key to continue....."; getch(); system("cls"); modify(); } if(cont==0) { cout<<"\n\t\tBook Not Found.\n"; cout<<"\n\t\tPress any key to continue....."; getch(); system("cls"); modify(); } else cout<<"\n\t\tDeletion Successful.\n"; } else if(i==4) { system("cls"); librarian(); } else { cout<<"\n\t\tWrong Input.\n"; cout<<"\n\t\tPress any key to continue....."; getch(); system("cls"); modify(); } cout<<"\n\t\tPress any key to continue....."; getch(); system("cls"); librarian(); } int Lib::branch(int x) { int i; cout<<"\n\t\t>>Please Choose one Branch :-\n"; cout<<"\n\t\t1.IT DEPARTMENT\n\n\t\t2.EDUCATION DEPARTMENT\n\n\t\t3.CRIMINOLOGY DEPARTMENT\n\n\t\t4.BA DEPARTMENT\n\n\t\t5.ENGENEERING DEPARTMENT\n\n\t\t6.COMSCI\n\n\t\t7.Go to menu\n"; cout<<"\n\t\tEnter youur choice : "; cin>>i; switch(i) { case 1: return 1; break; case 2: return 2; break; case 3: return 3; break; case 4: return 4; break; case 5: return 5; break; case 6: return 6; break; case 7: system("cls"); if(x==1) student(); else librarian(); default : cout<<"\n\t\tPlease enter correct option :("; getch(); system("cls"); branch(x); } } void Lib::see(int x) { int i,b,cont=0; char ch[100]; system("cls"); b=branch(x); ifstream intf("Booksdata.txt",ios::binary); if(!intf) { cout<<"\n\t\tFile Not Found.\n"; cout<<"\n\t\t->Press any key to continue....."; getch(); system("cls"); if(x==1) student(); else librarian(); } system("cls"); cout<<"\n\t\tPlease Choose one option :-\n"; cout<<"\n\t\t1.Search By Name\n\n\t\t2.Search By Book's ID\n"; cout<<"\n\t\tEnter Your Choice : "; cin>>i; fflush(stdin); intf.read((char*)this,sizeof(*this)); if(i==1) { cout<<"\n\t\tEnter Book's Name : "; cin.getline(ch,100); system("cls"); while(!intf.eof()) { for(i=0;b==B&&q!=0&&bookname[i]!='\0'&&ch[i]!='\0'&&(ch[i]==bookname[i]||ch[i]==bookname[i]+32);i++); if(bookname[i]=='\0'&&ch[i]=='\0') { cout<<"\n\t\tBook Found :-\n"; show(x); cont++; break; } intf.read((char*)this,sizeof(*this)); } } else if(i==2) { cout<<"\n\t\tEnter Book's ID : "; cin.getline(ch,100); system("cls"); while(!intf.eof()) { for(i=0;b==B&&q!=0&&sc[i]!='\0'&&ch[i]!='\0'&&ch[i]==sc[i];i++); if(sc[i]=='\0'&&ch[i]=='\0') { cout<<"\n\t\tBook Found :-\n"; show(x); cont++; break; } intf.read((char*)this,sizeof(*this)); } } else { cont++; cout<<"\n\t\tPlease enter correct option :("; getch(); system("cls"); see(x); } intf.close(); if(cont==0) cout<<"\n\t\tThis Book is not available :( \n"; cout<<"\n\t\tPress any key to continue....."; getch(); system("cls"); if(x==1) student(); else librarian(); } void Lib::issue() { char st[50],st1[20]; int b,i,j,d,m,y,dd,mm,yy,cont=0; system("cls"); cout<<"\n\t\t->Please Choose one option :-\n"; cout<<"\n\t\t1.Issue Book\n\n\t\t2.View Issued Book\n\n\t\t3.Search student who isuued books\n\n\t\t4.Reissue Book\n\n\t\t5.Return Book\n\n\t\t6.Go back to menu\n\n\t\tEnter Your Choice : "; cin>>i; fflush(stdin); if(i==1) { system("cls"); b=branch(2); system("cls"); fflush(stdin); cout<<"\n\t\t->Please Enter Details :-\n"; cout<<"\n\t\tEnter Book Name : "; cin.getline(bookname,100); cout<<"\n\t\tEnter Book's ID : "; cin.getline(sc,20); //strcpy(st,sc); der(sc,b,1); cout<<"\n\t\tEnter Student Name : "; cin.getline(auname,100); cout<<"\n\t\tEnter Student's ID : "; cin.getline(sc1,20); cout<<"\n\t\tEnter date : "; cin>>q>>B>>p; ofstream outf("student.txt",ios::binary|ios::app); outf.write((char*)this,sizeof(*this)); outf.close(); cout<<"\n\n\t\tIssue Successfully.\n"; } else if(i==2) { ifstream intf("student.txt",ios::binary); system("cls"); cout<<"\n\t\t->The Details are :-\n"; intf.read((char*)this,sizeof(*this)); i=0; while(!intf.eof()) { i++; cout<<"\n\t\t********** "<<i<<". ********** \n"; cout<<"\n\t\tStudent Name : "<<auname<<"\n\t\t"<<"Student's ID : "<<sc1<<"\n\t\t"<<"Book Name : "<<bookname<<"\n\t\t"<<"Book's ID : "<<sc<<"\n\t\t"<<"Date : "<<q<<"/"<<B<<"/"<<p<<"\n"; intf.read((char*)this,sizeof(*this)); } intf.close(); } else if(i==3) { system("cls"); fflush(stdin); cout<<"\n\t\t->Please Enter Details :-\n"; cout<<"\n\n\t\tEnter Student Name : "; cin.getline(st,50); cout<<"\n\n\t\tEnter Student's ID : "; cin.getline(st1,20); system("cls"); ifstream intf("student.txt",ios::binary); intf.read((char*)this,sizeof(*this)); cont=0; while(!intf.eof()) { for(i=0;sc1[i]!='\0'&&st1[i]!='\0'&&st1[i]==sc1[i];i++); if(sc1[i]=='\0'&&st1[i]=='\0') { cont++; if(cont==1) { cout<<"\n\t\t->The Details are :-\n"; cout<<"\n\t\tStudent Name : "<<auname; cout<<"\n\t\tStudent's ID : "<<sc1; } cout<<"\n\n\t\t******* "<<cont<<". Book details *******\n"; cout<<"\n\t\tBook Name : "<<bookname; cout<<"\n\t\tBook's ID : "<<sc; cout<<"\n\t\tDate : "<<q<<"/"<<B<<"/"<<p<<"\n"; } intf.read((char*)this,sizeof(*this)); } intf.close(); if(cont==0) cout<<"\n\t\tNo record found."; } else if(i==4) { system("cls"); fflush(stdin); cout<<"\n\t\t->Please Enter Details :-\n"; cout<<"\n\n\t\tEnter Student's ID : "; cin.getline(st,50); cout<<"\n\t\tEnter Book's ID : "; cin.getline(st1,20); fstream intf("student.txt",ios::in|ios::out|ios::ate|ios::binary); intf.seekg(0); intf.read((char*)this,sizeof(*this)); while(!intf.eof()) { for(i=0;sc[i]!='\0'&&st1[i]!='\0'&&st1[i]==sc[i];i++); for(j=0;sc1[j]!='\0'&&st[j]!='\0'&&st[j]==sc1[j];j++); if(sc[i]=='\0'&&sc1[j]=='\0'&&st[j]=='\0'&&st1[i]=='\0') { d=q; m=B; y=p; cout<<"\n\t\tEnter New Date : "; cin>>q>>B>>p; fine(d,m,y,q,B,p); //fn1 intf.seekp(intf.tellp()-sizeof(*this)); //fn3 intf.write((char*)this,sizeof(*this)); //fn5 cout<<"\n\n\t\tReissue successfully."; //fn3 break; } intf.read((char*)this,sizeof(*this)); } intf.close(); } else if(i==5) { system("cls"); b=branch(2); system("cls"); fflush(stdin); cout<<"\n\t\t->Please Enter Details :-\n"; cout<<"\n\t\tEnter Book's ID : "; cin.getline(st1,20); der(st1,b,2); cout<<"\n\n\t\tEnter Student's ID : "; cin.getline(st,20); cout<<"\n\t\tEnter Present date : "; cin>>d>>m>>y; ofstream outf("temp.txt",ios::app|ios::binary); ifstream intf("student.txt",ios::binary); intf.read((char*)this,sizeof(*this)); while(!intf.eof()) { for(i=0;sc[i]!='\0'&&st1[i]!='\0'&&st1[i]==sc[i];i++); for(j=0;sc1[j]!='\0'&&st[j]!='\0'&&st[j]==sc1[j];j++); if(sc[i]=='\0'&&sc1[j]=='\0'&&st[j]=='\0'&&st1[i]=='\0'&&cont==0) { cont++; intf.read((char*)this,sizeof(*this)); fine(q,B,p,d,m,y); cout<<"\n\t\tReturned successfully."; } else { outf.write((char*)this,sizeof(*this)); intf.read((char*)this,sizeof(*this)); } } intf.close(); outf.close(); getch(); remove("student.txt"); rename("temp.txt","student.txt"); } else if(i==6) { system("cls"); librarian(); } else cout<<"\n\t\tWrong Input.\n"; cout<<"\n\n\t\tPress any key to continue....."; getch(); system("cls"); librarian(); } void Lib::fine(int d,int m,int y,int dd,int mm,int yy) { long int n1,n2; int years,l,i; const int monthDays[12] = {31, 28, 31, 30, 31, 30,31, 31, 30, 31, 30, 31}; n1 = y*365 + d; for (i=0; i<m - 1; i++) n1 += monthDays[i]; //fn1353 years = y; if (m <= 2) years--; l= years / 4 - years / 100 + years / 400; n1 += l; n2 = yy*365 + dd; for (i=0; i<mm - 1; i++) n2 += monthDays[i]; years = yy; if (m <= 2) years--; l= years / 4 - years / 100 + years / 400; n2 += l; n1=n2-n1; n2=n1-15; if(n2>0) cout<<"\n\t\tThe Total Fine is : "<<n2; } void Lib::der(char st[],int b,int x) { int i,cont=0; fstream intf("Booksdata.txt",ios::in|ios::out|ios::ate|ios::binary); intf.seekg(0); intf.read((char*)this,sizeof(*this)); while(!intf.eof()) { for(i=0;b==B&&sc[i]!='\0'&&st[i]!='\0'&&st[i]==sc[i];i++); if(sc[i]=='\0'&&st[i]=='\0') { cont++; if(x==1) { q--; } else { q++; } intf.seekp(intf.tellp()-sizeof(*this)); intf.write((char*)this,sizeof(*this)); break; } intf.read((char*)this,sizeof(*this)); } if(cont==0) { cout<<"\n\t\tBook not found.\n"; cout<<"\n\n\t\tPress any key to continue....."; getch(); system("cls"); issue(); } intf.close(); } void Lib::get() { int i; cout<<"\n\t*********** LIBRARY MANAGEMENT SYSTEM ***********\n"<<"\n\t\t\t L M S C++\n"; cout<<"\n\t\t>>Please Choose Any Option To login \n"; cout<<"\n\t\t1.Student\n\n\t\t2.Librarian\n\n\t\t3.Close Application\n"; cout<<"\n\t\tEnter your choice : "; cin>>i; if(i==1) { system("cls"); student(); } else if(i==2) pass(); else if(i==3) exit(0); else { cout<<"\n\t\tPlease enter correct option :("; getch(); system("CLS"); get(); } } void Lib::student() { int i; cout<<"\n\t************ WELCOME STUDENT ************\n"; cout<<"\n\t\t>>Please Choose One Option:\n"; cout<<"\n\t\t1.View BookList\n\n\t\t2.Search for a Book\n\n\t\t3.Go to main menu\n\n\t\t4.Close Application\n"; cout<<"\n\t\tEnter your choice : "; cin>>i; if(i==1) booklist(1); else if(i==2) see(1); else if(i==3) { system("cls"); get(); } else if(i==4) exit(0); else { cout<<"\n\t\tPlease enter correct option :("; getch(); system("cls"); student(); } } void Lib::pass() { int i=0; char ch,st[21],ch1[21]={"pass"}; cout<<"\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++; } } ifstream inf("password.txt"); inf>>ch1; inf.close(); for(i=0;st[i]==ch1[i]&&st[i]!='\0'&&ch1[i]!='\0';i++); if(st[i]=='\0'&&ch1[i]=='\0') { system("cls"); librarian(); } else { cout<<"\n\n\t\tWrong Password.\n\n\t\ttry again.....\n"; getch(); system("cls"); get(); } } void Lib::librarian() { int i; cout<<"\n\t************ WELCOME LIBRARIAN ************\n"; cout<<"\n\t\t>>Please Choose One Option:\n"; cout<<"\n\t\t1.View BookList\n\n\t\t2.Search for a Book\n\n\t\t3.Modify/Add Book\n\n\t\t4.Issue Book\n\n\t\t5.Go to main menu\n\n\t\t6.Change Password\n\n\t\t7.Close Application\n"; cout<<"\n\t\tEnter your choice : "; cin>>i; switch(i) { case 1:booklist(2); break; case 2:see(2); break; case 3:modify(); break; case 4:issue(); break; case 5:system("cls"); get(); break; case 6:password(); break; case 7:exit(0); default:cout<<"\n\t\tPlease enter correct option :("; getch(); system("cls"); librarian(); } } void Lib::password() { int i=0,j=0; char ch,st[21],ch1[21]={"pass"}; system("cls"); cout<<"\n\n\t\tEnter Old 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++; } } ifstream intf("password.txt"); intf>>ch1; intf.close(); for(i=0;st[i]==ch1[i]&&st[i]!='\0'&&ch1[i]!='\0';i++); if(st[i]=='\0'&&ch1[i]=='\0') { system("cls"); cout<<"\n\t**The Password Should be less than 20 characters & don't use spaces**\n\n"; cout<<"\n\t\tEnter New Password : "; fflush(stdin); i=0; while(1) { j++; ch=getch(); if(ch==13) { for(i=0;st[i]!=' '&&st[i]!='\0';i++); if(j>20 || st[i]==' ') { cout<<"\n\n\t\tYou did't follow the instruction \n\n\t\tPress any key for try again....."; getch(); system("cls"); password(); librarian(); } st[i]='\0'; break; } else if(ch==8&&i>0) { i--; cout<<"\b \b"; } else { cout<<"*"; st[i]=ch; i++; } } ofstream outf("password.txt"); outf<<st; outf.close(); cout<<"\n\n\t\tYour Password has been changed Successfully."; cout<<"\n\t\tPress any key to continue......"; getch(); system("cls"); librarian(); } else { cout<<"\n\n\t\tPassword is incorrect.....\n"; cout<<"\n\t\tEnter 1 for retry or 2 for menu"; cin>>i; if(i==1) { system("cls"); password(); } else { system("cls"); librarian(); } } } int main() { Lib obj; obj.get(); getch(); return 0; } |
Run Quick Virus Scan for secure Download
Run Quick Scan for safe DownloadDownloadable Source Code
Summary
The whole project is designed in ‘C++’ language and different variables and strings have been used for the development of this project. This mini project is easy to operate and understand by the users.
This simple project can enhance the knowledge of the beginners or the students to develop their skills in programming, also this project is easy to understand the module and their variables.
Related Articles
- School Management System In C++ With Source Code
- Library Management System Project In Python and MySQL
- Library Management System In C With Source Code | Video| 2020
Inquiries
If you have any questions or suggestions about Library Management System In C++ With Source Code , please feel free to leave a comment below.