0% found this document useful (0 votes)
6 views5 pages

Report PSP

The document outlines a C-based Bus Ticket Booking System that allows users to book bus tickets by selecting from 10 available buses and checking seat availability. It details the program structure, including header files, constants, global variables, and the booking process, which involves user inputs and seat selection. Future enhancements may include multiple bookings and data storage to improve functionality.

Uploaded by

shrish3636
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views5 pages

Report PSP

The document outlines a C-based Bus Ticket Booking System that allows users to book bus tickets by selecting from 10 available buses and checking seat availability. It details the program structure, including header files, constants, global variables, and the booking process, which involves user inputs and seat selection. Future enhancements may include multiple bookings and data storage to improve functionality.

Uploaded by

shrish3636
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

1.

Header Files
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

 stdio.h: Used for input/output functions (printf, scanf).


 stdlib.h: Provides functions like exit() (though not explicitly used in this code).
 time.h: Included but not used (likely for future enhancements, such as generating
timestamps).

2. Constants and Global Variables


#define TOTAL_BUSES 10
#define SEATS_PER_BUS 30

int seats[TOTAL_BUSES][SEATS_PER_BUS] = {0}; // 0 means available, 1 means


booked

 TOTAL_BUSES = 10: The system handles 10 different buses.


 SEATS_PER_BUS = 30: Each bus has 30 seats.
 seats array: A 2D array (10 x 30) where:
o 0 means an available seat.
o 1 means a booked seat.

3. Function to Determine Seat Type


char get_seat_type(int seat_number) {
if (seat_number % 3 == 1) return 'W'; // Window Seat
if (seat_number % 3 == 2) return 'A'; // Aisle Seat
return 'M'; // Middle Seat
}

 This function categorizes seats as:


o Window (W): If seat number modulo 3 equals 1.
o Aisle (A): If seat number modulo 3 equals 2.
o Middle (M): Otherwise.

4. Booking a Ticket

void book_ticket() {

Step 1: User Inputs Travel Details


char from[50], to[50], date[15];
int bus_choice, seat_number;

printf("Enter Departure Location: ");


scanf("%s", from);
printf("Enter Destination: ");
scanf("%s", to);
printf("Enter Date (DD/MM/YYYY): ");
scanf("%s", date);

 The user enters:


o from: Departure location.
o to: Destination.
o date: Travel date.

Step 2: Display Available Buses

printf("\nSelect Bus:\n");
for (int i = 0; i < TOTAL_BUSES; i++) {
int hours = 6 + (i * 1.5);
int minutes = (hours % 2) * 30;
hours = hours / 2 * 2;
printf("%d. Bus %d - Departure Time: %02d:%02d\n", i + 1, i + 1,
hours, minutes);
}

 Displays 10 bus options with dynamically generated departure times.


 The first bus departs at 6:00 AM, and subsequent buses leave 1.5 hours apart.

Step 3: User Selects a Bus

printf("Enter your choice: ");


scanf("%d", &bus_choice);
bus_choice--; // Adjust for zero-based index

if (bus_choice < 0 || bus_choice >= TOTAL_BUSES) {


printf("Invalid bus choice!\n");
return;
}

 The user selects a bus (1–10).


 The input is adjusted for zero-based indexing (bus_choice--).
 If the user enters an invalid bus number, an error message is displayed.

Step 4: Display Available Seats

printf("\nAvailable Seats in Bus %d:\n", bus_choice + 1);


for (int i = 0; i < SEATS_PER_BUS; i++) {
if (seats[bus_choice][i] == 0) {
printf(" %c-%d", get_seat_type(i + 1), i + 1);
}
int a = i + 1;
if (a % 3 == 0) { printf("\n"); }
}

 The system lists available seats.


 Seats are labeled with their type (W/A/M) and number.
 New line is printed every 3 seats for better formatting.

Step 5: User Selects a Seat

printf("\nEnter seat number: ");


scanf("%d", &seat_number);

if (seat_number < 1 || seat_number > SEATS_PER_BUS ||


seats[bus_choice][seat_number - 1] == 1) {
printf("Invalid or already booked seat!\n");
return;
}

 User selects a seat number.


 The program checks:
o If the seat number is within the valid range (1-30).
o If the seat is already booked.

Step 6: Confirm and Book Seat

seats[bus_choice][seat_number - 1] = 1; // Mark seat as


booked

char seat_label[10];
sprintf(seat_label, "%c-%d", get_seat_type(seat_number),
seat_number);

 The selected seat is marked as booked (seats[bus_choice][seat_number - 1]


= 1).
 sprintf formats the seat label (e.g., W-5, A-12).

Step 7: Display Ticket Confirmation

printf("\n Ticket Confirmed \n");


printf("From: %s\nTo: %s\nDate: %s\nBus: Bus %d \n Seat: Seat Number
%s\n",
from, to, date, bus_choice + 1, seat_label);
}

 Displays the final booking details.

5. Main Function
int main() {
printf("\n Welcome to Bus Booking System \n");
book_ticket();
return 0;
}

 The program starts by printing a welcome message.


 Calls book_ticket() function.
 The program exits after booking one ticket (no loop for multiple bookings).

Programming is an essential skill in the modern era, and learning it effectively


requires both theoretical knowledge and practical application. The Bus Ticket
Booking System is a simple yet effective C-based application designed to make
bus ticket reservations quick and hassle-free. It allows users to select a bus from
a list of 10 available options, check seat availability, and book a seat of their
choice. The system categorizes seats into Window (W), Aisle (A), and Middle
(M) to enhance user preference and comfort. Once a seat is selected, the system
confirms the booking instantly and provides a summary of travel details,
including the departure location, destination, date, bus number, and seat type.

The motivation behind this project stems from the common difficulties in
traditional bus booking methods, where passengers often face seat
mismanagement, overbooking issues, and lack of transparency in seat selection.
By automating this process, the system ensures that every booking is accurate,
real-time, and user-friendly.

From a technical perspective, the system makes use of C programming


fundamentals, such as arrays for seat management, functions for modularity,
and conditional statements for validation. While the current version allows a
single booking per execution, future enhancements could include multiple ticket
booking, cancellation options, and persistent data storage to improve
functionality further.

This project not only serves as a practical implementation of programming


concepts but also lays the groundwork for a more comprehensive and scalable
bus ticket reservation system in the future.

You might also like