0% found this document useful (0 votes)
33 views

CS Project Class XII

Uploaded by

2401200010
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)
33 views

CS Project Class XII

Uploaded by

2401200010
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/ 19

RAILWAY

RESERVATION
SYSTEM

Submitted By : Rashi Rajput


Class : XII-A (Computer Science)

Roll No : 31
Ramjas Public school (Day Boarding), Anand Parbat,
DELHI

RAILWAY RESERVATION SYSTEM age 1


INDEX
1. Acknowledgment
2. Certificate
3. Aim of Project
4. Program Code
5. Output
6. Bibliography

RAILWAY RESERVATION SYSTEM age 2


ACKNOWLEDGMENT

I have made this project under the kind guidance of our


Teacher Mr. Vinay Kumar Pandey. I am also thankful to
the principal Mrs. Sarika Arora to provide me an
environment in the school to develop this project.

Rashi Rajput
XII-A (Computer Science)
Roll No. : 31
Ramjas Public School (Day Boarding)
Anand Parbat, New Delhi

RAILWAY RESERVATION SYSTEM age 3


CERTIFICATE

This is to certify that Rashi Rajput of Class XII-


A has completed this project under my
guidance. I wish her all the best for her
Examination.

(VINAY KUMAR PANDEY)


PGT (COMPUTER SCIENCE)
Ramjas Public School (Day Boarding)
Anand Parbat, New Delhi

RAILWAY RESERVATION SYSTEM age 4


AIM OF THE
PROJECT
The main objective of the Railway Reservation
System is to manage the details of
Train,Booking,Ticket. It manages all the in-
formation about Train, Customer, Ticket,
Train. The project is totally built at
administrative end and thus only the ad-
ministrator is guaranteed the access. The
purpose of the project is to build an
application program to reduce the manual
work for managing the Train, Booking,
Customer. It tracks all the details about the
Passangers.

RAILWAY RESERVATION SYSTEM age 5


Program
Code

RAILWAY RESERVATION SYSTEM age 6


import random

import pickle

def main_menu():

while True:

print('\n')

print("Welcome to Railway Reservation System")

print("1. Book Tickets")

print("2. View Details")

print("3. Cancel Tickets")

print("4. Sign in as Administrator")

print("5. Exit")

choice = int(input("Enter your choice: "))

if choice==1:

global s

global d

global date1

s=input('Enter The Source city: ')

d=input('Enter The Destination city: ')

date1=input('Enter The Date(YYYY-MM-DD): ')

user_menu()

elif choice==2:

pnr = int(input("Enter PNR number: "))

RAILWAY RESERVATION SYSTEM age 7


display_ticket(pnr)

elif choice==3:

pnr = int(input("Enter PNR number: "))

cancel_ticket(pnr)

elif choice == 4:

while True:

admin=input("Username:")

if admin=='Rashi':

while True:

password=input("Password:")

if password=='RR@2509':

print("~~~~~~~Admin login Successfull~~~~~~~~~")

print("-----------------------------------------------------------------------")

while True:

print('\n')

print("1. View all tickets")

print("2. to exit")

c=int(input("Enter your choice:"))

if c==1:

display_all_tickets()

elif c==2:

break

else:

print('Wrong Choice, Please try again')

break

RAILWAY RESERVATION SYSTEM age 8


else:

print('Incorrect Password, Try Again')

break

elif choice == 5:

print("Have a safe journey!")

exit()

else:

print("Invalid choice. Try again.")

main_menu()

def user_menu():

print('----------------------------------------------')

print('Available Trains on',date1,'are:')

print('----------------------------------------------')

trains = generate_trains()

display_trains(trains)

choice = int(input("Enter train number: "))

if choice < 1 or choice > len(trains):

print("Invalid choice. Try again.")

user_menu()

else:

train = trains[choice-1]

pnr = random.randint(100000, 999999)

print("PNR Number:", pnr)

RAILWAY RESERVATION SYSTEM age 9


details = get_details()

save_ticket(pnr, train, details)

print("Ticket booked successfully!")

