Library Management System Project in C++ with Output - LMS Project with C

Published October 01, 2021

A library management system(LMS) is a software built to handle the primary housekeeping functions of library. LMS help libraries keep track of the books and their checkouts.
It is used by librarian to manage the library using computerized system. It has been opted by a lot of orgnizations, including a lots of schools and public libraries. To run this program you have to put the correct password which is "codewithc" . Along with this you can read also more C Projects for Beginners

 

Difficulties in LMS

  1. To check availability of the book.
  2. Manual system
  3. Librarian has to perform every task every single time
  4. Updating is a tedious work
  5. Addition and editing book records is complex
  6. Very hard to maintain bigger data.

 

Features

  1. Making addition of books easy
  2. Easy Searching of Books
  3. Easy editing of book records
  4. More Accuracy
  5. Speed Improvement
  6. Time Saving
  7. Better error handling
  8. Addition of books
  9. Viewing of books list
  10. Editing book records

 

System Requirements

  1. Processor - Intel Core Pentium or above
  2. Operating System - Windows vista or above
  3. Memory - 1Gb Ram or more
  4. Hard Disk Space - According to the size of DataBase

 

AddBook

void addbooks(void)    //funtion that add books
{
system("cls");
int i;
gotoxy(20,5);
printf("\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2SELECT CATEGOIES\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2");
gotoxy(20,7);
printf("\xDB\xDB\xDB\xDB\xB2 1. Computer");
gotoxy(20,9);
printf("\xDB\xDB\xDB\xDB\xB2 2. Electronics");
gotoxy(20,11);
printf("\xDB\xDB\xDB\xDB\xB2 3. Electrical");
gotoxy(20,13);
printf("\xDB\xDB\xDB\xDB\xB2 4. Civil");
gotoxy(20,15);
printf("\xDB\xDB\xDB\xDB\xB2 5. Mechanical");
gotoxy(20,17);
printf("\xDB\xDB\xDB\xDB\xB2 6. Architecture");
gotoxy(20,19);
printf("\xDB\xDB\xDB\xDB\xB2 7. Back to main menu");
gotoxy(20,21);
printf("\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2");
gotoxy(20,22);
printf("Enter your choice:");
scanf("%d",&s);
if(s==7)

mainmenu() ;
system("cls");
fp=fopen("Bibek.dat","ab+");
if(getdata()==1)
{
a.cat=catagories[s-1];
fseek(fp,0,SEEK_END);
fwrite(&a,sizeof(a),1,fp);
fclose(fp);
gotoxy(21,14);
printf("The record is sucessfully saved");
gotoxy(21,15);
printf("Save any more?(Y / N):");
if(getch()=='n')
mainmenu();
else
system("cls");
addbooks();
}
}

 

Delete Book

void deletebooks()    //function that delete items from file fp
{
system("cls");
int d;
char another='y';
while(another=='y')  //infinite loop
        {
        system("cls");
        gotoxy(10,5);
        printf("Enter the Book ID to  delete:");
        scanf("%d",&d);
        fp=fopen("Bibek.dat","rb+");
        rewind(fp);
        while(fread(&a,sizeof(a),1,fp)==1)
        {
            if(a.id==d)
            {
            
                gotoxy(10,7);
                printf("The book record is available");
                gotoxy(10,8);
                printf("Book name is %s",a.name);
                gotoxy(10,9);
                printf("Rack No. is %d",a.rackno);
                findbook='t';
            }
        }
        if(findbook!='t')
            {
                gotoxy(10,10);
                printf("No record is found modify the search");
                if(getch())
                mainmenu();
            }
            if(findbook=='t' )
            {
                gotoxy(10,9);
                printf("Do you want to delete it?(Y/N):");
                if(getch()=='y')
                    {
                    ft=fopen("test.dat","wb+");  //temporary file for delete
                    rewind(fp);
                    while(fread(&a,sizeof(a),1,fp)==1)
                    {
                        if(a.id!=d)
                        {
                            fseek(ft,0,SEEK_CUR);
                            fwrite(&a,sizeof(a),1,ft); //write all in tempory file except that
                        }                              //we want to delete
                    }
                    fclose(ft);
                    fclose(fp);
                    remove("Bibek.dat");
                    rename("test.dat","Bibek.dat"); //copy all item from temporary file to fp except that
                    fp=fopen("Bibek.dat","rb+");    //we want to delete
                    if(findbook=='t')
                    {
                        gotoxy(10,10);
                        printf("The record is sucessfully deleted");
                        gotoxy(10,11);
                        printf("Delete another record?(Y/N)");
                    }
                    }
                else
                mainmenu();
                fflush(stdin);
                another=getch();
            }
    }
gotoxy(10,15);
mainmenu();
}

 

 

