Cs Synopsis

Download as pdf or txt
Download as pdf or txt
You are on page 1of 27

DR RAJU DAVIS INTERNATIONAL SCHOOL

A SENIOR SECONDARY SCHOOL AFFILIATED TO CBSE NEW DELHI,931314


MALA, THRISSUR, KERALA

SENIOR SCHOOL CERTIFICATE EXAMINATION


PROJECT RECORD

COMPUTER SCIENCE (083)

Name : ………………………………………………………………………..……
Reg No. : …………………………………………………………………………
Certified that this is a bonafide record of project work done by
Mr. /Mrs. : ………………………………………………………………………….
In this school and submitted for the practical examination on:
………………………………………………………………………………………

Teacher In-Charge : ………………………………………………………………

……………………………… …………………………..

External Examiner Principal


ACKNOWLEDGEMENT
In the successful completion of this Project……………………………………………………………………
……………………………………………………………………………………… as a part of the partial fulfillment
of the Internal Assessment of the subject…………………………………based on the
guidelines of the Central Board of Secondary Education, many have contributed
their effort and wholehearted support to me. Here, I take this opportunity to
thank each one of them in a special manner.

At first, I thank God Almighty, who has granted me the power of intelligence and
knowledge to prepare this project in a beautiful way with perfection.

Secondly, I thank our Principal, who made her timely intervention and gave advice on
various occasions. I also thank our Subject Teacher, who shared her valuable
guidance and suggestions for the progress of the project. Her valuable guidance has
helped me to patch the work and complete the project successfully.

Then I would like to thank my parents and friends who have helped me with their
valuable suggestions during the various phases of this project.

Lastly, I express my sincere thanks to my dear classmates who have helped me to


collect data from different sources to complete the project.

I hereby submit this project for your acceptance and evaluation,

….………………………………………………
INDEX

Sl.No CONTENTS Pg.No


1 INTRODUCTION 1
2 ABOUT THIS PROJECT 2-4
3 CONCEPT USED 5-7
4 PROGRAM MODULE 8
HARDWARE AND
5 SOFTWARE 9
REQUIREMENTS

6 SOURCE CODE 10 - 18
7 OUTPUT 19 - 23
8 BIBLIOGRAPHY 24
INTRODUCTION

PYTHON

Python is a high-level, general-purpose programming language. Its design philosophy


emphasizes code readability with the use of significant indentation. Python is dynamically
typed and garbage-collected. It supports multiple programming paradigms, including
structured (particularly procedural), object-oriented and functional programming. It is often
described as a "batteries included" language due to its comprehensive standard library.

Python consistently ranks as one of the most popular programming languages, and has
gained widespread use in the machine learning community.

Why python?

•Python is a cross platform language (works in windows, Mac, Linux, etc.)

•It has simple syntax similar to the English language.

•Python runs on an interpreter system, meaning that code can be executed as soon as it is
written. This means that prototyping can be very quick.

•Python can be treated in a procedural way, an object-oriented way or a functional way.

1
ABOUT THIS PROJECT

PREFACE
The project "Kochi Metro Ticket Booking System" was inspired by the need for
streamlined, efficient, and user-friendly metro booking solutions. With the increasing
number of metro commuters in Kochi, having a digital platform that allows people to
book tickets, view bookings, and manage travel details became essential. Through this
project, we would bridge the gap between traditional ticketing methods and a more
accessible, digital alternative. In using concepts such as programming, file handling, and
databases, the project reflects an interest in creating solutions to enhance convenience in
daily lives and how technology can improve public services.

INTRODUCTION TO PROJECT
The Kochi Metro Ticket Booking System is a Python-based project that allows users to
register, log in, and book tickets easily for the metro. While booking, the user can select
the departure and destination stations, choose dates of travel, and mention how many
passengers. The system will calculate the fare based on distance and the passenger count,
which provides a total cost for the journey. Also, user bookings can be viewed or
cancelled. This project encompasses database management for fare and user information
combined with file handling for user and booking information, focusing on streamlining
the process of ticketing and doing away with several problems arising from manual
ticketing such as errors and the long queue.

