-
Notifications
You must be signed in to change notification settings - Fork 0
/
PPS_Bus_Reservation.c
283 lines (283 loc) · 9.58 KB
/
PPS_Bus_Reservation.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
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
void display1(int a[6][5],int n);
void display2(int a1[6][5],int n);
void display3(int a2[6][5],int n);
void read();
int main(){
int a[6][5]={{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0}};
int a1[6][5]={{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0}};
int a2[6][5]={{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0}};
int flag=1;
while(flag==1){
printf("\n\nWelcome to Yatra Travels!\n\nPress 1 to book your ticket\nPress 2 to view Passenger Database\nPress 3 to exit\n");
int ch,c,n,n1,n2,i;
scanf("%d",&ch);
if(ch==1){
printf("Book your tickets ASAP!\n\nAvailable Buses:\n1.Chennai to Bangalore\n2.Chennai to Kochi\n3.Chennai to Mumbai\nEnter your choice:");
scanf("%d",&c);
if(c==1){
printf("Enter number of tickets:");
scanf("%d",&n);
display1(a,n);
}
else if(c==2){
printf("Enter number of tickets:");
scanf("%d",&n1);
display2(a1,n1);
}
else if(c==3){
printf("Enter number of tickets:");
scanf("%d",&n2);
display3(a2,n2);
}
else{
printf("Invalid Input");
}
}
else if (ch==2){
read();
}
else if (ch==3){
flag=0;
break;
}
else{
printf("Invalid Input");
}
}
return 0;
}
void display1(int a[6][5],int n){
printf("Chennai to Bangalore\n");
int count=0;
for(int i=0;i<6;i++){
for(int j=0;j<5;j++){
if(a[i][j]==0){
count++;
}
}
}
printf("\n* ==> Occupied\no ==> Empty\n");
if(count>=n){
for(int i=0;i<6;i++){
if(i==0){
printf("\t1\t2\t3\t4\t5\n");
}
for(int j=0;j<5;j++){
if(j==0){
printf("%c\t",(65+i));
}
if(a[i][j]==0){
printf("o\t");
}
else if(a[i][j]==1){
printf("*\t");
}
}
printf("\n");
}
int amount=0;
for(int i=0;i<n;i++){
printf("Enter your choice of seats:\n");
char seat[3];
scanf("%s",&seat);
char alpha;
int num1,num2;
alpha=seat[0];
num2= ((int)(alpha))-65;
num1=(int)seat[1]-48;
a[num2][num1-1]=1;
amount=3600;
struct Details{
char name[100];
int busno;
char seat[3];
int amount;
};
struct Details s[n];
printf("Enter First Name:");
scanf("%s",&s[i].name);
s[i].busno=9801;
strcpy(s[i].seat,seat);
s[i].amount=amount;
FILE *bus;
bus=fopen("YatraTravels.txt","a+");
/*if(bus==NULL){
printf("Error");
exit();
}*/
fprintf(bus,"Name:%s\tBus Number:%d\tSeat Number:%s\tAmount to be paid:%d\tStatus:%s\n",s[i].name,s[i].busno,s[i].seat,s[i].amount,"Confirmed");
fclose(bus);
}
if(n*amount==n*3600){
printf("Your %d tickets have been booked succesfully. Please pay the total amount at the counter before boarding\nTotal amount to be paid: %d\nBus Number:9801\nHave a nice jouney! Thank you for choosing Yatra Travels!",n,n*amount);
}
else{
printf("Sorry your seats couldn't be booked. Please try again later. Feel free to contact our customer care toll free number.");
}
}
else{
printf("Sorry seats are not available right now. Please try agian later.");
}
}
void display2(int a1[6][5],int n){
printf("Chennai to Kochi");
int count=0;
for(int i=0;i<6;i++){
for(int j=0;j<5;j++){
if(a1[i][j]==0){
count++;
}
}
}
printf("\n* ==> Occupied\no ==> Empty\n");
if(count>=n){
for(int i=0;i<6;i++){
if(i==0){
printf("\t1\t2\t3\t4\t5\n");
}
for(int j=0;j<5;j++){
if(j==0){
printf("%c\t",65+i);
}
if(a1[i][j]==0){
printf("o\t");
}
else if(a1[i][j]==1){
printf("*\t");
}
}
printf("\n");
}
int amount=0;
for(int i=0;i<n;i++){
printf("Enter your choice of seats:");
char seat[3];
scanf("%s",&seat);
char alpha;
int num1,num2;
alpha=seat[0];
num2= ((int)(alpha))-65;
num1=(int)seat[1]-48;
a1[num2][num1-1]=1;
amount=3600;
struct Details{
char name[100];
int busno;
char seat[3];
int amount;
}s[n];
printf("Enter First Name:");
scanf("%s",&s[i].name);
s[i].busno=9802;
strcpy(s[i].seat,seat);
s[i].amount=amount;
FILE *bus;
bus=fopen("YatraTravels.txt","a+");
/*if(bus==NULL){
printf("Error");
exit();
}*/
fprintf(bus,"Name:%s\tBus Number:%d\tSeat Number:%s\tAmount to be paid:%d\tStatus:%s\n",s[i].name,s[i].busno,s[i].seat,s[i].amount,"Confirmed");
fclose(bus);
}
if(n*amount==n*3600){
printf("Your %d have been booked succesfully. Please pay the total amount at the counter before boarding\nTotal amount to be paid: %d\nBus Number:9802\nTo cancel your tickets please contact our customer service\nHave a nice jouney! Thank you for using Yatra Travels!",n,n*amount);
}
else{
printf("Sorry your seats couldn't be booked. Please try again later. Feel free to contact our customer care toll free number.");
}
}
else{
printf("Sorry seats are not available right now. Please try agian later.");
}
}
void display3(int a2[6][5],int n){
printf("Chennai to Mumbai\n");
int count=0;
for(int i=0;i<6;i++){
for(int j=0;j<5;j++){
if(a2[i][j]==0){
count++;
}
}
}
printf("\n* ==> Occupied\no ==> Empty\n");
if(count>=n){
for(int i=0;i<6;i++){
if(i==0){
printf("\t1\t2\t3\t4\t5\n");
}
for(int j=0;j<5;j++){
if(j==0){
printf("%c\t",65+i);
}
if(a2[i][j]==0){
printf("o\t");
}
else if(a2[i][j]==1){
printf("*\t");
}
}
printf("\n");
}
int amount=0;
for(int i=0;i<n;i++){
printf("Enter your choice of seats:");
char seat[3];
scanf("%s",&seat);
char alpha;
int num1,num2;
alpha=seat[0];
num2= ((int)(alpha))-65;
num1=(int)seat[1]-48;
a2[num2][num1-1]=1;
amount=3600;
struct Details{
char name[100];
int busno;
char seat[3];
int amount;
}s[n];
printf("Enter First Name:");
scanf("%s",&s[i].name);
s[i].busno=9803;
strcpy(s[i].seat,seat);
s[i].amount=amount;
FILE *bus;
bus=fopen("YatraTravels.txt","a+");
/*if(bus==NULL){
printf("Error");
exit();
}*/
fprintf(bus,"Name:%s\tBus Number:%d\tSeat Number:%s\tAmount to be paid:%d\tStatus:%s\n",s[i].name,s[i].busno,s[i].seat,s[i].amount,"Confirmed");
fclose(bus);
}
if(n*amount==n*3600){
printf("Your %d have been booked succesfully. Please pay the total amount at the counter before boarding\nTotal amount to be paid: %d\nBus number: 9803\nTo cancel your tickets please contact our customer service\nHave a nice jouney! Thank you for using Yatra Travels!",n,n*amount);
}
else{
printf("Sorry your seats couldn't be booked. Please try again later. Feel free to contact our customer care toll free number.");
}
}
else{
printf("Sorry seats are not available right now. Please try again later.");
}
}
void read(){
FILE *bus;
bus=fopen("YatraTravels.txt","r");
/*if(bus==NULL){
printf("Error");
exit();
}*/
printf("Yatra Travels Database\n");
char ch;
do {
ch = fgetc(bus);
printf("%c", ch);
} while (ch != EOF);
fclose(bus);
}