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

Train Waiting List Simulation in C

The document describes a train waiting list simulation project (M3.10) that involves adding passenger details, managing confirmed and waiting lists, and implementing auto-shifting for cancellations. It outlines the learning outcomes, algorithm, and provides a C program that demonstrates the functionality of the system. The project enhances understanding of arrays, structures, and menu-driven programming while improving logical thinking and coding skills.

Uploaded by

amitjapulkar20
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)
3 views8 pages

Train Waiting List Simulation in C

The document describes a train waiting list simulation project (M3.10) that involves adding passenger details, managing confirmed and waiting lists, and implementing auto-shifting for cancellations. It outlines the learning outcomes, algorithm, and provides a C program that demonstrates the functionality of the system. The project enhances understanding of arrays, structures, and menu-driven programming while improving logical thinking and coding skills.

Uploaded by

amitjapulkar20
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

Activity Details

Name of Project Module:

M3.10 – Train Waiting List Simulation

Module Description
Task1: Add passenger details.

Task2: Add to waiting list if full.

Task3: Auto‑shift waiting → confirmed.

Learning Outcomes
- Understanding arrays and structures.

- Implemented waiting list queue.

- Improved logic using auto-shift.

- Practiced menu-driven programming.

About the Module


This module simulates a train reservation system with confirmed and waiting lists.
Passengers are added based on seat availability, and cancellations automatically promote
waiting passengers.

Algorithm
1. Start

2. Initialize confirmed & waiting arrays

3. Display menu

4. Book: add to confirmed or waiting

5. Cancel: remove ID & auto-shift waiting

6. View lists

7. Repeat till exit

8. Stop
Program:
#include <stdio.h>

#include <string.h>

#define MAX_CONFIRMED 5

#define MAX_WAITING 5

typedef struct {

int id;

char name[30];

int age;

} Passenger;

Passenger confirmed[MAX_CONFIRMED];

Passenger waiting[MAX_WAITING];

int confCount = 0, waitCount = 0;

int nextId = 1;

void bookTicket();

void cancelTicket();

void viewConfirmed();

void viewWaiting();

int main() {

int choice;

do {

printf("\n--- Train Waiting List Simulation (M3.10) ---\n");

printf("1. Book Ticket\n");

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

printf("3. View Confirmed List\n");

printf("4. View Waiting List\n");


printf("5. Exit\n");

printf("Enter choice: ");

scanf("%d", &choice);

switch (choice) {

case 1: bookTicket(); break;

case 2: cancelTicket(); break;

case 3: viewConfirmed(); break;

case 4: viewWaiting(); break;

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

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

} while (choice != 5);

return 0;

void bookTicket() {

Passenger p;

printf("Enter name: ");

scanf("%s", [Link]);

printf("Enter age: ");

scanf("%d", &[Link]);

[Link] = nextId++;

if (confCount < MAX_CONFIRMED) {

confirmed[confCount++] = p;

printf("Ticket CONFIRMED. ID = %d\n", [Link]);

else if (waitCount < MAX_WAITING) {


waiting[waitCount++] = p;

printf("Added to WAITING list. ID = %d, Position = %d\n",

[Link], waitCount);

else {

printf("Both confirmed and waiting lists are full.\n");

void cancelTicket() {

if (confCount == 0) {

printf("No confirmed bookings.\n");

return;

int id, i, j, found = 0;

printf("Enter passenger ID to cancel: ");

scanf("%d", &id);

for (i = 0; i < confCount; i++) {

if (confirmed[i].id == id) {

found = 1;

for (j = i; j < confCount - 1; j++)

confirmed[j] = confirmed[j + 1];


confCount--;

printf("Ticket cancelled for ID %d.\n", id);

if (waitCount > 0) {

confirmed[confCount] = waiting[0];

confCount++;

for (j = 0; j < waitCount - 1; j++)

waiting[j] = waiting[j + 1];

waitCount--;

printf("Passenger moved WAITING → CONFIRMED.\n");

break;

if (!found)

printf("ID not found.\n");

void viewConfirmed() {

if (confCount == 0) {

printf("No confirmed passengers.\n");

return;

printf("\n-- Confirmed List --\n");

printf("ID\tName\tAge\n");
for (int i = 0; i < confCount; i++)

printf("%d\t%s\t%d\n",

confirmed[i].id,

confirmed[i].name,

confirmed[i].age);

void viewWaiting() {

if (waitCount == 0) {

printf("Waiting list empty.\n");

return;

printf("\n-- Waiting List --\n");

printf("Pos\tID\tName\tAge\n");

for (int i = 0; i < waitCount; i++)

printf("%d\t%d\t%s\t%d\n",

i + 1,

waiting[i].id,

waiting[i].name,

waiting[i].age);

}
Output
Sample output showing booking, waiting list, cancellation and auto-shift operations.
Conclusion
In this module, I successfully implemented a train waiting list simulation using C. The
program uses arrays, structures, loops, and menu-driven logic to manage bookings. I
learned how to handle waiting lists and implement auto-shifting techniques. This activity
improved my logical thinking, coding skills, and understanding of real-world data handling.

Reference:
-Programming in ANSI C by Balaguruswamy Book
- PPS Lab Manual

- Classroom Notes

- C Programming Documentation

You might also like