-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode1.cpp
499 lines (478 loc) · 19.4 KB
/
code1.cpp
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
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
//initializing the arrays for storing arlines data
string AirlineTitle[5] = {"American-Airline", "Emirates-Airline", "Singapore-Airline", "Turksih-Airline", "British-Airways"};
string Sample1[5] = {};
string AirlineTime[5] = {"11:26AM-06:10PM", "12:28PM-07:00PM", "03:00AM-08:15PM", "02:15PM-06:30PM", "09:00PM-12:00AM"};
string Sample2[5] = {};
int AirlineCode[5] = {112, 102, 297, 235, 125};
int AirlinePass[5] = {150, 458, 600, 225, 125};
//finding arrays lenght to calculate the total number of elements present in the arrays and storing them into thier size variables
int titleSize = sizeof(AirlineTitle) / sizeof(AirlineTitle[0]);
int codeSize = sizeof(AirlineCode) / sizeof(AirlineCode[0]);
int PassSize = sizeof(AirlinePass) / sizeof(AirlinePass[0]);
int TimeSize = sizeof(AirlineTime) / sizeof(AirlineTime[0]);
int op;
char choice;
cout << "\t Welcome To Airport Managment System\t" << endl;
//for menu using do-while loop
do
{
cout << "\nSelect which operation would you like to perform:" << endl;
cout << "1. Traverse\n2. Search\n3. Update\n4. Insert\n5. Delete\n6. Exit" << endl;
cin >> op;
//using switch loop because we want our operations in cases
switch (op)
{
case 1:
//for traversing just display stored data in arrays
cout << "Which array would you like to traverse:\n1. Airline Title\n2. Airline #Code\n3. Airline #Passengers\n4. A & D Time\n5. All Data" << endl;
int slct1;
cin >> slct1;
if (slct1 == 1)
{
for (int i = 0; i < titleSize; i++)
{
cout << "AirlineTitle[" << i << "] = " << AirlineTitle[i] << endl;
}
}
else if (slct1 == 2)
{
for (int i = 0; i < codeSize; i++)
{
cout << "AirlineCode[" << i << "] = " << AirlineCode[i] << endl;
}
}
else if (slct1 == 3)
{
for (int i = 0; i < PassSize; i++)
{
cout << "AirlinePass[" << i << "] = " << AirlinePass[i] << endl;
}
}
else if (slct1 == 4)
{
for (int i = 0; i < TimeSize; i++)
{
cout << "AirlineTime[" << i << "] = " << AirlineTime[i] << endl;
}
}
else if (slct1 == 5)
{
cout<<"1. Before Insertation \n2. After Insertation "<<endl;
int choice;
cin>>choice;
if(choice==1)
{
cout<< "=========================================================================\n";
for (int i = 0; i <5; i++)
{
cout << " " << AirlineTitle[i] << "\t" << AirlineCode[i] << "\t\t" << AirlinePass[i] << "\t\t" << AirlineTime[i] << endl;
}
}
if(choice==2)
{
cout << " Airline Title\t Airline Code Airline #Pass\t A&D Time" << endl
<< "=========================================================================\n";
for (int i = 0; i < 6; i++)
{
cout << " " << AirlineTitle[i] << "\t" << AirlineCode[i] << "\t\t" << AirlinePass[i] << "\t\t" << AirlineTime[i] << endl;
}
}
}
break;
case 2:
cout << "Which array would you like to search:\n1. Airline Title\n2. Airline #Code\n3. Airline #Passengers\n4. A&D Time" << endl;
int slct2;
cin >> slct2;
if (slct2 == 1)
{
cout << "Enter the item you want to search for" << endl;
string item;
cin >> item;
int i;
//for searching element in array we start our our loop untill less than titleSize
//and in if condition we compare AirlineTitle[] with item which storing given input
//if match then index found otherwise not
for (i = 0; i < titleSize; i++)
{
if (AirlineTitle[i] == item)
{
cout << "Element found at index AirlineTitle[" << i << "]" << endl;
break;
}
}
if (i == titleSize)
{
cout << "Oops! Element Not Present in Input Array\n";
}
}
else if (slct2 == 2)
{
cout << "Enter the item you want to search for" << endl;
int item;
cin >> item;
int i;
for (i = 0; i < codeSize; i++)
{
if (AirlineCode[i] == item)
{
cout << "Element found at index AirlineCode[" << i << "]" << endl;
break;
}
}
if (i == codeSize)
{
cout << "Oops! Element Not Present in Input Array\n";
}
}
else if (slct2 == 3)
{
cout << "Enter the item you want to search for" << endl;
int item;
cin >> item;
int i;
for (i = 0; i < PassSize; i++)
{
if (AirlinePass[i] == item)
{
cout << "Element found at index AirlinePass[" << i << "]" << endl;
break;
}
}
if (i == PassSize)
{
cout << "Oops! Element Not Present in Input Array\n";
}
}
else if (slct2 == 4)
{
cout << "Enter the item you want to search for" << endl;
string item;
cin >> item;
int i;
for (i = 0; i < TimeSize; i++)
{
if (AirlineTime[i] == item)
{
cout << "Element found at index AirlineTime[" << i << "]" << endl;
break;
}
}
if (i == TimeSize)
{
cout << "Oops! Element Not Present in Input Array\n";
}
}
break;
case 3:
cout << "Which array would you like to update:\n1. Airline Title\n2. Airline #Code\n3. Airline #Passengers\n4. A&D Time" << endl;
int slct3;
cin >> slct3;
if (slct3 == 1)
{
cout << "The array before updation is :" << endl;
for (int i = 0; i < titleSize; i++)
{
cout << "AirlineTitle[" << i << "] = " << AirlineTitle[i] << endl;
}
//for updating arrays element we take position and value from user
//then we pass our postion into AirlineTitle[] array then equal it with our value
cout << "Enter the position of item you want to update:\n";
int pos;
cin >> pos;
cout << "Enter the value of the updated element:" << endl;
string item;
//getline(cin,item);
cin >> item;
AirlineTitle[pos] = item;
cout << "The updated array is :" << endl;
for (int i = 0; i < titleSize; i++)
{
cout << "AirlineTitle[" << i << "] = " << AirlineTitle[i] << endl;
}
}
if (slct3 == 2)
{
cout << "The array before updation is :" << endl;
for (int i = 0; i < codeSize; i++)
{
cout << "AirlineCode[" << i << "] = " << AirlineCode[i] << endl;
}
cout << "Enter the position of item you want to update:\n";
int pos;
cin >> pos;
cout << "Enter the value of the updated element :" << endl;
int item;
cin >> item;
AirlineCode[pos] = item;
cout << "The updated array is :" << endl;
for (int i = 0; i < codeSize; i++)
{
cout << "AirlineCode[" << i << "] = " << AirlineCode[i] << endl;
}
}
if (slct3 == 3)
{
cout << "The array before updation is :" << endl;
for (int i = 0; i < PassSize; i++)
{
cout << "AirlinePass[" << i << "] = " << AirlinePass[i] << endl;
}
cout << "Enter the position of item you want to update:\n";
int pos;
cin >> pos;
cout << "Enter the value of the updated element:" << endl;
int item;
cin >> item;
AirlinePass[pos] = item;
cout << "The updated array is:" << endl;
for (int i = 0; i < PassSize; i++)
{
cout << "AirlinePass[" << i << "] = " << AirlinePass[i] << endl;
}
}
if (slct3 == 4)
{
cout << "The array before updation is :" << endl;
for (int i = 0; i < titleSize; i++)
{
cout << "AirlineTime[" << i << "] = " << AirlineTime[i] << endl;
}
cout << "Enter the position of item you want to update:\n";
int pos;
cin >> pos;
cout << "Enter the value of the updated element:" << endl;
string item;
//getline(cin,item);
cin >> item;
AirlineTime[pos] = item;
cout << "The updated array is :" << endl;
for (int i = 0; i < titleSize; i++)
{
cout << "AirlineTime[" << i << "] = " << AirlineTime[i] << endl;
}
}
break;
case 4:
cout << "Which array would you like to insert:\n1. Airline Title\n2. Airline #Code\n3. Airline #Passengers\n4. A&D Time" << endl;
int slct4;
cin >> slct4;
if (slct4 == 1)
{
string item;
int pos, i;
cout << "The array elements before insertion are :\n";
for (i = 0; i < titleSize; i++)
{
cout << "AirlineTitle[" << i << "] = " << AirlineTitle[i] << endl;
}
// Take a position of a new element
cout << "\nWhere you would you like to insert the element:\n0.Start of Array\n1-4.Between\n5.End of Array\n";
cin >> pos;
//Input value of an element to be inserted
cout << "Enter the element you would like to insert:" << endl;
cin >> item;
titleSize++; //increment in size
//Shift element by one position
for (i = titleSize; i >= pos; i--)
{
AirlineTitle[i + 1] = AirlineTitle[i];
}
//Insert new value in an array
AirlineTitle[pos] = item;
cout << "\nThe array elements after insertion are :\n";
for (i = 0; i < titleSize; i++)
{
cout << "AirlineTitle[" << i << "] = " << AirlineTitle[i] << endl;
}
}
else if (slct4 == 2)
{
int pos, i, item;
cout << "The array elements before insertion are :\n";
for (i = 0; i < codeSize; i++)
{
cout << "AirlineCode[" << i << "] = " << AirlineCode[i] << endl;
}
// Take a position of a new element
cout << "\nWhere you would you like to insert the element:\n0.Start of Array\n1-4.Between\n5.End of Array\n";
cin >> pos;
//Input value of an element to be inserted
cout << "Enter the element you would like to insert:" << endl;
cin >> item;
codeSize++;
//Shift element by one position
for (i = codeSize; i >= pos; i--)
{
AirlineCode[i + 1] = AirlineCode[i];
}
//Insert new value in an array
AirlineCode[pos] = item;
cout << "\nThe array elements after insertion are :\n";
for (i = 0; i < codeSize; i++)
{
cout << "AirlineCode[" << i << "] = " << AirlineCode[i] << endl;
}
}
else if (slct4 == 3)
{
int pos, i, item;
cout << "The array elements before insertion are :\n";
for (i = 0; i < PassSize; i++)
{
cout << "AirlinePass[" << i << "] = " << AirlinePass[i] << endl;
}
// Take a position of a new element
cout << "\nWhere you would you like to insert the element:\n0.Start of Array\n1-4.Between\n5.End of Array\n";
cin >> pos;
//Input value of an element to be inserted
cout << "Enter the element you would like to insert:" << endl;
cin >> item;
PassSize++;
//Shift element by one position
for (i = PassSize; i >= pos; i--)
{
AirlinePass[i + 1] = AirlinePass[i];
}
//Insert new value in an array
AirlinePass[pos] = item;
cout << "The array elements after insertion are :\n";
for (i = 0; i < PassSize; i++)
{
cout << "AirlinePass[" << i << "] = " << AirlinePass[i] << endl;
}
}
if (slct4 == 4)
{
string item;
int pos, i;
cout << "The array elements before insertion are :\n";
for (i = 0; i < TimeSize; i++)
{
cout << "AirlineTime[" << i << "] = " << AirlineTime[i] << endl;
}
cout << "\nWhere you would you like to insert the element:\n0.Start of Array\n1-4.Between\n5.End of Array\n";
cin >> pos;
cout << "Enter the element you would like to insert:" << endl;
cin >> item;
TimeSize++;
for (i = TimeSize; i >= pos; i--)
{
AirlineTime[i + 1] = AirlineTime[i];
}
//Insert new value in an array
AirlineTime[pos] = item;
cout << "\nThe array elements after insertion are :\n";
for (i = 0; i < TimeSize; i++)
{
cout << "AirlineTime[" << i << "] = " << AirlineTime[i] << endl;
}
}
break;
case 5:
cout << "Which array would you like to delete:\n1. Airline Title\n2. Airline #Code\n3. Airline #Passengers\n4. A&D Time" << endl;
int slct5;
cin >> slct5;
if (slct5 == 1)
{
int pos, i;
cout << "Stored values in AirlineTitle array are :" << endl;
for (i = 0; i < titleSize; i++)
{
cout << "AirlineTitle[" << i << "] = " << AirlineTitle[i] << endl;
}
// Take a position of a new element
cout << "\nEnter the index number where you want to delete value:";
cin >> pos;
//Shift element by one position
for (i = pos; i < titleSize; i++)
{
AirlineTitle[i] = AirlineTitle[i + 1];
}
titleSize--;
cout << "\nThe array elements after deletion are :\n";
for (i = 0; i < titleSize; i++)
{
cout << "AirlineTitle[" << i << "] = " << AirlineTitle[i] << endl;
}
}
else if (slct5 == 2)
{
int pos, i;
cout << "Stored values in AirlineCode array are :" << endl;
for (i = 0; i < codeSize; i++)
{
cout << "AirlineCode[" << i << "] = " << AirlineCode[i] << endl;
}
// Take a position of a new element
cout << "\nEnter the index number where you want to delete value:";
cin >> pos;
//Shift element by one position
for (i = pos; i < codeSize; i++)
{
AirlineCode[i] = AirlineCode[i + 1];
}
codeSize--;
cout << "\nThe array elements after deletion are :\n";
for (i = 0; i < codeSize; i++)
{
cout << "AirlineCode[" << i << "] = " << AirlineCode[i] << endl;
}
}
else if (slct5 == 3)
{
int pos, i;
cout << "Stored values in AirlinePass array are :" << endl;
for (i = 0; i < PassSize; i++)
{
cout << "AirlinePass[" << i << "] = " << AirlinePass[i] << endl;
}
// Take a position of a new element
cout << "\nEnter the index number where you want to delete value:";
cin >> pos;
//Shift element by one position
for (i = pos; i < PassSize; i++)
{
AirlinePass[i] = AirlinePass[i + 1];
}
cout << "\nThe array elements after deletion are :\n";
for (i = 0; i < PassSize; i++)
{
cout << "AirlinePass[" << i << "] = " << AirlinePass[i] << endl;
}
}
else if (slct5 == 4)
{
int pos, i;
cout << "Stored values in AirlineTitle array are :" << endl;
for (i = 0; i < TimeSize; i++)
{
cout << "AirlineTime[" << i << "] = " << AirlineTime[i] << endl;
}
cout << "\nEnter the index number where you want to delete value:";
cin >> pos;
for (i = pos; i < TimeSize; i++)
{
AirlineTime[i] = AirlineTime[i + 1];
}
TimeSize--;
cout << "\nThe array elements after deletion are :\n";
for (i = 0; i < TimeSize; i++)
{
cout << "AirlineTime[" << i << "] = " << AirlineTime[i] << endl;
}
}
default:
break;
}
//cout << "If you want to continue press (y) if not press something else ?";
//cin >> choice;
} while (op != 6);
//(choice == 'y' || choice == 'Y');
return (0);
}