0% found this document useful (0 votes)
21 views22 pages

OM Project Report

The document is a project report for a Railway Reservation System developed by a student, detailing its objectives, functionalities, and technical implementation using MySQL and Python. It includes sections such as a certificate, acknowledgement, declaration, introduction, objectives, source code, output screenshots, and bibliography. The system aims to modernize railway management by providing an efficient platform for booking and managing train reservations.

Uploaded by

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

OM Project Report

The document is a project report for a Railway Reservation System developed by a student, detailing its objectives, functionalities, and technical implementation using MySQL and Python. It includes sections such as a certificate, acknowledgement, declaration, introduction, objectives, source code, output screenshots, and bibliography. The system aims to modernize railway management by providing an efficient platform for booking and managing train reservations.

Uploaded by

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

Index

S.No. Content Page No.


1 Certificate 02
2 Acknowledgement 03
3 Declaration 04
4 Introduction 05
5 Objective 06
6 Database Tables 07
7 Source Code 08
8 Output Screenshots 18
9 Bibliography 21

1
Dr. Virendra Swarup Education Centre,
N-Block, Kidwai Nagar, Kanpur

CERTIFICATE
This is to certify that (name of student) of class XII-B has prepared the report
on the project titled ‘Railway Reservation System’. This report is the result of
his/her efforts and endeavours. The report is found worthy of acceptance as
final project report for the subject Computer Science. The report has been
prepared under the guidance of P.G.T. Computer Science, Mr. Rajat Valecha
within the stipulated time as prescribed by CBSE.

Mr. Rajat Valecha Mrs. Preeti Poddar


(Internal) (Principal)

(External Examiner)

2
Acknowledgement

On completion and submission of the project, I would like to express my deep


sense of gratitude to our project guide and teacher Mr. Rajat Valecha for his
support during the project whenever needed. Without his co-operation, it was
impossible to reach this stage.

I am thankful to him for giving us this assignment with the purpose of


enhancing our knowledge and technical skills.

At last, I sincerely regard to my parents and friends who have directly or


indirectly helped me in this project.

3
Declaration

We declare that the work presented in this project titled “Railway Reservation
System”, submitted to Mr. Rajat Valecha, P.G.T. Computer Science. We have
not plagiarized or submitted the same work for the award of any other
examination. In case this undertaking is found incorrect, we accept that our
Certificates may be unconditionally withdrawn.

4
Introduction

The Railway Reservation System presented herein is a comprehensive and


user-friendly solution designed to streamline and enhance the efficiency of
railway management processes. Developed using MySQL and Python, this
system offers administrators the ability to seamlessly add and remove trains,
view train details, and customize ticket pricing structures. Additionally, users
can conveniently explore available trains, book their preferred seats, and
cancel reservations as needed. The system's intuitive interfaces cater to both
administrators and users, fostering a seamless experience and ensuring that
railway operations are conducted with precision and ease.

This Railway Reservation System features a well-structured database with


tables for trains, reservations, and relevant details, allowing for the organized
storage and retrieval of information. The codebase leverages the MySQL
database management system for data persistence and the Python
programming language for its versatility and readability. With a robust set of
functionalities, including seat selection, dynamic pricing, and cancellation
options, the project stands as a practical and efficient solution for railway
authorities seeking to manage and optimize their reservation processes
effectively.

5
Objective

The primary objective of the Railway Reservation System is to revolutionize


and modernize the traditional railway management process by introducing a
sophisticated and user-centric platform. The project aims to provide railway
administrators with an advanced tool to efficiently manage and monitor train
schedules, seat availability, and pricing structures. Simultaneously, the system
endeavors to enhance the passenger experience by offering a seamless and
accessible means to explore, book, and manage train reservations. Through the
utilization of MySQL and Python technologies, the objective is to create a
robust and scalable system that can adapt to the dynamic demands of railway
operations.

Another key objective is to improve the overall transparency and accuracy of


