0% found this document useful (0 votes)
42 views24 pages

Cs Project Final

Uploaded by

neilder44
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)
42 views24 pages

Cs Project Final

Uploaded by

neilder44
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/ 24

COMPUTER SCIENCE

CBSE BOARD PROJECT FILE


2024-2025

Name: Neilder Bura


Grade: 12-A
Roll no: ______________________________________

Page | 1
Acknowledgement

I take this opportunity to sincerely express my gratitude to

all who have helped me complete this project .

My sincere thanks to the Ms.Ambika Gulati, our

principal, Ms.Mini Nair, our Viceprincipal,

Ms. Priyanka Bhattacharya, our Head of section and

Mr.Mehmood Mudassir, our supervisor for constant

support and encouragement.

My sincere gratitute to Ms. Elsy Varghese, my Computer

Science teacher whose constant support and guidance

helped me complete this Project file.

Page | 2
COMPUTER SCIENCE
CERTIFICATE

Certified to be the bonafide record of the project


work done by Master / Miss Neilder Bura of Grade
XII as prescribed by the Central Board of Secondary
Education, Delhi during the academic year 2024-
2025.

_______________ ______________

Teacher in-charge Principal

Submitted for the Practical Examination on _______


held in The Millennium School, Dubai

_______________ ______________

Internal Examiner External Examiner

Page | 3
Index
1. Aim of the project Page No.5

2. System Requirements Page No.6


3. Installation Procedure Page No.7

4. System Layout Page No.10


5. Functions and Modules used Page No.11

6. Script (Source code) Page No.12


7. Output Page No.19

8. Errors Identified Page No.22


9. Future Modifications Page No.23

10. Bibliography Page No.24

Page | 4
Aim of the Project

The aim of this project is to develop a Library Management System that


facilitates the efficient management of library operations.

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.

Additionally, the system will provide a visual representation of available books


by genre, enabling better resource planning and genre-specific analysis. The
project will utilize Python and MySQL to create a user-friendly, menu-driven
interface for streamlined and organized library management.

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

Step 1: Install Python


1. Download the latest version of Python from python.org.
2. Run the installer and check the option Add Python to PATH before
installing.

Step 2: Install MySQL Server


1. Download the MySQL Installer from MySQL Community Downloads.
2. Run the installer and choose Custom setup, then select MySQL Server
and MySQL Workbench.
3. Set up a root password during installation. Make sure to remember this,
as it will be needed to connect from Python.
4. Complete the installation and verify by opening MySQL Workbench or
Command Line Client.

Step 3: Install Required Python Packages


1. Open Command Prompt and run the following commands to install the
necessary libraries:
pip install mysql-connector-python
pip install matplotlib
2. Verify installation by running:
python -c "import mysql.connector; import matplotlib.pyplot as plt"
If no errors appear, the packages are installed successfully.
Step 4: Set Up the MySQL Database
1. Open MySQL Workbench or MySQL Command Line Client.
2. Create a database named LIBRARY_MGT_SYS:
Sql:

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)
);

CREATE TABLE BOOKS (


BOOK_ID INT PRIMARY KEY,
TITLE VARCHAR(200),
AUTHOR VARCHAR(100),
GENRE VARCHAR(50),
TOTAL_COPIES INT,
AVAILABLE_COPIES INT
);

CREATE TABLE BOOKS_ISSUED (


ISSUE_ID INT PRIMARY KEY,
BOOK_ID INT,
STUDENT_ID INT,
ISSUE_DATE DATE,
RETURN_DATE DATE,
FOREIGN KEY (BOOK_ID) REFERENCES BOOKS(BOOK_ID),
FOREIGN KEY (STUDENT_ID) REFERENCES STUDENTS(STUDENT_ID)
);
5. Confirm that the tables have been created by running:

Page | 8
SHOW TABLES;

Step 5: Run the Program


1. Open your code editor or IDE (such as Visual Studio Code or PyCharm).
2. Open the Python file containing your Library Management System code.
3. Run the program. You should see the main menu displayed with options
to add, delete, issue, return, display records, and generate genre
statistics.

Step 6: Testing the Program


