-
Notifications
You must be signed in to change notification settings - Fork 0
/
Project.c
262 lines (231 loc) · 4.11 KB
/
Project.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
/// Airline System
//By-Aditya Prabhu
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct book
{
char code[20];
char name[20];
char date[20];
int cost;
}b;
int seat = 60;
void ta_det();
void viewall();
void find();
void book_tic();
void old_rec();
void main()
{
int ch;
do{
printf("\n==================================");
printf("\n");
printf(" Airline Ticket booking ");
printf("\n");
printf("\n==================================");
printf("\n 1 Booking");
printf("\n 2 View All Ticket");
printf("\n 3 Find Ticket ");
printf("\n 4 Booked Ticket");
printf("\n 5 View All Record");
printf("\n 6 Delete Record");
printf("\n 0 Exit \n");
printf("\nEnter your Choice: ");
scanf("%d",&ch);
switch (ch)
{
case 1 :
ta_det();
break;
case 2:
viewall();
break;
case 3:
find();
break;
case 4:
book_tic();
break;
case 5:
old_rec();
break;
/* case 6:
delete();
break; */
case 0:
exit(0);
break;
default:
printf("Wrong choice !");
break;
}
}while(ch!=0);
}
void ta_det()
{
FILE *fp;
struct book b;
printf("Enter ticket code : ");
scanf("%s",b.code);
printf("Enter passenger name : ");
scanf("%s",b.name);
printf("Enter Date: ");
scanf("%s",b.date);
printf("Enter Ticket Price: ");
scanf("%d",&b.cost);
fp=fopen("data.txt","a");
if(fp == NULL)
{
printf("FIle not Found");
}
else
{
fprintf(fp,"%s %s %s %d\n",b.code,b.name,b.date,b.cost);
printf("Congratulations,Booking successfull");
}
printf("\n");
fclose(fp);
}
void find()
{
struct book b;
FILE *fp;
char ch[5];
printf("Enter ticket code :");
scanf("%s",ch);
fp = fopen("data.txt","r");
if(fp == NULL)
{
printf("file does not found !");
exit(1);
}
else
{
while(getc(fp) != EOF)
{
fscanf(fp,"%s %s %s %d",b.code,b.name,b.date,&b.cost);
if(strcmp(b.code,ch) == 0)
{
printf("%s %s %s %d\n",b.code,b.name,b.date,b.cost);
printf("\n Record Found\n");
printf("\n\t\tTicket Code : %s",b.code);
printf("\n\t\tPassenger name : %s",b.name);
printf("\n\t\tDate : %s",b.date);
printf("\n\t\tPrice : %d",b.cost);
break;
}
}
}
fclose(fp);
}
void viewall()
{
char ch;
FILE *fp;
fp = fopen("data.txt","r");
if(fp == NULL)
{
printf("Not found !");
exit(1);
}
else
{
while( (ch=fgetc(fp))!= EOF )
printf("%c",ch);
}
fclose(fp);
}
void book_tic()
{
struct book b;
FILE *fp;
FILE *ufp;
int total_seat,phone;
char name[20];
char ch;
char ticket_code[20];
fp = fopen("data.txt","r");
if(fp == NULL)
{
printf("Not found !");
exit(1);
}
else
{
while( ( ch = fgetc(fp) ) != EOF )
printf("%c",ch);
}
fclose(fp);
printf("\n Enter ticket code :");
scanf("%s",ticket_code);
fp = fopen("data.txt","r");
if(fp == NULL)
{
printf("File not found !");
exit(1);
}
else
{
while(getc(fp)!=EOF)
{
fscanf(fp,"%s %s %s ",b.code,b.name,b.date);
if(strcmp(b.code,ticket_code) == 0)
{
printf("\n Record Found\n");
printf("\n\t\tCode :%s",b.code);
printf("\n\t\tPassenger name :%s",b.name);
}
}
}
printf("\n===========================");
printf("\n");
printf("\t Passenger Details ");
printf("\n");
printf("\n===========================");
printf("\n Passenger name :");
scanf("%s",name);
printf("\n Phone number :");
scanf("%d",&phone);
printf("\n Total seat :");
scanf("%d",&total_seat);
printf("\n===========================");
printf("\n");
printf("\t Happy Journey ");
printf("\n");
printf("\n===========================");
printf("\n\t\tname : %s",name);
printf("\n\t\tphone Number : %d",phone);
printf("\n\t\tTotal seats : %d",total_seat);
ufp=fopen("record.txt","a");
if(ufp == NULL)
{
printf("FIle not Found");
}
else
{
fprintf(ufp,"%d %d %s \n",phone,total_seat,b.name);
printf("\n Re-enter in record");
}
printf("\n");
fclose(ufp);
fclose(fp);
}
void old_rec()
{
char ch;
FILE *fp;
fp = fopen("record.txt","r");
if(fp == NULL)
{
printf("Not found !");
exit(1);
}
else
{
while(( ch=fgetc(fp)) != EOF )
printf("%c",ch);
}
fclose(fp);
}