You are on page 1of 9

RAILWAY RESERVATION SYSTEM

#include<stdio.h>
#include<stdlib.h>
typedef struct node
{
int seat;
char name[15];
int age;
char sex;
struct node* next;
}list,*ptr;
//void delete(ptr a);
void add(ptr a);
void printseat(ptr temp);
void print(ptr a);
//void delete(ptr a);
int main()
{
int i,input;
ptr a;
a=(ptr)malloc(1*sizeof(list)); // dummy node
a->next=NULL;
a->seat=0;
for(i=0;i<100;i++)
{
printf("enter 1 to book a ticket and 2 for deleting a TICKETand 3 to print the chart
and 4 to exit the loop \n");
scanf("%d",&input);
if(input==1)
{
add(a);
}
else if(input==2)
{
delete(a);
}
else if(input==3)
{
print(a);
}
else if(input==4)
{
break;
}
else
{
printf("not able to recognise the command \n");
}

}
printf("thank you \n");
return 0;
}
void add(ptr a)
{
int input,input2;
ptr temp=NULL;
while(a->next!=NULL)
{
a=a->next;
}
if(a->seat>70)
{
printf("train full \n");
return ;
}
else if(a->seat>50)
{
printf("%d waiting awailable \n",(a->seat)-50);
printf("enter 1 to exit 0 to continue ");
scanf("%d",&input2);
if(input2==1)
{
return ;
}
}
temp=(ptr)malloc(1*sizeof(
list));
temp->next=NULL;
printf("enter name ");
scanf("%s",temp->name);
printf("enter age ");
scanf("%d",&temp->age);
printf("enter sex ");
scanf("%s",&temp->sex);
temp->seat=(a->seat)+1;
printf("enter 1 to print the ticket 0 for ot to print the ticket \n");
scanf("%d",&input);
if(input==1)
{
printseat(temp);
}
a->next=temp;
return ;
}
void printseat(ptr temp)
{
if(temp->seat>50)
{
printf("WL=%d",(temp->seat)-
50);
}
else
{
printf("confirm seat=%d",temp->seat);
}
printf(" name=%s ",temp->name);
printf("sex=%c ",temp->sex);
printf("age=%d \n",temp->age);
return ;
}
void print(ptr a)
{
a=a->next;
while(a!=NULL)
{
printf("seat number=%d,name=%s ,age=%d,sex=%c \n",a->seat,a->name,a-
>age,a->
sex);
a=a->next;
}
return ;
}

RAILWAY RESERVATION SYSTEM PROGRAM


#include<stdio.h>
#include<string.h>
int flag[50]={0};
struct ticket
{
char customer_name[20];
char train_name[20];
int phone_num;
int ticket_num;
}o;
void book();
void check();
void cancel();
void func();
void view();
void view()
{
printf("******ROUTING DETAILS*****\n");
printf("Chennai---Banglore::5.00\n");
printf("Cochi---Coimbatore::6.00\n");
printf("Hydrabad---Manglore::4.00\n");
}

void func()
{
int ch,s;
do
{
printf("\t\t\t_______Ticket Reservation_______\n");
printf("\t\t\t1.BOOKING\n");
printf("\t\t\t2.CHECKING\n");
printf("\t\t\t3.CANCEL\n");
printf("Enter the choice:\n");
scanf("%d",&ch);
switch(ch)
{
case 1: book();
break;
case 2: check();
break;
case 3: cancel();
break;
case 4: view();
break;
default:
printf("Enter the valid choice!\n");
}
printf("Press 1 to continue???\n");
scanf("%d",&s);
}while(s==1);
}
void book()
{
int number;
printf("**^^**^^**BOOKING PROCESS**^^**^^**\n");
printf("ENTER THE TRAIN NAME\n");
scanf("%s",o.train_name);
printf("ENTER THE PHONE NUMBER:\n");
scanf("%d",&o.phone_num);
printf("ENTER THE TICKET NUMBER:\n");
scanf("%d",&o.ticket_num);
number=o.ticket_num;
if(flag[number]==0)
{
flag[number]=1;
}
else
{
printf("Soory!!ticket is already reserved..\n");
}
}
void check()
{
int i,count=0;
printf("The total reserved seats are:\n");

for(i=0;i<50;i++)
{
if(flag[i]!=0)
{
count++;
}
}
printf("%d ",count);
count=0;
}

void cancel()
{
int seat;
printf("ENTER THE TICKET\n");
scanf("%d",&seat);
if(seat>=1 && seat<=50)
{
if(flag[seat]==1)
{
flag[seat]=0;
{
printf("YOUR TICKET IS SUCCESSFULLY CANCELLED\n");
}
}
else
{
printf("This ticket is not reserved yet!!!!\n");
}
}
else
{
printf("Invalid seat number!!!\n");
}
}
void main()
{
func();
}

ZOHO PRACTICE PROBLEM

RAILWAY RESERVATION SYSTEM


Here they asked us to create a “Railway reservation system” and gave us 3 modules. The modules were:
1. Booking
2. Availability checking
3. Cancellation
We were asked to create the modules for representing each data first and to continue with the implementation phase.

SOLUTION:
USING STRUCTURE AND FUNCTION
#include<stdio.h>
struct ticket
{
int train_no,ph_no,id_no,ticket_no;
char train_name[20],passenger_name[20],src[20],des[20];
}z;
void booking();
void checking();
void cancel();
void main()
{
printf("#### WELCOME TO IRCTC WEBSITE ####");
int ch;
printf("\nRailway reservation system");
printf("\n1.Book the train");
printf("\n2.Checking availability");
printf("\n3.cancel the ticket");
while(1)
{
printf("\nEnter the choices");
scanf("%d",&ch);
switch(ch)
{

case 1: printf("\nWelcome to booking");


booking();
break;
case 2: printf("\nAvaillability checking");
checking();
break;
case 3: printf("\ncancellation of tickets");
cancel();
break;
//case 4: exit();
}
}
}
void booking()
{
printf("\nEnter ticket number:");
scanf("%d",&z.train_no);
printf("\nEnter train_name:");
scanf("%s",&z.train_name);
printf("\nEnter passenger name:");
scanf("%s",&z.passenger_name);
printf("\nEnter source:");
scanf("%s",&z.src);
printf("\nEnter destination:");
scanf("%s",&z.des);
printf("Enter phone number:");
scanf("%d",&z.ph_no);
printf("\nEnter identification number:");
scanf("%d",&z.id_no);
printf("\n #### BOOK HERE ####");
printf("\nTICKET BOOKED FOR TRAIN SUCCESSFULLY");
}
void checking()
{
int train_code,available_seats,ticket_reserved=0,compartment;
printf("\nEnter available seats");
scanf("%d",&available_seats);
if(ticket_reserved<available_seats)
{
ticket_reserved++;
printf("\nEnter the train code");
scanf("%d",&train_code);
booking();
int ch1;
printf("\nEnter choice for checking:");
scanf("%d",&ch1);
switch(ch1)
{
case 1: printf("\n 101.SLEEPER COMPARTMENT Your amount is $300");
booking();
break;
case 2: printf("\n 102.LADIES COMPARTMENT Your amount is $250");
booking();
break;
case 3: printf("\n 103.GENERAL Your amount is $150");
booking();
break;
}
}
}
void cancel()
{
int ticket,ticket_no;
char ch;
printf("\nenter the booked ticket no");
scanf("%d",&ticket);
if(ticket==z.ticket_no)
{
printf("\nyour ticket is cancelled");
}
else
{
printf("\nticket no is invalid");
booking();
}
}
http://sarueverythingishere.blogspot
.com/2016/06/zoho-complex-coding-
railway-reservation.html

You might also like