railway reservations, eliminating manual errors and ensuring precise tracking
of seat availability. By incorporating dynamic pricing based on seat types, the
system seeks to optimize revenue generation for railway authorities. The
development of an intuitive user interface aims to empower passengers with
an easy-to-use platform, enabling them to make informed decisions about
their travel plans. Ultimately, the Railway Reservation System aspires to
contribute to the efficiency, accessibility, and customer satisfaction within the
realm of railway management.

6
Database Tables

7
Source Code
import mysql.connector

def admin_login():
password = input("Enter admin password: ")
return password == "admin123"

def add_train():
train_name = input("Enter Train Name: ")
source = input("Enter Source Station: ")
destination = input("Enter Destination Station: ")
departure_day = input("Enter Departure Day: ")
departure_time = input("Enter Departure Time (HH:MM:SS): ")
first_class_seats = int(input("Enter First Class Seats: "))
second_class_seats = int(input("Enter Second Class Seats: "))
sleeper_seats = int(input("Enter Sleeper Seats: "))
ticket_price = int(input("Enter Ticket Price: "))

cur.execute("""
INSERT INTO trains
(train_name, source, destination, departure_day, departure_time,
first_class_seats, second_class_seats, sleeper_seats, ticket_price)
VALUES
(%s, %s, %s, %s, %s, %s, %s, %s, %s)
""", (train_name, source, destination, departure_day, departure_time,
first_class_seats, second_class_seats, sleeper_seats, ticket_price))
con.commit()
8
print("Train added successfully!")
print("-----------------------------")

def remove_train():
train_id = int(input("Enter Train ID to remove: "))
cur.execute(f"DELETE FROM trains WHERE train_id = {train_id}")
con.commit()
print("Train removed successfully!")
print("-----------------------------")

def display_trains():
print("Available Trains:")
cur.execute("SELECT * FROM trains")
rows = cur.fetchall()
for row in rows:
print("Train ID:", row[0])
print("Train Name:", row[1])
print("Source:", row[2])
print("Destination:", row[3])
print("Departure Day:", row[4])
print("Departure Time:", row[5])
print("First Class Seats:", row[6])
print("Second Class Seats:", row[7])
print("Sleeper Seats:", row[8])
print("Ticket Price:", row[9])
print("-----------------------------")

