forked from MozPhoenixClubJUET/Winter-of-Code19
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bus_Reservation_System.c
425 lines (396 loc) · 10.9 KB
/
Bus_Reservation_System.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char ch[10][130]={"Kamla Travels","Raj Kalpana Express","Hans Express","Volvo Express","Rail Yatri Express"};
char name[32][100]={'\0'};
char number[32][2]={'\0'};
int num1[32]={0};
int trno;
void login();
void bus();//for list of bus
void name_number(int booking,char numstr[100]);
void booking();//for booking the tickets
int read_number(int trno);//for reading the number from the file
void read_name(int trno);//for reading the name from the file
void status();//for printing the status by user input
void status_1(int trno);//for printing the status while booking ticket
void cancel();
int main()
{
login();
int num,i;
do{
system("cls");
printf("\n\n\n");
printf("====================================== WELCOME TO BUS RESERVATION SYSTEM ======================================\n\n\n");
printf("\t\t\t\t\t[1]=> View Bus List\n");
printf("\n");
printf("\t\t\t\t\t[2]=> Book Tickets\n");
printf("\n");
printf("\t\t\t\t\t[3]=> Cancel Booking\n");
printf("\n");
printf("\t\t\t\t\t[4]=> Bus Status Board\n");
printf("\n");
printf("\t\t\t\t\t[5]=> Exit\n\n");
printf("===============================================================================================================\n\n");
printf("\t\t\tEnter Your Choice:: ");
scanf("%d",&num);
switch(num)
{
case 1:
bus();//for list of bus
break;
case 2:
booking();//for booking the tickets
break;
case 3:
cancel();
break;
case 4:
status();
break;
}
getch();
}while(num != 5);
system("CLS");
printf("\t----------------------------------------------------------------------------------------------------------\n");
printf("\t\t\t\t\tThank You For Using This System\t\t\t\t\t\t\n");
printf("\t----------------------------------------------------------------------------------------------------------\n");
getch();
return 0;
}
void bus()
{
system("cls");
printf("\n\n\n");
printf("=========================================== BUS RESERVATION SYSTEM ============================================\n\n\n");
printf("\t\t\t\t\t[1] => %s\n",ch[0]);
printf("\n");
printf("\t\t\t\t\t[2] => %s\n",ch[1]);
printf("\n");
printf("\t\t\t\t\t[3] => %s\n",ch[2]);
printf("\n");
printf("\t\t\t\t\t[4] => %s\n",ch[3]);
printf("\n");
printf("\t\t\t\t\t[5] => %s\n",ch[4]);
}
void booking()
{
int i=0;
char numstr[100];
system("cls");
printf("=========================================== BUS RESERVATION SYSTEM ============================================\n\n\n");//for entering train number
bus();//for seeing train least
printf("Enter the Bus number:--->");
scanf("%d",&trno);
system("cls");
printf("=========================================== BUS RESERVATION SYSTEM ============================================\n\n\n");//for selecting coach
printf("Your Bus Number is %d ********** %s",trno,ch[trno-1]);
status_1(trno);
FILE *f1, *fopen();//for reading the seats from the user.
char str1[80]="32",str2[4],str3[4];
int seat1,seat2,booking=0;
if(trno == 1)
{
f1 = fopen("tr1.txt","r+");
fgets(str1,80,f1);
fclose(f1);
}else if(trno == 2)
{
f1 = fopen("tr2.txt","r+");
fgets(str1,80,f1);
fclose(f1);
}else if(trno == 3)
{
f1 = fopen("tr3.txt","r+");
fgets(str1,80,f1);
fclose(f1);
}
else if(trno == 4)
{
f1 = fopen("tr4.txt","r+");
fgets(str1,80,f1);
fclose(f1);
}
else if(trno == 5)
{
f1 = fopen("tr5.txt","r+");
fgets(str1,80,f1);
fclose(f1);
}
seat1=atoi(str1);//covert the string into number
if(seat1 <= 0)
{
printf("There is no blank seat in this bus ");
}else
{
printf("\n\n\n\t\t\t\tAvailable Seats:------>%d\n",seat1);
printf("\n\t\t\t\tNumber of Tickets:----->");
scanf("%d",&booking);
printf("\n");
seat1=seat1-booking;
itoa(trno,numstr,10);
name_number(booking,numstr);
printf("\n\t\t\t\tThe Total booking amount is %d",200*booking);
itoa(seat1, str1, 10);
//for reading the seats from the user.
if(trno == 1)
{
f1 = fopen("tr1.txt","w");
fputs(str1,f1);
fclose(f1);
}
else if(trno == 2)
{
f1 = fopen("tr2.txt","w");
fputs(str1,f1);
fclose(f1);
}
else if(trno == 3)
{
f1 = fopen("tr3.txt","w");
fputs(str1,f1);
fclose(f1);
}
else if(trno == 4)
{
f1 = fopen("tr4.txt","w");
fputs(str1,f1);
fclose(f1);
}
else if(trno == 5)
{
f1 = fopen("tr5.txt","w");
fputs(str1,f1);
fclose(f1);
}
}
}
void name_number(int booking,char numstr[100])
{
char tempstr[100],tempstr1[12]="status",tempstr2[12]="number";
int number;
FILE *a,*b;
int i=0;
strcat(numstr,".txt");
strcat(tempstr1,numstr);
strcat(tempstr2,numstr);
a = fopen(tempstr1,"a");//for open the file to write the name in the file
b = fopen(tempstr2,"a");//for open the file for writing the number in the file
for(i=0; i<booking; i++)//for entering the person name and seat number in the file
{
printf("============================Enter the details for ticket no %d============================\n\n\n",i+1);
printf("\t\t\t\tEnter the seat number:--->");
scanf("%d",&number);
printf("\t\t\t\tEnter the name of person:--->");
scanf("%s",name[number-1]);
printf("\n======================================================================================================\n\n");
printf("\n");
itoa(number, tempstr, 10);
fprintf(a,"%s ",name[number-1]);
fprintf(b,"%s ",tempstr);
}
fclose(a);
fclose(b);
}
int read_number(int trno)//for putting the numeric value in the array
{
char tempstr[100],tempstr2[12]="number";
FILE *a,*b;
char numstr[100];
int i=0,j=0,k;
itoa(trno,numstr,10);
strcat(numstr,".txt");
strcat(tempstr2,numstr);
a = fopen(tempstr2,"a+");//for open the file to write the name in the file
while(!feof(a))
{
number[i][j] = fgetc(a);
if(number[i][j] == ' ')
{
j=0;
i++;
}
else
{
j++;
}
}
k=i;
for(i=0; i<k; i++)
{
num1[i] = atoi(number[i]);
}
fclose(a);
return k;
}
void read_name(int trno)//for putting the numeric value in the array
{
char tempstr1[12]="status";
FILE *b;
char numstr[100];
int i=0,j=0,k=0;
itoa(trno,numstr,10);
strcat(numstr,".txt");
strcat(tempstr1,numstr);
b = fopen(tempstr1,"a+");//for open the file to write the name in the file
while(!feof(b))
{
name[i][j] = fgetc(b);
if(name[i][j] == ' ')
{
j=0;
i++;
}
else
{
j++;
}
}
name[i][j]='\0';
k=i;
fclose(b);
}
void status()
{
system("cls");
printf("=========================================== BUS RESERVATION SYSTEM ============================================\n\n\n");
int i,trno,index=0,j;
printf("Enter the number of bus:---->");
scanf("%d",&trno);
j=read_number(trno);
read_name(trno);
printf("____________________________________________________________________________________________________________________\n");
printf(" Bus.no-->%d---->%s \n",trno,ch[trno-1]);
printf("____________________________________________________________________________________________________________________\n");
char tempname[33][10]={"Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty "};
for(i=0; i<j; i++)
{
strcpy(tempname[num1[i]],name[i]);
}
for(i=0; i<8; i++)
{
printf("\t\t\t\t");
for(j=0; j<4; j++)
{
printf("%d.%s\t",index+1,tempname[index+1]);
index++;
}
printf("\n");
}
}
void status_1(int trno)
{
printf("Your Bus Number is %d ********** %s",trno,ch[trno-1]);
system("cls");
printf("=========================================== BUS RESERVATION SYSTEM ============================================\n\n\n");
int i,index=0,j;
j=read_number(trno);
read_name(trno);
char tempname[33][10]={"Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty ","Empty "};
for(i=0; i<j; i++)
{
strcpy(tempname[num1[i]],name[i]);
}
for(i=0; i<8; i++)
{
printf("\t\t\t\t");
for(j=0; j<4; j++)
{
printf("%d.%s\t",index+1,tempname[index+1]);
index++;
}
printf("\n");
}
}
void cancel()
{
int seat_no,i,j;
char numstr[100],tempstr2[15]="number",tempstr1[15]="status";
printf("Enter the bus number:---->");
scanf("%d",&trno);
itoa(trno,numstr,10);
strcat(numstr,".txt");
strcat(tempstr1,numstr);
strcat(tempstr2,numstr);
read_number(trno);
read_name(trno);
status_1(trno);
printf("Enter the seat number:--->");
scanf("%d",&seat_no);
FILE *a,*b;
a = fopen(tempstr1,"w+");
b = fopen(tempstr2,"w+");
for(i=0; i<32; i++)
{
if(num1[i] == seat_no)
{
for(j=0; j<32; j++)
{
if(num1[j] != seat_no && num1[j] != 0)
{
fprintf(b,"%d ",num1[j]);
fprintf(a,"%s",name[j]);
}
else if(num1[j] == seat_no && num1[j] != 0)
{
strcpy(name[j],"Empty ");
}
}
}
}
fclose(a);
fclose(b);
printf("\n\n");
printf("======================================================================================================\n");
printf("\t\t\t\tYour 200 rupees has been Returned\t\t\t\n");
printf("======================================================================================================\n");
}
void login()
{
int a=0,i=0;
char uname[10],c=' ';
char pword[10],code[10];
char user[10]="aman";
char pass[10]="aman";
do
{
system("cls");
printf("\n ========================= LOGIN FORM ========================= ");
printf(" \n ENTER USERNAME:-");
scanf("%s", &uname);
printf(" \n ENTER PASSWORD:-");
while(i<10)
{
pword[i]=getch();
c=pword[i];
if(c==13) break;
else printf("*");
i++;
}
pword[i]='\0';
//char code=pword;
i=0;
//scanf("%s",&pword);
if(strcmp(uname,"aman")==0 && strcmp(pword,"aman")==0)
{
printf(" \n\n\n WELCOME TO OUR SYSTEM !!!! LOGIN IS SUCCESSFUL");
printf("\n\n\n\t\t\t\tPress any key to continue...");
getch();//holds the screen
break;
}
else
{
printf("\n SORRY !!!! LOGIN IS UNSUCESSFUL");
a++;
getch();//holds the screen
}
}
while(a<=2);
if (a>2)
{
printf("\nSorry you have entered the wrong username and password for four times!!!");
getch();
}
system("cls");
}