0% found this document useful (0 votes)
2 views

CLASS XII (CBSE) COMPUTER SCIENCE PROJECT

The document outlines a Library Management System project, detailing its purpose, features, and functionalities for both users and administrators. It includes SQL table structures, source code for the system, and various functions for managing books, rentals, and returns. The project aims to provide a user-friendly interface for efficient library operations.

Uploaded by

alekh.renjith
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

CLASS XII (CBSE) COMPUTER SCIENCE PROJECT

The document outlines a Library Management System project, detailing its purpose, features, and functionalities for both users and administrators. It includes SQL table structures, source code for the system, and various functions for managing books, rentals, and returns. The project aims to provide a user-friendly interface for efficient library operations.

Uploaded by

alekh.renjith
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

COMPUTER SCIENCE

PROJECT
2024-25
ACKNOWLEDGEMENT
I would like to convey my heartfelt gratitude to my
computer Teacher, Mrs Divya M for her continuous
support and help in the completion of my project.

I would also like to thank our Principal,

Mrs Shajeena V for providing me with this wonderful


opportunity to work on a project on the topic of source
code for library management system. The completion of
this project would not have been possible without their
insights and help
INDEX
Serial No. Topic Page No.
1 Introduction
2 SQL Tables
3 Source Code
4 Python Output
5 SQL Output
6 Conclusion
7 Bibliography
INTRODUCTION
The Library Management System is software designed
to simplify digital library operations. It provides a
central platform where users can browse, rent, and
return books, while administrators manage the
collection through a secure interface.

Users can:

 View books by section, author, genre, and age


rating.
 Rent and return books with real-time availability
updates.
 The Admin Panel enables administrators to:
 Add, delete, and update book details.
 Access an intuitive interface for managing the
collection and interactions.

With secure authentication, the system restricts specific


actions to administrators, ensuring data integrity and
efficient data retrieval, ultimately offering a streamlined,
user-friendly library experience.
SQL TABLES
Source Code
import mysql.connector
import time

connection = mysql.connector.connect(
host='localhost',
user='root',
password='123456',
database='LibraryDB'
)
cursor = connection.cursor()

cursor.execute('''
CREATE TABLE IF NOT EXISTS BookLibs (
book_id INT PRIMARY KEY AUTO_INCREMENT,
book_title VARCHAR(255),
author VARCHAR(255),
section VARCHAR(100),
age_rating VARCHAR(10),
availability VARCHAR(50)
)
''')

admin_username = "admin"
admin_password = "password"

cursor.execute('SELECT * FROM BookLibs')


results = cursor.fetchall()

if not results:
cursor.execute('''
INSERT INTO BookLibs (book_title, author, section, age_rating,
availability)
VALUES
('To Kill a Mockingbird', 'Harper Lee', 'Fiction', '13+',
'Available'),
('1984', 'George Orwell', 'Fiction', '16+', 'Available'),
('Moby Dick', 'Herman Melville', 'Fiction', '13+', 'Available'),
('The Great Gatsby', 'F. Scott Fitzgerald', 'Fiction', '16+',
'Available'),
('War and Peace', 'Leo Tolstoy', 'Historical', '18+', 'Available'),
('Pride and Prejudice', 'Jane Austen', 'Romance', '13+', 'Available'),
('Brave New World', 'Aldous Huxley', 'Science Fiction', '16+',
'Available'),
('The Hobbit', 'J.R.R. Tolkien', 'Fantasy', '12+', 'Available'),
('Fahrenheit 451', 'Ray Bradbury', 'Science Fiction', '14+',
'Available'),
('The Divine Comedy', 'Dante Alighieri', 'Classics', '18+',
'Available')
''')
connection.commit()

