Skip to content

Info All | Umar Jameel Web Developer

logo umar jameel

Simple Library Management System Program in C++

Library Management System in c++

Write a C++ program for Library Management System. Digital LMS is most demanding need cause everything is revolutionizing digitally. So there should be a system in which user can search and borrow a book from library online. Admin can add user, delete user, update user and maintain data of user etc. And user can search Book, purchase book and return book.

C++ Program for Library Management System

So, here is a simple C++ program for library management system in which user can borrow book. I advice you to take only help from this code, make a logic and solve by yourself. And don’t forget to share informative content. Thank you

Read Also: Hakeem Muhammad Saeed Infoall.org

Complete simple Program for Library Management System in C++


#include <ionstream>

#include<conio.h>
#include<string>

using namespace std;

int isbn2,index;
int search(int isbn);
int nstaff=0,nstud=0,bkid=0;
class library
{
public:
virtual int returnbook(){return 0;}
virtual int takebook(){return 0;}

virtual void addstaff(){}
virtual int isb(){return 0;}
virtual void addbook(){}
virtual void adds(){}
virtual string str(){return””;}
virtual int sto(){return 0;}
};
library stud[100],sta[100],*bks[100];

class library_store:public library
{
public:
string bookname;
int isbn;
int stock;
library_store():stock(0)
{ }

int isb(){return isbn;}
string str(){return bookname;}
int sto(){ return stock;}

int returnbook()
{
stock++;
return 1;
}
int takebook()
{
if(stock>0)
{
stock–;
return 1;
}
else
{
cout<<“\n The book not available”; return -1; } } void addbook() { cout<<“Kindly enter book name \n”; cin>>bookname;
cout<<“Kindly enter book number:\n”; cin>>isbn;
cout<<“Enter number of books available: \n”; cin>>stock;
}

};

class students:public library
{
public:
string name;

int returnbook()
{
int days;
cout<<“\nKindly Enter book number: “; cin>>isbn2;
index=search(isbn2);
if(index!=-1)
{
cout<<“\nEnter ductration for borrowing book “; cin>>days;
cout<<“\nFine to be paid: Rs.”<<(days-5)*1; return bks[index]->returnbook();
}
else
return -1;
}

int takebook()
{
cout<<“\nEnter the book number: “; cin>>isbn2;
index=search(isbn2);
if(index!=-1)
{
cout<<“\nKindly return book in 10 days:”; return bks[index]->takebook();
}
else
return -1;
}

void adds()
{
cout<<“\nEnter the name of the student:”; cin>>name;
}
};

void display()
{
cout<<“\nThe available books are:\n\nISBN\t-\tName\t-\tStock\n”; for(int i=0;iisb()<<“\t-\t”<str()<<“\t-\t”<sto();
}
}

void student()
{
int ch,id,cont=1;
system(“cls”);
cout<<“\nSTUDENT\n——–\n”; cout<<“Enter library number: “; cin>>id;
id–;
while(cont==1)
{
system(“cls”);
cout<<“\n1.Display books\n2.Take books\n3.Return book\n4.Go to main menu\n”; cin>>ch;
switch(ch)
{
case 1: display();
break;

case 2: if(stud[id]->takebook()==-1)
cout<<“\nInvalid Number!!!”;
else
cout<<“\nPlease wait…\n”;
break;

case 3: if(stud[id]->returnbook()==-1)
cout<<“\nInvalid Number!!!”;
else
cout<<“\nPlease wait…\n”;
break;

case 4: cont=0;
break;
}
getch();
}
}

void admin()
{
int ch,rep=1;
system(“cls”);
while(rep==1)
{
system(“cls”);
cout<<“\nDATABASE\n———\n\n\n2.Add student\n3.Add books\n4.Display\n5.Exit\n”; cin>>ch;
switch(ch)
{

case 2: stud[nstud]=new students;
stud[nstud]->adds();
nstud++;
cout<<“\nThe Library number is: “<<nstud;
break;

case 3: bks[bkid]=new library_store;
bks[bkid]->addbook();
bkid++;
break;

case 4: display();
break;

case 5: rep=0;
break;
}
cout<<“\nPress Enter to continue:”;
getch();
}
}

int search(int isbn)
{
for(int i=0;iisb()==isbn)
return i;
}
cout<<“No book found!!!”;
return -1;
}

int main()
{
int choice,cont=1;
while(cont==1)
{
cout<<“\n1.Admin Login\n\n2.Student\n3.Exit\nEnter your choice: “; cin>>choice;
switch(choice)
{
case 1: admin();
break;

case 2: student();
break;

case 3: cont=0;
break;

default: cout<<“\n\nInvalid Entry!!”;
}
}
}

Output of the above Library Management System Program

Library Management System Program C++

1 thought on “Simple Library Management System Program in C++”

  1. Pingback: How to Install and Configure SonarQube for Automation Testing - Info All | Umar Jameel Web Developer

Comments are closed.