0% found this document useful (0 votes)
22 views17 pages

CS Project

Best of luck

Uploaded by

pankajkumerdey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views17 pages

CS Project

Best of luck

Uploaded by

pankajkumerdey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Delhi Public School

Siliguri

COMPUTER SCIENCE PROJECT


ON
LIBRARY MANAGEMENT SYSTEM

Done by: Isaac Thakur


Class: XII Science Roll no.:
Session: 2024-25

Page:
Index
1. Certificate
2. Acknowledgment
3. Introduction
4. Database Schema
5. Code
11. Screenshots
14. Suggested Improvements
15. Bibliography
Certificate
This is to certify that Isaac Thakur of XII-Science has
successfully completed and submitted his Computer Science
project on the topic “Library Management System” under the
guidance of his teacher Mithun Chakraborty in the given
time frame.

Internal Examiner External Examiner

Page: 1
Acknowledgment
I sincerely express my gratitude to Mrs. Anisha Sharma,
our respected Principal, for her encouragement and support
throughout this project.

A special thanks to Mr. Mithun Chakraborty, my subject teacher,


for his invaluable guidance and insightful suggestions.

I am also deeply thankful to my parents and friends, whose


motivation and help were crucial in the completion of this
project.

Lastly, I extend my gratitude to everyone who contributed,


directly or indirectly, to making this project a success.

Yours Sincerely,
Isaac Thakur

Page: 2
Introduction
The Library Management Software is a simple Command Line
Interface program that aims to help with basic tasks for
maintaining a library in a digital way. The project uses
MySQL to store the data on tables and functions are made in
Python for basic functions like adding/removing books, adding/
removing users, borrow records/information and viewing the
existing records. It is a lightweight and efficient program for
reducing manual work and can maintain large databases too.

System Requirements
Software:
1. mysql ; Version: 8.0.40
2. python ; Version: 3.13
3. mysql-connector-python ; Version: 9.1.0
4. Windows 7/8//10/11 (x86 or 64 based)
Hardware
1. Processor: i3 CPU
2. Ram: 2GB
3. Storage: at least 256GB

Page: 3
Database Schema
The SQL database contains three tables for storing the record
of books, users and the borrowings. Their structures are
given below:

1. Books:

+-----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+----------------+
| BookID | int | NO | PRI | NULL | auto_increment |
| Title | varchar(255) | NO | | NULL | |
| Author | varchar(255) | YES | | NULL | |
| Available | tinyint(1) | YES | |1 | |
+-----------+--------------+------+-----+---------+----------------+

2. Users:

+--------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------+--------------+------+-----+---------+----------------+
| UserID | int | NO | PRI | NULL | auto_increment |
| Name | varchar(255) | NO | | NULL | |
| Email | varchar(255) | YES | | NULL | |
+--------+--------------+------+-----+---------+----------------+

3. Borrowings:

+-------------+------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+------+------+-----+---------+----------------+
| BorrowingID | int | NO | PRI | NULL | auto_increment |
| UserID | int | YES | MUL | NULL | |
| BookID | int | YES | MUL | NULL | |
+-------------+------+------+-----+---------+----------------+

Page: 4
Code
import mysql.connector

# -------------------------------------------------------
# Database Connection
# -------------------------------------------------------

def connect_db():
“””Establish connection to the database.”””
return mysql.connector.connect(
host=”localhost”,
user=”root”,
password=”0703”,
database=”library_management”
)

# Database connection and cursor


conn = connect_db()
cursor = conn.cursor()

# -------------------------------------------------------
# Functions for Library Management System
# -------------------------------------------------------

def view_users():
“””Display all registered users.”””
cursor.execute(“SELECT * FROM Users”)
users = cursor.fetchall()
print(“\nUsers:”)
for u in users:
print(f”UserID: {u[0]} | Name: {u[1]} | Email: {u[2]}”)

def view_books():
“””Display all books in the library.”””
cursor.execute(“SELECT * FROM Books”)
books = cursor.fetchall()
print(“\nBooks:”)
for book in books:

Page: 5
print(f”BookID: {book[0]} | Title: {book[1]} | Author:
{book[2]} | Available: {‘Yes’ if book[3] else ‘No’}”)
print()

def view_borrowings():
“””Display borrowing details (User, Book, Period).”””
cursor.execute(“””
SELECT Borrowing.BorrowingID, Users.Name, Books.Title
FROM Borrowing
JOIN Users ON Borrowing.UserID = Users.UserID
JOIN Books ON Borrowing.BookID = Books.BookID
“””)
borrowings = cursor.fetchall()
print(“\nBorrowings:”)
for b in borrowings:
print(f”BorrowingID: {b[0]} | User: {b[1]} | Book:{b[2]}”)
print()

def view_infos():
“””Allow the user to view Users, Books, or Borrowings.”””
while True:
print(“\nView Information”)
print(“1. View Users”)
print(“2. View Books”)
print(“3. View Borrowings”)
print(“4. Back to Main Menu”)

choice = input(“Enter your choice: “)


if choice == ‘1’:
view_users()
elif choice == ‘2’:
view_books()
elif choice == ‘3’:
view_borrowings()
elif choice == ‘4’:
break
else:
print(“Invalid choice. Please try again.”)

def add_book():
“””Add a new book to the library.”””
view_books()

Page: 6
title = input(“Enter the book title: “)
author = input(“Enter the book author: “)
cursor.execute(“INSERT INTO books (Title, Author) VALUES (%s,
%s);”, (title, author))
conn.commit()
print(f”Book ‘{title}’ by {author} added successfully.”)

