T Final Cs Project PDF
T Final Cs Project PDF
COMPUTER PROJECT
___________________
___________________
External Examiner Internal
Examiner
__________________
__________________
School Stamp Principal’s
Signature
Aayush Pant
INDEX
Hardware specification
Software specification
Project objective
Project usage
Program specifications
Source code
Output
References
Hardware Specifications:
This project was made on the system with the following configuration:
Intel i3 8 gen processor or above
th
Windows 7 or higher
Software Specification:
The following are the software specifications of the program:
Pycharm
Spyder
MySQL 8.0 Command Line Client
Project Objective:
To create a theatre data management system that can do as follows:
1. Add movies
2. List movies
3. Make Booking
4. List Bookings
5. Cancel Booking
6. Delete Movie
Project usage:
This project can be used by anyone to test their basic knowledge on
various topics.
PROJECT OUTLINE:
Movie Booking System
Objective:
- The Movie Booking System is a Python-based application designed
to manage movie bookings, allowing users to add movies, book
seats, view bookings, cancel reservations, list movies, and delete
movies from a MySQL database.
Key Functionality:
- Database setup: Establishes a connection to MySQL, creates
essential tables, and populates seat information.
- Movie Management: Enables the addition of movies, listing
available movies, and setting seat prices.
- Booking System: Allows users to make movie bookings, view their
bookings, and cancel reservations.
- Deletion of Movies: Provides an option to delete movies from the
database.
Data Storage:
- Movie and booking information is stored in a MySQL database for
easy retrieval and management.
Conclusion:
- The Movie Booking System streamlines movie reservations and
provides a foundation for building more advanced ticketing systems.
Packages used- MySQL connector
SOURCE CODE:
import mysql.connector
# Create Tables
def setup_database():
# Setup tables for movies, seats, reservations, and bookings
mycursor.execute("""
CREATE TABLE IF NOT EXISTS movies2 (
id INT AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(255) NOT NULL UNIQUE,
duration INT NOT NULL,
protagonist VARCHAR(40)
) AUTO_INCREMENT = 1
""")
mycursor.execute("""
CREATE TABLE IF NOT EXISTS seats1 (
id INT AUTO_INCREMENT PRIMARY KEY,
seat_number INT NOT NULL,
is_reserved BOOLEAN DEFAULT 0,
price INT DEFAULT 0,
UNIQUE (seat_number)
)
""")
mycursor.execute("""
CREATE TABLE IF NOT EXISTS reservations (
id INT AUTO_INCREMENT PRIMARY KEY,
seat_number INT NOT NULL,
customer_name VARCHAR(255) NOT NULL,
reservation_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
""")
mycursor.execute("""
CREATE TABLE IF NOT EXISTS booking2 (
id INT AUTO_INCREMENT PRIMARY KEY,
movie_id INT,
seats_id INT,
reservation_id INT,
FOREIGN KEY (movie_id) REFERENCES movies2(id),
FOREIGN KEY (seats_id) REFERENCES seats1(id),
FOREIGN KEY (reservation_id) REFERENCES reservations(id)
)
""")
setup_database()
query = "INSERT IGNORE INTO movies2 (title, duration, protagonist) VALUES (%s,
%s, %s)"
data_movies = [
('RaOne', 155, 'ShahRukhKhan'),
('Dream Girl', 160, 'AayushManKhuranna'),
('DeadPool', 140, 'Ryan Reynolds'),
('Agent Vinod', 159, 'SaifAliKhan'),
('Baby', 170, 'AkkshayKumar')
]
mycursor.executemany(query, data_movies)
#adding seats
def set_seat_prices():
price_brackets = [(1, 10, 500), (11, 20, 400), (21, 30, 300), (31, 40,
200), (41, 50, 100)]
for start, end, price in price_brackets:
mycursor.execute("""
UPDATE seats1
SET price = %s
WHERE seat_number BETWEEN %s AND %s
""", (price, start, end))
obj.commit()
set_seat_prices()
def display_available_seats(movie_title):
# Get the movie's ID based on the title
mycursor.execute("SELECT id FROM movies2 WHERE title = %s",
(movie_title,))
movie_id = mycursor.fetchone()
if not movie_id:
print(f"Movie '{movie_title}' does not exist.")
return []
available_seats = mycursor.fetchall()
if available_seats:
print("Available seats (Price):", [(seat[0], int(seat[1])) for seat in
available_seats])
return [seat[0] for seat in available_seats]
else:
print("No available seats.")
return []
# View reservations
# Cancel reservations
def add_movie():
title = input("Enter movie name: ")
duration = int(input("Enter movie duration: "))
protagonist = input("Enter protagonist name: ")
try:
mycursor.execute("INSERT INTO movies2 (title, duration, protagonist)
VALUES (%s, %s, %s)", (title, duration, protagonist))
obj.commit()
print("Movie added successfully!")
except mysql.connector.Error as err:
print(f"Error: {err}")
def make_booking():
list_movie()
movie_title = input("Enter movie title for which you want to book: ")
available_seats = display_available_seats(movie_title)
if not available_seats:
return
seat_choice = int(input("Enter the seat number you want to book from the
available seats: "))
if seat_choice not in available_seats:
print("Invalid choice. Seat not available.")
return
reservation_id = mycursor.lastrowid
mycursor.execute("UPDATE seats1 SET is_reserved = 1 WHERE seat_number =
%s", (seat_choice,))
mycursor.execute("""
INSERT INTO booking2 (movie_id, seats_id, reservation_id)
VALUES (%s, %s, %s)
""", (movie_id[0], seat_choice, reservation_id))
obj.commit()
def list_bookings():
try:
mycursor.execute("""
SELECT r.seat_number, r.reservation_date, m.title, m.duration, s.price
FROM booking2 b
INNER JOIN reservations r ON b.reservation_id = r.id
INNER JOIN movies2 m ON b.movie_id = m.id
INNER JOIN seats1 s ON r.seat_number = s.seat_number
""")
bookings = mycursor.fetchall()
if not bookings:
print("No bookings found.")
else:
print("Seat Number | Reservation Date | Title | Duration (minutes)
| Price")
for booking in bookings:
print("{:11} | {} | {} | {} | {}".format(
booking[0], booking[1], booking[2], booking[3],
booking[4]))
except mysql.connector.Error as err:
print(f"Error: {err}")
def delete_movie(title):
# Check if the movie with the provided title exists
mycursor.execute("SELECT id FROM movies2 WHERE title = %s", (title,))
movie_id = mycursor.fetchone()
if movie_id:
# Delete the movie from the movies2 table
mycursor.execute("DELETE FROM movies2 WHERE id = %s", (movie_id[0],))
obj.commit()
print(f"Movie with title '{title}' deleted successfully!")
else:
print(f"Movie with title '{title}' not found.")
def cancel_booking():
customer_name = input("Enter your name: ")
movie_title = input("Enter the movie title of your booking: ")
new_cursor = obj.cursor(buffered=True)
# Retrieve the reservation details for the given movie and customer name
new_cursor.execute("""
SELECT r.id, r.seat_number
FROM reservations r
JOIN booking2 b ON r.id = b.reservation_id
WHERE r.customer_name = %s AND b.movie_id = %s
""", (customer_name, movie_id[0]))
reservations = new_cursor.fetchall()
if not reservations:
print(f"No reservations found for {customer_name} for the movie
{movie_title}.")
return
if len(reservations) > 1:
print("You have multiple seats booked for this movie. Here are the
seats:")
for reservation in reservations:
_, seat_number = reservation
print(f"Seat number: {seat_number}")
seat_number_to_cancel = int(input("Enter the seat number you want to
cancel: "))
else:
_, seat_number_to_cancel = reservations[0]
obj.commit()
print(f"Booking for movie '{movie_title}' seat number
{seat_number_to_cancel} canceled successfully!")
new_cursor.close()
if __name__ == "__main__":
while True:
print("\nOptions:")
print("1. Add movies")
print("2. List movies")
print("3. Make Booking")
print("4. List Bookings")
print("5. Cancel Booking")
print("6. Delete Movie")
print("0. Quit")
if choice == '1':
add_movie()
elif choice == '2':
list_movie()
elif choice == '3':
make_booking()
elif choice == '4':
list_bookings()
elif choice == '5':
cancel_booking()
elif choice == '6':
delete_movie()
elif choice == '0':
break
else:
print("Invalid choice. Please try again.")
obj.close()
OUTPUT:
REFERENCES:
www.wikipedia.org