0% found this document useful (0 votes)
12 views3 pages

Lab Project - 2

The document outlines a Queue-based Online Ticket Booking System for a bus service, implementing FIFO principles. It includes requirements for booking, processing, viewing, and displaying tickets, along with a C code implementation. The code features functions for managing a queue of passengers, including enqueue, dequeue, peek, and display operations.

Uploaded by

Athili navin
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)
12 views3 pages

Lab Project - 2

The document outlines a Queue-based Online Ticket Booking System for a bus service, implementing FIFO principles. It includes requirements for booking, processing, viewing, and displaying tickets, along with a C code implementation. The code features functions for managing a queue of passengers, including enqueue, dequeue, peek, and display operations.

Uploaded by

Athili navin
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/ 3

Lab Project - 2

Statement: Imagine you are developing a Queue-based Online Ticket Booking System for a bus service. The
system follows the FIFO (First In, First Out) principle, ensuring that passengers who book first get processed
first.

Requirements :

1. Book Ticket
2. Process Ticket
3. View Next Ticket
4. Show All Tickets
5. Exit

CODE:

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

#define MAX 10

// Structure to hold passenger details


typedef struct
{
char name[50];
int ticket_no;
} passengers;

// Initializing array of passengers in the form of queue


passengers queue[MAX];
int front = -1, rear = -1;

// To insert passenger details into the queue


void enqueue(passengers p)
{
if (rear == MAX - 1)
{
printf("Queue is full. Cannot add more passengers.\n");
return;
}
if (front == -1)
{
front = 0;
}
queue[++rear] = p;
printf("Ticket Booked: %s (Ticket Number: %d)\n", p.name, p.ticket_no);
}

// To remove passenger details from the queue


void dequeue()
{
if (front == -1 || front > rear)
{
printf("Queue is empty. No passengers to remove.\n");
return;
}
printf("Processing Ticket: %s (Ticket Number: %d)\n", queue[front].name,
queue[front].ticket_no);
front++;
}

// To view the next passenger in the queue without removing them


void peek()
{
if (front == -1 || front > rear)
{
printf("Queue is empty. No passengers to display.\n");
return;
}
printf("Next passenger to process: %s (Ticket Number: %d)\n", queue[front].name,
queue[front].ticket_no);
}

// To display all passengers in the queue


void display()
{
if (front == -1 || front > rear)
{
printf("Queue is empty. No passengers to display.\n");
return;
}
printf("Passengers in the queue:\n");
for (int i = front; i <= rear; i++)
{
printf("%s (Ticket Number: %d)\n", queue[i].name, queue[i].ticket_no);
}
}

int main(void)
{
int choice;
passengers p;
do
{
printf("1. Add passenger to queue\n");
printf("2. Remove passenger from queue\n");
printf("3. Display passengers in queue\n");
printf("4. View next passenger\n");
printf("5. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice)
{
case 1:
printf("Enter passenger name: ");
scanf("%s", p.name);
printf("Enter ticket number: ");
scanf("%d", &p.ticket_no);
enqueue(p);
break;
case 2:
dequeue();
break;
case 3:
display();
break;
case 4:
peek();
break;
case 5:
printf("Exiting...\n");
break;
default:
printf("Invalid choice. Please try again.\n");
}
} while (choice != 5);
return 0;
}

Input: Output:
Enter your choice: 1
Enter Passenger Name: Abhishek Ticket Booked: Abhishek (Ticket Number: 101)
Enter Ticket Number: 101
Enter your choice: 1
Enter Passenger Name: Ramesh Ticket booked: Ramesh (Ticket Number: 102)
Enter Ticket Number: 102
Enter your choice: 4 Next passenger to process: Abhishek (Ticket Number: 101)
Enter your choice: 2 Processing Ticket: Abhishek (Ticket Number: 101)
Enter your choice: 3 Passengers in the queue:
Ramesh (Ticket Number: 102)
Enter your choice: 5 Exiting...

You might also like