-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrailwayreservation.cpp
512 lines (500 loc) · 15.1 KB
/
railwayreservation.cpp
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
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
//---------------------------rail way reservation project by using c programming language--------------------------
//---------------------------------------header file start-----------------------------------------
#include<stdio.h>
#include<windows.h>
#include<stdlib.h>
#include<conio.h>
#include<time.h>
#include<string.h>
//---------------------------------------header file close-------------------------------------------
//---------------------------------------user define function start----------------------------------
void viewinfo();
void bookticket();
void cancelticket();
void admin();
void password();
void viewpassenger();
void addtrain();
void dlttrain();
void awrite();
void aread();
void bookticket_write();
void viewpassengers_read();
//-----------------------------------------user define function close-----------------------------------
//-----------------------------------------structure start----------------------------------------------
struct adddata
{
char si[10];
char train_number[10];
char train_name[20];
char start[10];
char destination[10];
char price[10];
int seat;
char time[10];
} add[1000];
struct bookticket
{
char train_number[20];
char name[20];
char phone[20];
char date[20];
int seat;
}book[1000];
//---------------------------------------structure close----------------------------------------------
//---------------------------------------global variable----------------------------------------------
int k=0,u=0;
char trn_nmbr[100],name[100],phn[100];
//---------------------------------------main function start------------------------------------------
int main()
{
aread();
viewpassengers_read();
system("COLOR 0f");
int ch;
time_t currentTime;
time(¤tTime);
printf("\n\t\t\t %s\n",ctime(¤tTime));
printf("\n\t\t\t*********************************\n");
printf("\t\t\t*******RAILWAY RESERVATION SYSTEM*******\n");
printf("\t\t\t*********************************\n");
printf("\n\t\t\t<<<<<<<<<<WELCOME USERS>>>>>>>>>>\n");
printf("\n\n\t\t\t\t MENU\n");
printf("\t\t\t ******");
printf("\n\t\t\t[1] VIEW INFORMATION\n");
printf("\n\t\t\t[2] BOOK TICKET\n");
printf("\n\t\t\t[3] CANCEL TICKET\n");
printf("\n\t\t\t[4] ADMIN");
printf("\n\n\t\t\t[5] EXIT\n");
printf("\n\t\t\t********************************");
printf("\n\t\t\t********************************");
printf("\n\t\t\tENTER YOUR CHOICE: ");
scanf("%d",&ch);
switch(ch)
{
case 1:
viewinfo();
break;
case 2:
bookticket();
break;
case 3:
cancelticket();
break;
case 4:
password();
break;
case 5:
system("cls");
printf("\n\t\t\t =========================================\n");
printf("\t\t\t *******RAILWAY RESERVATION SYSTEM*******\n");
printf("\t\t\t ===============================================\n");
printf("\n\n\t\t\tBMROUGHT TO YOU BY\n\n");
printf("\t\t\t\t***Learnprogramo***\n");
getch();
exit(0);
break;
default:
system("cls");
printf("\n\t\t\t==============================================\n");
printf("\t\t\t *******RAILWAY RESERVATION SYSTEM*******\n");
printf("\t\t\t ==============================================\n");
printf("\n\n\t\t\t<<<<<<<<YOU ENTERED WRONG CHOICE>>>>>>>>\n");
printf("\t\t\t<<<<<<<<PLEASE ENTER RIGHT THING>>>>>>>>\n");
getch();
system("cls");
main();
}
return 0;
}
//---------------------------------------main function close--------------------------------------------------
//---------------------------------------book ticket function-----------------------------------------------
void bookticket()
{
int c,j,n,i,found=-1;
char v,train_number[10];
system ("cls");
aread();
printf("\n\n\t\t\t============================================");
printf("\n\t\t\t**********RAILWAY RESERVATION SYSTEM**********\n");
printf("\t\t\t==================================================");
printf("\n\n\t\t\thow many ticket do you want to buy: ");
scanf("%d",&n);
for(j=u;j<u+n;j++)
{
printf("\n\n\t\t\tEnter train number: ");
scanf("%s", book[j].train_number);
for(i=0;i<k;i++)
{
if(strcmp(book[j].train_number,add[i].train_number)==0)
{
if(add[i].seat==0)
{
printf("\n\n\t\t\tnot available seat");
getch();
system("cls");
main();
}
else
{
found=1;
printf("\n\t\t\tenter book %d no ticket: ",j+1);
printf("\n\t\t\tenter date: ");
scanf("%s",book[j].date);
printf("\n\t\t\tenter your name: ");
scanf("%s",book[j].name);
printf("\n\t\t\tenter your phone number: ");
scanf("%s",book[j].phone);
printf("\n\t\t\tseat number : %d",add[i].seat );
book[j].seat=add[i].seat;
bookticket_write();
add[i].seat--;
awrite();
}
}
}
if(found==-1)
{
printf("\n\n\t\t\ttrain not found!!!");
getch();
system("cls");
main();
}
}
u=j;
bookticket_write();
printf("\n\n\t\t\tenter '1' for main menu & press any key to exit: ");
scanf("%d",&c);
if(c==1)
{
system("cls");
main();
}
if(c!=1)
{
exit;
}
}
//---------------------------------------cancel ticket function---------------------------------------------
void cancelticket()
{
viewpassengers_read();
char pnnmbr[100];
int location = -1,e;
printf ("\n\n\t\t\tenter phone number: ");
scanf ("%s",pnnmbr);
for (e=0;e<u;e++)
{
if (strcmp(pnnmbr,book[e].phone)==0)
{
location=e;
break;
}
}
if (location==-1)
{
printf ("\n\n\t\t\t<<<<<<<<<<<<<<Data Not Found>>>>>>>>>>>>>>>>> \n");
getch();
system("cls");
main();
}
else
{
for (e=location;e<u;e++)
{
strcpy(book[e].date,book[e+1].date);
strcpy(book[e].train_number,book[e+1].train_number);
strcpy(book[e].name,book[e+1].name);
strcpy(book[e].phone,book[e+1].phone);
bookticket_write();
}
u--;
bookticket_write();
printf("\n\n\t\t\t<<<<<<<<<<<<<<<ticket cancelled successfully>>>>>>>>>>>>");
getch();
system("cls");
main();
}
}
//-------------------------------------admin portal function----------------------------------------
void admin()
{
int chhh;
system("cls");
printf("\n ==================================================================");
printf("\n ********************RAILWAY RESERVATION SYSTEM*******************");
printf("\n ====================================================================");
printf("\n\n");
printf(" <<<<<<<<<<<<<<<WELCOME_ADMIN>>>>>>>>>>>>>>>\n");
printf("\n\n");
printf(" ************************************\n");
printf(" || CHOOSE YOUR OPERATION ||\n");
printf(" ||--------------------------------||\n");
printf(" || [1] VIEW PASSENGERS ||\n");
printf(" || [2] ADD TRAIN ||\n");
printf(" || [3] DELETE TRAIN ||\n");
printf(" || [4] BACK ||\n");
printf(" || ||\n");
printf(" ************************************\n\n");
printf(" **********************************************************\n");
printf("\n\t\tENTER YOUR CHOICE: ");
scanf("%d",&chhh);
switch(chhh)
{
case 1:
viewpassenger();
break;
case 2:
addtrain();
break;
case 3:
dlttrain();
break;
case 4:
system("cls");
getch();
main();
break;
default:
getch();
printf("\n\t\t\tyou entered wrong KEY!!!!");
getch();
system("cls");
main();
}
getch();
}
//-----------------------------password function----------------------------------
void password()
{
int number=1234567;
int pass;
printf("\n\t\t\tenter password: ");
scanf("%d",&pass);
if(pass==number)
{
printf("\n\n\t\t\t<<<<<login successfully>>>>>");
getch();
system("cls");
admin();
}
else
{
printf("\n\n\t\t\t\t ERROR!!!!!");
printf("\n\n\t\t\t<<<<<<<<wrong password>>>>>>>>");
getch();
system("cls");
main();
}
}
//------------------------------------delete train function----------------------------------------------
void dlttrain()
{
aread();
char train[100];
int location = -1,f;
printf ("\n\n\tenter train number: ");
scanf ("%s",train);
for (f=0;f<k;f++)
{
if (strcmp(train,add[f].train_number)==0)
{
location=f;
break;
}
}
if (location==-1)
{
printf ("\n\n\t<<<<<<<<<<<<<<Data Not Found>>>>>>>>>>>>>>>>> \n");
getch();
system("cls");
admin();
}
else
{
for (f=location;f<k;f++)
{
strcpy(add[f].si,add[f+1].si);
strcpy(add[f].train_number,add[f+1].train_number);
strcpy(add[f].train_name,add[f+1].train_name);
strcpy(add[f].start,add[f+1].start);
strcpy(add[f].destination,add[f+1].destination);
strcpy(add[f].price,add[f+1].price);
strcpy(add[f].time,add[f+1].time);
awrite();
}
k--;
awrite();
printf("\n\n\t<<<<<<<<<<<<<train deleted successfully>>>>>>>>>>>>>");
getch();
system("cls");
admin();
}
}
//--------------------------------------view passengers function----------------------------------------
void viewpassenger()
{
int a,j;
system("cls");
viewpassengers_read();
printf("\n\t\t\t **********************************************************");
printf("\n\t\t\t ********************RAILWAY RESERVATION SYSTEM********************");
printf("\n\t\t\t **********************************************************");
printf("\n\n\t\t\ttrain number\t\tname\t\tphone number\t\tdate\t\tseat\n");
printf("\n\t\t\t**********************************************************************************\n");
for(j=0;j<u;j++)
{
printf("\n\t\t\t%s\t\t\t%s\t\t%s\t\t%s\t%d",book[j].train_number,book[j].name,book[j].phone,book[j].date,book[j].seat);
book[j].seat++;
}
printf("\n\t\t\t**********************************************************************************\n");
printf("\n\n\t\t\tenter '1' for main menu & enter '0' for back: ");
scanf("%d",&a);
if(a==1)
{
system("cls");
main();
}
if(a==0)
{
system("cls");
admin();
}
}
//--------------------------------------add train function--------------------------------------------
void addtrain()
{
system("cls");
int ch;
aread();
int i,a;
printf("\n\t\t **********************************************************");
printf("\n\t\t ********************RAILWAY RESERVATION SYSTEM********************");
printf("\n\t\t **********************************************************");
printf("\n\n\t\t\thow many trains do you want to add: ");
scanf("%d",&a);
for(i=k;i<k+a;i++)
{
printf("\n\t\t\tenter %d train details: ",i+1);
printf("\n\t\t\tenter serial number: ");
scanf("%s",add[i].si);
printf("\n\t\t\tenter train number: ");
scanf("%s",add[i].train_number);
printf("\n\t\t\tenter train name: ");
scanf("%s",add[i].train_name);
printf("\n\t\t\tenter start place: ");
scanf("%s",add[i].start);
printf("\n\t\t\tenter destination place: ");
scanf("%s",add[i].destination);
printf("\n\t\t\t enter price: ");
scanf("%s",add[i].price);
printf("\n\t\t\t enter seat: ");
scanf("%d", & add[i].seat);
printf("\n\t\t\t enter time: ");
scanf("%s",add[i].time);
}
printf("\n\n\t\t\tconfirm train: (y=1/n=0):- ");
scanf("%d",&ch);
if(ch==1)
{
awrite();
k=i;
awrite();
system("cls");
printf("\n\n\t\t\t**********************************************************");
printf("\n\t\t\t********************RAILWAY RESERVATION SYSTEM********************");
printf("\n\t\t\t**********************************************************");
printf("\n\n");
printf("\n\t\t\t\t **********************************");
printf("\n\t\t\t\t *<<<<<train add successfully>>>>>*");
printf("\n\t\t\t\t **********************************");
getch();
system("cls");
main();
}
if(ch==0)
{
system("cls");
admin();
}
if((ch!=1)&&(ch!=0))
{
system("cls");
main();
}
}
//-----------------------------------view information function--------------------------------------
void viewinfo()
{
int ch,i;
system("cls");
aread();
printf("\n\t\t **********************************************************");
printf("\n\t\t ********************RAILWAY RESERVATION SYSTEM********************");
printf("\n\t\t **********************************************************");
printf("\n\n\n SI\ttrain number\ttrain name\tstart place\tdestination place\tprice\tseat\ttime\n\n");
for(i=0;i<k;i++)
{
printf(" %s\t%s\t\t%s\t\t%s\t\t%s\t\t\t%s\t%d\t%s\n",add[i].si,add[i].train_number,add[i].train_name,add[i].start,add[i].destination,add[i].price,add[i].seat,add[i].time);
}
printf(" ***********************************************************************************************\n");
printf("\n\t\t\tpress '1' for main menu & press any key for exit: ");
scanf("%d",&ch);
switch(ch)
{
case 1:
system("cls");
main();
break;
default:
exit(0);
}
}
//------------------------------------------book ticket file start-----------------------------------------
void bookticket_write()
{
FILE *booklist;
booklist=fopen("booklist.txt","w");
fwrite(&book,sizeof(book),1,booklist);
fclose(booklist);
FILE *booklistreport;
booklistreport=fopen("booklistreport.txt","w");
fwrite(&u,sizeof(u),1,booklistreport);
fclose(booklistreport);
}
void viewpassengers_read()
{
FILE *booklist;
booklist=fopen("booklist.txt","r");
fread(&book,sizeof(book),1,booklist);
fclose(booklist);
FILE *booklistreport;
booklistreport=fopen("booklistreport.txt","r");
fread(&u,sizeof(u),1,booklistreport);
fclose(booklistreport);
}
//-----------------------------------------add train file start---------------------------------------------------
void awrite()
{
FILE *train_details;
train_details = fopen("train_details.txt","w");
fwrite(&add,sizeof(add),1,train_details);
fclose(train_details);
FILE *train_report;
train_report = fopen("train_report.txt","w");
fwrite(&k,sizeof(k),1,train_report);
fclose(train_report);
}
void aread()
{
FILE *train_details;
train_details = fopen("train_details.txt","r");
fread(&add,sizeof(add),1,train_details);
fclose(train_details);
FILE *train_report;
train_report = fopen("train_report.txt","r");
fread(&k,sizeof(k),1,train_report);
fclose(train_report);
}
//----------------------------------------------------file close----------------------------------------------
//----------------------------------------------------program close----------------------------------------