Cs Project Final
Cs Project Final
Page | 1
Acknowledgement
Page | 2
COMPUTER SCIENCE
CERTIFICATE
_______________ ______________
_______________ ______________
Page | 3
Index
1. Aim of the project Page No.5
Page | 4
Aim of the Project
This system will allow librarians to handle essential tasks such as adding new
books and student records, issuing and returning books, deleting outdated
records, and displaying current inventory and membership information.
Page | 5
System Requirements
1. Software Requirements:
Operating System: Windows 10 or higher / macOS / Linux
• Python Version: Python 3.7 or higher
• Database Management System: MySQL Server (version 5.7 or higher)
• Python Libraries:
o mysql-connector-python: For connecting and interacting with the
MySQL database.
o matplotlib: For generating visualizations (bar graphs) of available
books by genre.
• Text Editor/IDE: Any code editor such as Visual Studio Code, PyCharm,
or IDLE for Python scripting.
• Command-Line Interface: Command Prompt or Terminal for installing
packages and running the program.
2. Hardware Requirements:
• Processor: Intel i3 (or equivalent) and above
• RAM: Minimum 4 GB
• Storage: Minimum 500 MB of free space for software installations and
database storage
• Screen Resolution: 1024x768 or higher for optimal display of graphical
elements
Page | 6
Installation Procedure
Page | 7
CREATE DATABASE LIBRARY_MGT_SYS;
3. Switch to the newly created database:
USE LIBRARY_MGT_SYS;
4. Create the necessary tables:
CREATE TABLE STUDENTS (
STUDENT_ID INT PRIMARY KEY,
STUDENT_NAME VARCHAR(100),
GRADE INT,
EMAIL VARCHAR(100),
PHONE VARCHAR(15)
);
Page | 8
SHOW TABLES;
Page | 9
System Layout
1. User 2. Backend
3. Database
Interface (UI) (Python Code)
(MySQL)
Functions
Main Menu ⇨ TABLES:
insertrec() ⇨Inserts
Options for adding, new student/book
deleting, issuing, records
returning books, STUDENTS
deleterec() ⇨Deletes
displaying records, student/book BOOKS
generating stats records
issue() ⇨ Issues a BOOKS_ISSUED
Input Prompts ⇨
Requests user book, updates BOOKS_RETURNED
information (e.g., availability
student ID, book return_book() ⇨
title) Returns a book,
updates availability
Output Display ⇨ display() ⇨ Displays
Shows student/book
confirmations, records
errors, and data genre_bar_graph()
(student/book ⇨ Generates a
details) genre-based bar
graph
menu() ⇨ Displays
main menu, calls
functions based on
user choice
↳ Error Handling
⇨ Manages errors, Page | 10
provides feedback
(e.g., invalid input,
database issues)
Functions and Modules
used
Functions
• insert_record()
• delete_record()
• issue_book()
• return_book()
• display_records()
• genre_bar_graph()
• menu()
Modules
• mysql.connector as c
• random
• datetime
• matplotlib.pyplot as plt
Page | 11
Script (Source code)
# Importing necessary modules
import mysql.connector as c
import random
from datetime import datetime
import matplotlib.pyplot as plt
Page | 12
"Each option guides you through entering the required details.\n\n")
f.write("Thank you for using the Library Management System!\n")
def menu():
print("--- Library Management System ---")
print("1. Insert Records")
print("2. Delete Records")
print("3. Issue Book")
print("4. Return Book")
print("5. Display Records")
print("6. Display Genre Bar Graph")
print("7. Exit")
def insert_record():
print("1. Insert new Student")
print("2. Insert new Book")
choice = input("Enter choice (1 or 2): ")
cursor = con.cursor()
if choice == '1':
STUDENT_ID = input("Enter Student ID: ")
Page | 13
STUDENT_NAME = input("Enter Student Name: ")
GRADE = input("Enter Grade: ")
EMAIL = input("Enter EMAIL: ")
PHONE = input("Enter PHONE: ")
query = "INSERT INTO STUDENTS (STUDENT_ID, STUDENT_NAME,
GRADE, EMAIL, PHONE) VALUES (%s, %s, %s, %s, %s)"
cursor.execute(query, (STUDENT_ID, STUDENT_NAME, GRADE, EMAIL,
PHONE))
con.commit()
print("Student data inserted successfully: ID=", STUDENT_ID, ", Name=",
STUDENT_NAME, ", Grade=", GRADE, ", Email=", EMAIL, ", Phone=", PHONE,
"\n")
elif choice == '2':
BOOK_ID = input("Enter Book ID: ")
TITLE = input("Enter Book Title: ")
AUTHOR = input("Enter Author Name: ")
GENRE = input("Enter Genre: ")
TOTAL_COPIES = input("Enter total number of copies: ")
AVAILABLE_COPIES = input("Enter number of available copies: ")
query = "INSERT INTO BOOKS (BOOK_ID, TITLE, AUTHOR, GENRE,
TOTAL_COPIES, AVAILABLE_COPIES) VALUES (%s, %s, %s, %s, %s, %s)"
cursor.execute(query, (BOOK_ID, TITLE, AUTHOR, GENRE,
TOTAL_COPIES, AVAILABLE_COPIES))
con.commit()
print("Book data inserted successfully: ID=", BOOK_ID, ", Title=", TITLE,
", Author=", AUTHOR, ", Genre=", GENRE, ", Total Copies=", TOTAL_COPIES,
", Available Copies=", AVAILABLE_COPIES, "\n")
def delete_record():
print("1. Delete Student record")
print("2. Delete Book record")
choice = input("Enter choice (1 or 2): ")
Page | 14
cursor = con.cursor()
if choice == '1':
STUDENT_ID = input("Enter Student ID to delete: ")
cursor.execute("DELETE FROM STUDENTS WHERE STUDENT_ID = %s",
(STUDENT_ID,))
con.commit()
print("Student record with ID=", STUDENT_ID, " deleted successfully\n")
elif choice == '2':
BOOK_ID = input("Enter Book ID to delete: ")
cursor.execute("DELETE FROM BOOKS WHERE BOOK_ID = %s",
(BOOK_ID,))
con.commit()
print("Book record with ID=", BOOK_ID, " deleted successfully\n")
def issue_book():
cursor = con.cursor()
STUDENT_ID = input("Enter Student ID: ")
BOOK_ID = input("Enter Book ID: ")
# Check if the student exists and if the book is available
cursor.execute("SELECT * FROM STUDENTS WHERE STUDENT_ID = %s",
(STUDENT_ID,))
student_exists = cursor.fetchone()
cursor.execute("SELECT * FROM BOOKS WHERE BOOK_ID = %s AND
AVAILABLE_COPIES > 0", (BOOK_ID,))
book_available = cursor.fetchone()
# Only proceed if both conditions are met
if student_exists and book_available:
ISSUE_ID = random.randint(1000, 9999)
issue_date = datetime.now()
Page | 15
query = "INSERT INTO BOOKS_ISSUED (ISSUE_ID, BOOK_ID,
STUDENT_ID, ISSUE_DATE, RETURN_DATE) VALUES (%s, %s, %s, %s,
NULL)"
cursor.execute(query, (ISSUE_ID, BOOK_ID, STUDENT_ID, issue_date))
cursor.execute("UPDATE BOOKS SET AVAILABLE_COPIES =
AVAILABLE_COPIES - 1 WHERE BOOK_ID = %s", (BOOK_ID,))
con.commit()
print("Book issued successfully with ISSUE_ID:", ISSUE_ID, "for Student
ID=", STUDENT_ID, "and Book ID=", BOOK_ID, "\n")
else:
print("Issue failed: Check student ID and book availability\n")
def return_book():
cursor = con.cursor()
STUDENT_ID = input("Enter Student ID: ")
BOOK_ID = input("Enter Book ID: ")
# Check if there is a matching record of the issued book
cursor.execute("SELECT * FROM BOOKS_ISSUED WHERE STUDENT_ID =
%s AND BOOK_ID = %s AND RETURN_DATE IS NULL", (STUDENT_ID,
BOOK_ID))
issued_record_exists = cursor.fetchone()
if issued_record_exists:
return_date = datetime.now()
cursor.execute("UPDATE BOOKS_ISSUED SET RETURN_DATE = %s
WHERE STUDENT_ID = %s AND BOOK_ID = %s", (return_date, STUDENT_ID,
BOOK_ID))
cursor.execute("UPDATE BOOKS SET AVAILABLE_COPIES =
AVAILABLE_COPIES + 1 WHERE BOOK_ID = %s", (BOOK_ID,))
con.commit()
print("Book with ID=", BOOK_ID, "returned successfully for Student ID=",
STUDENT_ID, "\n")
else:
Page | 16
print("Return failed: No matching issued record found\n")
def display_records():
print("1. Display Student Records")
print("2. Display Book Records")
choice = input("Enter choice (1 or 2): ")
cursor = con.cursor()
if choice == '1':
cursor.execute("SELECT STUDENT_ID, STUDENT_NAME, GRADE,
EMAIL, PHONE FROM STUDENTS")
print("\n--- Student Records ---")
for i in cursor.fetchall():
print("STUDENT_ID:", i[0], ", STUDENT_NAME:", i[1], ", GRADE:", i[2],
", EMAIL:", i[3], ", PHONE:", i[4])
print()
elif choice == '2':
cursor.execute("SELECT BOOK_ID, TITLE, AUTHOR, GENRE,
TOTAL_COPIES, AVAILABLE_COPIES FROM BOOKS")
print("\n--- Book Records ---")
for i in cursor.fetchall():
print("BOOK_ID:", i[0], ", TITLE:", i[1], ", AUTHOR:", i[2], ", GENRE:",
i[3], ", TOTAL_COPIES:", i[4], ", AVAILABLE_COPIES:", i[5])
print()
def genre_bar_graph():
cursor = con.cursor()
cursor.execute("SELECT GENRE, SUM(AVAILABLE_COPIES) FROM BOOKS
GROUP BY GENRE")
data = cursor.fetchall()
Page | 17
genres = [i[0] for i in data]
available_copies = [i[1] for i in data]
plt.figure(figsize=(10, 6))
plt.bar(genres, available_copies, color='skyblue')
plt.xlabel("Genre")
plt.ylabel("Available Copies")
plt.title("Available Books per Genre")
plt.xticks(rotation=45)
plt.tight_layout()
plt.show()
Page | 18
OUTPUT
Page | 19
Page | 20
Page | 21
Errors Identified
4. ValueError: Triggered if the user inputs non-integer data where integers are
expected. Solution: Use try-except to catch and handle invalid inputs.
Page | 22
Future Modifications
3. User Authentication:
• Introduce login functionality with role-based access control (e.g., admin
and user roles) to enhance security and prevent unauthorized data
access.
Page | 23
Bibliography
Page | 24