Airline reservation System

Write your question here.
Pls help me with the reservation part
It is a visual c++ version 6
The reservation function is either not reading the file or the comparing is not working .It is directly going to part 2 of the reservation function . We are using visual c++ version 6 . We need your help to solve the issue.


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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
#include<iostream.h>
#include<ctype.h>
#include<stdio.h>
#include<string.h>
#include<time.h>
#include<dos.h>
#include<fstream.h>
#include<process.h>
#include<stdlib.h>
#include<conio.h>

class customer 
{
public:
	char name[20], ppn[25];
	customer()
	{
		strcpy(name,"nil");
		strcpy(ppn,"nil");
	}
	void getcust() //Function to get details from user/customer
	{
		cout<<"Welcome to RV detail obtaining centre"<<endl;
                             cout<<endl;
                             cout<<"Enter the name : ";	
		cin.getline(name, 20);
		cout<<endl;
		cout<<"Enter passport number : ";
		cin.getline(ppn, 25);
		cout<<endl;
                             cout<<endl;
	}
	void displaycust() //Function to display details of the user/customer
	{
		cout<<"Welcome to RV detail distribution centre"<<endl;
                             cout<<endl;
                             cout<<"Name : ";
		for(int z=0;name[z]!='\0';z++)
			cout<<name[z];
		cout<<endl;
		cout<<"Passport number : ";
		for(int f=0;ppn[f]!='\0';f++)
			cout<<ppn[f];
		cout<<endl;
                             cout<<endl;
	}
	char *getname() //Accessor function to return name of user/customer
	{
		return name;
	}
	char *getppn() //Accessor function to return passport number of user/customer
	{
		return ppn;
	}
};
class flight
{
	public: customer C[20];
	int fltno, seat;
	char dep[20], arr[20], fltname[25];
	float fare;

	flight()
	{
		seat = 20;
	}
	
	void inputdetails() //Function to input all the details of user/customer
	{
		char ch;
		cout<<"Welcome, please enter the following details"<<endl;
                             cout<<endl;
                             cout<<"Enter the flight number : ";
		cin>>fltno;
		cout<<endl;
		cin.get(ch);
		cout<<"Enter the flight name : ";
		cin.getline(fltname,9);
		
		cout<<endl;
		cout<<"Enter the port of departure  : ";
		cin.getline(dep, 20);
		cout<<endl;
		cout<<"Enter the port of arrival : ";
		cin.getline(arr, 20);
		cout<<endl;
		cout<<"Enter the flight fare : ";
		cin>>fare;
		cout<<endl;
                             cout<<endl;

	}
	void displaydetails() //Function to display all the details of user/customer
	{
		int x;
cout<<"*****************************************"<<endl;
cout<<endl;
		cout<<"Flight name : ";
		cout<<fltname;
		cout<<"Flight number : "<<fltno<<endl;
		cout<<endl;
		int ls= strlen(dep);
		cout<<"Departure : ";
	               cout.write(dep,ls);
				int la=strlen(arr);
		cout<<"Arrival : ";
		cout.write(arr,la);
		cout<<endl;
		cout<<"Fare : Rs. "<<fare<<endl;
		cout<<endl;
		x=seatavailable();
		cout<<"Seats available : "<<x<<endl;
		cout<<endl;
cout<<"**************************************************"<<endl;
cout<<endl;
	}
	char *getdep() //Accessor function to return location of departure  of user/customer
	{
		return dep;
	}
	char *getarr() //Accessor function to return location of arrival of user/customer
	{ 
		return arr;
	}
	char *getfltname()  //Accessor function to return flight name of user/customer
	{ 
		return fltname;
	}
	int getfltno()  //Accessor function to return flight number of user/customer
	{
		return fltno;
	}
	int getseat()  //Accessor function to return no. of seats available
	{
		return seat;
	}
	float getfare()  //Accessor function to return fare of user/customer
	{
		return fare;
	}
	
	void updateseat(int n)  //Function which updates the no. of seats as a booking is                          made by user/customer
	{
		seat= seat-n;
	}
int seatavailable(); //prototype of seatavailable
void displaycustomer(); //prototype of displaycustomer
	
};
void flight::displaycustomer() //Definition of displaycustomer function, outside class
	{
		int i;
		for(i=1;i<=20;i++)
		{	cout<<i<<"-";
		    C[i].displaycust();
			cout<<endl;
                                            cout<<endl;
		}

	}

 int flight:: seatavailable() //Definition of seatavailable function, outside class
	{
		int count=0, i;
		for(i=1;i<=20;i++)
		{	if((strcmp(C[i].getname(),"nil")==0)&&(strcmp(C[i].getppn(), "nil")==0))
			
				count++;
}
			return count;
                                           cout<<endl;
	}




