Reservation
Reservation
Reservation
#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 ;
}
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();
}
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)
{