OBJECTIVE OF THE PROJECT


The prime objectives of the Kochi Metro Ticket Booking System are:

1. Simplify Booking: This system allow easy booking of a metro ticket. Thus, users
may easily enter the travel details, compute fares, and obtain tickets.
2. Data Management: Manage user information, booking history, and calculate
fares efficiently by the data handling practices that assure data safety.
3. User Convenience: Provide viewing and cancelling facilities, as frequent
travellers may change the travel plans.
4. Automation: Reduce the reliance on manual ticket booking by providing an
electronic alternative, thereby reducing waiting times and enhancing the user
experience

2
SCOPE OF THE PROJECT

The Kochi Metro Ticket Booking System will go beyond simple ticket booking to
potential future additions such as:
1. Payment Systems Integration: Include online payment options to complete the
purchase of tickets electronically.
2. Real-time Updates: Online updates of train timings and stations ensuring timely
planning
3. Mobile friendly: Availability in mobile, web version and mobile-friendly to
ensure wider reach
4. Security: To protect user’s sensitive data with various encryptions and secure
authentications

The project mainly targets the metro commuters, administrators managing fares, and
other metro operation staff who may find automation useful.

PRESENT SYSTEM
Currently, the booking of tickets to the metro is mainly carried out at the stations. Here,
the passengers queue up for booking their tickets at the counter or machines at the ticket
counter. This is a totally manual system with a lot of shortcomings:

1. It is time-consuming: It normally take longer hours at the peak and that will cause
some delay in their journey and even crowd the area
2. Human Error: Calculation error of fare or mistakes in entry due to typing error
etc.
3. Limited flexibility: The passenger cannot cancel or change his booking easily.

As the commuter base for metro services grows the above drawbacks affect user
experience and operational performance, and it is rather a must-have ticketing system
that is more automated, flexible, and accessible.

PROPOSED SYSTEM

Kochi Metro Ticket Booking System can remove the problems present in the current
ticketing process and provide a digital mode for booking, viewing, and cancellation of
metro tickets. The characteristics of the proposed system are;

1. Automated Fare Calculation: Users can choose origin and destination stations
and then according to the distance between them and the count of passengers, the
system will automatically calculate the fare.
2. User Account Management: The features of registration and login allow them to
log in with secure access to their bookings.

3
3. Easy Accessibility: Enables users to book tickets, view history of bookings as well
as cancel their tickets in case the plan change
4. Data Security: The use of file handling and database management assures that user
credentials and booking details are stored safely.

The proposed system not only improves user experience by providing a quick, reliable
alternative to manual booking but also reduces wait times and minimizes human errors,
making metro travel more efficient.

4
CONCEPT USED
FLOW OF CONTROL
A program's control flow is the order in which the program's code executes. The control
flow of a Python program is regulated by decision making statements, loops, iterations
and function calls.

Decision making statements:

Decision making is prediction of conditions arising when the program is being executed
and defining actions to be performed based on the arising conditions. Decision structures
perform several expressions that yield a result of either TRUE or FALSE. Some of the
decision-making statements are if, else, etc.

if statement: If statements are control flow statements which helps us to run a particular
code only when a certain condition is satisfied.

else statement: An else statement consists of a block of code that will be executed if the
expression in the if statement is 0 or a FALSE value. An else statement is an optional
statement, and there may be at most only one else statement following if.

Iteration:

Repeating identical or similar tasks without making errors is something that computers do
well and people do poorly. Repeated execution of a set of statements is called iteration.
Because iteration is so common, Python provides several language features to make it
easier. There are two types of iterations are there, definite iteration (for loops) and
indefinite iteration (while loops).

for loops: For loops are used when we have a block of code which you want to repeat a
fixed number of times.

while loops: A while loop statement in Python programming language repeatedly


executes a target statement as long as a given condition is true

FUNCTION
A function is a reusable block of code that performs a specific task. A function only runs
when it is called and can accept inputs, known as parameters, to work with. Functions
help make code modular, organized, and easier to maintain. They can also return data as
output using the return statement. Functions are defined using the def keyword followed
by the function name and parentheses.