void reserve2() //Function to reserve seat for administrator	
{
	cout<<"Welcome Juhi ma'am, to RV main reservation centre"<<endl;
               cout<<endl;
               flight F;
	int flightno,i,n;
	ifstream fin;
	fstream fout;
	fin.open("reserve.dat",ios::binary);
	cout<<"Enter the flight number selected : ";
	cin>>flightno;
	cout<<endl;
	while(!fin.eof())
	{
		if(flightno==F.getfltno())
		{
			cout<<"Enter the number of customer : ";
			cin>>n;
			cout<<endl;
			if(n<F.seat)
			{
				for(i=0;i<n;i++)
				{
					F.C[i].getcust();
					fout.write((char*)&F, sizeof(F));

				}
				float cost=n*F.getfare();
				cout<<"Your total fare is : Rs."<<cost<<endl;
				cout<<endl;
				F.updateseat(n);
                                                          cout<<endl;
			}
			else
				cout<<"Reduce the no. of bookings!"<<endl;
                                                           cout<<endl;
		}
		else
			cout<<"No such flight exists"<<endl;
		cout<<endl;

	}
	fin.close();
	fout.close();
}
void reserve() //Function to reserve seat for common user
{char c;
flight F;
	char from[15], to[15];
	ifstream fin;
	ofstream fout;
	cout<<"Welcome to RV reservation centre"<<endl;
               cout<<endl;
               

	cout<<"Enter the post of departure : ";
	cin.getline(from,15);
	cout<<endl;
	cin.get(c);
	cout<<"Enter the post of arrival : ";
	cin.getline(to,15);

	cout<<endl;
	cin.get(c);
	fin.open("flight.dat",ios::in);
	fout.open("reserve.dat",ios::out);
	while(!fin.eof())
	{
		fin.read((char*)&F, sizeof(F));
		if((stricmp(from,F.getdep())==0)&&(stricmp(to,F.getarr())==0))
		{
			fout.write((char*)&F, sizeof(F));
			F.displaydetails();
		}
		
		fout.close();
		fin.close();
		reserve2();
                            cout<<endl;
	}
}

void cancellation() //Function to cancel a reservation
{
	cout<<"Welcome to RV cancellation centre"<<endl;
               cout<<endl;
               ifstream fin; flight F; char nm[20], pop[25]; int flight1no,i;
	ofstream fout;
	display();
	fin.open("flight.dat",ios::binary);
	fout.open("flight.dat",ios::binary);
	cout<<"Enter the fligh number : ";
	cin>>flight1no;
	cout<<endl;
	cout<<"Enter the name : ";
	gets(nm);
	cout<<endl;
	cout<<"Enter the passport number : ";
	gets(pop);
	cout<<endl;
	while(!fin.eof())
	{
		fin.read((char*)&F,sizeof(F));
		if(flight1no==F.getfltno())
		{
			for(i=1;i<=20;i++)
			{
				if((strcmpi(nm,F.C[i].getname())==0)&&(strcmpi(pop,F.C[i].getppn())==0))
				{
				strcpy(F.C[i].getname(),"nil");
				strcpy(F.C[i].getppn(),"nil");
				}
			}
			fout.write((char*)&F,sizeof(F));
		}
	}
	fout.close();
	fin.close();
               cout<<endl;
}
void admin() //Function for the menu of the administrator
{

	int ch1;
	do
	{
		cout<<"Goodmorning Juhi ma'am"<<endl;
                             cout<<endl;
                             cout<<"MENU"<<endl;
		cout<<endl;
		cout<<"1. Create master file "<<endl;
		cout<<"2. Add a record to the master file"<<endl;
		cout<<"3. Dispay records"<<endl;
		cout<<"4. Exit"<<endl;
		cout<<endl;
		cout<<"Enter your choice : ";
		cin>>ch1;
		switch(ch1)
		{
		case 1 : create();
		         break;
		case 2 : addmore();
		         break;
		case 3 : display();
		         break;
		case 4 : exit(0);
				//	goto lbl;
		         break;
		default : 
		cout<<"Wrong choice"<<endl;
		
		}
	}
	while(ch1!=4);
}
Topic archived. No new replies allowed.