#include<stdio.h>
struct train
{
int seats[100];
char t_name[30];
char dept_time[5];
char source[30];
char dest[30];
char t_id[5];
}t[4];
void book(char nam[],char id[],char dt[],char src[],char dst[],int *s,int j)
{
int ch,nb,i,n,k=1;
while(k=1)
{
printf("Enter ur choice:\n1. Availability checking\n 2. Booking\n
3. Cancellation\n");
scanf("%d",&ch);
switch(ch)
{
case 1:
{
printf("1.Train Name:%s\n 2.Train id:%s\n
3.Train Departure time:%s\n 4.Source:%s\n 5.Destination:%s\n
6.Availabe Seats:%d\n",nam,id,dt,src,dst,*s);
struct train
{
int seats[100];
char t_name[30];
char dept_time[5];
char source[30];
char dest[30];
char t_id[5];
}t[4];
void book(char nam[],char id[],char dt[],char src[],char dst[],int *s,int j)
{
int ch,nb,i,n,k=1;
while(k=1)
{
printf("Enter ur choice:\n1. Availability checking\n 2. Booking\n
3. Cancellation\n");
scanf("%d",&ch);
switch(ch)
{
case 1:
{
printf("1.Train Name:%s\n 2.Train id:%s\n
3.Train Departure time:%s\n 4.Source:%s\n 5.Destination:%s\n
6.Availabe Seats:%d\n",nam,id,dt,src,dst,*s);
for(i=0;i<*s;i++)
{
if(t[j].seats[i]==0)
{
printf("%d ",i);
}
}
break;
}
case 2:
{
printf("\nEnter the number of seats");
scanf("%d",&nb);
printf("\nEnter the seat numbers");
for(i=0;i<nb;i++)
{
scanf("%d",&n);
t[j].seats[n]=1;
}
break;
}
case 3:
{
printf("\nEnter the number of seats to be cancelled");
scanf("%d",&nb);
printf("\nEnter the seat numbers");
for(i=0;i<nb;i++)
{
scanf("%d",&n);
t[j].seats[n]=0;
}
break;
}
}
printf("\nEnter 1 to continue");
scanf("%d",&k);
}
}
main()
{
int i,j,st[4];
char nm[30];
for(j=0;j<4;j++)
{
for(i=0;i<100;i++)
{
t[j].seats[i]=0;
}
}
for(i=0;i<4;i++)
{
scanf("%s %s %s %s %s %d",t[i].t_name,t[i].t_id,t[i] .dept_time,
t[i].source,t[i]. dest,&st[i]);
}
for(i=0;i<4;i++)
{
printf("%s\n %s\n %s\n %s\n %s\n %d\n",t[i].t_name,t[i].t_id,t[ i].dept_time,t[i].source,t[i]. dest,st[i]);
}
printf("\nChoose the train");
scanf("%s",nm);
for(i=0;i<4;i++)
{
if(strcmp(nm,t[i].t_name)==0)
{
book(t[i].t_name,t[i].t_id,t[ i].dept_time,t[i].source,t[i]. dest,
&st[i],i);
break;
}
}
}
{
if(t[j].seats[i]==0)
{
printf("%d ",i);
}
}
break;
}
case 2:
{
printf("\nEnter the number of seats");
scanf("%d",&nb);
printf("\nEnter the seat numbers");
for(i=0;i<nb;i++)
{
scanf("%d",&n);
t[j].seats[n]=1;
}
break;
}
case 3:
{
printf("\nEnter the number of seats to be cancelled");
scanf("%d",&nb);
printf("\nEnter the seat numbers");
for(i=0;i<nb;i++)
{
scanf("%d",&n);
t[j].seats[n]=0;
}
break;
}
}
printf("\nEnter 1 to continue");
scanf("%d",&k);
}
}
main()
{
int i,j,st[4];
char nm[30];
for(j=0;j<4;j++)
{
for(i=0;i<100;i++)
{
t[j].seats[i]=0;
}
}
for(i=0;i<4;i++)
{
scanf("%s %s %s %s %s %d",t[i].t_name,t[i].t_id,t[i]
t[i].source,t[i].
}
for(i=0;i<4;i++)
{
printf("%s\n %s\n %s\n %s\n %s\n %d\n",t[i].t_name,t[i].t_id,t[
}
printf("\nChoose the train");
scanf("%s",nm);
for(i=0;i<4;i++)
{
if(strcmp(nm,t[i].t_name)==0)
{
book(t[i].t_name,t[i].t_id,t[
&st[i],i);
break;
}
}
}
No comments:
Post a Comment