-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRailway_system_management.cpp
486 lines (452 loc) · 11.4 KB
/
Railway_system_management.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
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include<time.h>
#include<ctype.h>
#include <time.h>
#include <windows.h>
#include <process.h>
#include <unistd.h>
#include<iostream>
#include<istream>
#include<ostream>
#include<fstream>
using namespace std;
int number_of_trains = 1;
void process_time(int index, int coo);
void gotoxy(int x, int y);
int options();
void setter_basic();
void setter_infos(int n);
void time_sc();
void current_time();
void intro();
void allocate_trains();
void change_current_info();
/*bool timelag()
{
time_t ob;
int seconds;
ob = clock();
seconds = ob/CLOCKS_PER_SEC;
if(seconds == 60)
{
system("cls");
}
}*/
class train
{
private:
char from[50];
char to[50];
bool seats[100];
int leaveing_time[3];
int price_of_ticket;
public:
train()
{
strcpy(from,"dhaka");
strcpy(to , "NULL");
for(int i=0;i<100;i++)
{
seats[i] = 0;
}
price_of_ticket = 250;
leaveing_time[0]=0;
leaveing_time[1]=0;
leaveing_time[2]=0;
}
void set_from(char from_temp[20])
{
strcpy(from, from_temp);
}
void set_price_of_ticket(int temp)
{
price_of_ticket = temp;
}
void set_to(char to_temp[20])
{
strcpy(to,to_temp);
}
void set_seats(bool temp, int pos)
{
seats[pos] = temp;
}
void set_leaveing_time(int temp[3])
{
for(int i=0; i<3; i++)
{
leaveing_time[i]=temp[i];
}
}
char* get_from()
{
return from;
}
char* get_to()
{
return to;
}
bool* get_seats_com()
{
return seats;
}
int* get_leaveing_time()
{
return leaveing_time;
}
int get_price_of_tickets(int i)
{
return i*price_of_ticket;
}
void book_seats(int i)
{
int book;
cout<<"Loading... Please wait"<<endl;
for(int c=0; c<i; c++)
{
while(1)
{
srand(time(NULL));
book = rand() % 100;
if(seats[book] == 0)
{
break;
}
}
seats[book] = 1;
}
}
int available_seats()
{
int available=0;
for(int i=0; i<100;i++)
{
if(seats[i]==0)
{
available++;
}
}
return available;
}
} *ob;
void check_seats()
{
system("cls");
Sleep(1000);//////
int j=3;
system("cls");
current_time();
int trains=0;
gotoxy(2, 2);
cout<<"---------------------------------------------------------------------------";
for(j=3; j<(number_of_trains*2)+3; j=j+2)
{
for(int i=0; i<75; i++)
{
gotoxy(2+i, j+1);
cout<<"-";
gotoxy(25, j);
cout<<"|";
gotoxy(50, j);
cout<<"|";
gotoxy(15, j);
cout<<ob[trains].get_to();
gotoxy(35,j);
cout<<ob[trains].available_seats();//////seats available
process_time(trains,j);
}
trains++;
}/////deletable
gotoxy( 0, j+1);
int booked_seats;
int train_no;
cout<<"Please enter the number of train you want to book ticket in: ";
cin>>train_no;
cout<<"There are "<<ob[train_no-1].available_seats()<<" available sits"<<endl;
cout<<"Please enter how many seats you want to book: ";
cin>>booked_seats;
cout<<"The price of those ticket is: "<<ob[train_no-1].get_price_of_tickets(booked_seats)<<endl;
cout<<"Do you want to proceed? (yes = 1 and no = 0): ";
bool choice;
cin>>choice;
if(choice)
{
ob[train_no-1].book_seats(booked_seats);
cout<<"Seats has been booked"<<endl<<"There are about "<<ob[train_no-1].available_seats()<<" remaining seats"<<endl;
}
}
void file_to_class()
{
system("cls");
ifstream iopen;
char filename[20];
char from[100][20];
char to[100][20];
int train_time[100][3];
int counter_train=0;
int price[100];
cout<<"Please enter the name of the file (make sure it is in the same folder as the cpp file itself):";
cin>>filename;
iopen.open(filename);
if(!iopen.is_open())
{
system("cls");
cout<<"Failed to open the file you were looking for. Please enter the name correctly with .txt ";
// return 0;
}
while(iopen>>from[counter_train]>>to[counter_train]>>train_time[counter_train][0]>>train_time[counter_train][1]>>train_time[counter_train][2]>>price[counter_train])
{
counter_train++;
}
number_of_trains = counter_train;
allocate_trains();
system("cls");
cout<<"Loading all the files.....Please wait"<<endl;
for(int i=0; i<counter_train; i++)
{
ob[i].set_from(from[i]);
ob[i].set_to(to[i]);
ob[i].set_leaveing_time(train_time[i]);
ob[i].set_price_of_ticket(price[i]);
}
cout<<"Successful..."<<endl;
Sleep(1000);
int c=0;
while(c<=10)
{
system("cls");
time_sc();
c++;
Sleep(1000);
}
}
void process_time(int index, int coo)
{
int *temp_time = ob[index].get_leaveing_time();
time_t now;
tm leaving_time;
int seconds, temp_second, temp_minutes, temp_hour;
time(&now); /* get current time; same as: now = time(NULL) */
leaving_time = *localtime(&now);
leaving_time.tm_hour = temp_time[0]; leaving_time.tm_min = temp_time[1]; leaving_time.tm_sec = temp_time[2];
leaving_time.tm_mon = 10; leaving_time.tm_mday = 17;
seconds = difftime(mktime(&leaving_time),now);
if(seconds/60 >= 60)
{
temp_hour= seconds / 3600;
seconds = seconds % 3600;
temp_minutes = seconds / 60;
seconds = seconds % 60;
}
else if(seconds >=60)
{
temp_hour= 0;
temp_minutes = seconds / 60;
seconds = seconds % 60;
}
else
{
temp_hour = 0;
temp_minutes = 0;
}
gotoxy(59, coo);
printf ("%d : %d : %d",temp_hour, temp_minutes, seconds);
}
void gotoxy(int x, int y)
{
COORD coord;
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
int options()
{
while(1)
{
gotoxy(20, 0);
cout<<"Railway Station Of Dhaka"<<endl;
current_time();
cout<<"Please choose what you want to do-"<<endl;
cout<<"1. Take informations from file"<<endl;
cout<<"2. Check informations about trains"<<endl;
//cout<<"2. Check seats on a particular train"<<endl;
cout<<"3. Tickets booking"<<endl;
cout<<"4. Pause the system"<<endl;
cout<<"5. Edit the train information"<<endl;
cout<<"6. Put in information about trains"<<endl;
cout<<"7. Refresh the screen"<<endl;
cout<<"8. Exit"<<endl;
cout<<"Set your choice: ";
int choice;
cin>>choice;
if(choice == 1)
{
file_to_class();
}
else if(choice == 2)
{
int c=0;
while(c<=10)
{
system("cls");
time_sc();
c++;
Sleep(1000);
}
}
else if(choice == 3)
{
check_seats();
system("pause");
}
else if(choice == 4)
{
cout<<endl;
system("pause");
}
else if(choice == 6)
{
setter_basic();
}
else if(choice == 7)
{
system("cls");
}
else if(choice == 8)
{
exit(0);
}
else if(choice == 5)
{
change_current_info();
}
system("cls");
}
}
void change_current_info()
{
system("cls");
time_sc();
gotoxy(0, (number_of_trains*2)+3);
cout<<"put the serial number of the train: ";
int train_no;
cin>>train_no;
cout<<"Please select what do you want to change: "<<endl;
cout<<"1. Destination";
cout<<"2. Departure time";
cout<<"3. Amount of seats";
cout<<"4. Price of a ticket";
int i;
cin>>i;
if(i==1)
{
system("cls");
Sleep(1000);
char changed_destination[20];
cout<<"Please enter the name of that place: ";
cin>>changed_destination;
ob[train_no].set_to(changed_destination);
}
}
void allocate_trains()
{
ob = new train[number_of_trains];
}
void setter_basic()
{
system("cls");
cout<<"Please enter the number of trains you want to keep track of:";
cin>>number_of_trains;
allocate_trains();
setter_infos(number_of_trains);
}
void setter_infos(int n)
{
for(int i=0; i<n; i++)
{
char from[50], to[50];
cout<<"Please enter the place where it is leaving from: ";
cin>>from;
ob[i].set_from(from);
cout<<"Where is the train headed: ";
cin>>to;
ob[i].set_to(to);
int temp_time[3];
cout<<"Please enter the time when the train will leave"<<endl;
cout<<"hour :";
cin>>temp_time[0];
cout<<"minutes : ";
cin>>temp_time[1];
cout<<"seconds : ";
cin>>temp_time[2];
ob[i].set_leaveing_time(temp_time);
cout<<"Price of a ticket is: ";
int price;
cin>>price;
ob[i].set_price_of_ticket(price);
system("cls");
Sleep(1000);
}
}
void time_sc()
{
// system("cls");
int c=0;
//while(1 && c<=10)
{
// Sleep(1000);
// system("cls");
current_time();
int trains=0;
gotoxy(2, 2);
cout<<"---------------------------------------------------------------------------";
for(int j=3; j<(number_of_trains*2)+3; j=j+2)
{
for(int i=0; i<75; i++)
{
gotoxy(2+i, j+1);
cout<<"-";
gotoxy(20, j);
cout<<"|";
gotoxy(38, j);
cout<<"|";
gotoxy(56, j);
cout<<"|";
gotoxy(8, j);
cout<<ob[trains].get_to();
gotoxy(25,j);
cout<<ob[trains].available_seats();//////seats available
gotoxy(42, j);
cout<<ob[trains].get_price_of_tickets(1);
gotoxy(59, j);
process_time(trains,j);
}
trains++;
}
// c++;
}
}
void current_time()
{
time_t rawtime;
struct tm * timeinfo;
time (&rawtime);
timeinfo = localtime (&rawtime);
gotoxy(50,1);
cout<<asctime(timeinfo);
}
void intro()
{
/*gotoxy(20, 0);
cout<<"This is the railway station of Dhaka"<<endl;
current_time();*/
options();
}
int main()
{
ob = new train;
intro();
Sleep(1000);
system("cls");
}