-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbluesky.cpp
More file actions
375 lines (303 loc) · 9.07 KB
/
Copy pathbluesky.cpp
File metadata and controls
375 lines (303 loc) · 9.07 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
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
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
#include <iostream>
#include <iomanip>
#include "bluesky.h"
using namespace std;
int reserve = 9999;
//********************************************************************************************
//fills seat array with zeros
int seat[size];
void seat_fill()
{
for (int i = 0; i < size; i++)
{
seat[i] = 0;
}
}
//********************************************************************************************
bool taken=false;
bool seat_no(int y)
{
for (int i = 0; i < size; i++ ) //loop checks if the seat is taken or not.
{
if( seat[i] == -1 )
{
taken=true;
cout << "The seat is taken already. \n";
cout << "Please choose another seat number from below."<<endl;
int j = 1;
while ( j < size+1 )
{
if ( seat[j-1] == -1)
j++;
else
{
cout <<"|" << j << "|";
if ( j%10 == 0 )
cout << endl;
j++;
}
}
}
}
} // this will print the available seat numbers only
//********************************************************************************************
void menu()
{
char choice;
do{
cout <<"\t\t ------------------------------ \n";
cout <<"\t\t Make Reservation ...... '1' \n";
cout <<"\t\t ------------------------------ \n";
cout <<"\t\t Cancel Reservation ...... '2' \n ";
cout <<"\t\t ------------------------------ \n";
cout <<"\t\t Search Passenger ...... '3' \n";
cout <<"\t\t ------------------------------ \n";
cout <<"\t\t Change Reservation ...... '4' \n";
cout <<"\t\t ------------------------------ \n";
cout <<"\t\t Print a list ...... '5' \n";
cout <<"\t\t ------------------------------ \n";
cout <<"\t\t Print status Report ...... '6' \n ";
cout <<"\t\t ------------------------------ \n";
cout <<"\t\t Quit ...... '7' \n ";
cout <<"\t\t ------------------------------ \n";
cout <<"::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::\n";
cout <<"\n Option :: ";
cin >> choice;
choice = ((int)(choice)-48);
switch (choice) //starting casefn1353.
{
case 1: system("CLS"); bluesky.make_reservation();
break;
case 2: system("CLS"); bluesky.cancel_reservation();
break;
case 3: system("CLS"); bluesky.search_passenger();
break;
case 4: system("CLS"); bluesky.change_reservation();
break;
case 5: system("CLS"); bluesky.print_list();
break;
case 6: system("CLS"); bluesky.print_report();
break;
case 7: cout << "\n\n-- Run Again --\n\n\n";
break;
default: cout<<" Don't be like a DORK!!! \n\n";
break;
} // Ending case loop.
cout<<"\n\nxxxxxxxxx:::::: PROCESS COMPLETED: NEXT NODE ENTRY:::::::xxxxxxxxx"<<endl;
cout<<"xxxxxxxxx:::::: PRESS ANY KEY TO RETURN TO THE MAIN MENU:::::::xxxxxxxxx\n\n";
cin.get();
if(cin.get()=='\n')
system("CLS");
cout<<"\n\n ..................... MENU OPTIONS .............................\n"<<endl;
}while(choice != 7 );
} // ending void menu function
//************************************************************************
airlines::airlines() //Constructor sets the pointer to null.
{
start = NULL;
}
//*************************************************************************
void airlines:: make_reservation() //This function makes reservation.
{
int meal_choice, x;
temp = new node; //adding new nodes.
cout<<"\n\nEnter First Name of person: ";
cin>>temp->fname;
cout<<"--------------------------------\n";
cout<<"Enter Last Name of Person: ";
cin>>temp->lname;
cout<<"--------------------------------\n";
cout<<"Enter ID of the person: ";
cin>>temp->ID;
cout<<"--------------------------------\n";
cout<<"Enter Phone Number of Person: ";
cin>>temp->phone_num;
cout<<"--------------------------------\n";
do{
cout << "Please Enter the Seat Number: ";
cin>>x;
while(x>size){
cout<<" Try again:: ";
cin >>x;
}
cout<<"--------------------------------\n";
if((seat[x-1])>-1) // if seat value is 0 and more than it's is empty
taken = false;
else //cp
seat_no(x); // if taken print available seat from another function
seat[x-1] = -1; // make current seat unavailable as -1 value representation
temp->seat_num = x;
}while(taken==true);
//******************************************************************************
// prints the menu list and prompts to make a choice.
cout << "Please Enter Your Menu Preference from below: \n\n";
cout << " Veg ..... '1'\n";
cout << " Non-Veg ..... '2'\n";
cout << " No meal ..... '3'\n\n";
cout <<" Your Choice :: ";
cin >> meal_choice;
while(meal_choice>3 || meal_choice<1){
cout<<" Try Again:: ";
cin>>meal_choice;
}
if (meal_choice == 1)
temp->menu = "veg";
else if (meal_choice == 2)
temp->menu = "Non-Veg";
else
temp->menu = "No meal";
reserve++; //increments the reservation numbers
temp->reserve_num=reserve;
cout <<"\n::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::\n";
cout << "YOUR RESERVATION NUMBER IS :: " << reserve << "\n\n";
cout <<"::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::\n";
temp->next = NULL;
if(start == NULL)
start = temp;
else
{
temp2 = start;
while (temp2->next != NULL)
{
temp2 = temp2->next;
}
temp2->next = temp;
}
} // insert function close
//********************************************************************************************
int cancel=0;
void airlines:: cancel_reservation() //This function cancels reservation.
{ int num;
cout << "Please Enter your reservation Number here: ";
cin >> num;
node *cur = start;
if(cur!=NULL)
{ // error checking for empty node deletion which cause segm fault error.
if ( start->reserve_num == num ) //first node.
{
node *del = start;
start = start->next;
delete del;
seat[0] = 0;
cancel++;
return;
}
else
{
node *pre, *cur; //To delete a middle or last node.
pre = start;
cur = start->next;
while(cur != NULL)
{
if ( cur->reserve_num == num )
break;
pre = cur;
cur = cur->next;
}
seat[cur->seat_num-1] = 0;
if (cur != NULL )
pre->next = cur->next;
}
cancel++;
//reserve--;
//temp->reserve_num=reserve;
}// error checking if statement ends here
else
{
cout<<"!!! *** Nothing to delete or invalid entry *** !!! \n"<<endl;
}
}
//********************************************************************************************
void airlines:: search_passenger() //This function helps to search a passenger
{//either by first name
string fakename;
cout << "Please enter your first name here: ";
cin >> fakename;
node *cur = start;
while (cur != NULL)
{
if (cur->fname == fakename) //found
{
cout << "First Name : " << cur->fname << endl;
cout << "Last Name : " << cur->lname << endl;
cout << "ID " << cur->ID << endl;
cout << "Phone number: " << cur->phone_num << endl;
cout << "seat Number: " << cur->seat_num << endl;
cout << "Reservation No. " << cur->reserve_num<< endl;
return;
} cur = cur->next;
} cout << " Sorry!!! NOT FOUND \n\n";
}
//********************************************************************************************
void airlines:: change_reservation() //This function helps to upgrade class or seats.
//or to make more reservations.
{
int option , next_seat;
cout << " Please enter your seat number: ";
cin >> option;
node *cur;
cur = start;
while(cur != NULL)
{
if ( cur->seat_num == option )
break;
cur = cur->next;
}
cout << "Please choose another seat number from below.";
int j = 1;
while ( j < size+1 )
{
if ( seat[j-1] == -1)
j++;
else
{
cout <<"| " << j << "|";
if ( j%10 == 0 )
cout << endl;
j++;
}
}
cin >> next_seat;
seat[cur->seat_num-1]=0;
cur->seat_num = next_seat;
seat[next_seat-1] = -1;
}
//********************************************************************************************
void airlines:: print_list() //This function prints the list of the passengers.
{
temp=start;
if(temp == NULL)
cout<<" End of lists"<<endl;
else
{ int cnt = 1;
cout << "\tNumber\t First Name\t Last Name\t ID\t";
cout << "Phone Number\t seat Number\t Reservation No\t Menu\n";
while(temp != NULL) // Display details for what temp points to
{
cout << "\t" << cnt <<setw(15);
cout << temp->fname <<setw(15);
cout << temp->lname << setw(12);
cout << temp->ID << setw(12);
cout << temp->phone_num <<setw(15);
cout << temp->seat_num <<setw(15);
cout << temp->reserve_num <<setw(12);
cout << temp->menu << "\n";
// Move to next node
temp=temp->next;
cnt++;
}
cout << "\n\n";
}
}
//********************************************************************************************
void airlines:: print_report() //This function prints the status report of the flight.
{ int count = 0;
for (int i =0; i < size; i++ )
{
if (seat[i] == -1)
count++;
}
cout<<"The number of reserved seats are: " << count <<endl;
cout<<"The number of cancellations are: " << cancel <<endl;
}
//********************************************************************************************