cs project ir
cs project ir
3
RAILWAY
MANAGEMENT
SYSTEM
4
INTRODUCTION
5
PROJECT DESCRIPTION :
To explain briefly, this project will consist of these functionalities:
• Booking ticket: Users will be prompted to enter their name,
address, phone no, boarding station, destination station, and the
class they want to travel. Based on the boarding and destination
and the availability of seats in the requested class, the users will
be shown all the available trains and the fares. Then the user can
input the desired train no. and their ticket gets booked and the
unique PNR also gets displayed.
• Viewing ticket: Users can view their booked ticket by entering
their unique PNR of their ticket.
• Canceling ticket: Users can cancel their booked ticket by
entering their unique PNR of their ticket.
• Showing Customer Table: Users can view the details of all the
customers those who booked a ticket in this table.
• Showing Train Table: Users can view all the trains currently
running.
• Showing Train Seat Availability Table: Users. can view the
corresponding seat availability of all the classes of all the trains.
• Adding train in Train Table: Users can add a new train in the
existing train table.
• Removing train from train table: Users can remove a train from
the existing train table.
6
• Alter the Train Seat Availability Table: Users can change the
availability count of a particular class of a particular train.
Since the concept of railway reservation is much complex in reality,
some limitations has been considered:
• It is expected by the user to give fairly correct inputs as all the
possible incorrect test-cases has not been considered in the
project. • Only 6-7 trains are shown as
an example. • The train classes are limited to 6
(ACl/AC2/AC3ISL/CC/2S) • Date and time have not been
considered in train availability and booking to keep it simple.
• Only two types of train status,are considered: CONFIRMED and
CANCELLED.
7
SOFTWARE & HARDWARE
SPECIFICATION:
Hardware :
Processor - Intel® Core™ i3-2120 @ 3.30GHz
Installed RAM - 8 GB
Graphics - NVDIA GeForce GT 1030
Software :
Operation System - Windows 10 Pro
Programming Language - Python 3.10.5
Database Management - MySQL Community Server 8.0
IDE: Microsoft Visual Studio Cod (version 1.74)
8
DATA DICTIONARY:
MAIN PROGRAM:
Sl.
Name Type Description
No.
Used to connect the program with MySQL
1 mysql.connector module
Database
DATABASE TABLES:
10
SOURCE CODE:
SQL CODES :
DROP DATABASE IF EXISTS railway;
USE railway;
PRIMARY KEY(trno)
);
SL integer default 0,
CC integer default 0,
2S integer default 0,
);
CREATE TABLE customer_table(
pnr integer not null auto_increment,
trno varchar(5) not null,
11
cust_name varchar(60) not null,
cust_addr varchar(150) ,
cust_ph varchar(15),
);
(“12036", “NDLS SDAH RAJDHANI EXPRESS", ‘["new delhi". “kanpur cantral” “dd
upadhyaya”, "gaya" ,“dhanbad" ,"durgapur","sealdah”)’,’["AC3", "AC2",”AC 1”]’),
(“22387". “HWH DHN BLACKDIAMOND EXPRESS",‘("howrah” ,"seoraphuli”, “bandel”,
“barddhaman" ,"“mankar”
“panagarh",."durgapur” ,"waria”,”andal" ,“raniganj”,“asansol” ,“sitarampur”,"kulti",
”barakar”,"kumardubi”,“dhanbad"]' , '["CC" "25"]' ),
12
VALUES
("12041" ,0,0,0,0,200,0),
("12042",0,0,0,0,200,0),
("12035",100,100,100,0,0,0),
("22387" ,0,0,0,0,200,200),
(“22388" ,0,0,0,0,200,200);
13
PYTHON CODES :
import mysql.connector as sql import pandas as pd
pd. set_option( 'display.max_rows', None) pd.
set_option( 'display.width’, 2000) pd.
set_option( 'display.max_columns’, None)
print("Connecting to database...")
if connection, is_connected():
print("Successfully connected to the database“)
cursor = connection. cursor() return connection,
cursor
def book_ticket(db_con,.db_cursor):
try: print()
name = input("Enter your name: ") addr
= input("Enter your address: “) ph_no = input(“Enter your
phone number: “) boarding = input(“Enter your boarding station:
"). lower() dest = input("Enter your destination station: "). lower()
tr_class = input("Enter the train class you want to travel (ACI/AC2/AC3/SL/00/25) :
“).upper ()
if db_cursor. rowcount>0:
for i in all_trains:
stoppage = eval(i(2]) if boarding in stoppage and dest in
stoppage:
if len(avail_trains)>0:
for i in range(len(avail_trains)):
print("\nAvailable Trains...")
print(f’{i+1}.")
Name: {avail_trains[i][1]}")
choose: “)
price = n_seats*FARE[tr_class]
15
db_cursor.execute(f” INSERT INTO
customer_table(trno, cust_name, cust_addr , cust_ph, boarding, destination,
class ,n_seats, price, stats) VALUES (\“
{booked_tr}\",\"{name}\" ,\"{addr}\", \"{ph_no}\" ,\"{boarding}\", \"
{dest}\" ,\"{tr_class}\" , {n_seats}, {price}, \"CONFIRMED\" ) ” )
db_con. commit ()
1] [0]
else:
else:
else:
except:
def cancel_ticket(db_con,db_cursor):
print()
pnr = input("Enter your PNR Number: “)
try:
if db_cursor. rowcount>0:
db_con. commit ()
else:
else:
except:
def show_ticket(db_cursor):
print() pnr =
input("Enter your PNR Number: ")
try:
ticket = db_cursor.fetchal1()
if db_cursor. rowcount>0:
18
print(’PNR:”,ticket[0][0])
print(“Train:", ticket [0] [1], train)
print (“Boarding:”, ticket [0] [5].upper())
print("Destination:", ticket [0] [6] .upper())
print("Class:", ticket [0][7])
print("No. of Seats:", ticket [0][8])
print(“Status:”, ticket[0][10])
print(“Amount Paid:",ticket[0][9])
print(“-----------------------------------------------------------------------")
else:
except:
def show_trainDB(db_cursor):
try:
output_df.index+=1
print()
print(output_df)
except:
19
def show_customerDB(db_cursor):
try:
output_df. index+=1
print()
print(output_df)
except:
def show_availDB(db_cursor):
try:
except :
print("Some error occured! Please try again!")
def add_train(db_con,db_cursor):
try:
print()
trno = input("Train no. : “)
20
if len(trno)!=5 and not trno.isnumeric():
print("Train No. is not valid!")
return None
trname = input("Train Name: "). upper()
print(“Enter the classes available and the available seats one by one:”)
classes={}
for i in range(n):
n_class=input().upper().split()
classes [n_class[0].upper()]=int(n_class[1])
else :
return none
stoppage_str=str(stoppage).replace(“\’ “,”\””)
class_str = str(list(classes.keys())).replace(“\ ‘ “,”\””)
db_con.commit()
21
except :
print(“Some error occured! Please try again!")
try:
print()
db_cursor.execute(f”SELECT trno FROM train_table”)
all_trains = [I[0] for i = db_cursor.fetchall()]
trno = input(“Enter the train no. of the train you want to remove :”)
tr_details = db_cursor.fetchone()
print(“Train Details:”)
print(“Train Name:”,tr_details[1])
print(“Train Stoppages:”,”,”.join(eval (tr_details[2])))
print(“Available Classes:”,”,”.join(eval (tr_details[3])))
if remove in ["Y",”YES"]:
22
else:
except:
try:
if tr_class in avail_classes:
db_cursor.execute(f"SELECT {tr_class} FROM avail_table WHERE
trno=\"{trno}\"")
prev_count = db_cursor.fetchone()[0]
print(’Prev. available no. of seats:",prev_count)
new_count = input("Enter the new no. of seats: “) if
new_count.isnumeric():
db_con. commit()
print("\nUpdated successfully!")
23
else:
print("Invalid input!”)
else:
print("This class is not present in this train.”)
else:
except:
print(“Loading...")
con,cur = database_connect (“localhoast’, “root”, “mypass” , DATABASE)
print (“Successfully Loaded... \n\n")
while True:
print(f'\n\n{'-'*30}")
print("MENU:")
print("Enter 1 to Book Ticket")
print("Enter 2 to View Ticket")
print("Enter 3 to Cancel Ticket")
print(“Enter 4 to View Customer Table")
print("Enter 5 to View Train Table")
print("Enter 6 to View Train Seat Availability Table")
print(“Enter 7 to Add Train in Train Table")
print("Enter 8 to Remove Train from Train Table")
print("Enter 9 to Make Changes in Train Seat Availability Table")
print("Press E to Exit")
24
if key=='1':
book_ticket(con, cur)
elif key=='2':
show_ticket (cur) elif
key=='3':
cancel_ticket(con, cur) elif
key=='4':
show_customerDB (cur) elif
key=='5":
show_trainDB(cur) elif. Key==’6’:
show_avaiIDB
(cur)
25
OUTPUT:
STARTING AND MENU PAGE :
BOOK A TICKET :
26
VIEW A TICKET :
CANCEL A TICKET :
27
BOOK TWO MORE TICKETS :
28
SHOWING TRAIN TABLE :
29
ADDING TRAIN IN TRAIN TABLE :
30
UPDATING AVAILABILITY OF SEATS TRAIN TABLE :
31
EXITING APPLICATION :
32
BIBLIOGRAPHY :
SITES:
1. www.geeksforgeeks.org
2. www.w3schools.com
3. www.stackoverflow.com
4. www.github.com
5. https://docs.python.org/
6. https://dev.mysql.com/doc/
BOOKS:
1. Computer Science with Python Textbook Class XII
2. NCERT Computer Science Class XII
_____________
33