def display_books(cursor):
cursor.execute('SELECT * FROM BookLibs')
results = cursor.fetchall()
print("ID | Title | Author | Section | Age Rating | Availability")
for each in results:
print(each[0], each[1], each[2], each[3], each[4], each[5], sep="
| ")

def display_books_by_section(cursor):
message = "Enter the section you want to "
message += "view (e.g., Fiction, Romance, Science Fiction): "
section = input(message).title()
cursor.execute('SELECT * FROM BookLibs WHERE section = %s',
(section,))
results = cursor.fetchall()
if results:
print(f"Books in the '{section}' section:")
print("ID | Title | Author | Section | Age Rating | Availability")
for each in results:
print(each[0],each[1], each[2], each[3], each[4], each[5],
sep=" | ")
else:
print(f"No books found in the '{section}' section.")

def display_books_by_author(cursor):
author = input("Enter the author name to view their books: ").title()
cursor.execute('SELECT * FROM BookLibs WHERE author = %s', (author,))
results = cursor.fetchall()
if results:
print(f"Books by {author}:")
print("ID | Title | Author | Section | Age Rating | Availability")
for each in results:
print(each[0], each[1],each[2], each[3], each[4], each[5],
sep=" | ")
else:
print(f"No books found by '{author}'.")

def display_books_by_genre_and_age(cursor):
message = "Enter the genre you want to view"
message += " (e.g., Fiction, Romance, Science Fiction): "
genre = input(message).title()
message = "Enter the age rating to filter by (e.g., 12+, 13+, 16+): "
age_rating = input().upper()
query = 'SELECT * FROM BookLibs WHERE section = %s AND age_rating =
%s'
cursor.execute(query, (genre, age_rating))
results = cursor.fetchall()
if results:
print(f"Books in the '{genre}' genre for age '{age_rating}':")
print("ID | Title | Author | Section | Age Rating | Availability")
for each in results:
print(each[0],each[1], each[2], each[3], each[4], each[5],
sep=" | ")
else:
print(f"No books found in the '{genre}' genre for age
'{age_rating}'.")

def rent_book(cursor, connection):


display_books(cursor)
book_id = int(input("\nEnter the Book ID you want to rent: "))
query = 'SELECT * FROM BookLibs WHERE book_id = %s AND availability =
%s'
cursor.execute(query, (book_id, 'Available'))
result = cursor.fetchone()
if result:
query = 'UPDATE BookLibs SET availability = "Rented" WHERE book_id
= %s'
cursor.execute(query, (book_id,))
connection.commit()
message = "\nSuccessfully rented '{}' by {}. Please return it on
time."
print(message.format(result[1], result[2]))
else:
print("\nSorry, the book is either rented or unavailable.")

def return_book(cursor, connection):


display_books(cursor)
book_id = int(input("\nEnter the Book ID you want to return: "))
query = 'SELECT * FROM BookLibs WHERE book_id = %s AND availability =
%s'
cursor.execute(query, (book_id, 'Rented'))
result = cursor.fetchone()
if result:
query = 'UPDATE BookLibs SET availability="Available" WHERE
book_id = %s'
cursor.execute(query, (book_id,))
connection.commit()
message = "\nYou have successfully returned '{}' by {}. Thank
you!"
print(message.format(result[1], result[2]))
else:
print("\nThe book is either already returned or does not exist.")

def admin_menu(cursor, connection):


while True:
print("\n--- Admin Menu ---")
print("1: Add Book")
print("2: Delete Book")
print("3: View All Books")
print("4: View Books by Section")
print("5: View Books by Author")
print("6: View Books by Genre and Age Rating")
print("7: Logout")
choice = int(input("Enter your choice: "))

if choice == 1:
title = input("Enter book title: ")
author = input("Enter book author: ")
section = input("Enter book section: ")
age_rating = input("Enter book age rating (e.g., 12+, 13+): ")
query = 'INSERT INTO BookLibs '
query += '(book_title,author,section,age_rating,availability)'
query += ' VALUES (%s, %s, %s, %s, %s)'
cursor.execute(query,
(title,author,section,age_rating,'Available'))
connection.commit()
message = "\n'{}' by {} has been added to the '{}' section."
print(message.format(title, author, section))
elif choice == 2:
display_books(cursor)
book_id = int(input("Enter the Book ID you want to delete: "))
cursor.execute('DELETE FROM BookLibs WHERE book_id = %s',
(book_id,))
connection.commit()
print(f"\nBook with ID {book_id} has been deleted.")

elif choice == 3:
display_books(cursor)

elif choice == 4:
display_books_by_section(cursor)

elif choice == 5:
display_books_by_author(cursor)

elif choice == 6:
display_books_by_genre_and_age(cursor)

elif choice == 7:
print("Logging out...")
time.sleep(2)
return

else:
print("Invalid Choice! Please try again.")

def library_system(connection, cursor):


while True:
print("Welcome to the Library!")
print("1: Rent a Book")
print("2: Return a Book")
print("3: View Books by Section")
print("4: View Books by Author")
print("5: View Books by Genre and Age Rating")
print("6: Exit")
choice = int(input("Enter your choice: "))

if choice == 1:
rent_book(cursor, connection)

elif choice == 2:
return_book(cursor, connection)

elif choice == 3:
display_books_by_section(cursor)

elif choice == 4:
display_books_by_author(cursor)

elif choice == 5:
display_books_by_genre_and_age(cursor)

elif choice == 6:
connection.close()
print("Goodbye!")
break
else:
print("Invalid Choice! Please try again.")

def login():
username = input("Enter admin username: ")
password = input("Enter admin password: ")

if username == admin_username and password == admin_password:


print("Access granted!")
admin_menu(cursor, connection)
else:
print("Access denied!")

def main():
print("1: Customer Login")
print("2: Admin Login")
print("3: Exit")
choice = int(input("Enter your choice: "))

if choice == 1:
library_system(connection, cursor)
elif choice == 2:
login()
elif choice == 3:
print("Goodbye!")
connection.close()
else:
print("Invalid Choice! Please try again.")
main()

main()
Python Output
Customer
1: Customer Login
2: Admin Login
3: Exit
Enter your choice: 1
Welcome to the Library!
1: Rent a Book
2: Return a Book
3: View Books by Section
4: View Books by Author
5: View Books by Genre and Age Rating
6: Exit
Enter your choice: 1
ID | Title | Author | Section | Age Rating | Availability
1 | To Kill a Mockingbird | Harper Lee | Fiction | 13+ | Available
2 | 1984 | George Orwell | Fiction | 16+ | Available
3 | Moby Dick | Herman Melville | Fiction | 13+ | Available
4 | The Great Gatsby | F. Scott Fitzgerald | Fiction | 16+ | Available
5 | War and Peace | Leo Tolstoy | Historical | 18+ | Available
6 | Pride and Prejudice | Jane Austen | Romance | 13+ | Available
7 | Brave New World | Aldous Huxley | Science Fiction | 16+ | Available
8 | The Hobbit | J.R.R. Tolkien | Fantasy | 12+ | Available
9 | Fahrenheit 451 | Ray Bradbury | Science Fiction | 14+ | Available
10 | The Divine Comedy | Dante Alighieri | Classics | 18+ | Available
11 | a | b | c | 12+ | Available

Enter the Book ID you want to rent: 1

Successfully rented 'To Kill a Mockingbird' by Harper Lee. Please return


it on time.
Welcome to the Library!
1: Rent a Book
2: Return a Book
3: View Books by Section
4: View Books by Author
5: View Books by Genre and Age Rating
6: Exit
Enter your choice: 2
ID | Title | Author | Section | Age Rating | Availability
1 | To Kill a Mockingbird | Harper Lee | Fiction | 13+ | Rented
2 | 1984 | George Orwell | Fiction | 16+ | Available
3 | Moby Dick | Herman Melville | Fiction | 13+ | Available
4 | The Great Gatsby | F. Scott Fitzgerald | Fiction | 16+ | Available
5 | War and Peace | Leo Tolstoy | Historical | 18+ | Available
6 | Pride and Prejudice | Jane Austen | Romance | 13+ | Available
7 | Brave New World | Aldous Huxley | Science Fiction | 16+ | Available
8 | The Hobbit | J.R.R. Tolkien | Fantasy | 12+ | Available
9 | Fahrenheit 451 | Ray Bradbury | Science Fiction | 14+ | Available
10 | The Divine Comedy | Dante Alighieri | Classics | 18+ | Available
11 | a | b | c | 12+ | Available

Enter the Book ID you want to return: 1

You have successfully returned 'To Kill a Mockingbird' by Harper Lee.


Thank you!
Welcome to the Library!
1: Rent a Book
2: Return a Book
3: View Books by Section
4: View Books by Author
5: View Books by Genre and Age Rating
6: Exit
Enter your choice: 3
Enter the section you want to view (e.g., Fiction, Romance, Science
Fiction): Fiction
Books in the 'Fiction' section:
ID | Title | Author | Section | Age Rating | Availability
1 | To Kill a Mockingbird | Harper Lee | Fiction | 13+ | Available
2 | 1984 | George Orwell | Fiction | 16+ | Available
3 | Moby Dick | Herman Melville | Fiction | 13+ | Available
4 | The Great Gatsby | F. Scott Fitzgerald | Fiction | 16+ | Available
Welcome to the Library!
1: Rent a Book
2: Return a Book
3: View Books by Section
4: View Books by Author
5: View Books by Genre and Age Rating
6: Exit
Enter your choice: 4
Enter the author name to view their books: George Orwell
Books by George Orwell:
ID | Title | Author | Section | Age Rating | Availability
2 | 1984 | George Orwell | Fiction | 16+ | Available
Welcome to the Library!
1: Rent a Book
2: Return a Book
3: View Books by Section
4: View Books by Author
5: View Books by Genre and Age Rating
6: Exit
Enter your choice: 5
Enter the genre you want to view (e.g., Fiction, Romance, Science
Fiction): Fiction
Enter the age rating to filter by (e.g., 12+, 13+, 16+): 12+
No books found in the 'Fiction' genre for age '12+'.
Welcome to the Library!
1: Rent a Book
2: Return a Book
3: View Books by Section
4: View Books by Author
5: View Books by Genre and Age Rating
6: Exit
Enter your choice: 6
Goodbye!

You might also like