0% found this document useful (0 votes)
20 views47 pages

Python Railway Reservation

Uploaded by

b.rajivrao94
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)
20 views47 pages

Python Railway Reservation

Uploaded by

b.rajivrao94
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/ 47

COMPUTER SCIENCE PROJECT ON

RAILWAY RESERVATION SYSTEM

NAME-B.Rajiv Kumar Rao

CLASS-XII

ROLL NO.-

YEAR -2024-25
COMPUTER
SCIENCE
PROJECT
ON RAILWAY
RESERVATION

Done By - B.RAJIV KUMAR RAO


TABLE OF CONTENT

SNO TOPIC PGNO

1. Introduction

2. Algorithm

3. SourceCode

4. Output
Screenshots

5. Biblography
INTRODUCTION
Our project introduces railway reservation system with
an objective to make the reservation system more
efficient, easier and fast. This project explores how
computer technology can be used to solve the problem
of user. The main objectives provided by this software areas
follows:
a) We can enquire about availability of trains
b) We can reserve the seats
c) We can cancel the seats
d) We can check the pnr status
e) We can modify the information
This project is dedicated to model existing railway
reservation systems that aim at development of
Railway Reservation System that facilitates the railway
customer to manage their reservations and the railway
administrator to modify the back end database in a user -
friendly manner.
ALGORITHM
CLASS NAME-tickets
DATAMEMBERS-no.of 1stclass, no. of2ndclass, no.of3rdclass,
no.ofsleeper, no.of tickets, name, age, resno, status

MEMBER FUNCTIONS-
ret,retname,display,pending,confirmation,cancellation,reservation
OBJECT-tick

MEMBERFUNCTIONS
FUNCTION NAME-create_book()
PARAMETERS-nil
RETURN TYPE-nil
TASK-Allows the user to reads the values of book number,
bookname and author name and create an book record

FUNCTION NAME-ret()
PARAMETERS-nil
RETURN TYPE-integer
TASK-returning reservation number

FUNCTION NAME-retname()
PARAMETERS-nil
RETURN TYPE-string
TASK-returns the name

FUNCTION NAME-display()
PARAMETERS- nil
RETURN TYPE-nil
TASK-print passanger name,age,pnrno.,status,no.of seats booked

FUNCTION NAME-pending()
PARAMETERS-nil
RETURN TYPE-nil
TASK-prints the pnr status

FUNCTION NAME-confirmation()
PARAMETERS-nil
RETURN TYPE-nil
TASK-prints the seat confirmation

FUNCTION NAME-cancellation()
PARAMETERS-nil
RETURN TYPE-nil
TASK-cancels the seat with pnrno.
FUNCTION NAME-reservation()
PARAMETERS-nil
RETURN TYPE-nil
TASK-reserves the seat in particular class and prints the amount to be
paid and says whether it is confirm or waiting.

CLASS NAME-train()
DATA MEMBERS-no.of 1stclass, no.of 2ndclass, no.of 3rdclass, no.of
sleeper, total seats, train name, starting point, destination point.
MEMBER FUNCTIONS- Get input, output, get train name,
get train no, get no.of ac class, get no.of 1stclass, get no.of
2ndclass, get no.of 3rdclass, get starting point, get destination
OBJECT-tr

MEMBERFUNCTIONS
FUNCTION NAME-getinput()
PARAMETERS-nil
RETURN TYPE-nil
TASK-alows user to enter the train in which he want to travel and
which class.

FUNCTIONNAME-output()
PARAMETERS-nil
RETURNTYPE-nil
TASK-enters the information entered by user

FUNCTIONNAME-gettrainname()
PARAMETERS-nil
RETURNTYPE-string
TASK-returns train name

FUNCTIONNAME-gettrainno()
PARAMETERS-nil
RETURNTYPE-integer
TASK-returns train number

FUNCTIONNAME-getno_ofac1stclass()
PARAMETERS-nil
RETURNTYPE-integer
TASK-returns first class tickets booked

FUNCTIONNAME-getno_ofac2ndclass()
PARAMETERS-nil
RETURNTYPE-integer
TASK-returns no.of second class tickets booked
FUNCTION NAME-ret_token()
PARAMETERS-nil
RETURNTYPE-integer
TASK-returns the value of an student’s token number

FUNCTION NAME-getno_ofac3rdclass
PARAMETERS-nil
RETURNTYPE-integer
TASK-returns no.of 3rdclass seats booked

FUNCTIONNAME-getno_ofsleeper()
PARAMETERS-nil
RETURNTYPE-integer
TASK-returns no.of sleeper seats booked

FUNCTION NAME-getstartingpt
PARAMETERS-nil
RETURNTYPE-string
TASK-returns the starting point

