Library Management System Using C++ With Source Code
Library Management System Using C++ With Source Code
Java Ebook
Free Projects
Python Projects
Java Projects
C++ Projects
Free Ebooks
Python Ebook
Java Ebook
The LibraryAllManagement
Browse Ebooks System is developed in C++ and offers a command-line interface. The system handles student accounts and book management, including adding, editing,
viewing books, and managing student transactions.
This Library Management System allows administrators to manage books and student accounts, while students can manage their balances and issue books. The system includes
functionalities for creating student accounts, depositing funds, issuing books, and viewing or editing book details.
1. Save the Code: Copy the provided C++ code into a file named library_management_system.cpp.
2. Compile the Code: Use a C++ compiler to compile the For example, using g++:
./library_management_system
Code Explanation :
Initialization of Books:
https://codewithcurious.com/projects/library-management-system-using-c/ 1/14
11/21/24, 7:42 PM Library Management System Using C++ With Source Code - CodeWithCurious
Initializes the library with 15 books (default titles and authors) and sets their availability to true.
Free Ebooks
Login and Menu Selection:
Python Ebook
Java Ebook
true)
while (true ) {
cout lt;;>
Python&Games
lt gt;; option
option;
Ebook ;
// ... additional code
Interview QnA Ebook
}
Browse All Ebooks
Presents login options for Admin, Student, or Exit. Continues in a loop until Exit is
Password Verification:
Free Projects
if (password
Python Projects == "password")
"password") {
// Admin or student options based on role
Java Projects
} else {
cout
C++ lt;
<
Projects;<
lt;; "
quot;;Incorrect password.
password.\n
\n&
"
quot;
;;
}
HTML CSS JS Projects
Verifies the entered password. If correct, proceeds to role-specific options; otherwise, displays an error message.
Free Ebooks
Admin Actions:
Python Ebook
is_admin)
if (is_admin ) {
JavaAdmin-specific
// Ebook options
}
Python Games Ebook
Student Actions:
else {
int roll;
roll;
lt;
cout < ;>
gt;; roll
roll;;
// ... additional student actions
}
Allows students to view balance, deposit money, or issue a book based on their roll
if (index == -1) {
lt;
cout < ;>
gt;; option
option;;
create_account(
if (option == 1) { create_account ();
}
}
If the student is not found, prompts to create a new account if the user chooses
else {
cout <
lt;<
lt; "
quot;Incorrect password.
password.\n&
\n"
quot;;
}
https://codewithcurious.com/projects/library-management-system-using-c/ 2/14
11/21/24, 7:42 PM Library Management System Using C++ With Source Code - CodeWithCurious
Join our Telegram for Free Coding Ebooks & Handwritten Notes!
Source Code :
Free Ebooks
main.cpp
Python Ebook
Java
# Ebook
include
#include
Python Games Ebook
#include
Interview QnA Ebook
using namespace std;
std;
Browse All Ebooks
// Constants
const int MAX_STUDENTS = 20
20;
;
constProjects
Free 15;
int MAX_BOOKS = 15 ;
50;
const int MAX_NAME_LENGTH = 50 ;
// Global variables
Python Projects
int student_count = 0;
int book_count
Java Projects = 0;
student_balance[
double student_balance [MAX_STUDENTS
MAX_STUDENTS]
];
C++
intProjects
student_roll[
student_roll [MAX_STUDENTS
MAX_STUDENTS]];
student_name[
charCSS
HTML JS Projects [MAX_STUDENTS
student_name MAX_STUDENTS]][MAX_NAME_LENGTH
MAX_NAME_LENGTH]];
book_title[
char book_title [MAX_BOOKS
MAX_BOOKS]][MAX_NAME_LENGTH
MAX_NAME_LENGTH]];
book_author[
char book_author [MAX_BOOKS
MAX_BOOKS]][MAX_NAME_LENGTH
MAX_NAME_LENGTH]];
book_isbn[
int book_isbn [MAX_BOOKS
MAX_BOOKS]
];
book_available[
Free book_available
bool Ebooks [MAX_BOOKS
MAX_BOOKS]];
// Function prototypes
Pythoncreate_account
void Ebook
create_account(();
display(
void display (int roll
roll)
);
Java Ebook
deposit_amount(
void deposit_amount (int roll,
roll, double amount
amount));
Pythonissue_item
void Games Ebook
issue_item((int roll
roll)
);
display_sorted(
void display_sorted ();
Interview QnA Ebook
find_student(
int find_student (int roll
roll));
find_book(
Browse
int (int isbn
All Ebooks
find_book isbn));
add_book(
void add_book ();
void edit_book(
edit_book();
void view_books
view_books(();
int main(
main() {
// Initialization
// Add initial 15 books to the library
// TODO: Replace with actual book data
for (int i = 0; i <
lt;; MAX_BOOKS
MAX_BOOKS;; i
i++
++)
) {
strcpy(
strcpy (book_title
book_title[[i], "
quot;;Title
Title&"
quot;;);
strcpy(
strcpy (book_author
book_author[[i], "
quot;;Author
Author&"
quot;;);
book_isbn[
book_isbn [i] = i + 1000
1000;
;
book_available[
book_available[i] = true
true;;
}
book_count = MAX_BOOKS;
MAX_BOOKS;
option;
int option ;
is_admin;
bool is_admin ;
string password;
password;
true)
while (true ) {
lt;
cout < ;>
gt;; option
option;;
if (option == 0) {
break;
break ;
}
lt;
cout < ;>
gt;; password
password;;
if (password == "password"
"password")) { // Use a simple password for demonstration purposes.
if (is_admin)
is_admin) {
lt;
cout < ;>
gt;; option
option;;
option)
switch (option ) {
https://codewithcurious.com/projects/library-management-system-using-c/ 3/14
11/21/24, 7:42 PM Library Management System Using C++ With Source Code - CodeWithCurious
case 1: {
add_book(
add_book ();
break;
break;
}
case 2: {
edit_book(
edit_book ();
break;
break;
Free Ebooks }
case 3: {
view_books(
view_books ();
Python Ebook break;
break;
}
Java Ebook
case 4: {
Python Games Ebook display_sorted(
display_sorted ();
break;
break ;
Interview QnA Ebook
}
Browse All Ebooks case 5: {
int roll;
roll;
lt;
cout < ;>
gt;; roll;
roll;
display(
display (roll
roll));
Free Projects break;
break ;
}
}
Python Projects } else {
roll;
int roll ;
Java Projects lt;
cout < ;>
gt;; roll
roll;;
C++ Projects
find_student(
int index = find_student (roll
roll)
);
HTML CSS JS Projects if (index == -1) {
lt;
cout < ;>
gt;; option
option;;
if (option == 1) {
create_account(
create_account();
Free Ebooks
}
} else {
lt;
cout < ;>
gt;; option
option;;
Python Ebook
roll;
int roll ;
lt;
cout < ;>
gt;; roll
roll;;
if (find_student
find_student((roll
roll)) != -1) {
cout <
lt;<
lt; "
quot;Account already exists for this roll number.
number.\n&
\n"
quot;;
return;
return ;
}
student_roll[
student_roll [student_count
student_count]] = roll
roll;;
lt;
cout < ;<
lt;
; "
quot;;Enter student name:
name: "
quot;;;
cin.
cin .ignore
ignore(();
cin.
cin .getline
getline((student_name
student_name[[student_count
student_count]], MAX_NAME_LENGTH
MAX_NAME_LENGTH));
initial_deposit;
double initial_deposit ;
lt;
cout < ;>
gt;; initial_deposit
initial_deposit;;
if (initial_deposit <lt;
; 50
50)
) {
lt;
cout < ;<
lt;; "
quot;;Initial deposit must be at least $50.
$50.\n
\n&
"
quot;
;;
https://codewithcurious.com/projects/library-management-system-using-c/ 4/14
11/21/24, 7:42 PM Library Management System Using C++ With Source Code - CodeWithCurious
return;
return ;
}
student_balance[
student_balance [student_count
student_count]] = initial_deposit - 20 - 30
30;; // Account opening and security deposit
student_count++
student_count++;;
}
Free display
void Ebooks
display((int roll
roll)) {
int index = find_student(
find_student(roll)
roll);
if (index == -1) {
Python Ebook
cout lt;
< ;<
lt;; "
quot;;Student not found
found..\n
\n&"
quot;;;
return;
return ;
Java Ebook
}
Python Games Ebook
cout <lt;
;<
lt;; "
quot;;Roll No:
No: "
quot;; <
lt;
;<
lt;
; student_roll
student_roll[[index
index]] <
lt;
;<
lt;
; endl
endl;;
Interview QnA Ebook
cout <lt;
;<
lt;; "
quot;;Name
Name:: "
quot;; <
lt;;<
lt;; student_name
student_name[[index
index]] <
lt;;<
lt;; endl
endl;;
Browse<
cout All;Ebooks
lt; lt;
< ; "
quot;;Balance
Balance:: $
$&"
quot;; <
lt;;<
lt;; fixed <
lt;;<
lt;; setprecision
setprecision((2) <
lt;;<
lt;; student_balance
student_balance[[index
index]] <
lt;;<
lt;; endl
endl;;
}
deposit_amount(
void deposit_amount (int roll
roll,, double amount
amount)) {
Free Projects
int index find_student(
= find_student (roll
roll));
if (index == -1) {
cout <lt;;<
lt;; "
quot;;Student not found
found..\n
\n&"
quot;;;
return;
Projects;
Pythonreturn
}
Java Projects
student_balance[
student_balance
C++ Projects [index
index]] += amount
amount;;
cout <lt;;<
lt;; "
quot;;New balance:
balance: $ $&
"
quot;
; <
lt;;<
lt;; fixed <
lt;;<
lt;; setprecision
setprecision((2) <
lt;;<
lt;; student_balance
student_balance[[index
index]] <
lt;;<
lt;; endl
endl;;
HTML
} CSS JS Projects
issue_item(
void issue_item (int roll
roll)) {
int index = find_student(
find_student(roll)
roll);
Free Ebooks
if (index == -1) {
lt;
cout < ;<
lt;; "
quot;;Student not found
found..\n
\n&"
quot;;;
return;
return ;
Python Ebook
}
Java Ebook
cout <
lt;<
lt; "
quot;Available books:
books:\n&
\n"
quot;;
Python Games Ebook
for (int i = 0; i <lt;
; book_count
book_count;; i
i++
++)
) {
Interview book_available[
if (QnA Ebook
book_available [i]) {
cout <lt;
;<
lt;; i + 1 <
lt;
;<
lt;; "
quot;;. "
quot;; <
lt;;<
lt;; book_title
book_title[[i] <
lt;;<
lt;; "
quot;; by "
quot;; <
lt;;<
lt;; book_author
book_author[[i] <
lt;;<
lt;;
Browse All Ebooks
quot;
" ; (ISBN
ISBN:: "
quot;
; <
lt;
;<
lt;; book_isbn
book_isbn[[i] <
lt;
;<
lt;; "
quot;)\n\n&
"
quot;
;;
}
}
choice;
int choice ;
lt;
cout < ;>
gt;; choice
choice;;
if (choice == 0) {
return;
return ;
}
if (book_available
book_available[[choice - 1] &
amp;
;&
amp;; student_balance
student_balance[[index
index]] >
gt;;= 2) {
book_available[
book_available [choice - 1] = false
false;
;
student_balance[
student_balance [index
index]] -= 2;
cout <
lt;<
lt; "
quot;Book issued successfully.
successfully. New balance:
balance: $
$&"
quot;; <
lt;;<
lt;; fixed <
lt;;<
lt;; setprecision
setprecision((2) <
lt;;<
lt;;
student_balance[
student_balance [index
index]] <
lt;;<
lt;; endl
endl;;
} else {
cout <
lt;<
lt; "
quot;Cannot issue the book.
book. Insufficient balance or book is unavailable.
unavailable.\n&
\n"
quot;;
}
}
void display_sorted(
display_sorted() {
for (int i = 0; i <
lt;; student_count
student_count;; i++
i++)) {
for (int j = i + 1; j student_roll[
student_roll[j]) {
swap(
swap (student_roll
student_roll[[i], student_roll
student_roll[[j]);
swap(
swap (student_balance
student_balance[[i], student_balance
student_balance[[j]);
swap(
swap (student_name
student_name[[i], student_name
student_name[[j]);
}
}
}
https://codewithcurious.com/projects/library-management-system-using-c/ 5/14
11/21/24, 7:42 PM Library Management System Using C++ With Source Code - CodeWithCurious
int find_student(
find_student(int roll
roll)) {
for (int i = 0; i <
lt;; student_count
student_count;; i
i++
++)
) {
if (student_roll[
student_roll[i] == roll)
roll) {
i;
return i ;
}
}
return -1;
Free Ebooks
}
find_book(
int find_book (int isbn)
isbn) {
Python
for Ebook
(int i = 0; i = MAX_BOOKS)
MAX_BOOKS) {
lt;
cout < ;<
lt;
; "
quot;;Book limit reached.
reached. Cannot add more books.
books.\n
\n&
"
quot;
;;
Java Ebook
return;
return ;
Python Games Ebook
}
cout <lt;
;<
lt;; "
quot;;Enter book title:
title: "
quot;;;
Interview QnA Ebook
cin.
cin .ignore
ignore(();
Browse
cin.
cin All Ebooks
.getline
getline( (book_title
book_title[[book_count
book_count]], MAX_NAME_LENGTH
MAX_NAME_LENGTH));
lt;
cout < ;<
lt;; "
quot;;Enter book author:
author: "
quot;
;;
cin.
cin .getline
getline((book_author
book_author[[book_count
book_count]], MAX_NAME_LENGTH
MAX_NAME_LENGTH));
Free Projects
isbn;
int isbn ;
lt;
cout < ;>
gt;; isbn
isbn;;
Python Projects
find_book(
if (find_book (isbn
isbn)) != -1) {
Java Projects
cout <lt;
;<
lt;
; "
quot;
;A book with this ISBN already exists.
exists.\n
\n&
"
quot;
;;
return;
return
C++ Projects ;
}
HTML CSS JS Projects
book_isbn[
book_isbn [book_count
book_count]] = isbn
isbn;;
book_available[
book_available [book_count
book_count]] = true
true;
;
book_count++
book_count++;;
Free Ebooks
}
edit_book(
void edit_book () {
Python Ebook
int isbn;
isbn;
lt;
Java Ebook
cout < ;>
gt;; isbn
isbn;;
find_book(
int index = find_book (isbn
isbn)
);
Python Games Ebook
if (index == -1) {
coutQnA
Interview lt;
< ;<
lt;
Ebook ; "
quot;;Book not found
found..\n
\n&"
quot;;;
return;
return ;
Browse All Ebooks
}
cout <
lt;
;<
lt;
; "
quot;;Current book title:
title: "
quot;; <
lt;;<
lt;; book_title
book_title[[index
index]] <
lt;;<
lt;; endl
endl;;
cout <
lt;<
lt;
; "
quot;Enter new book title:
title: "
quot;;;
cin.
cin .ignore
ignore(();
cin.
cin .getline
getline((book_title
book_title[[index
index]], MAX_NAME_LENGTH
MAX_NAME_LENGTH));
cout <
lt;
;<
lt;; "
quot;;Current book author:
author: "
quot;; <
lt;
;<
lt;; book_author
book_author[[index
index]] <
lt;;<
lt;; endl
endl;;
cout <
lt;<
lt;; "
quot;;Enter new book author:
author: "
quot;;;
cin.
cin .getline
getline((book_author
book_author[[index
index]], MAX_NAME_LENGTH
MAX_NAME_LENGTH));
lt;
cout < ;<
lt;; "
quot;;Book details updated.
updated.\n
\n&
"
quot;
;;
}
view_books(
void view_books () {
for (int i = 0; i <lt; book_count
book_count; ; i
i++
++)
) {
lt;
cout < ;<
lt;; "
quot;;Title
Title:: "
quot;; <
lt;;<
lt;
; book_title[
book_title[i] <
lt;;<
lt;; endl
endl;;
cout <
lt;<
lt; "
quot;Author:
Author: "
quot; <
lt;<
lt; book_author[
book_author[i] <
lt;<
lt; endl;
endl;
cout <
lt;;<
lt;; "
quot;;ISBN
ISBN:: "
quot;; <
lt;;<
lt;; book_isbn
book_isbn[[i] <
lt;;<
lt;; endl
endl;;
cout <
lt;<
lt;; "
quot;Available
Available:: "
quot;
; <
lt;;<
lt;; (book_available
book_available[[i] ? "
quot;
;Yes
Yes&
"
quot;
; : "
quot;;No
No&"
quot;;) <
lt;;<
lt;; endl <
lt;;<
lt;; endl
endl;;
}
}
Output :
This screenshot shows the login and main menu options of the Library Management
https://codewithcurious.com/projects/library-management-system-using-c/ 6/14
11/21/24, 7:42 PM Library Management System Using C++ With Source Code - CodeWithCurious
Free Ebooks
Python Ebook
Java Ebook
Python Projects
Java Projects
C++ Projects
Free Ebooks
Python Ebook
Java Ebook
Browse All Ebooks Architectural Website using HTML CSS and JavaScript
Nikhil Kamble • October 17, 2024 • projects, Web Development Projects
Architectural Website using HTML CSS and JavaScript Introduction : This is a Architectural Website using HTML CSS and
JavaScript. This website contains …
https://codewithcurious.com/projects/library-management-system-using-c/ 7/14
11/21/24, 7:42 PM Library Management System Using C++ With Source Code - CodeWithCurious
Free Ebooks
Python Ebook
Java Ebook
Free Projects
Interior Design Website using HTML CSS and JavaScript
Nikhil Kamble • October 15, 2024 • projects, Web Development Projects
Python Projects Interior Design Website using HTML CSS and JavaScript Introduction : This project is an interior design website, created for
showing the services, …
Java Projects
C++ Projects
Free Ebooks
Python Ebook
Java Ebook
Candy Crush Game Using HTML CSS & JavaScript Introduction Hello friends, welcome to my new blog post. Today I have
created a …
https://codewithcurious.com/projects/library-management-system-using-c/ 8/14
11/21/24, 7:42 PM Library Management System Using C++ With Source Code - CodeWithCurious
Free Ebooks
Python Ebook
Java Ebook
Free Projects
Python Projects
Java Projects
Archery Game Using HTML CSS and JavaScript
C++ Projects
Goutam Prajapat • October 8, 2024 • projects, Web Development Projects
HTML CSS JS Projects
Archery Game Using HTML CSS and JavaScript Introduction Hello friends, you all are welcome to our new blog post. Today
we have …
Free Ebooks
Python Ebook
Java Ebook
Complain Management using Python with a Graphical User Interface (GUI) Introduction: The Complain Management using
Python program designed to manage complaints effectively …
https://codewithcurious.com/projects/library-management-system-using-c/ 9/14
11/21/24, 7:42 PM Library Management System Using C++ With Source Code - CodeWithCurious
Free Ebooks
Python Ebook
Java Ebook
Free Projects
Python Projects
Java Projects
C++ Projects
Browse All Ebooks Banking Management System Using C++ With Source Code
https://codewithcurious.com/projects/library-management-system-using-c/ 10/14
11/21/24, 7:42 PM Library Management System Using C++ With Source Code - CodeWithCurious
Free Ebooks
Python Ebook
Java Ebook
Free Projects
Python Projects
Java Projects
C++ Projects
Free Ebooks
Python Ebook
Java Ebook
https://codewithcurious.com/projects/library-management-system-using-c/ 11/14
11/21/24, 7:42 PM Library Management System Using C++ With Source Code - CodeWithCurious
Free Ebooks
Python Ebook
Java Ebook
Free Projects
Python Projects
Java Projects
← Previous Post Next Post →
C++ Projects
Search...
Free Ebooks
BuyEbook
Python Handwritten Notes
Java Ebook
Get Discount on Top EdTech Compnies
Python Games Ebook
s s s
https://codewithcurious.com/projects/library-management-system-using-c/ 12/14
11/21/24, 7:42 PM Library Management System Using C++ With Source Code - CodeWithCurious
Java Handwritten Notes
DSA Handwritten Notes
Free Ebooks
Python Ebook
Java Ebook
Free Projects
Python Projects
Java Projects
C++ Projects
Free Ebooks
Python Ebook
Java Ebook
CodeWithCurious is a Best Place to Learn & grow your Career in IT sector. Best Content on the latest technology in including C, C++, Java, Python, Sql, Web development & Interview
Preparation Material free of cost.
Info
Home
Projects
E books
Blogs
About Us
Support
Contact us
Privacy Policy
Terms & Conditions
Affiliate Discloser
https://codewithcurious.com/projects/library-management-system-using-c/ 13/14
11/21/24, 7:42 PM Library Management System Using C++ With Source Code - CodeWithCurious
Free Ebooks
Python Ebook
Java Ebook
Free Projects
Python Projects
Java Projects
C++ Projects
Free Ebooks
Python Ebook
Java Ebook
https://codewithcurious.com/projects/library-management-system-using-c/ 14/14