Railway Reservation System Formatted
Railway Reservation System Formatted
Problem Definition
The railway reservation system is designed to streamline the process of booking,
managing, and canceling train tickets. The program addresses the following user
needs:
- Searching for trains based on source and destination.
- Booking tickets with age-based discounts.
- Canceling tickets and updating availability.
- Checking the status of booked tickets.
Problem Analysis
1. **Challenges Identified:**
- Manual train ticket booking processes are time-consuming.
- Lack of automated discounts for specific age groups.
- Difficulty in checking real-time ticket availability.
2. **Proposed Solution:**
- A Python-based railway reservation system integrated with a MySQL database to
manage trains, passengers, and tickets.
- Automation of ticket booking, cancellation, and status tracking.
System Functionality
1. **Display Trains**: Users input the source and destination to view available
trains.
2. **Book Tickets**: Users provide their details and select a train to book tickets.
Discounts are automatically applied for children and senior citizens.
3. **Cancel Tickets**: Users can cancel booked tickets, and the system updates
seat availability.
4. **Check Ticket Status**: Users can view the status of their booked tickets,
including seat details and payment status.
Functions Used
**User-Defined Functions:**
- `connect_to_db()`: Establishes a connection to the MySQL database.
- `create_database_and_tables()`: Sets up the database and required tables.
- `display_trains(source, destination)`: Displays trains based on input source and
destination.
- `apply_discount(age)`: Calculates discount based on passenger age.
- `book_ticket(passenger_name, passenger_age, passenger_gender, train_id)`:
Books a ticket for a passenger.
- `cancel_ticket(ticket_id)`: Cancels a booked ticket.
- `check_ticket_status(ticket_id)`: Checks the status of a ticket.
**Inbuilt Functions:**
- `random.randint()`: Generates random numbers for ticket and seat assignment.
- `datetime.date.today()`: Retrieves the current date for booking records.
- `tabulate()`: Formats database query results into a tabular structure for display.
Database Design
Table Name Columns Description
train_id,
Trains
train_name, source, destination, available_seats, train_class, departure_time,
Details
arrival_time
about trains.
Passengers passenger_id, name, age, gender Details about passengers.
Tickets
ticket_id, passenger_id, train_id, booking_date, status, seat_number, payment_status
Details about ticket bookings.
Offers offer_id, description, discount_percentage, applicable_to Details about available offers.