Search Book

void searchbooks()
    {
    system("cls");
    int d;
    printf("*****************************Search Books*********************************");
    gotoxy(20,10);
    printf("\xDB\xDB\xDB\xB2 1. Search By ID");
    gotoxy(20,14);
    printf("\xDB\xDB\xDB\xB2 2. Search By Name");
    gotoxy( 15,20);
    printf("Enter Your Choice");
    fp=fopen("Bibek.dat","rb+"); //open file for reading propose
    rewind(fp);   //move pointer at the begining of file
    switch(getch())
            {
            case '1':
                {
                system("cls");
                gotoxy(25,4);
                printf("****Search Books By Id****");
                gotoxy(20,5);
                printf("Enter the book id:");
                scanf("%d",&d);
                gotoxy(20,7);
                printf("Searching........");
                while(fread(&a,sizeof(a),1,fp)==1)
                    {
                    if(a.id==d)
                        {
                        Sleep(2);
                        gotoxy(20,7);
                        printf("The Book is available");
                        gotoxy(20,8);
                        printf("\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2");
                        gotoxy(20,9);
                        printf("\xB2 ID:%d",a.id);gotoxy(47,9);printf("\xB2");
                        gotoxy(20,10);
                        printf("\xB2 Name:%s",a.name);gotoxy(47,10);printf("\xB2");
                        gotoxy(20,11);
                        printf("\xB2 Author:%s ",a.Author);gotoxy(47,11);printf("\xB2");
                        gotoxy(20,12);
                        printf("\xB2 Qantity:%d ",a.quantity);gotoxy(47,12);printf("\xB2"); gotoxy(47,11);printf("\xB2");
                        gotoxy(20,13);
                        printf("\xB2 Price:Rs.%.2f",a.Price);gotoxy(47,13);printf("\xB2");
                        gotoxy(20,14);
                        printf("\xB2 Rack No:%d ",a.rackno);gotoxy(47,14);printf("\xB2");
                        gotoxy(20,15);
                        printf("\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2");
                        findbook='t';
                    }
                
                }
                if(findbook!='t')  //checks whether conditiion enters inside loop or not
                    {
                    gotoxy(20,8);
                    printf("\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2");
                    gotoxy(20,9);printf("\xB2");  gotoxy(38,9);printf("\xB2");
                    gotoxy(20,10);
                    printf("\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2");
                    gotoxy(22,9);printf("\aNo Record Found");
                }
                gotoxy(20,17);
                printf("Try another search?(Y/N)");
                if(getch()=='y')
                searchbooks();
                else
                mainmenu();
                break;
            }
            case '2':
                {
                char s[15];
                system("cls");
                gotoxy(25,4);
                printf("****Search Books By Name****");
                gotoxy(20,5);
                printf("Enter Book Name:");
                scanf("%s",s);
                int d=0;
                while(fread(&a,sizeof(a),1,fp)==1)
                    {
                    if(strcmp(a.name,(s))==0) //checks whether a.name is equal to s or not
                        {
                        gotoxy(20,7);
                        printf("The Book is available");
                        gotoxy(20,8);
                        printf("\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2");
                        gotoxy(20,9);
                        printf("\xB2 ID:%d",a.id);gotoxy(47,9);printf("\xB2");
                        gotoxy(20,10);
                        printf("\xB2 Name:%s",a.name);gotoxy(47,10);printf("\xB2");
                        gotoxy(20,11);
                        printf("\xB2 Author:%s",a.Author);gotoxy(47,11);printf("\xB2");
                        gotoxy(20,12);
                        printf("\xB2 Qantity:%d",a.quantity);gotoxy(47,12);printf("\xB2");
                        gotoxy(20,13);
                        printf("\xB2 Price:Rs.%.2f",a.Price);gotoxy(47,13);printf("\xB2");
                        gotoxy(20,14);
                        printf("\xB2 Rack No:%d ",a.rackno);gotoxy(47,14);printf("\xB2");
                        gotoxy(20,15);
                        printf("\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2");
                        d++;
                    }
                
                }
                if(d==0)
                    {
                    gotoxy(20,8);
                    printf("\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2");
                    gotoxy(20,9);printf("\xB2");  gotoxy(38,9);printf("\xB2");
                    gotoxy(20,10);
                    printf("\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2\xB2");
                    gotoxy(22,9);printf("\aNo Record Found");
                }
                gotoxy(20,17);
                printf("Try another search?(Y/N)");
                if(getch()=='y')
                searchbooks();
                else
                mainmenu();
                break;
            }
            default :
            getch();
            searchbooks();
    }
    fclose(fp);
}

 

