Trending Articles       10 Flutter Listview Examples       Flutter Custom Button Example       Flutter Audio Recording       Flutter 2.0 Autocomplete TextField       Current Location Google Maps

C++ Library Management System Project with Source Code

In this tutorial, we are going to program the library management system project in C++ with simple and easy code. Basically, we are going to program different features to add, delete, or update books. There are many more features we are going to use in the library management system project. Let's have a brief look at the features of this LMS project.

 

Features of Library Management System Project

  • Students Details- We will be able to add or update the student details such as name, roll number, etc. These details will be stored in different variables.

  • Add/Remove/Update Books- This library management system project will be programmed to add, remove, or update books easily that will make it more efficient.

  • Complete Books Details- This C++ program will include all the complete details of books present in the store. 

  • Authentication- You can easily login to the LMS service with different roles. If you are an admin then you will get the admin id and password from which you can easily access the admin services and the same for all the users.

  • Database- All the information added or removed will be updated in the database. If you are an admin then you can access and edit the database


As a beginner programmer you should also know about how to Conver String to Char Array using C++

 

Project Explanation:

  • We will create a menu to select a user whether he/she is a student or teacher. 

  • After selection of role, the user will enter his username and password which will give them access to the library management system

 

Project Management Library in C++

 

 

1. Teacher

Library  Management Project in C++

 

If you logged in as a teacher then there will be access to different services like add, remove or update the books. Also, there is an access to see the list of all the books. 

  • If you click on add books then you can easily add the book by entering the book id, book name and author name.

  • You can also delete or update the books, just select the option from the list, that's it.

 

2. Student

Library Management System in C++

 

If you logged in as a student then there will be access of different services like:

  • Borrow a book

  • Return a book

  • List of books

Let's program our library management system using simple code in C++

 

Program For Library Management System in C++

Step 1: Create a new C++ file named as main.cpp and paste the following code in that file

#include <iostream>
#include "main.h"
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <fstream>

using namespace std;


/* run this program using the console pauser or add your own getch,
system("pause") or input loop */

int main (int argc, char **argv)
{


int outerChoice = 0;

while (outerChoice != 9)
{

system ("cls");

cout << "\n Library Management System \n\n";

cout << "\n1. Teacher";

cout << "\n2. Student";

cout << "\n9. Exit";

cout << "\n\nEnter your choice : ";

cin >> outerChoice;


if (outerChoice == 1)

{

char adminUser[10];

char adminPassword[10];


system ("cls");

cout << "\n ---------- Teacher Login -------";

cout << "\n\n Please enter your username: ";

cin >> adminUser;

cout << "\n Please enter your password:";

cin >> adminPassword;

if ((strcmp (adminUser, ADMINUSER) == 0) &&
(strcmp (adminPassword, ADMINPASSWORD) == 0))
{


getchar ();
getchar ();

system ("cls");

int innerChoice = 0;

while (innerChoice != 9)
{

cout <<
"\n\n Teacher Login is Successful !! Press any button to continue..";

cout << "\n1. Add new book";

cout << "\n2. Update any Book";

cout << "\n3. Delete Book";

cout << "\n4. List of all Books";

cout << "\n9. Exit";

cout << "\n\n Please enter your choice : ";

cin >> innerChoice;

switch (innerChoice)
{

case 1:
addBook ();
break;

case 2:
updateBook ();
break;

case 3:
deleteBook ();
break;

case 4:
listOfAllBooks ();
break;

default:
cout <<
"\n\n Invalid Choice. Please enter the valid one";

getchar ();

}

system ("cls");

}


}

else

{

cout <<
"\n\n Error : Invalid Credentials. Please check your Credentials";

getchar ();
getchar ();

}


}

else if (outerChoice == 2)
{

char studentUser[10];

char studentPassword[10];


system ("cls");

cout << "\n ---------- Student Login -------";

cout << "\n\n Please enter your username: ";

cin >> studentUser;

cout << "\n Please enter your password:";

cin >> studentPassword;


if ((strcmp (studentUser, USER) == 0) &&
(strcmp (studentPassword, USERPASSWORD) == 0))
{

int innerChoice = 0;

while (innerChoice != 9)
{

system ("cls");

cout << "\n1. Borrow a Book";

cout << "\n2. Return a Book";

cout << "\n3. List of All Books";

cout << "\n9. Exit";

cout << "\n\n Enter your choice : ";

cin >> innerChoice;


switch (innerChoice)
{

case 1:
borrowBook ();
break;

case 2:
returnBook ();
break;

case 3:
listOfAllBooks ();
break;

case 9:
break;

default:
cout <<
"\n\n Error: Invalid Choice. Please enter the valid one";

getchar ();
getchar ();

}


}

system ("cls");

} else {

cout <<
"\n\n Error : Invalid Credentials. Please check your Credentials";

getchar ();
getchar ();

}

}

else if (outerChoice != 9)
{

cout << "\n\n Invalid choice. Press any key to continue..";

getchar ();
getchar ();

} else {

cout << "\n\n Thank you for using it !! Press any key to exit";

getchar ();
getchar ();

}

}
 return 0;

}



int addBook ()
{

int bookid;
char bookname[20];
char bookauthor[20];
int year, month, day;

 


time_t t = time (NULL);
struct tm tm = *localtime (&t);
year = tm.tm_year + 1900;
month = tm.tm_mon + 1;
day = tm.tm_mday;


system ("cls");
cout << "\n ---- Add a new Book ----";
cout << "\n\n Please enter 4 digit numberic id :";
cin >> bookid;
cout << "\n Please enter book name : ";
cin >> bookname;
cout << "\n Please enter book author : ";
cin >> bookauthor;
char filename[20];
sprintf (filename, "%d%s", bookid, ".dat");
ofstream file (filename);
file << bookname << "\n";
file << bookauthor << "\n";
file << year << "\n";
file << month << "\n";
file << day << "\n";
file.close ();
cout << "\n Your file Saved Successfully !!";
getchar ();
getchar ();

}

int deleteBook ()
{ }

int updateBook ()
{ }

int listOfAllBooks ()
{
 }

int borrowBook ()
{
}

int returnBook ()
{
}
int adminLogin ()
{
}

int userLogin ()
{
}
?

 

 

Step 2: Create one more file as class.h

/* class.h */

#define ADMINUSER "Teacher"
#define ADMINPASSWORD "teacher123"

#define USER "Student"
#define USERPASSWORD "student123"

#define FINE 500

int addBook();

int deleteBook();

int updateBook();

int listOfAllBooks();

int borrowBook();

int returnBook();

int adminLogin();

int userLogin();

 

Step 3: Now run the project.

 

Login Credentials for Users

For Students:

Username- Student

Password- student123

 

For Teachers:

Username- Teacher

Password- teacher123

 

 

Output of Library Management System in C++

 

Library Management System in C++

 

 

Book saved in Database

Library Management System in C++

 

Conclusion:

This is a Just simple C++ Project to create Library Management System. To make this project as your Accademic Project add More modules and feature to this project.

 

Related

Python Library Management System

Java Library Management System Source code


7668 Views

Author: Vikas Ohja

Flutter Questions

Android Questions