0% found this document useful (0 votes)
36 views18 pages

CS Project (J)

Uploaded by

rjanardhanan2008
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)
36 views18 pages

CS Project (J)

Uploaded by

rjanardhanan2008
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/ 18

VELAMMAL VIDYALAYA

MEL AYANAMBAKKAM

COMPUTER SCIENCE PROJECT


ACADEMIC YEAR: 2024 – 2025

TOPIC: RAILWAY RESERVATION


SYSTEM
PREPARED BY
NAME : R. JANARTHANAN
CLASS & SEC : XII R
DATE OF SUBMISSION :
CERTIFICATE

This is to certify that R. Janarthanan has successfully


completed Computer Science Project towards partial
completion of Practical examination of SSCE 2025 as
prescribed by CBSE.

Internal Examiner External Examiner


Acknowledgement

I wish to express my deep gratitude and sincere thanks to all


my teachers for the encouragement, and the management
for
providing all facilities to successfully complete the project
work.
I extend my sincere thanks to my principal and my Computer
Science teacher, whose valuable guidance helped to
successfully complete the project.
I extend my gratitude to my parents and classmates for their
valuable support and time.
Contents

 Introduction

 Software and Hardware Requirements

 Source Code

 Output

 Bibliography
INTRODUCTION
This is a project on railway reservation system. It helps
us to enter or alter the train details, it helps us to
reserve or cancel a ticket. It also enables us to check
the status of booking.
This Python script facilitates a simple railway reservatio
n
system with various functionalities. The script connects
to a MySQL database named "rail" using the mysql.con
nector
module. It initializes a Passenger Name Record (PNR)
number and provides a menu-driven interface with opti
ons for entering train details,
making reservations, canceling tickets, and displaying P
NR status.
The traindetail function allows users to input train infor
mation, including the train name, number, and seat
availability across different classes. This data is then
inserted into the traindetail table in the database.
The reservation function handles ticket bookings by
collecting passenger details, calculating the fare based
on
the class chosen, and updating the passengers table wi
th
these details, including generating a unique PNR numb
er and confirming the booking.
The cancel function updates the status of a ticket to 'de
letedbased on the provided PNR number, indicating tha
t the ticket has been cancelled.
The displayPNR function retrieves and displays the stat
us
of a ticket using the PNR number, showing the details
stored in the passenger’s table.
Overall, this program provides a user-friendly interface
for managing railway reservations,
ensuring data is accurately stored and retrieved from a
MySQL database.
Software and Hardware Requirements

Software:
1. Ubuntu 16.04 / Windows 7.0 or later
2. Pydroid 3.6

Hardware:
The hardware used to run the project are:
1. 2 GHz Dual Core Processor
2. 2 GB RAM
PYTHON

SOURCE
CODE
import mysql.connector as q

pnr = 2125

con = q.connect(
host="localhost",
user="root",
password="admin",
database="rail_")

cur = con.cursor()

def create_tables():
cur.execute("""
CREATE TABLE traindetail (
id INT AUTO_INCREMENT PRIMARY KEY,
tname VARCHAR(100),
tnum INT,
ac1 INT,
ac2 INT,
ac3 INT,
nonac INT)
""")

cur.execute("""
CREATE TABLE passengers (
id INT AUTO_INCREMENT PRIMARY KEY,
pname VARCHAR(100),
age INT,
trainno INT,
noofp INT,
cls VARCHAR(20),
amt DECIMAL(10, 2),
status VARCHAR(20),
pnrno INT UNIQUE)
""")

con.commit()

def railresmenu():
print("Railway Reservation")
print("1. Train Detail")
print("2. Ticket Reservation")
print("3. Ticket Cancelling")
print("4. PNR status")
print("5. Quit")
try:
choice = int(input("Enter your choice: "))
if choice == 1:
traindetail()
elif choice == 2:
reservation()
elif choice == 3:
cancel()
elif choice == 4:
displayPNR()
elif choice == 5:
exit(0)
else:
print("Invalid choice")
except ValueError:
print("Please enter a valid number")

def traindetail():
print("Train Details")
while True:
try:
name = input("Enter train name: ")
tnum = int(input("Enter train number: "))
ac1 = int(input("Enter number of AC 1 class seats: "))
ac2 = int(input("Enter number of AC 2 class seats: "))
ac3 = int(input("Enter number of AC 3 class seats: "))
nonac = int(input("Enter number of NON AC class seats: "))

train = (tname, tnum, ac1, ac2, ac3, nonac)


sql = "INSERT INTO traindetail (tname, tnum, ac1, ac2, ac3, nonac)
VALUES (%s, %s, %s, %s, %s, %s)"
cur.execute(sql, train)
con.commit()

print("Insertion completed")
more = input("Do you want to insert more train details? (yes/no): ").strip().lower()
if more != 'yes':
break
except ValueError:
print("Please enter valid information")
railresmenu()

def reservation():
global pnr
pname = input("Enter passenger name: ")
try:
age = int(input("Enter age of passenger: "))
trainno = int(input("Enter train number: "))
np = int(input("Enter number of passengers: "))

print("Select a class you would like to travel in:")


print("1. AC FIRST CLASS")
print("2. AC SECOND CLASS")
print("3. AC THIRD CLASS")
print("4. NON AC CLASS")
cp = int(input("Enter your choice: "))

if cp == 1:
amount = np * 1000
cls = 'ac1'
elif cp == 2:
amount = np * 800
cls = 'ac2'
elif cp == 3:
amount = np * 500
cls = 'ac3'
else:
amount = np * 350
cls = 'nonac'

pnr += 1
print("PNR Number:", pnr)
print("Status: confirmed")

reservation_details = (pname, age, trainno, noofp, cls, amount, 'conf', pnr)


sql = "INSERT INTO passengers (pname, age, trainno, noofp, cls, amt, status, pnrno)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s)"
cur.execute(sql, reservation_details)
con.commit()

print("Insertion completed")
except ValueError:
print("Please enter valid information")
railresmenu()

def cancel():
print("Ticket cancellation")
pnr = input("Enter PNR for cancellation: ")
try:
sql = "UPDATE passengers SET status='deleted' WHERE pnrno=%s"
cur.execute(sql, (pnr,))
con.commit()

print("Deletion completed")
except q.Error as err:
print("Error: {}".format(err))
railresmenu()

def displayPNR():
print("PNR Status")
pnr = input("Enter PNR number: ")
try:
sql = "SELECT * FROM passengers WHERE pnrno=%s"
cur.execute(sql, (pnr,))
result = cur.fetchall()

print("PNR Status:")
print("(pname, age, trainno, noofp, cls, amt, status, pnrno)")
for record in result:
print(record)
except q.Error as err:
print("Error: {}".format(err))
railresmenu()

create_tables()

railresmenu()
OUTPUT
SCREEN 1:
SCREEN 2:
SCREEN 3:
SCREEN 4:
BIBLIOGRAPHY:

 SUMITA ARORA COMPUTER SCIENCE


TEXTBOOK

 PYTHON
https://www.python.org

 MYSQL
https://www.mysql.com

 www.quora.com

~
THANK
YOU ~

You might also like