Issue Book

void issuebooks(void)  //function that issue books from library
{
    int t;
    
    system("cls");
    printf("********************************ISSUE SECTION**************************");
    gotoxy(10,5);
    printf("\xDB\xDB\xDB\xDb\xB2 1. Issue a Book");
    gotoxy(10,7);
    printf("\xDB\xDB\xDB\xDb\xB2 2. View Issued Book");
    gotoxy(10,9);
    printf("\xDB\xDB\xDB\xDb\xB2 3. Search Issued Book");
    gotoxy(10,11);
    printf("\xDB\xDB\xDB\xDb\xB2 4. Remove Issued Book");
    gotoxy(10,14);
    printf("Enter a Choice:");
    switch(getch())
    {
        case '1':  //issue book
        {
            system("cls");
            int c=0;
            char another='y';
            while(another=='y')
            {
                system("cls");
                gotoxy(15,4);
                printf("***Issue Book section***");
                gotoxy(10,6);
                printf("Enter the Book Id:");
                scanf("%d",&t);
                fp=fopen("Bibek.dat","rb");
                fs=fopen("Issue.dat","ab+");
                if(checkid(t)==0) //issues those which are present in library
                {
                    gotoxy(10,8);
                    printf("The book record is available");
                    gotoxy(10,9);
                    printf("There are %d unissued books in library ",a.quantity);
                    gotoxy(10,10);
                    printf("The name of book is %s",a.name);
                    gotoxy(10,11);
                    printf("Enter student name:");
                    scanf("%s",a.stname);
                    //struct dosdate_t d; //for current date
                    //_dos_getdate(&d);
                    //a.issued.dd=d.day;
                    //a.issued.mm=d.month;
                    //a.issued.yy=d.year;
                    gotoxy(10,12);
                    printf("Issued date=%d-%d-%d",a.issued.dd,a.issued.mm,a.issued.yy);
                    gotoxy(10,13);
                    printf("The BOOK of ID %d is issued",a.id);
                    a.duedate.dd=a.issued.dd+RETURNTIME;   //for return date
                    a.duedate.mm=a.issued.mm;
                    a.duedate.yy=a.issued.yy;
                    if(a.duedate.dd>30)
                    {
                        a.duedate.mm+=a.duedate.dd/30;
                        a.duedate.dd-=30;
                    
                    }
                    if(a.duedate.mm>12)
                    {
                        a.duedate.yy+=a.duedate.mm/12;
                        a.duedate.mm-=12;
                    
                    }
                    gotoxy(10,14);
                    printf("To be return:%d-%d-%d",a.duedate.dd,a.duedate.mm,a.duedate.yy);
                    fseek(fs,sizeof(a),SEEK_END);
                    fwrite(&a,sizeof(a),1,fs);
                    fclose(fs);
                    c=1;
                }
                if(c==0)
                {
                gotoxy(10,11);
                printf("No record found");
                }
                gotoxy(10,15);
                printf("Issue any more(Y/N):");
                fflush(stdin);
                another=getche();
                fclose(fp);
        }
        
        break;
        }
        case '2':  //show issued book list
            {
                system("cls");
                int j=4;
                printf("*******************************Issued book list*******************************\n");
                gotoxy(2,2);
                printf("STUDENT NAME    CATEGORY    ID    BOOK NAME    ISSUED DATE    RETURN DATE");
                fs=fopen("Issue.dat","rb");
                while(fread(&a,sizeof(a),1,fs)==1)
                {
                
                    gotoxy(2,j);
                    printf("%s",a.stname);
                    gotoxy(18,j);
                    printf("%s",a.cat);
                    gotoxy(30,j);
                    printf("%d",a.id);
                    gotoxy(36,j);
                    printf("%s",a.name);
                    gotoxy(51,j);
                    printf("%d-%d-%d",a.issued.dd,a.issued.mm,a.issued.yy );
                    gotoxy(65,j);
                    printf("%d-%d-%d",a.duedate.dd,a.duedate.mm,a.duedate.yy);
                    //struct dosdate_t d;
                    //_dos_getdate(&d);
                    gotoxy(50,25);
                    //            printf("Current date=%d-%d-%d",d.day,d.month,d.year);
                    j++;
                
                }
                fclose(fs);
                gotoxy(1,25);
                returnfunc();
        }
        break;
        case '3':   //search issued books by id
        {
            system("cls");
            gotoxy(10,6);
            printf("Enter Book ID:");
            int p,c=0;
            char another='y';
            while(another=='y')
            {
            
            scanf("%d",&p);
            fs=fopen("Issue.dat","rb");
            while(fread(&a,sizeof(a),1,fs)==1)
            {
                if(a.id==p)
                {
                    issuerecord();
                    gotoxy(10,12);
                    printf("Press any key.......");
                    getch();
                    issuerecord();
                    c=1;
                }
            
            }
            fflush(stdin);
            fclose(fs);
            if(c==0)
            {
                gotoxy(10,8);
                printf("No Record Found");
            }
            gotoxy(10,13);
            printf("Try Another Search?(Y/N)");
            another=getch();
        }
        }
        break;
        case '4':  //remove issued books from list
        {
            system("cls");
            int b;
            FILE *fg;  //declaration of temporary file for delete
            char another='y';
            while(another=='y')
            {
                gotoxy(10,5);
                printf("Enter book id to remove:");
                scanf("%d",&b);
                fs=fopen("Issue.dat","rb+");
                while(fread(&a,sizeof(a),1,fs)==1)
                {
                    if(a.id==b)
                    {
                        issuerecord();
                        findbook='t';
                    }
                    if(findbook=='t')
                    {
                        gotoxy(10,12);
                        printf("Do You Want to Remove it?(Y/N)");
                        if(getch()=='y')
                            {
                            fg=fopen("record.dat","wb+");
                            rewind(fs);
                            while(fread(&a,sizeof(a),1,fs)==1)
                            {
                                if(a.id!=b)
                                {
                                    fseek(fs,0,SEEK_CUR);
                                    fwrite(&a,sizeof(a),1,fg);
                                }
                            }
                            fclose(fs);
                            fclose(fg);
                            remove("Issue.dat");
                            rename("record.dat","Issue.dat");
                            gotoxy(10,14);
                            printf("The issued book is removed from list");
                        
                        }
                    
                    }
                    if(findbook!='t')
                    {
                    gotoxy(10,15);
                    printf("No Record Found");
                    }
                }
                gotoxy(10,16);
                printf("Delete any more?(Y/N)");
                another=getch();
            }
        }
        default:
        gotoxy(10,18);
        printf("\aWrong Entry!!");
        getch();
        issuebooks();
        break;
    }
    gotoxy(1,30);
    returnfunc();
}

 

 

