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

Untitled Document

Uploaded by

reddygreeshma742
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 views26 pages

Untitled Document

Uploaded by

reddygreeshma742
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/ 26

COMPUTER SCIENCE

PROJECT
SESSION: 2024-2025
Project Topic: Booking Train Tickets System

Name:
Class:
Roll No:
Certificate

This is to certify that_____________ of class 12-A


Has successfully completed the investigatory project
on ‘ TRAIN TICKET BOOKING SYSTEM’. Under the
guidance of____________ during the academic
session 2024-2025 in partial fulfilment of the
Computer Science practical examination conducted
by CBSE.

_________ _________
Signature of signature of
Internal examiner external examiner
ACKNOWLEDGEMENT
I would like to express my special thanks of gratitude
to my respected principal ma’am
Dr Eshwari Prabhakar
and also to my computer science teacher
____________________
Who have gave me the golden opportunity
to do this wonderful project on
‘TRAIN TICKET BOOKING SYSTEM’
And who has also helped me in completing my
project. I came to know about so many new things, I
am really thankful to them.
Secondly , I would also like to thank my parents and
friends who have helped me a lot in finalizing this
project within the limited time frame.
INDEX

1.​Certificate
2.​ Acknowledgement
3.​ Hardware and Software
4.​ Introduction
5.​ Objective of the project
6.​ Core Functionalities
7.​ Significance of the project
8.​ SQLite Databases
9.​ Python Source Code
10.​Output
11.​Bibliography
HARDWARE AND
SOFTWARE REQUIRED

HARDWARE
1.​ Desktop computer/laptop
2.​ Mobile Phone

SOFTWARE
1.​ Python
2.​ SQLite
3.​ Python connector module
INTRODUCTION
A train ticket booking system lets passengers easily
book tickets online, select routes, dates, and seats,
and pay securely. It offers features like instant
confirmation, e-tickets, and booking modifications.
With multiple payment options and real-time
updates, it enhances convenience for travelers and
improves efficiency for railway operators.

Evolution of train ticket booking system


The evolution of train ticket booking systems began
with in-person purchases at stations, followed by
telephone bookings in the mid-20th century. In the
late 1990s, online booking websites allowed
passengers to reserve tickets from home. The 2000s
introduced mobile apps and kiosks for real-time
bookings and e-ticketing, eliminating the need for
paper tickets. Today, integrated systems offer
features like dynamic pricing, seat selection, and
instant updates, making booking faster, easier, and
more accessible while improving efficiency for
railway operators.
Objective Of The Project
The objective of a train ticket booking system is to offer a
convenient, efficient, and user-friendly platform for
passengers to easily reserve tickets for train travel. It aims
to streamline the entire booking process by providing
real-time information on train schedules, seat availability,
and pricing. The system ensures secure payment
transactions through multiple payment methods,
including credit/debit cards and digital wallets, while
offering added features like seat selection, e-tickets, and
booking modifications or cancellations.
Additionally, the system is designed to enhance customer
experience by providing instant confirmation,
personalized recommendations, and timely notifications
about train delays or schedule changes. The goal is not
only to make the booking process quicker and more
accessible for passengers but also to reduce congestion and
wait times at physical ticket counters. For railway
operators, the system helps optimize resource
management, improve revenue generation, and minimize
operational inefficiencies. Ultimately, the objective is to
create a seamless, digital solution that enhances both the
passenger experience and the overall efficiency of train
services.
CORE FUNCTIONS
1. create_db():

●​ Purpose: Sets up the SQLite database and creates the necessary


