0% found this document useful (0 votes)
8 views10 pages

Source Code CS Practical File

Uploaded by

savitur.gts
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)
8 views10 pages

Source Code CS Practical File

Uploaded by

savitur.gts
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/ 10

SOURCE CODE

Creating Database and Table


import mysql.connector
def cr_con():
con =
mysql.connector.connect(host='localhost',user='root',password='cheeku@18',dat
abase='flightmanage')
return con
def tb(cur):
cur.execute("CREATE DATABASE IF NOT EXISTS flightmanage")
cur.execute("USE flightmanage")
cur.execute("""
CREATE TABLE IF NOT EXISTS flights (
fid INT AUTO_INCREMENT PRIMARY KEY,
fname VARCHAR(100) NOT NULL,
departure VARCHAR(100) NOT NULL,
destination VARCHAR(100) NOT NULL,
departure_time TIME NOT NULL,
arrival_time TIME NOT NULL,
total_seats INT NOT NULL,
available_seats INT NOT NULL)""")
cur.execute("""
CREATE TABLE IF NOT EXISTS passengers (
pid INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
phone BIGINT NOT NULL,
email VARCHAR(100) NOT NULL,
password VARCHAR(100) NOT NULL)""")
cur.execute("""
CREATE TABLE IF NOT EXISTS bookings (
bid INT AUTO_INCREMENT PRIMARY KEY,
pid INT NOT NULL,
fid INT NOT NULL,
bookdate DATE NOT NULL,
FOREIGN KEY (pid) REFERENCES passengers(pid),
FOREIGN KEY (fid) REFERENCES flights(fid))""")
ADDING NEW FLIGHT
def addflight(cur, a):
fname = input("Enter flight name: ")
departure = input("Enter departure city: ")
destination = input("Enter destination city: ")
departure_time = input("Enter departure time : ")
arrival_time = input("Enter arrival time : ")
total_seats = int(input("Enter total seats: "))
available_seats = total_seats
cur.execute("""
INSERT INTO flights (fname, departure, destination, departure_time,
arrival_time, total_seats, available_seats)
VALUES (%s, %s, %s, %s, %s, %s, %s)
""", (fname, departure, destination, departure_time, arrival_time,
total_seats, available_seats))
a.commit()
print("Flight added successfully!")

REGISTERATION
def register(cur, a):
name = input("Enter passenger name: ")
phone = int(input("Enter phone number: "))
email = input("Enter email: ")
password = input("Set a password: ")
cur.execute("""
INSERT INTO passengers (name, phone, email, password)
VALUES (%s, %s, %s, %s)
""", (name, phone, email, password))
a.commit()
print("Passenger added successfully! Remember your password for booking
flights")

BOOKING
def book(cur, a):
try:
phone = int(input("Enter your phone number: "))
password = input("Enter your password: ")
cur.execute("SELECT pid FROM passengers WHERE phone = %s AND password
= %s", (phone, password))
passenger = cur.fetchone()
if not passenger:
print("Invalid phone number or password. Please try again.")
return
pid = passenger[0]
departure = input("Enter flight departure place: ")
destination = input("Enter flight destination place: ")
bookdate = input("Enter booking date (YYYY-MM-DD):")
cur.execute("SELECT fid, available_seats FROM flights WHERE departure
= %s AND destination = %s", (departure, destination))
flights = cur.fetchall()
if not flights:
print("No flights available for this route.")
return
fid = flights[0][0]
available_seats = flights[0][1]

AVAILABLE SEATS
if available_seats > 0:
cur.execute("""
INSERT INTO bookings (pid, fid, bookdate)
VALUES (%s, %s, %s)
""", (pid, fid, bookdate))
cur.execute("UPDATE flights SET available_seats = available_seats
- 1 WHERE fid = %s", (fid,))
a.commit()
print("Flight booked successfully!")
else:
print("No available seats on this flight.")
except ValueError:
print("Invalid input. Please enter valid values.")

AVAILABLE FLIGHTS
def show_flights(cur):
cur.execute("SELECT * FROM flights")
flights = cur.fetchall()
print("Available Flights:")
for i in flights: #flight = "i"
print(f"Flight ID: {i[0]}, Flight Name: {i[1]}, Departure: {i[2]},
Destination: {i[3]}, Departure Time: {i[4]}, Arrival Time: {i[5]}, Available
Seats: {i[7]}")
ADMIN INTERFACE
def admin(cur, a):
while True:
print("\nAdmin Menu:")
print("1. Add Flight")
print("2. Show Flights")
print("3. Exit")
try:
choice = int(input("Enter your choice: "))
if choice == 1:
addflight(cur, a)
elif choice == 2:
show_flights(cur)
elif choice == 3:
break
else:
print("Please choose a correct option.")
except ValueError:
print("Invalid choice. Please enter a number.")

USER INTERFACE
def user(cur, a):
while True:
print("\nUser Menu:")
print("1. Register Passenger")
print("2. Book Flight")
print("3. Show Flights")
print("4. Exit")
try:
choice = int(input("Enter your choice: "))
if choice == 1:
register(cur, a)
elif choice == 2:
book(cur, a)
elif choice == 3:
show_flights(cur)
elif choice == 4:
break
else:
print("Please choose a correct option.")
except ValueError:
print("Invalid choice. Please enter a number.")
MAIN
def main():
con = cr_con()
cur = con.cursor()
tb(cur)
while True:
print("\nMain Menu:")
print("1. Admin")
print("2. User")
print("3. Exit")
try:
choice = int(input("Enter your choice: "))
if choice == 1:
admin(cur, con)
elif choice == 2:
user(cur, con)
elif choice == 3:
break
else:
print("Please choose a correct option.")
except ValueError:
print("Invalid choice. Please enter a number.")

con.close()
print("Welcome to the FlyteX Flight Management & Booking System!")
main()
WORKING SCREENSHOTS
➢ MAIN INTERFACE

➢ ADMIN INTERFACE

➢ ADD FLIGHTS

➢ SHOW FLIGHTS
➢ USER INTERFACE

➢ REGISTER PASSENGER

➢ BOOK FLIGHT
➢ SHOW FLIGHTS (AFTER BOOKING)

➢ EXITING
DATABASE (MY SQL)
➢ FLIGHTMANAGE

➢ TABLES

➢ DATA IN BOOKINGS

➢ DATA IN FLIGHTS
➢ DATA IN PASSENGERS

You might also like