-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTicket_Management_System.cpp
More file actions
254 lines (242 loc) · 4.31 KB
/
Ticket_Management_System.cpp
File metadata and controls
254 lines (242 loc) · 4.31 KB
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
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<conio.h>
#include<string.h>
using namespace std;
class TourBus
{
int bid;
char destination[200];
char time[50];
int max_seats;
int booked;
int fare;
public:
TourBus()
{
bid=0;
max_seats=50;
booked=0;
fare=0;
strcpy(time,"9:10am");
strcpy(destination,"");
}
void input();
void show();
void display();
int getid()
{
return bid;
}
void book()
{
booked++;
}
char* getDestination()
{
return destination;
}
char* getTime()
{
return time;
}
int getBooked(){
return booked;
}
int getMax(){
return max_seats;
}
int getFare()
{
return fare;
}
};
class Ticket
{
char name[50];
TourBus bus;
public:
void generate(char cname[], TourBus tb)
{
strcpy(name,cname);
bus=tb;
}
void display()
{
cout<<"Customer Name "<<name<<endl;
cout<<"Details of Bus "<<endl;
bus.show();
}
};
void TourBus::input()
{
cout<<"Enter bus id ";
cin>>bid;
cout<<"Enter bus destination ";
gets(destination);
cout<<"Enter time of bus ";
cin>>time;
cout<<"Enter fare of the bus ";
cin>>fare;
}
void TourBus::display()
{
cout<<bid<<"\t"<<destination<<"\t"<<time<<"\t"<<max_seats<<"\t"<<booked<<"\t"<<fare<<"\n";
}
void TourBus::show()
{
cout<<"Bus Id "<<bid<<endl;
cout<<"Desination "<<destination<<endl;
cout<<"Time "<<time<<endl;
cout<<"No. of seats remaining "<<max_seats-booked<<endl;
}
void main()
{
int ch;
fstream F,G;
TourBus b;
do
{
// clrscr();
cout<<"Press 1 - Add a New Tour Bus"<<endl;
cout<<"Press 2 - Show Selected Bus"<<endl;
cout<<"Press 3 - Display All Buses"<<endl;
cout<<"Press 4 - Delete a Bus"<<endl;
cout<<"Press 5 - Book a ticket "<<endl;
cout<<"Press 6 - Display Booked Tickets "<<endl;
cout<<"Press 7 - Exit "<<endl;
cout<<"Enter your choice ";
cin>>ch;
switch(ch)
{
case 1:
F.open("tour.dat",ios::app | ios::binary);
b.input();
F.write((char*)&b, sizeof(b));
F.close();
cout<<"Bus added Successfully "<<endl;
getch();
// clrscr();
break;
case 2:
int id = 0, chk = 0;
cout<<"Enter the bus id to be displayed ";
cin>>id;
F.open("tour.dat",ios::in | ios::binary);
if(F.fail())
cout<<"Can't open file "<<endl;
else
{
while(F.read((char*)&b,sizeof(b)))
{
if(b.getid()==id)
{
b.show();
chk=1;
break;
}
}
if(chk==0)
cout<<"Bus not Found"<<endl;
}
F.close();
break;
case 3:
F.open("tour.dat",ios::in | ios::binary);
if(F.fail())
cout<<"Can't open file "<<endl;
else
{
while(F.read((char*)&b,sizeof(b)))
b.display();
}
F.close();
cout<<"Press a key to continue ";
getch();
// clrscr();
break;
case 4:
chk=0;
cout<<"Enter the bus id to be deleted ";
cin>>id;
F.open("tour.dat",ios::in | ios::binary);
G.open("temp.dat",ios::out | ios::binary);
if(F.fail())
cout<<"Can't open file "<<endl;
else
{
while(F.read((char*)&b,sizeof(b)))
{
if(b.getid()!=id)
{
G.write((char*)&b,sizeof(b));
}
else
{
b.show();
chk=1;
}
}
if(chk==0)
cout<<"Bus not Found"<<endl;
else
cout<<"Bus Deleted "<<endl;
}
F.close();
G.close();
remove("tour.dat");
rename("temp.dat","tour.dat");
break;
case 5:
char dest[70],cname[50];
int bid;
Ticket t;
cout<<"Enter the destination ";
gets(dest);
F.open("tour.dat",ios::in | ios::out | ios::binary);
if(F.fail())
cout<<"Can't open file "<<endl;
else
{
while(F.read((char*)&b,sizeof(b)))
{
if(strcmp(b.getDestination(),dest)==0)
{
b.show();
chk=1;
cout<<"Enter the customer name ";
gets(cname);
b.book();
t.generate(cname,b);
G.open("tickets.dat",ios::app | ios::binary);
G.write((char*)&t,sizeof(t));
G.close();
F.seekp(F.tellg()-sizeof(b),ios::beg);
F.write((char*)&b,sizeof(b));
cout<<"Ticket booked"<<endl;
getch();
break;
}
}
if(chk==0)
cout<<"No Bus Found"<<endl;
}
F.close();
break;
case 6:
cout<<"Booked Tickets "<<endl;
G.open("tickets.dat",ios::in | ios::binary);
if(G.fail())
cout<<"can't open file "<<endl;
else
{
while(G.read((char*)&t,sizeof(t)))
t.display();
}
G.close();
cout<<"Press a key to continue ";
getch();
}
}while(ch!=7);
}