-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathticket_booking_sym.c
160 lines (152 loc) · 3.89 KB
/
ticket_booking_sym.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
//train booking system
//simple implementation
//not yet completed
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
// global variables
int running = 1, option, user_pnr;
char search[20];
char availableTrain[5][20];
static int current_booking = 0;
const int capacity = 5;
char passengerName[20];
int pnrArray[5];
struct Booking
{
int pnr;
char name[20];
char train[20];
} booking[5];
void initBooking()
{
// default list of trains
strcpy(availableTrain[0], "Vanchinadu Exp");
strcpy(availableTrain[1], "Venad Exp");
strcpy(availableTrain[2], "Chennai Exp");
strcpy(availableTrain[3], "Malabar Exp");
strcpy(availableTrain[4], "Guruvayoor Exp");
for (int i = 0; i < capacity; i++)
{
pnrArray[i] = rand() % 100;
}
}
void showAvailableTrain()
{
printf("available trains\n");
printf("_________________\n");
for (int i = 0; i < 5; i++)
{
printf("%d. %s\n", i + 1, availableTrain[i]);
}
}
int serachTrains()
{
int option;
showAvailableTrain();
printf("\nchoose any train....\n");
printf("press 0 to exit from this menu\n");
scanf("%d", &option);
if (option != 0)
return option;
else
{
printf("logic to previous menu! not implemented\n");
exit(0);
}
}
void bookingTrain()
{
int choice;
choice = serachTrains();
if (current_booking <= capacity)
{
printf("Enter name\n");
scanf("%s", passengerName);
printf("\nBooking sucess\n");
printf("_____________________________\n");
printf("Booking details\n");
printf("Name: %s\n", passengerName);
strcpy(booking[current_booking].name, passengerName);
printf("PNR NO: %d\n", pnrArray[current_booking]);
booking[current_booking].pnr = pnrArray[current_booking];
printf("Train: %s\n", availableTrain[choice - 1]);
strcpy(booking[current_booking].train, availableTrain[choice - 1]);
current_booking++;
}
else
{
printf("NO seats available...\n");
exit(0);
}
}
void passengerDetails()
{
printf("Passenger details\n");
printf("___________________\n");
for (int i = 0; i < capacity; i++)
{
printf("%s ", booking[i].name);
printf("%d ", booking[i].pnr);
printf("%s ", booking[i].train);
printf("\n");
}
}
void cancelTrain()
{
int j;
printf("enter pnr no to cancel\n");
scanf("%d", &user_pnr);
printf("Searching for pnr no\n");
for (j = 0; j < capacity; j++)
{
if (booking[j].pnr == user_pnr)
{
printf("PNR found....\n");
strcpy(booking[j].name, "cancelled");
booking[j].pnr = 0;
strcpy(booking[j].train, "cancelled");
printf("Ticket cancelled...\n");
break;
}
}
if (j==capacity)
printf("PNR no not found.. try again\n");
}
int main()
{
initBooking();
while (running)
{
printf("_______________________________________\n");
printf("welcome :)\n");
printf("1.Book a ticket\n");
printf("2.Cancel a ticket\n");
printf("4.Passenger Details\n");
printf("5.Exit\n");
scanf("%d", &option);
switch (option)
{
case 1:
printf("\nBooking....");
bookingTrain();
break;
case 2:
printf("\nCancel ....");
cancelTrain();
break;
case 3:
printf("\nupdate available train\n");
// updataAvailableTrain();
break;
case 4:
passengerDetails();
break;
default:
printf("Exiting .....\n");
exit(0);
break;
}
}
}