tables.
●​ Core Actions:
○​ Connects to the SQLite database (train_booking.db).
○​ Creates the trains, users, and bookings tables (if they
don't already exist).
○​ Ensures the database is ready to store and retrieve data
related to trains, users, and bookings.

2. insert_sample_data():

●​ Purpose: Inserts some predefined train data into the database


to simulate available trains.
●​ Core Actions:
○​ Inserts multiple rows of sample data into the trains table
(train name, origin, destination, departure time, and
available seats).

3. view_trains():

●​ Purpose: Displays all available trains along with their details.


●​ Core Actions:
○​ Retrieves all rows from the trains table.
○​ Prints out the train information including ID, name, origin,
destination, departure time, and available seats.
4. book_ticket(user_id, train_id, num_seats):

●​ Purpose: Books a ticket for a user on a selected train.


●​ Core Actions:
○​ Checks the number of available seats for the chosen train.
○​ If there are enough seats, reduces the available seats by the
number of booked seats.
○​ Assigns a seat number for the booking (based on the
highest seat number in the bookings table).

5. view_bookings(user_id):

●​ Purpose: Displays all bookings made by a specific user.


●​ Core Actions:
○​ Retrieves the bookings made by the user from the
bookings table by joining with the trains table to get
train details.
○​ Prints the booking information including booking ID, train
name, origin, destination, departure time, seat number,
and booking time.
Technology Stack

1.​ SQLite
Serves as the backend database, ensuring secure
and structured data storage.

2.​ Python
Acts as the interface for the system.
Features user-friendly, menu driven
programming to simplify navigation and
execution.
SIGNIFICANCE OF THE PROJECT
1.​ Database Integration: Demonstrates how to use SQLite
with Python to manage and store data in a database, a crucial
skill for building data-driven applications.
2.​CRUD Operations: Covers basic Create, Read, Update,
Delete (CRUD) operations, which are essential for
managing data in real-world applications.
3.​Real-World Application: Provides a simple example of a
ticket booking system, simulating a real-world scenario that
can be expanded into more complex systems.
4.​User Interaction: Teaches how to interact with users,
retrieve data, and update it based on user input—core
functionality in most software.
5.​Data Integrity: Ensures that operations like seat booking
are handled correctly by checking available seats and
preventing overbooking.
6.​Scalability: Offers a basic structure that can be easily
extended with additional features like payment processing,
user authentication, and more.
7.​ Python & SQLite Skills: Provides hands-on experience
with Python and SQLite, widely used technologies in
software development for creating database-backed
applications.

In summary, this code is valuable for understanding database


operations, user interaction, and building scalable, real-world
systems.
SQLite Databases:

import sqlite3

def create_db():
# Connect to SQLite database (or create it if
it doesn't exist)
conn = sqlite3.connect('train_booking.db')
cursor = conn.cursor()

# Create tables for trains, users, and


bookings
cursor.execute('''
CREATE TABLE IF NOT EXISTS trains (
train_id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
origin TEXT NOT NULL,
destination TEXT NOT NULL,
departure_time TEXT NOT NULL,
available_seats INTEGER NOT NULL
);
''')

cursor.execute('''
CREATE TABLE IF NOT EXISTS users (
user_id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
email TEXT NOT NULL UNIQUE,
phone TEXT NOT NULL
);
''')
cursor.execute('''
CREATE TABLE IF NOT EXISTS bookings
(
booking_id INTEGER PRIMARY KEY,
user_id INTEGER NOT NULL,
train_id INTEGER NOT NULL,
seat_number INTEGER NOT NULL,
booking_time TEXT NOT NULL,
FOREIGN KEY (user_id) REFERENCES
users(user_id),
FOREIGN KEY (train_id) REFERENCES
trains(train_id)
);
''')
conn.commit()
conn.close()

# Create the database and tables


create_db()
def insert_sample_data():
conn = sqlite3.connect('train_booking.db')
cursor = conn.cursor()

# Insert sample train data


trains = [
('Express 101', 'New York', 'Los Angeles',
'2025-01-20 08:00', 50),
('Fast Train 202', 'Chicago', 'San
Francisco', '2025-01-21 09:30', 40),
('Supertrain 303', 'Miami', 'Seattle',
'2025-01-22 10:15', 60)
]
cursor.executemany('''
INSERT INTO trains (name, origin,
destination, departure_time, available_seats)
VALUES (?, ?, ?, ?, ?)
''', trains)

conn.commit()
conn.close()

# Insert sample data into the trains table


insert_sample_data()
Python Source Code:

import sqlite3
from datetime import datetime

def view_trains():
conn = sqlite3.connect('train_booking.db')
cursor = conn.cursor()

cursor.execute('SELECT * FROM trains')


trains = cursor.fetchall()

print("\nAvailable Trains:")
print("-" * 50)
for train in trains:
print(f"ID: {train[0]}, Name: {train[1]},
From: {train[2]} To: {train[3]}, Departure:
{train[4]}, Seats Available: {train[5]}")
conn.close()

def book_ticket(user_id, train_id,


num_seats):
conn = sqlite3.connect('train_booking.db')
cursor = conn.cursor()

# Check if there are enough available seats


cursor.execute('SELECT available_seats
FROM trains WHERE train_id = ?',
(train_id,))
train = cursor.fetchone()

if train:
available_seats = train[0]
if available_seats >= num_seats:
# Reduce available seats
cursor.execute('UPDATE trains SET
available_seats = available_seats - ? WHERE
train_id = ?', (num_seats, train_id))

# Get the next available seat number


cursor.execute('SELECT
MAX(seat_number) FROM bookings
WHERE train_id = ?', (train_id,))
max_seat = cursor.fetchone()[0] or 0
seat_number = max_seat + 1

# Insert the booking record


booking_time =
datetime.now().strftime('%Y-%m-%d
%H:%M:%S')
cursor.execute('''
INSERT INTO bookings (user_id,
train_id, seat_number, booking_time)
VALUES (?, ?, ?, ?)
''', (user_id, train_id, seat_number,
booking_time))

conn.commit()
print(f"\nBooking successful! Your seat
number is {seat_number}.")
else:
print(f"\nNot enough available seats.
Only {available_seats} seats are available.")
else:
print("\nTrain not found.")

conn.close()

def view_bookings(user_id):
conn = sqlite3.connect('train_booking.db')
cursor = conn.cursor()

cursor.execute('''
SELECT b.booking_id, t.name, t.origin,
t.destination, t.departure_time,
b.seat_number, b.booking_time
FROM bookings b
JOIN trains t ON b.train_id = t.train_id
WHERE b.user_id = ?
''', (user_id,))
bookings = cursor.fetchall()

if bookings:
print("\nYour Bookings:")
print("-" * 50)
for booking in bookings:
print(f"Booking ID: {booking[0]},
Train: {booking[1]}, From: {booking[2]} To:
{booking[3]}, Departure: {booking[4]}, Seat
Number: {booking[5]}, Booking Time:
{booking[6]}")
else:
print("\nYou have no bookings.")

conn.close()
# Test the system
if __name__ == '__main__':
# Let's assume the user has a user_id of 1
for simplicity.
user_id = 1

# View available trains


view_trains()

# Book a ticket (train_id 1, 2 seats)


book_ticket(user_id, 1, 2)

# View user's bookings


view_bookings(user_id)
EXAMPLE OUTPUT:
Available Trains:
--------------------------------------------------
ID: 1, Name: Express 101, From: New York To: Los
Angeles, Departure: 2025-01-20 08:00, Seats
Available: 50
ID: 2, Name: Fast Train 202, From: Chicago To: San
Francisco, Departure: 2025-01-21 09:30, Seats
Available: 40
ID: 3, Name: Supertrain 303, From: Miami To: Seattle,
Departure: 2025-01-22 10:15, Seats Available: 60

Booking successful! Your seat number is 1.

Your Bookings:
--------------------------------------------------
Booking ID: 1, Train: Express 101, From: New York To:
Los Angeles, Departure: 2025-01-20 08:00, Seat
Number: 1, Booking Time: 2025-01-18 10:45:32
BIBLIOGRAPHY

1.Python.org. (2023). "Python


Documentation." Retrieved from
https://docs.python.org/3/
2. Chatgpt
3.
https://www.slideshare.net/slideshow/co
mputer-project-final-for-class-12-student
s/43575351

You might also like