5
MODULE
A module lets you logically group your Python code. Grouping related code into a
module makes it easier to read and more convenient to work with. A module is a Python
object with attributes of arbitrarily named values which you may bind and reference.
Briefly, it is an ordinary file that contains your Python code. A module can define any
number of functions, classes, variables. A module can also include runnable code.
Modules may be imported from other files written in Python in order to access their
functionalities there.

MY SQL
MySQL is a relational database management system. Databases are the essential data
repository for all software applications. For example, whenever someone conducts a web
search, logs in to an account, or completes a transaction, a database system is storing the
information so it can be accessed in the future.

A relational database stores data in separate tables rather than putting all the data in one
big storeroom. The database structure is organized into physical files optimized for
speed. The logical data model, with objects such as data tables, views, rows, and
columns, offers a flexible programming environment. You set up rules governing the
relationships between different data fields, such as one to one, one to many, unique,
required, or optional, and “pointers” between different tables.

The database enforces these rules so that with a well-designed database your application
never sees data that’s inconsistent, duplicated, orphaned, out of date, or missing.

FILE HANDLING
File handling is an important feature in Python wherein programs can interact with the
files to read, write, and manage data, which is very useful where data persistence is
required-for example, storing the information of users, maintaining booking records, or
for log files. Files in Python open using the open() function by specifying the file name
with an access mode like reading 'r', writing 'w' and appending 'a'. For instance, 'r' mode
opens a file for reading and returns an error if the file does not exist, while 'w' mode
opens a file for writing and truncates any existing content; it creates the file if it doesn't
already exist. The 'a' mode allows data to be added to the end of the file without altering
the existing content. If the file does not exist, it will be created.

After a file has been opened, Python offers several methods to read the content of that
file. For example, the entire content can be read by using read(), or just one line by using
readline(). Using readlines() can get all lines as a list. Writing to a file can be done using
methods such as write() to append a single string or writelines() to write a list of strings
at once. After file operations, it is good practice to close the file using the close()
function to free up system resources.

6
Python also includes a convenient with statement for file handling, which automatically
opens and closes files even if there is an error during the execution of file operations.
This makes file handling in Python robust and easy to use since it ensures proper
management of files without the need to manually close them. All in all, file handling in
Python is a robust tool that supports applications with the need for persistent data storage
without necessarily using a database.

7
PROGRAM MODULES

Login module
The Login module is a portal module that allows users to type a user name and password to
log in.

This module contains other modules which act as sub modules for this. Options include book
tickets, view bookings, Cancel bookings.

Register module
The Module helps in creation of a new login credentials for a new customer. It also checks in
for any duplicate usernames so as there is not an issue of security.

8
HARDWARE AND SOFTWARE
REQUIREMENTS

1.Operating System: Windows 7 and above


2.Processor: PENTIUM (any) or AMD ATHALON (3800+ - 4200+ DUAL
CORE)
3.Motherboard: 1.845 or 915, 995 for PENTIUM or MSI K9MM- V VIA
K8M800+8237R PLUS CHIPSE for AMD ATHALON
4.RAM: 512MB+
5.Hard disk: SATA 40 GB or above
6.Monitor: 14.1 or 15-17 INCH
7.Keyboard and Mouse

9
SOURCE CODE

import os
import mysql.connector as mycon
try:
mydbs=mycon.connect(host="localhost",user="root",pass
word="mysql",database="metro")
c=mydbs.cursor()
c.execute("create database if not exists metro")
c.execute("use metro")
except Exception as e:
print(f"Error during registration: {e}")

# File paths
USERS_FILE = 'data/users.txt'
BOOKINGS_FILE = 'data/bookings.txt'

# Ensure the data directory exists


os.makedirs('data', exist_ok=True)

# Function to register a new user


def register_user():
try:
username = input("Enter username: ")
password = input("Enter password: ")

# Check if user already exists


with open(USERS_FILE, 'r') as f:
users = f.readlines()