9
def book_train():
display_trains()
train_id = int(input("Enter the Train ID to book: "))
user_name = input("Enter your name: ")
seat_type = input("Enter the type of seat (first_class, second_class, sleeper):
").lower()
seats_booked = int(input("Enter the number of seats to book: "))

# Get the seat price based on the selected seat type


cur.execute(f"SELECT {seat_type}_seats, ticket_price FROM trains WHERE
train_id = {train_id}")
result = cur.fetchone()

if result:
seat_capacity, ticket_price = result
rate = 1
if seat_type == 'second_class':
rate = 0.8
elif seat_type == 'sleeper':
rate = 0.6

if seats_booked <= seat_capacity:


total_price = seats_booked * ticket_price

# Insert into reservations table


cur.execute("""

10
INSERT INTO reservations (train_id, user_name, seats_booked,
total_price)
VALUES (%s, %s, %s, %s)
""", (train_id, user_name, seats_booked, total_price))

# Get the reservation ID of the last inserted row


reservation_id = cur.lastrowid

con.commit()
print("Booking successful!")
print("Reservation ID:", reservation_id)
print("Total Price: $", total_price)
print("Selected Seat Type:", seat_type)
print("-----------------------------")
else:
print("Not enough seats available.")
else:
print("Train not found.")

def cancel_train():
reservation_id = int(input("Enter the Reservation ID to cancel: "))
cur.execute(f"SELECT * FROM reservations WHERE reservation_id =
{reservation_id}")
reservation = cur.fetchone()

if reservation:

11
cur.execute(f"DELETE FROM reservations WHERE reservation_id =
{reservation_id}")
con.commit()
print("Booking canceled successfully!")
print("Refund Amount: $", reservation[4])
print("-----------------------------")
else:
print("Reservation not found.")

def view_trains():
print("\nTrain List:")
print("1. View All Trains")
print("2. View Trains with Different Pricing")
view_choice = input("Enter your choice: ")

if view_choice == '1':
display_trains()
elif view_choice == '2':
display_trains_with_pricing()
else:
print("Invalid choice. Returning to Admin Menu.")

def display_trains_with_pricing():
print("\nTrains with Different Pricing:")
cur.execute("SELECT * FROM trains")
rows = cur.fetchall()
for row in rows:
12
print("Train ID:", row[0])
print("Train Name:", row[1])
print("Source:", row[2])
print("Destination:", row[3])
print("Departure Day:", row[4])
print("Departure Time:", row[5])
print("First Class Seats:", row[6], "Price:", row[9])
print("Second Class Seats:", row[7], "Price:", row[9] * 0.8) # 80% of ticket
price for second class seats
print("Sleeper Seats:", row[8], "Price:", row[9] * 0.6) # 60% of ticket price
for sleeper seats
print("-----------------------------")

def admin_menu():
while True:
print("\nAdmin Menu:")
print("1. Add Train")
print("2. Remove Train")
print("3. View Trains")
print("4. Exit")
admin_choice = input("Enter your choice: ")

if admin_choice == '1':
add_train()
elif admin_choice == '2':
remove_train()
elif admin_choice == '3':

13
view_trains()
elif admin_choice == '4':
break
else:
print("Invalid choice. Please try again.")

def user_menu():
while True:
print("\nUser Menu:")
print("1. Display Available Trains")
print("2. Book a Train")
print("3. Cancel a Train")
print("4. Exit")
user_choice = input("Enter your choice: ")

if user_choice == '1':
display_trains()
elif user_choice == '2':
book_train()
elif user_choice == '3':
cancel_train()
elif user_choice == '4':
break
else:
print("Invalid choice. Please try again.")

14
# Database Connection
con = mysql.connector.connect(host='localhost', user='root', password='!
q@W#e123321')
cur = con.cursor()

# Create or use the database


cur.execute("CREATE DATABASE IF NOT EXISTS railway_reservation")
cur.execute("USE railway_reservation")

# Create tables if they don't exist


cur.execute("""
CREATE TABLE IF NOT EXISTS trains (
train_id INT AUTO_INCREMENT PRIMARY KEY,
train_name VARCHAR(255) NOT NULL,
source VARCHAR(255) NOT NULL,
destination VARCHAR(255) NOT NULL,
departure_day VARCHAR(20) NOT NULL,
departure_time TIME NOT NULL,
first_class_seats INT NOT NULL,
second_class_seats INT NOT NULL,
sleeper_seats INT NOT NULL,
ticket_price INT NOT NULL
)
""")

cur.execute("SELECT COUNT(*) FROM trains")


row_count = cur.fetchone()[0]
15
if row_count == 0:
cur.execute("""
INSERT INTO trains
(train_name, source, destination, departure_day, departure_time,
first_class_seats, second_class_seats, sleeper_seats, ticket_price)
VALUES
('Train1', 'City1', 'City2', 'Monday', '12:00:00', 10, 15, 100, 500),
('Train2', 'City2', 'City3', 'Tuesday', '14:30:00', 8, 20, 120, 600),
('Train3', 'City1', 'City3', 'Wednesday', '10:00:00', 12, 18, 80, 400)
""")
con.commit()

cur.execute("""
CREATE TABLE IF NOT EXISTS reservations (
reservation_id INT AUTO_INCREMENT PRIMARY KEY,
train_id INT,
user_name VARCHAR(255) NOT NULL,
seats_booked INT NOT NULL,
total_price INT NOT NULL,
FOREIGN KEY (train_id) REFERENCES trains(train_id)
)
""")
con.commit()

# Main Menu
while True:
print("\nWelcome to Railway Reservation System")
16
print("1. Admin Login")
print("2. User Menu")
print("3. Exit")
choice = input("Enter your choice: ")

if choice == '1':
if admin_login():
admin_menu()
else:
print("Invalid admin password!")
elif choice == '2':
user_menu()
elif choice == '3':
break
else:
print("Invalid choice. Please try again.")

# Close the database connection


con.close()

17
Output Screenshots

18
19
20
21
Bibliography

1. python.org
2. Code Academy
3. tutorialsPoint.com
4. PythonChallenge.com
5. LearnPython.org

22

You might also like