cities = ["Delhi", "Mumbai", "Chennai", "Kolkata", "Bangalore"]

train_names = ["Rajdhani ", "Shatabdi ", "Mahaman", "Maharaja", "Gatimaan"]

def generate_trains():

trains = []

for i in range(5):

train = {}

train["name"] = random.choice(train_names)

train["time"] = str(random.randint(1, 12)) + random.choice(["AM", "PM"])

train['source']=s

train['destination']=d

train['date']=date1

trains.append(train)

a=open('initial.dat','wb')

pickle.dump(trains,a)

a.close()

return trains

def display_trains(trains):

print("Train No.\tExpress Name\t\t Source\t\tDestination\t\tTime")

print("-----------------------------------------------------------------------------------------------------------------")

for i, train in enumerate(trains):

print(str(i+1),'\t\t', train["name"],'\t\t',train['source'],'\t\t',train

RAILWAY RESERVATION SYSTEM age 10


['destination'],'\t\t',train["time"])

def get_details():

details = {}

details["name"] = input("Enter name: ")

details["age"] = input("Enter age: ")

details["gender"] = input("Enter gender: ")

details["phone"] = input("Enter phone number: ")

return details

def save_ticket(pnr, train, details):

ticket = {}

ticket["pnr"] = pnr

ticket["train"] = train

ticket['source']=s

ticket['destination']=d

ticket['date']=date1

ticket["details"] = details

with open("tickets.dat", "ab") as f:

pickle.dump(ticket, f)

def display_ticket(pnr):

f=open("tickets.dat", "rb")

while True:

try:

ticket = pickle.load(f)

if ticket["pnr"] == pnr:

RAILWAY RESERVATION SYSTEM age 11


print("PNR Number:", ticket["pnr"])

print("Train Name:", ticket["train"]["name"])

print('Source:',ticket['source'])

print('Destination:',ticket['destination'])

print('Date:',ticket['date'])

print("Time:", ticket["train"]["time"])

print("Name:", ticket["details"]["name"])

print("Age:", ticket["details"]["age"])

print("Gender:", ticket["details"]["gender"])

print("Phone:", ticket["details"]["phone"])

break

except EOFError:

break

f.close()

##sd

def display_all_tickets():

f=open("tickets.dat", "rb")

print("PNR No.\t Express\t Source\t\tDestination\t\tName\t\tAge\t\tGender\t Phone")

print("----------------------------------------------------------------------------------------------------------------------------")

while True:

try:

ticket = pickle.load(f)

print(str(ticket["pnr"]),'\t',ticket["train"]["name"]

,'\t',ticket['train']['source'],'\t\t',ticket['train']['destination']

,'\t\t',ticket["details"]["name"],'\t\t',ticket["details"]["age"]

RAILWAY RESERVATION SYSTEM age 12


,'\t\t',ticket["details"]["gender"],'\t',ticket["details"]["phone"])

except EOFError:

break

f.close()

print('\n')

def cancel_ticket(pnr):

f=open("tickets.dat", "rb")

tickets = []

while True:

try:

ticket = pickle.load(f)

if ticket["pnr"] == pnr:

print("Ticket cancelled successfully!")

else:

tickets.append(ticket)

except EOFError:

break

f.close()

with open("tickets.dat", "wb") as f:

for ticket in tickets:

pickle.dump(ticket, f)

main_menu()

RAILWAY RESERVATION SYSTEM age 13


Output

RAILWAY RESERVATION SYSTEM age 14


RAILWAY RESERVATION SYSTEM age 15
RAILWAY RESERVATION SYSTEM age 16
RAILWAY RESERVATION SYSTEM age 17
BIBLIOGRAPHY
RAILWAY RESERVATION SYSTEM age 18
Informatics Practices By Sumita Arora

Informatics Practices by Preeti Arora

Guidance by Vinay Kumar Pandey (PGT Informatics practices Ramjas Day


Boarding, Anand Parbat, DELHI)

RAILWAY RESERVATION SYSTEM age 19

You might also like