-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmovies.c
294 lines (238 loc) · 4.99 KB
/
movies.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
284
285
286
287
288
289
290
291
292
/*
Movie ticket boking
Aditya Prabhu
*/
#include<stdio.h>
#include<stdlib.h>
struct book
{
char code[20];
char name[20];
char date[20];
int cost;
}b;
int seat = 60 ;
void insert_details();//for inserting movie details
void viewAll(); // for view all data
void find(); // for finding data
void book_ticket(); //for booking tickets
void old_record(); //for view old recorrds of users,booked tickets
void main()
{
int ch;
do{
printf("\n====================================================================");
printf("\n");
printf("\t Moive Ticket booking ");
printf("\n");
printf("\n====================================================================");
printf("\nPress <1> Insert Movie");
printf("\nPress <2> View All Movie");
printf("\nPress <3> Find Movie ");
printf("\nPress <4> Book Ticket");
printf("\nPress <5> View All Transections");
printf("\nPress <0> Exit ");
printf("\nEnter your Choice ::");
scanf("%d",&ch);
switch (ch)
{
case 1 :
insert_details();
break;
case 2:
viewAll();
break;
case 3:
find();
break;
case 4:
book_ticket();
break;
case 5:
old_record();
break;
case 0:
exit(0);
break;
default:
printf("Wrong choice !");
break;
}
}while(ch!=0);
}
void insert_details()
{
FILE *fp;
struct book b;
printf("Enetr movie code :- ");
scanf("%s",b.code);
printf("Enetr name :- ");
scanf("%s",b.name);
printf("Enetr Relice Date:- ");
scanf("%s",b.date);
printf("Enetr 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("Record insert Sucessfull");
}
printf("\n");
fclose(fp);
}
void find() //find details
{
struct book b;
FILE *fp;
char ch[20];
printf("Enter movie code :");
scanf("%s",ch);
//system("clear");
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\tCode ::%s",b.code);
printf("\n\t\tmovie name ::%s",b.name);
printf("\n\t\tmovie date ::%s",b.date);
printf("\n\t\tprice of ticket ::%d",b.cost);
break;
}
}
}
fclose(fp);
}
void viewAll()
{
char ch;
FILE *fp;
fp = fopen("data.txt","r");
if(fp == NULL)
{
printf("file does not found !");
exit(1);
}
else
{
system("clear");
while( ( ch = fgetc(fp) ) != EOF )
printf("%c",ch);
}
fclose(fp);
}
//for ticket booking
void book_ticket()
{
struct book b;
FILE *fp;
FILE *ufp;
int total_seat,mobile,total_amount;
char name[20];
char ch; //used in display all movies
char movie_code[20]; //for searching
// disply all moives by default for movie code
fp = fopen("data.txt","r");
if(fp == NULL)
{
printf("file does not found !");
exit(1);
}
else
{
system("cls");
while( ( ch = fgetc(fp) ) != EOF )
printf("%c",ch);
}
fclose(fp);
//display ends
printf("\n For Book ticket Choise Movie(Enter Movie Code First Latter Of Movie)\n");
printf("\n Enter movie code :");
scanf("%s",movie_code);
//system("clear");
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,movie_code) == 0)
{
//printf("%s / %s / %s / %d\n",b.code,b.name,b.date,b.cost);
printf("\n Record Found\n");
printf("\n\t\tCode ::%s",b.code);
printf("\n\t\tMovie name ::%s",b.name);
printf("\n\t\tdate name ::%s",b.date);
printf("\n\t\tPrice of ticket::%d",b.cost);
}
}
}
printf("\n* Fill Deatails *");
printf("\n your name :");
scanf("%s",name);
printf("\n mobile number :");
scanf("%d",&mobile);
printf("\n Total number of tickets :");
scanf("%d",&total_seat);
total_amount = b.cost * total_seat;
printf("\n ***** ENJOY MOVIE ****\n");
printf("\n\t\tname : %s",name);
printf("\n\t\tmobile Number : %d",mobile);
printf("\n\t\tmovie name : %s",b.name);
printf("\n\t\tTotal seats : %d",total_seat);
printf("\n\t\tcost per ticket : %d",b.cost);
printf("\n\t\tTotal Amount : %d",total_amount);
ufp=fopen("oldTransection.txt","a");
if(ufp == NULL)
{
printf("FIle not Found");
}
else
{
fprintf(ufp,"%s %d %d %d %s %d \n",name,mobile,total_seat,total_amount,b.name,b.cost);
printf("\n Record insert Sucessfull to the old record file");
}
printf("\n");
fclose(ufp);
fclose(fp);
}
//for view all user transections
void old_record()
{
char ch;
FILE *fp;
//system("clear");
fp = fopen("oldTransection.txt","r");
if(fp == NULL)
{
printf("file does not found !");
exit(1);
}
else
{
system("clear");
while( ( ch = fgetc(fp) ) != EOF )
printf("%c",ch);
}
fclose(fp);
}