def add_user():
“””Register a new user.”””
view_users()
name = input(“Enter the name of the user: “)
email = input(“Enter the email of the user: “)
cursor.execute(“INSERT INTO users (Name, Email) VALUES (%s,
%s);”, (name, email))
conn.commit()
print(f”User ‘{name}’ added successfully.”)

def borrow_book():
“””Borrow a book for a user.”””
view_users()
user_id = int(input(“Enter the user ID: “))

# Check if the user ID exists


cursor.execute(“SELECT UserID FROM Users WHERE UserID = %s;”,
(user_id,))
if not cursor.fetchone():
print(“Please enter a valid UserID”)
return

view_books()
book_id = int(input(“Enter the book ID: “))

# Check if the book is available


cursor.execute(“SELECT * FROM books WHERE BookID = %s AND
Available = TRUE;”, (book_id,))
book = cursor.fetchone()
if not book:
print(“Error: Book not available.”)
return

# Borrow the book


cursor.execute(“INSERT INTO borrowing (UserID, BookID) VALUES

Page: 7
(%s, %s);”, (user_id, book_id))
cursor.execute(“UPDATE books SET Available = FALSE WHERE
BookID = %s;”, (book_id,))
conn.commit()
print(f”Book ‘{book[1]}’ borrowed successfully by User ID
{user_id}.”)

def return_book():
“””Return a borrowed book.”””
view_users()
user_id = int(input(“Enter user ID: “))

# Display borrowed books


cursor.execute(“””
SELECT Borrowing.BorrowingID, Books.BookID, Books.Title,
Books.Author
FROM Borrowing
JOIN Books ON Borrowing.BookID = Books.BookID
WHERE Borrowing.UserID = %s;
“””, (user_id,))
borrowings = cursor.fetchall()

if not borrowings:
print(“No borrowed books for this user.”)
return

print(“Borrowed Books:”)
for b in borrowings:
print(f”BorrowingID: {b[0]}, BookID: {b[1]}, Title:
{b[2]}, Author: {b[3]}”)

borrowing_id = int(input(“Enter BorrowingID to return: “))


cursor.execute(“UPDATE Books SET Available = TRUE WHERE
BookID = (SELECT BookID FROM Borrowing WHERE BorrowingID = %s);”,
(borrowing_id,))
cursor.execute(“DELETE FROM borrowing WHERE BorrowingID =
%s;”, (borrowing_id,))
conn.commit()
print(“Book returned successfully.”)

def delete_record():
“””Delete a user or book from the system.”””

Page: 8
print(“\nDelete Record”)
print(“1. Delete a User”)
print(“2. Delete a Book”)
choice = input(“Enter your choice: “)

if choice == ‘1’:
view_users()
user_id = int(input(“Enter User ID to delete: “))

# Mark borrowed books as available before deleting the


user
cursor.execute(“””
UPDATE Books
SET Available = TRUE
WHERE BookID IN (SELECT BookID FROM Borrowing WHERE
UserID = %s)
“””, (user_id,))
conn.commit()

# Delete related borrowings and the user


cursor.execute(“DELETE FROM Borrowing WHERE UserID = %s;”,
(user_id,))
cursor.execute(“DELETE FROM Users WHERE UserID = %s;”,
(user_id,))
conn.commit()
print(“User and related borrowings deleted successfully.”)

elif choice == ‘2’:


view_books()
book_id = int(input(“Enter Book ID to delete: “))

# Delete all borrowings related to the book


cursor.execute(“DELETE FROM Borrowing WHERE BookID = %s;”,
(book_id,))

# Now delete the book


cursor.execute(“DELETE FROM Books WHERE BookID = %s;”,
(book_id,))
conn.commit()
print(“Book and related borrowings deleted successfully.”)

else:

Page: 9
print(“Invalid choice. Returning to main menu.”)

def menu():
“””Main menu for Library Management System.”””
while True:
print(“\nLibrary Management System”)
print(“1. Add Book”)
print(“2. Borrow Book”)
print(“3. Return Book”)
print(“4. Add User”)
print(“5. View Infos”)
print(“6. Delete Record”)
print(“7. Exit”)

choice = input(“Enter your choice: “)


if choice == ‘1’:
add_book()
elif choice == ‘2’:
borrow_book()
elif choice == ‘3’:
return_book()
elif choice == ‘4’:
add_user()
elif choice == ‘5’:
view_infos()
elif choice == ‘6’:
delete_record()
elif choice == ‘7’:
print(“Exiting system.”)
break
else:
print(“Invalid choice. Please try again.”)

# Run the system


if __name__ == “__main__”:
try:
menu()
finally:
cursor.close()
conn.close()

Page: 10
Screenshots
This section contains the screenshots of the programs
execution windows.

1. Adding a book:

2.Adding users:

Page: 11
3. Borrowing book:

4. Returning Book:

Page: 12
4. Deleting a book

5. Viewing users:

Page: 13
Suggested Improvements
1. User Authentication: Currently, the system does not have
user authentication. A user login system could be added
to track activities securely.
2. GUI Interface: The system currently operates through the
command line, but a graphical user interface (GUI) could
make it more user-friendly
3. Late Return Fines: The system does not handle late re-
turns or fines, which could be added in future versions.

Page: 14
Bibliography
1. www.geeksforgeeks.org
2. www.w3schools.com

Page: 15

You might also like