View Books

void viewbooks(void)  //show the list of book persists in library
   {
   int i=0,j;
   system("cls");
   gotoxy(1,1);
   printf("*********************************Book List*****************************");
   gotoxy(2,2);
   printf(" CATEGORY     ID    BOOK NAME     AUTHOR       QTY     PRICE     RackNo ");
   j=4;
   fp=fopen("Bibek.dat","rb");
   while(fread(&a,sizeof(a),1,fp)==1)
   {
      gotoxy(3,j);
      printf("%s",a.cat);
      gotoxy(16,j);
      printf("%d",a.id);
      gotoxy(22,j);
      printf("%s",a.name);
      gotoxy(36,j);
      printf("%s",a.Author);
      gotoxy(50,j);
      printf("%d",a.quantity);
      gotoxy(57,j);
      printf("%.2f",a.Price);
      gotoxy(69,j);
      printf("%d",a.rackno);
      printf("\n\n");
      j++;
      i=i+a.quantity;
   }
   gotoxy(3,25);
   printf("Total Books =%d",i);
   fclose(fp);
   gotoxy(35,25);
   returnfunc();
}

 

 

Edit Books

void editbooks(void)  //edit information about book
   {
   system("cls");
   int c=0;
   int d,e;
   gotoxy(20,4);
   printf("****Edit Books Section****");
   char another='y';
   while(another=='y')
      {
      system("cls");
      gotoxy(15,6);
      printf("Enter Book Id to be edited:");
      scanf("%d",&d);
      fp=fopen("Bibek.dat","rb+");
      while(fread(&a,sizeof(a),1,fp)==1)
      {
      if(checkid(d)==0)
      {
         gotoxy(15,7);
         printf("The book is availble");
         gotoxy(15,8);
         printf("The Book ID:%d",a.id);
         gotoxy(15,9);
         printf("Enter new name:");scanf("%s",a.name);
         gotoxy(15,10);
         printf("Enter new Author:");scanf("%s",a.Author);
         gotoxy(15,11);
         printf("Enter new quantity:");scanf("%d",&a.quantity);
         gotoxy(15,12);
         printf("Enter new price:");scanf("%f",&a.Price);
         gotoxy(15,13);
         printf("Enter new rackno:");scanf("%d",&a.rackno);
         gotoxy(15,14);
         printf("The record is modified");
         fseek(fp,ftell(fp)-sizeof(a),0);
         fwrite(&a,sizeof(a),1,fp);
         fclose(fp);
         c=1;
      }
      if(c==0)
      {
         gotoxy(15,9);
         printf("No record found");
      }
      }
      gotoxy(15,16);
      printf("Modify another Record?(Y/N)");
      fflush(stdin);
      another=getch() ;
   }
   returnfunc();
}

 

Outputs:

C LMS Project for beginners

 

C Library Management system project

 

C Beginner Projects - LMS

 

Conclusion: In this C examples we covered simple Library Management System (LMS) Project for beginners. We can also add Secured Password protection to the project

 

Download Source code

 

 

More Beginner Projects

Employee Management System with CPP

Python Library Management System

Java Library Management System Source code

More Beginner Projects

Employee Management System with CPP

Python Library Management System

C Library Management System - LMS Project with C

Java Library Management System Source code

Calendar application with C Language

Contact Management System with C

Bank Management System with C

Article Contributed By :
https://www.rrtutors.com/site_assets/profile/assets/img/avataaars.svg

1300 Views