1. Select each menu option to test functionality.
2. Verify that records are being added, updated, deleted, and displayed
correctly.
3. Check that the genre bar graph displays as expected.

Page | 9
System Layout

1. User 2. Backend
3. Database
Interface (UI) (Python Code)
(MySQL)

Purpose: Provides a Purpose: Processes Purpose: Stores and


text-based, menu- commands, handles manages data for
driven interface for logic, interacts with the students, books, issued
user interaction database and returned books

Components Components Components

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

# Write the introductory text file

with open("LibraryIntro.txt", "w") as f:

f.write("WELCOME TO LIBRARY MANAGEMENT SYSTEM\n\n")


f.write("This system helps to manage a library's day-to-day operations
efficiently.\n\n")
f.write("FEATURES:\n")
f.write("1. Add Records: Add new students and books to the library
database.\n")
f.write("2. Issue Books: Issue books to students, with automatic updates to
availability.\n")
f.write("3. Return Books: Update records when books are returned,
increasing available copies.\n")
f.write("4. Delete Records: Remove students or books from the database
when no longer needed.\n")
f.write("5. Display Records: View all student or book details in the library
database.\n")
f.write("6. Genre Statistics: Generate a bar graph of available books by
genre.\n\n")
f.write("USAGE:\n")
f.write("Choose an option from the menu and follow the prompts to perform
actions. "

Page | 12
"Each option guides you through entering the required details.\n\n")
f.write("Thank you for using the Library Management System!\n")

# Connect to the database


con = c.connect(host="localhost", user="root", passwd="tiger",
database="LIBRARY_MGT_SYS")
if con.is_connected():
print("Successfully connected to the database.\n")

# Function to display the main menu

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")

# Function to insert new records

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")

# Function to delete records

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")

# Function to issue a book to a student

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")

# Function to return a book

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")

# Function to display records

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()

# Function to display a genre bar graph

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()

# Main program loop


while True:
menu()
choice = input("Enter your choice: ")
if choice == '1':
insert_record()
elif choice == '2':
delete_record()
elif choice == '3':
issue_book()
elif choice == '4':
return_book()
elif choice == '5':
display_records()
elif choice == '6':
genre_bar_graph()
elif choice == '7':
print("Exiting the Library Management System. Goodbye!")
break

Page | 18
OUTPUT

Page | 19
Page | 20
Page | 21
Errors Identified

1. ModuleNotFoundError: Occurs if required modules (mysql.connector or


matplotlib) are not installed. Solution: Install missing packages via pip install.

2. Database Connection Error: Happens when connection credentials are


incorrect, or the MySQL server is down. Solution: Verify MySQL server status
and connection details.

3. IntegrityError (Duplicate Entry): Raised when attempting to insert a


record with a duplicate primary key. Solution: Check for existing entries before
insertion.

4. ValueError: Triggered if the user inputs non-integer data where integers are
expected. Solution: Use try-except to catch and handle invalid inputs.

5. Foreign Key Constraint Error: Occurs if issuing a book to a non-existent


student or book. Solution: Validate that STUDENT_ID and BOOK_ID exist
before inserting into BOOKS_ISSUED.

Page | 22
Future Modifications

1. Enhanced Search Functionality:


• Add advanced search options to find books or students by various
attributes (e.g., genre, author, student name) to make the system more
user-friendly.

2. Fine Management System:


• Implement a system to track overdue books and calculate fines based on
the number of days a book is late. This could include automated
reminders for students.

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.

4. Inventory Notification System:


• Add notifications or alerts when the number of available copies for a
book is low, helping library staff manage inventory more effectively.

5. Data Backup and Restore:


• Implement automated data backup and restore features to prevent data
loss and make the system more resilient to unexpected failures.

Page | 23
Bibliography

1. MySQL Documentation. "MySQL 8.0 Reference Manual." MySQL


Documentation. Retrieved from https://dev.mysql.com/doc/

2. Python Software Foundation. "Python 3 Documentation." Python.org.


Retrieved from https://docs.python.org/3/

3. Stack Overflow. "Python and MySQL Integration." Stack Overflow. Retrieved


from https://stackoverflow.com/questions/

Page | 24

You might also like