for i in users:
if username in i:
print("Username already exists. Please
choose another one.")
return

10
# Add new user
with open(USERS_FILE, 'a') as f:
f.write(f"{username},{password}\n")

print("User registered successfully.")


except Exception as e:
print(f"Error during registration: {e}")

# Function to log in
def login_user():
try:
username = input("Enter username: ")
password = input("Enter password: ")

with open(USERS_FILE, 'r') as f:


users = f.readlines()

for user in users:


user_info = user.strip().split(',')
if user_info[0] == username and
user_info[1]== password:
print("Login successful.")
return username

print("Invalid credentials. Please try again.")


return None
except FileNotFoundError:
print("User data file not found. Please register
first.")
except Exception as e:
print(f"Error during login: {e}")

# Function to book a ticket


def book_ticket(username):
try:
print("+------------------------+")
print("| STATION |")
print("+------------------------+")

11
print("| ALUVA |")
print("| PULINCHODU |")
print("| COMPANYPADY |")
print("| AMBATTUKAVU |")
print("| MUTTOM |")
print("| KALAMASSERRY |")
print("| COCHIN UNIVERSITY |")
print("| PATHADIPALAM |")
print("| EDAPALLY |")
print("| CHANGAMPUZHA |")
print("| PALARIVATTOM |")
print("| JLN STADIUM |")
print("| KALOOR |")
print("| TOWN HALL |")
print("| MG ROAD |")
print("| MAHARAJAS |")
print("| ERNAKULAM SOUTH |")
print("| KADAVANTHRA |")
print("| ELAMKULAM |")
print("| VYTILLA |")
print("| THAIKOODAM |")
print("| PETTA |")
print("| VADAKKEKOTTA |")
print("| SN JUNCTION |")
print("| THRIPUNITHURA TERMINAL |")
print("+------------------------+")

month=[“01”,”02”,”03”,”04”,”05”,”06”,”07”,”08”
“09”,”10”,”11”,”12”]

day=[“01”,”02”,”03”,”04”,”05”,”06”,”07”,”08”,”09”
“10”,”11”,”12”,”13”,”14”,”15”,”16”,”17”,”18”,”19”
“20”,”21”,”22”,”23”,”24”,”25”,”26”,”27”,”28”,”29”,
“30”,”31”]
origin = input("Enter origin station:").upper()
.replace(" ","_")

12
destination = input("Enter destination station:").upper()
travel_date = input("Enter travel date (YYYY-MM-
DD): ")
l = travel_date.split('-')
if len(l[0]) == 4:
if l[1] in month:
if l[1] == '01':
if not l[2] in day[0:31]:
print("Invalid day")
return
elif l[1] == '02':
if not l[2] in day[0:28]:
print("Invalid Day")
return
elif l[1] == '03':
if not l[2] in day[0:31]:
print("Invalid Day")
return
elif l[1] == '04':
if not l[2] in day[0:30]:
print("Invalid Day")
return
elif l[1] == '05':
if not l[2] in day[0:31]:
print("Invalid Day")
return
elif l[1] == '06':
if not l[2] in day[0:30]:
print("Invalid Day")
return
elif l[1] == '07':
if not l[2] in day[0:31]:
print("Invalid Day")
return
elif l[1] == '08':
if not l[2] in day[0:31]:
print("Invalid Day")
return

13
elif l[1] == '09':
if not l[2] in day[0:30]:
print("Invalid Day")
return
elif l[1] == '10':
if not l[2] in day[0:31]:
print("Invalid Day")
return
elif l[1] == '11':
if not l[2] in day[0:30]:
print("Invalid Day")
return
elif l[1] == '12':
if not l[2] in day[0:31]:
print("Invalid Day")
return
else:
print("Invalid Month")
return

else:
print("Invalid Format")
return
num_passengers = int(input("Enter number of
passengers: "))
query=f"select fare from {origin} where station =
'{destination}'"
c.execute(query)
origin=origin.replace("_"," ")
result = c.fetchone()

if result is None:
print("Invalid destination station.")
return

14
fare = 0

for i in result:
fare += i

total_fare = fare*num_passengers

#Check for duplicate record


with open(BOOKINGS_FILE,"r") as f:
booking=f.readlines()
x=f”{username},{origin},{destination},
{travel_date},{num_passengers},{total_fare}\n”
if x in booking:
print("No duplicate bookings can exist")
return
print(f”Total fare for {num_passengers} passenger(s)
from {origin} to {destination} on {travel_date} :
₹{total_fare}”)

# Record the booking


with open(BOOKINGS_FILE, 'a') as f:
f.write(f”{username},{origin},
{destination},{travel_date},{num_passsengers},
{total_fare}\n”)

print("Ticket booked successfully.")


except ValueError:
print("Please enter a valid number for passengers.")
except Exception as e:
print(f"Error while booking ticket: {e}")

# Function to view bookings


def view_bookings(username):
try:
with open(BOOKINGS_FILE, 'r') as f:
bookings = f.readlines()

user_bookings = []

15
for booking in bookings:
if booking.startswith(username):
user_bookings.append(booking.strip())

if not user_bookings:
print("No bookings found.")
return

print("Your bookings:")
for booking in user_bookings:
details = booking.split(',')
print(f"Origin:{details[1]},Destination:{details[2]},
Date: {details[3]}, Passengers: {details[4]}, Fare:
{details[5]}")

except FileNotFoundError:
print("Booking data file not found.")
except Exception as e:
print(f"Error while viewing bookings: {e}")

# Function to cancel a booking


def cancel_booking(username):
try:
view_bookings(username) # Show current bookings
if not os.path.exists(BOOKINGS_FILE) or
os.path.getsize(BOOKINGS_FILE) == 0:
print("No bookings available to cancel.")
return

origin = input("Enter the origin station of the booking


to cancel: ").upper()
destination = input("Enter the destination station of the
booking to cancel: ").upper()
travel_date = input("Enter the travel date (YYYY-MM-DD)
of the booking to cancel: ")
num_passengers = input("Enter the number of passengers of
the booking to cancel: ")

16
with open(BOOKINGS_FILE, 'r') as f:
bookings = f.readlines()

# Filter out the booking to cancel


new_bookings = []
for booking in bookings:
if not ( booking.startswith(username) and f”{origin}
,{destination},{travel_date},{num_passengers}” in
Booking ):
new_bookings.append(booking)

if len(new_bookings) == len(bookings):
print("No matching booking found.")
else:
with open(BOOKINGS_FILE, 'w') as f:
f.writelines(new_bookings)
print("Booking cancelled successfully.")
except Exception as e:
print(f"Error while cancelling booking: {e}")

# Main function to run the application


def main():
while True:
try:
print("+-------------------------+")
print("| Welcome to Kochi Metro! |")
print("+-------------------------+\n")
print(" 1. Register")
print(" 2. Login")
print(" 3. Exit\n")
choice = input("Choose an option: ")
if choice == '1':
register_user()
elif choice == '2':
username = login_user()

17
if username:
while True:
print("\n1. Book Ticket")
print("2. View Bookings")
print("3. Cancel Booking")
print("4. Logout")
user_choice = input("Choose an option: ")

if user_choice == '1':
book_ticket(username)
elif user_choice == '2':
view_bookings(username)
elif user_choice == '3':
cancel_booking(username)
elif user_choice == '4':
print("Logged out successfully.")
break
else:
print("Invalid option.")
elif choice == '3':
print("Goodbye!")
break
else:
print("Invalid option.")
except Exception as e:
print(f"Error in main menu: {e}")

main()

18
OUTPUT
+-------------------------+
| Welcome to Kochi Metro! |
+-------------------------+

1. Register
2. Login
3. Exit

Choose an option: 1
Enter username: Rahul
Enter password: 123
User registered successfully.
+-------------------------+
| Welcome to Kochi Metro! |
+-------------------------+

1. Register
2. Login
3. Exit

Choose an option: 2
Enter username: Rahul
Enter password: 123
Login successful.

1. Book Ticket
2. View Bookings
3. Cancel Booking
4. Logout

19
Choose an option: 1
+------------------------+
| STATION |
+------------------------+
| ALUVA |
| PULINCHODU |
| COMPANYPADY |
| AMBATTUKAVU |
| MUTTOM |
| KALAMASSERRY |
| COCHIN UNIVERSITY |
| PATHADIPALAM |
| EDAPALLY |
| CHANGAMPUZHA |
| PALARIVATTOM |
| JLN STADIUM |
| KALOOR |
| TOWN HALL |
| MG ROAD |
| MAHARAJAS |
| ERNAKULAM SOUTH |
| KADAVANTHRA |
| ELAMKULAM |
| VYTILLA |
| THAIKOODAM |
| PETTA |
| VADAKKEKOTTA |
| SN JUNCTION |
| THRIPUNITHURA TERMINAL |
+------------------------+
Enter origin station: ALUVA
Enter destination station: TOWN HALL
Enter travel date (YYYY-MM-DD): 2024-10-30
Enter number of passengers: 5
Total fare for 5 passenger(s) from ALUVA to TOWN HALL on 2024-10-
30: ₹250
Ticket booked successfully.
1. Book Ticket
2. View Bookings

20
3. Cancel Booking
4. Logout
Choose an option: 1
+------------------------+
| STATION |
+------------------------+
| ALUVA |
| PULINCHODU |
| COMPANYPADY |
| AMBATTUKAVU |
| MUTTOM |
| KALAMASSERRY |
| COCHIN UNIVERSITY |
| PATHADIPALAM |
| EDAPALLY |
| CHANGAMPUZHA |
| PALARIVATTOM |
| JLN STADIUM |
| KALOOR |
| TOWN HALL |
| MG ROAD |
| MAHARAJAS |
| ERNAKULAM SOUTH |
| KADAVANTHRA |
| ELAMKULAM |
| VYTILLA |
| THAIKOODAM |
| PETTA |
| VADAKKEKOTTA |
| SN JUNCTION |
| THRIPUNITHURA TERMINAL |
+------------------------+
Enter origin station: TOWN HALL
Enter destination station: VYTILLA
Enter travel date (YYYY-MM-DD): 2024-10-30
Enter number of passengers: 3
Total fare for 3 passenger(s) from TOWN HALL to VYTILLA on 2024-
10-30: ₹180
Ticket booked successfully.

21
1. Book Ticket
2. View Bookings
3. Cancel Booking
4. Logout
Choose an option: 2
Your bookings:
Origin: ALUVA, Destination: TOWN HALL, Date: 2024-10-30,
Passengers: 5, Fare: 250
Origin: TOWN HALL, Destination: VYTILLA, Date: 2024-10-30,
Passengers: 3, Fare: 180

1. Book Ticket
2. View Bookings
3. Cancel Booking
4. Logout
Choose an option: 3
Your bookings:
Origin: ALUVA, Destination: TOWN HALL, Date: 2024-10-30,
Passengers: 5, Fare: 250
Origin: TOWN HALL, Destination: VYTILLA, Date: 2024-10-30,
Passengers: 3, Fare: 180
Enter the origin station of the booking to cancel: TOWN HALL
Enter the destination station of the booking to cancel: VYTILLA
Enter the travel date (YYYY-MM-DD) of the booking to cancel:
2024-10-30
Enter the number of passengers of the booking to cancel:3
Booking cancelled successfully.

1. Book Ticket
2. View Bookings
3. Cancel Booking
4. Logout
Choose an option: 2

22
Your bookings:
Origin: ALUVA, Destination: TOWN HALL, Date: 2024-10-30,
Passengers: 5, Fare: 250

1. Book Ticket
2. View Bookings
3. Cancel Booking
4. Logout
Choose an option: 4
Logged out successfully.
+-------------------------+
| Welcome to Kochi Metro! |
+-------------------------+

1. Register
2. Login
3. Exit

Choose an option: 3
Goodbye!

23
BIBLIOGRAPHY

 https://www.geeksforgeeks.org

 https://github.com

 https://www.wikipedia.org

24

You might also like