FUNCTION NAME-getdestination()
PARAMETERS-nil
RETURNTYPE-string
TASK-returns destination

NON-MEMBER FUNCTION-

FUNCTIONNAME-menu()
PARAMETERS-nil
RETURNTYPE-nil
TASK-calls get input, output, reservation, cancellation, display
and creates files trdetails.dat and tickdetails.dat
PROGRAM
LISTING
# HEADER
frompickleimportload,dumpi
mporttime
importrandom
importos
# CLASSTICKETS
classtickets:
def init
(self):self.no_ofac1
stclass=0self.totaf=0sel
f.no_ofac2ndclass=0sel
f.no_ofac3rdclass=0sel
f.no_ofsleeper=0self.n
o_oftickets=0self.name
=''
self.age=''self.res
no=0self.status='
' \
# RETURNSRESERVATIONNUMBER
def
ret(self):return(s
elf.resno)
# RETURNSNAME
def
retname(self):ret
urn(self.name)
# DISPLAYSTHEDATA
defdisplay(self):
f=0
fin1=open("tickets.dat","rb")i
fnot fin1:
print"ERROR"
else:
print
n=int(raw_input("ENTERPNRNUMBER:"))pr
int"\n\n"
print("FETCHINGDATA...".center(80))ti
me.sleep(1)
print
print('PLEASE
WAIT...!!'.center(80))time.sleep(1)
os.system('cls')
try:
while
True:tick=load
(fin1)
if(n==tick.ret()):
f=1
print"="*80
print("PNRSTATUS".center(80))
print"="*80
print
print"PASSENGER'SNAME:",tick.namep
rint
print"PASSENGER'SAGE:",tick.agep
rint
print"PNRNO:",tick.resnop
rint
print"STATUS:",tick.status
print
print"NOOFSEATSBOOKED:",tick.no_ofticketsprin
t
except:
passfin1.
close()if(f=
=0):
print
print"WRONGPNRNUMBER..!!"
print
def
pending(self):self.status="WAITI
NGLIST"print"PNRNUMBER:",s
elf.resnoprint
time.sleep(1.2)
print"STATUS=",self.statusp
rint
print"NOOFSEATSBOOKED:",self.no_ofticketspri
nt
def confirmation
(self):self.status="CONFIRM
ED"
print"PNRNUMBER:",self.resnopr
int
time.sleep(1.5)
print"STATUS=",self.statusp
rint
defcancellation(self):
z=0
f=0fin=open("tickets.dat","rb"
)fout=open("temp.dat","ab")
print
r=int(raw_input("ENTERPNRNUMBER:"))try
:
while(True):tick
=load(fin)z=t
ick.ret()if(z!=
r):
dump(tick,fout)
elif(z==r):
f=1
except:
passfin.c
lose()fout.c
lose()
os.remove("tickets.dat")os.rename(
"temp.dat","tickets.dat")if(f==0):
print
print"NOSUCHRESERVATIONNUMBERFOUND"
printtime.sleep
(2)os.system('c
ls')
else:
print
print"TICKETCANCELLED"
print
# RESERVESTHETICKET
defreservation(self):
trainno=int(raw_input("ENTERTHETRAINNO:"))z
=0
f=0fin2=open("trdetails.da
t")fin2.seek(0)
ifnotfin2:
print"ERROR"
else:
try:
while
True:tr=load(fin2)
z=tr.gettrainno()n=
tr.gettrainname()if(
trainno==z):
print
print"TRAINNAMEIS:",n
f=1p
rint
print "-
"*80no_ofac1st=tr.getno_ofac1stcla
ss()no_ofac2nd=tr.getno_ofac2ndcla
ss()no_ofac3rd=tr.getno_ofac3rdcla
ss()no_ofsleeper=tr.getno_ofsleeper
()
if(f==1):fout1=open("tickets.dat","ab
")print
self.name=raw_input("ENTERTHEPASSENGER'S
NAME")
print
self.age=int(raw_input("PASSENGER'SAGE:"))p
rint
print"\t\t SELECTACLASSYOUWOULDLIKETO
TRAVELIN:-"
print"1.ACFIRSTCLASS"
print
print"2.ACSECONDCLASS"
print
print"3.ACTHIRDCLASS"
print
print"4.SLEEPERCLASS"
print
c=int(raw_input("\t\t\tENTERYOURCHOICE="))os
.system('cls')
amt1=0i
f(c==1):
self.no_oftickets=int(raw_input("ENTERNO_OF
FIRSTCLASSACSEATSTOBEBOOKED:"))
i=1while(i<=self.no_oftickets
):
self.totaf=self.totaf+1amt1=1
000*self.no_ofticketsi=i+1
print
print"PROCESSING..",
time.sleep(0.5)
print
".",time.sleep(
0.3)print'.'time
.sleep(2)os.sys
tem('cls')
print"TOTALAMOUNTTO BEPAID=",amt1
self.resno=int(random.randint(1000,2546))
x=no_ofac1st-
self.totafprint
if(x>0):
self.confirmation()d
ump(self,fout1)brea
k
else:
self.pending()du
mp(tick,fout1)br
eak
elif(c==2):
self.no_oftickets=int(raw_input("ENTERNO_OF
SECONDCLASSACSEATSTOBEBOOKED:"))
i=1while(i<=self.no_oftickets
):
self.totaf=self.totaf+1amt1=9
00*self.no_ofticketsi=i+1
print
print"PROCESSING..",
time.sleep(0.5)
print
".",time.sleep(
0.3)
print'.'time.sle
ep(2)os.system
('cls')
print"TOTALAMOUNTTO BEPAID=",amt1
self.resno=random.randint(1000,2546)
x=no_ofac2nd-self.totaf
printif(
x>0):
self.confirmation()d
ump(self,fout1)brea
k
else:
self.pending()du
mp(tick,fout1)br
eak

elif(c==3):self.no_oftickets=int(raw_input("ENTER
NO_OF
THIRDCLASSACSEATSTOBEBOOKED:"))
i=1while(i<=self.no_oftickets
):
self.totaf=self.totaf+1amt1=800*self.no_oftick
ets
i=i+1
print
print"PROCESSING..",
time.sleep(0.5)
print
".",time.sleep(
0.3)print'.'time
.sleep(2)os.sys
tem('cls')
print"TOTALAMOUNTTO BEPAID=",amt1
self.resno=random.randint(1000,2546)
x=no_ofac3rd-self.totaf
printif(
x>0):
self.confirmation()d
ump(self,fout1)brea
k
else:
self.pending()du
mp(tick,fout1)br
eak
elif(c==4):
self.no_oftickets=int(raw_input("ENTERNO_OF
SLEEPERCLASSSEATSTOBEBOOKED:"))
i=1while(i<=self.no_oftickets
):
self.totaf=self.totaf+1amt1=5
50*self.no_ofticketsi=i+1
print
print"PROCESSING..",
time.sleep(0.5)
print
".",time.sleep(
0.3)print'.'time
.sleep(2)os.sys
tem('cls')
print"TOTALAMOUNTTO BEPAID=",amt1
self.resno=random.randint(1000,2546)
x=no_ofsleeper-self.totaf
printif(
x>0):
self.confirmation()d
ump(self,fout1)brea
k
else:
self.pending()du
mp(tick,fout1)br
eak
except:
passif
(f==0):
time.sleep(2)
print"\n\n\n\n\n\n\t\t\t\tNOSUCHTRAINSFOUND!!"ti
me.sleep(2)
print
print
print
# CLASSTRAIN
classtrain:
def init
(self):self.trainno=
0self.no_ofac1stclass=
0self.no_ofac2ndclass=
0self.no_ofac3rdclass=
0self.no_ofsleeper=0se
lf.totalseats=0
self.trainname=''s
elf.startingpt=""s
elf.destination=''
# GETSINPUT
defgetinput(self):
print"="*80
print"\t\t\tENTERTHETRAINDETAILS"pri
nt
print"="*80
self.trainname=raw_input("ENTERTHETRAINNAME:").upp
er()
print
self.trainno=int(raw_input("ENTERTHETRAINNUMBER:"))pr
int
self.no_ofac1stclass=int(raw_input("ENTERNO_OFACFIRSTCLA
SSSEATSTOBERESERVED:"))
print
self.no_ofac2ndclass=int(raw_input("ENTER NO_OF
ACSECONDCLASSSEATSTOBERESERVED:"))
print
self.no_ofac3rdclass=int(raw_input("ENTER NO_OF
ACTHIRDCLASSSEATSTOBERESERVED:"))
print
self.no_ofsleeper=int(raw_input("ENTERNO_OFSLEEPER
CLASSSEATSTOBERESERVED:"))
print
self.startingpt=raw_input("ENTERTHESTARTINGPOINT:")pr
int
self.destination=raw_input("ENTERTHEDESTINATION
POINT: ")
os.system('cls')
# DISPALYSDATA
def
output(self):p
rint"="*80pri
nt
print"THEENTEREDTRAINNAMEIS:",self.trainnameprin
t"THETRAINNUMBER IS :",self.trainno
print"STARTINGPOINTENTEREDIS:",self.startingpt
print"DESTINATIONPOINTENTEREDIS:",self.destinationpri
nt"NO_OFACFIRSTCLASSSEATSRESERVED
ARE:",self.no_ofac1stclass
print"NO_OFACSECONDCLASSSEATSRESERVED
ARE:",self.no_ofac2ndclass
print"NO_OFACTHIRDCLASSSEATSRESERVED
ARE:",self.no_ofac3rdclass
print"NO_OFSLEEPERCLASSSEATSRESERVED
ARE:",self.no_ofsleeper
print
print"="*80
#
RETURNSTRAINNAME,NUMBER,CLASS,STARTING
PT.,DESTINATION
def
gettrainname(self):ret
urn(self.trainname)
def
gettrainno(self):ret
urn(self.trainno)
def
getno_ofac1stclass(self):retur
n(self.no_ofac1stclass)
def
getno_ofac2ndclass(self):retu
rn(self.no_ofac2ndclass)
def
getno_ofac3rdclass(self):retur
n(self.no_ofac3rdclass)
def
getno_ofsleeper(self):ret
urn(self.no_ofsleeper)
def
getstartingpt(self):ret
urn(self.startingpt)
def
getdestination(self):ret
urn(self.destination)
# MAIN
#
CALLSALLTHEFUNCTIONSACCORDINGTOU
SERCHOICE.
def
menu():tr=tr
ain()tick=tic
kets()print
print"WELCOMETODIVESHAGENCY".center(80)
whileTrue:
print
print"="*80
print"\t\t\t\tRAILWAY"pr
int
print"="*80
print
print"\t\t\t1.**UPDATETRAINDETAILS."pr
int
print"\t\t\t2.TRAINDETAILS."pr
int
print"\t\t\t3.RESERVATIONOFTICKETS."pr
int
print"\t\t\t4.CANCELLATIONOFTICKETS."
print
print "\t\t\t5. DISPLAY PNR
STATUS."print
print "\t\t\t6.
QUIT."print"**-
officeuse. ..................... "
ch=int(raw_input("\t\t\tENTERYOURCHOICE:"))os
.system('cls')
print"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t\
t\tLOADING..",
time.sleep(1)p
rint
("."),time.sleep
(0.5)print
(".")time.sleep
(2)os.system('c
ls')ifch==1:
j="*****"
r=raw_input("\n\n\n\n\n\n\n\n\n\n\n\t\t\t\tENTERTHEPASSW
ORD:")
os.system('cls')
if(j==r):
x='y'
while(x.lower()=='y'):
fout=open("trdetails.dat","ab")tr.getinp
ut()
dump(tr,fout)
fout.close()
print"\n\n\n\n\n\n\n\n\n\n\n\t\t\tUPDATINGTRAIN
LISTPLEASEWAIT..",
time.sleep(1)p
rint
("."),time.sleep
(0.5)print
("."),time.sleep
(2)os.system('c
ls')
print"\n\n\n\n\n\n\n\n\n\n\n"
x=raw_input("\t\tDOYOUWANTTOADDANYM
ORETRAINSDETAILS?")
os.system('cls')
continue
elif(j<>r):print"\n\
n\n\n\n"
print"WRONGPASSWORD".center(80)e
lif ch==2:
fin=open("trdetails.dat",'rb')i
fnot fin:
print"ERROR"
else:
try:
while
True:print"
*"*80
print"\t\t\t\tTRAINDETAILS"
print"*"*80
printtr=loa
d(fin)
tr.output()

raw_input("PRESSENTERTOVIEWNEXTT
RAINDETAILS")
os.system('cls')
exceptEOFError:
pass
elifch==3:
print'='*80
print"\t\t\t\tRESERVATIONOFTICKETS"p
rint'='*80
print
tick.reservation()
elif ch==4:
print"="*80
print"\t\t\t\tCANCELLATIONOFTICKETS"
print
print"="*80
print
tick.cancellation()
elif ch==5:
print"="*80
print("PNRSTATUS".center(80))
print"="*80
printtick.disp
lay()
elifch==6:
quit()
raw_input("PRESSENTERTOGOTOBACK
MENU".center(80))
os.system('cls')print"\t\t\t\tWELCOME
TOGSSRAILWAYS"print
print"\n\n\n\n\t\t\tBy:-"
print"\t\t\t\tN.DIVESH\n\t\t\t\tXII-A1\n\t\t\t\t12104"
print"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t\t\tLOA
DING..",
time.sleep(1)p
rint
("."),time.sleep
(0.5)print
(".")time.sleep
(2)os.system('c
ls')menu()
print”\t\t\t\t\n\n\n\n\n\tTHANKYOU ..... ”
print”\n\t\t\t\DONEBY:-
“print”\t\t\t\t
N.DIVESH”print”\t\t\t\t
XII-
A1”print”\t\t\t\t12104”
print"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t\t\tLOA
DING..",
time.sleep(1)p
rint
("."),time.sleep
(0.5)print
(".")time.sleep
(2)os.system('c
ls')
`

SCREEN
SHOTS

You might also like