0% found this document useful (0 votes)
21 views8 pages

Oops Project Team19

The document presents a Bus Reservation System implemented in C, which allows users to view available buses, book tickets, view bookings, and cancel tickets. It defines structures for buses and seats, manages seat bookings, and provides a simple command-line interface for user interaction. The system supports a maximum of three buses and ten seats per bus.

Uploaded by

ourname9227
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)
21 views8 pages

Oops Project Team19

The document presents a Bus Reservation System implemented in C, which allows users to view available buses, book tickets, view bookings, and cancel tickets. It defines structures for buses and seats, manages seat bookings, and provides a simple command-line interface for user interaction. The system supports a maximum of three buses and ten seats per bus.

Uploaded by

ourname9227
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/ 8

BCSE102P

STRUCTURED OBJECT – ORIENTED PROGRAMMING

Team No: 17

Task Name: Bus Reservation System

Reg No. 24BCE5172 – [Varun Teja Punati]

Reg No. 24BCE5158 – [Yamini Gali]

Reg No. 24BCE5024 – [Sreeraaga Gangavarapu]


SOURCE CODE:

#include <stdio.h>

#include <stdlib.h>
#include <string.h>

#define MAX_SEATS 10

#define MAX_BUSES 3

typedef struct {

int seat_number;

char passenger_name[50];
} Seat;

typedef struct {

int bus_id;

char bus_name[50];

Seat seats[MAX_SEATS];

int booked_seats;
} Bus;

Bus buses[MAX_BUSES] = {

{1, "Express Bus", {}, 0},

{2, "Luxury Bus", {}, 0},

{3, "Sleeper Bus", {}, 0}

};

1
void displayBuses() {

printf("\nAvailable Buses:\n");

for (int i = 0; i < MAX_BUSES; i++) {

printf("Bus ID: %d - %s (Seats Available: %d)\n",


buses[i].bus_id, buses[i].bus_name, MAX_SEATS - buses[i].booked_seats);

void bookTicket() {

int bus_id, seat_num;

char name[50];

displayBuses();

printf("\nEnter Bus ID to book a seat: ");

scanf("%d", &bus_id);

if (bus_id < 1 || bus_id > MAX_BUSES) {

printf("Invalid Bus ID!\n");

return;
}

Bus *bus = &buses[bus_id - 1];

if (bus->booked_seats >= MAX_SEATS) {

printf("No seats available on this bus.\n");

return;
}

2
printf("Enter Passenger Name: ");

scanf(" %[^\n]", name);

seat_num = bus->booked_seats + 1;

strcpy(bus->seats[bus->booked_seats].passenger_name, name);

bus->seats[bus->booked_seats].seat_number = seat_num;

bus->booked_seats++;

printf("Ticket booked successfully! Seat Number: %d\n", seat_num);

void viewBookings() {

int bus_id;

displayBuses();

printf("\nEnter Bus ID to view bookings: ");

scanf("%d", &bus_id);

if (bus_id < 1 || bus_id > MAX_BUSES) {


printf("Invalid Bus ID!\n");

return;

Bus *bus = &buses[bus_id - 1];

if (bus->booked_seats == 0) {
printf("No bookings for this bus.\n");

3
return;

printf("\nBooked Seats for %s:\n", bus->bus_name);


for (int i = 0; i < bus->booked_seats; i++) {

printf("Seat %d: %s\n", bus->seats[i].seat_number, bus-


>seats[i].passenger_name);
}

void cancelTicket() {

int bus_id, seat_num;

displayBuses();
printf("\nEnter Bus ID to cancel a ticket: ");

scanf("%d", &bus_id);

if (bus_id < 1 || bus_id > MAX_BUSES) {

printf("Invalid Bus ID!\n");

return;
}

Bus *bus = &buses[bus_id - 1];

if (bus->booked_seats == 0) {

printf("No bookings to cancel.\n");


return;

4
}

printf("Enter Seat Number to cancel: ");

scanf("%d", &seat_num);

int found = 0;

for (int i = 0; i < bus->booked_seats; i++) {

if (bus->seats[i].seat_number == seat_num) {

found = 1;

for (int j = i; j < bus->booked_seats - 1; j++) {

bus->seats[j] = bus->seats[j + 1];

}
bus->booked_seats--;

printf("Ticket for seat %d canceled successfully.\n", seat_num);

break;

if (!found) {
printf("Seat number not found!\n");

int main() {

int choice;

while (1) {

5
printf("\n--- Bus Reservation System ---\n");

printf("1. View Buses\n");

printf("2. Book a Ticket\n");

printf("3. View Bookings\n");


printf("4. Cancel Ticket\n");

printf("5. Exit\n");

printf("Enter your choice: ");

scanf("%d", &choice);

switch (choice) {

case 1: displayBuses(); break;

case 2: bookTicket(); break;


case 3: viewBookings(); break;

case 4: cancelTicket(); break;

case 5: printf("Exiting...\n"); exit(0);

default: printf("Invalid choice! Try again.\n");

return 0;

6
OUTPUT:

You might also like