-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccess navigation control.cpp
1604 lines (1416 loc) · 48.8 KB
/
access navigation control.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
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*access navigation control
Name: engine reservation Program
Author: apocalypse coder0
Date Started: 2018 /5/2
Date Stop: 2018/5/2
Version 1.0
Description: C++ engine reservation Database System
*/
//TODO (#0#): Work on passenger_information
//TODO (#1#): Work on Reservation
//TODO (#2#): Work on Seat Assignment
//TODO (#3#): Work out the Bugs
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <iostream>
#include <cctype>
struct flight; //Forward Declaration of Flight structure
//Airline List Structure And Function Declarations
struct engine reservation //Structure for Airline node, includes strings for Airline name
{ //pointer locations to the next airline and also to the flight list for that airline
char *engine reservation name;
struct engine reservation *next;
struct flight *node1;
} *start1 = NULL;
engine reservation * create_airline_node(engine reservation *start1); //Function Declarations
engine reservation * enter_airline_info(engine reservation *node);
engine reservation * delete_airline_node(engine reservation *start1);
void print_airline_list(engine reservation *start1);
engine reservation * enter_flight_menu(engine reservation *start1);
void write_to_file(engine reservation *start1);
engine reservation * read_from_file();
engine reservation * airline_menu(engine reservation *start1);
//Flight List Structure And Function Declarations
struct passenger; //Forward Declaration of passenger structure
struct flight //Structure for flight node, includes strings for flightname, from, to and time with
{ //pointer locations to the next flight and also to the passenger list
char *flightnumber;
char *date_of_flight;
char *departure_location;
char *arrival_location;
char *take_off_time;
char *arrival_time;
struct flight *next;
struct passenger *node2;
struct reservation *node3;
} *start2 = NULL;
flight* create_flight_node(flight *start2); //Function Declarations
flight* enter_flight_info(flight *node);
flight* delete_flight_node(flight *start2);
void print_flight_list(flight *start2);
flight* enter_passenger_menu(flight *start2);
flight* enter_reservation_menu(flight *start2);
flight* flight_menu(flight *start2);
//Passenger List Structure And Function Declarations
struct passenger //Passenger Structure includes name of the passenger and the ponter to the next
{ //passenger node, structure declaration also declares start as the first node
char *name_suffix; //Passenger Name Suffix
char *name; //Passenger Full Name
char *passenger_id; //(unique key)
char *address; //Passenger Address
char *city; //Passenger City
char *gender; //Passenger Gender
char *data_of_birth; //Passenger Data of Birth
char *weight; //Passenger Weight
struct passenger *next; //and declares it NULL
} *start3 = NULL;
passenger* create_passenger_node(passenger *start3); //Function Declarations
passenger* enter_passenger_info(passenger *node);
passenger* delete_passenger_node(passenger *start3);
passenger* passenger_menu(passenger *start3);
void print_passenger_list(passenger *node);
struct reservation //Reservation Structure includes name of the reservation and the ponter to the next
{ //Reservation node, structure declaration also declares start as the first node
char *reservation_id; //(unique key)
char *passenger_id; //Passenger ID
char *flight_number; //Flight Number
char *cost; //cost
struct reservation *next; // and declares it NULL
} *start4 = NULL;
reservation* create_reservation_node(reservation *start4); //Function Declarations
reservation* enter_reservation_info(reservation *node);
reservation* delete_reservation_node(reservation *start4);
reservation* reservation_menu(reservation *start4);
void print_reservation_list(reservation *node);
struct seat_assignment //Reservation Structure includes name of the reservation and the ponter to the next
{ //Reservation node, structure declaration also declares start as the first node
char pass_name[80];
int Available;
struct seat_assignment *next; //and declares it NULL
} *start5 = NULL;
seat_assignment* create_seat_assignment_node(seat_assignment *start5)
seat_assignment* enter_seat_assignment_info(seat_assignment *node);
seat_assignment* cancelled_seat_assignment_node(seat_assignment *start5
seat_assignment* seat_assignment_menu(seat_assignment *start5);
void print_seat_assignment_list(seat_assignment *node);
//------------------------------------------------------------------------------
//Member Functions To Manipulate The Airline Linked List
engine reservation * create_airline_node(engine reservation *start1) //Creates a sorted list of airlines (default entry sort condition by airline name)
{ //by entering the airline name in a node at the sorted position,
//it calls the function "enter_airline_info() to ask the
if (start1 == NULL) //user for its information
{
start1 = (engine reservation *) malloc(sizeof(engine reservation ));
start1 = enter_airline_info(start1);
start1->next = NULL;
}
else
{
engine reservation *count_node1, *count_node2, *node;
node = (engine reservation *) malloc(sizeof(engine reservation ));
node = enter_airline_info(node);
for (count_node1 = start1;
(count_node1 != NULL) && (strcmp(count_node1->airlinename, node->airlinename) <= 0);
count_node2 = count_node1, count_node1 = count_node1->next);
if(count_node1 == start1)
{
node->next = start1;
start1 = node;
}
else if (count_node1 == NULL)
{
count_node2->next = node;
node->next = NULL;
}
else
{
count_node2->next = node;
node->next = count_node1;
}
}
return start1;
}
engine reservation * enter_airline_info(engine reservation *node) //Function to enter the information about the airline, this function is
{ //called from the function create_airline_node(airline *start1)by itself.
printf("\n");
printf(" Welcome To Name Airport\n");
printf("Please enter the Airline Name\n");
printf("\n");
fflush(stdin);
node->airlinename = new char [80];
gets(node->airlinename);
node->node1 = NULL;
return node;
}
engine reservation * delete_airline_node(engine reservation *start) //Function to delete the name of a airline, function
{ //searches for the name and deletes if it is found.
if(start1 == NULL)
{
printf("\n");
printf("Sorry, this Airport is not operational at this moment\n");
}
else
{
char airlinename[80];
printf("\n");
printf("Please enter the name of the Airline you want to delete\n");
fflush(stdin);
gets(airlinename);
engine reservation *count_node1, *count_node2;
engine reservation *temp;
for(count_node1 = start1;
(count_node1 != NULL) && (strcmp(count_node1->airlinename, airlinename) != 0);
count_node2 = count_node1, count_node1 = count_node1->next);
if(count_node1!= NULL)
{
if (count_node1 == start1)
{
temp = start1;
start1 = start1->next;
free(temp);
}
else if(count_node1->next == NULL && count_node1 != start1)
{
temp = count_node1;
count_node2->next = NULL;
free (temp);
}
else
{
temp = count_node1;
count_node2->next = count_node1->next;
free (temp);
}
}
else
{
printf("\n");
printf("Sorry, this airline is currently not in service at this airport\n");
}
}
return start1;
}
void print_airline_list(engine reservation *start) /*Function to print all the airlines operating on the airport*/
{
if (start1 == NULL)
{
printf("\n");
printf("Sorry, this Airport is not operational at this moment\n");
}
else
{
printf("\n");
engine reservation *count;
for (count = start1; count != NULL; count = count->next)
printf("%s\n", count->airlinename);
}
}
engine reservation * enter_flight_menu(engine reservation *start1) /*Function to search for the airline
entered and enter its flight list menu*/
{
char airlinename[80];
printf("\n");
printf("Welcome to the Flight List Menu\n");
printf("Enter the Airline name you wish to check\n");
fflush(stdin);
gets(airlinename);
engine reservation *count;
for(count = start1;
(count != NULL) && (strcmp(count->airlinename, airlinename) != 0);
count = count->next);
if(count == NULL)
{
printf("\n");
printf("Sorry, this airline does not operate in this airport\n");
return start1;
}
else
{
printf("\n");
count->node1 = flight_menu(count->node1);
return start1;
}
}
void write_to_file(engine reservation *start1) //Write to file airline.txt
{
FILE *fp;
engine reservation *count1;
flight *count2;
passenger *count3;
reservation *count4;
seat_assignment *count5;
int length = 0;
int airline_count = 0;
int passenger_count = 0;
int flight_count = 0;
int reservation_count = 0;
int seat_assignment_count = 0;
fp = fopen("airline.txt","wb");
//Determine number of airlines and write to file
for( count1 = start1; count1 != NULL; count1 = count1->next) ++airline_count;
fwrite(&airline_count,sizeof(int),1,fp);
//Loop through and write airlines data to file
for( count1 = start1; count1 != NULL; count1 = count1->next)
{
//Determine length of airline name and write to file
length = strlen(count1->airlinename);
fwrite(&length,sizeof(int),1,fp);
//Write airline name to file
fwrite(count1->airlinename,length,1,fp);
//------------------------------------------------------------------------------
//Determine number of flights for the airline and write to file
for( count2 = count1->node1; count2 != NULL; count2 = count2->next) ++flight_count;
fwrite(&flight_count,sizeof(int),1,fp);
//Loop through and write flight data for the airline to file
for( count2 = count1->node1; count2 != NULL; count2 = count2->next)
{
//Determine length of flight number and write to file
length = strlen(count2->flightnumber);
fwrite(&length,sizeof(int),1,fp);
//Write flight number to file
fwrite(count2->flightnumber,length,1,fp);
//Determine length of date of flight and write to file
length = strlen(count2->date_of_flight);
fwrite(&length,sizeof(int),1,fp);
//Write data of flight to file
fwrite(count2->date_of_flight,length,1,fp);
//Determine length of departure location and write to file
length = strlen(count2->departure_location);
fwrite(&length,sizeof(int),1,fp);
//Write departure location to file
fwrite(count2->departure_location,length,1,fp);
//Determine length of arrival location and write to file
length = strlen(count2->arrival_location);
fwrite(&length,sizeof(int),1,fp);
//Write arrival location to file
fwrite(count2->arrival_location,length,1,fp);
//Determine length of take off time and write to file
length = strlen(count2->take_off_time);
fwrite(&length,sizeof(int),1,fp);
//Write departure location to file
fwrite(count2->take_off_time,length,1,fp);
//Determine length of arrival time and write to file
length = strlen(count2->arrival_time);
fwrite(&length,sizeof(int),1,fp);
//Write arrival location to file
fwrite(count2->arrival_time,length,1,fp);
//------------------------------------------------------------------------------
//Determine number of passengers for this flight and write to file
for( count3 = count2->node2; count3 != NULL;
count3 = count3->next) ++passenger_count;
fwrite(&passenger_count,sizeof(int),1,fp);
//Loop through and write passenger data for the flight to file
for( count3 = count2->node2; count3 != NULL; count3 = count3->next)
{
//Determine length of passenger name suffix and write to file
length = strlen(count3->name_suffix);
fwrite(&length,sizeof(int),1,fp);
//Write passenger name suffix to file
fwrite(count3->name_suffix,length,1,fp);
//Determine length of passenger name and write to file
length = strlen(count3->name);
fwrite(&length,sizeof(int),1,fp);
//Write passenger name to file
fwrite(count3->name,length,1,fp);
//Determine length of passenger ID and write to file
length = strlen(count3->passenger_id);
fwrite(&length,sizeof(int),1,fp);
//Write passenger ID to file
fwrite(count3->passenger_id,length,1,fp);
//Determine length of passenger address and write to file
length = strlen(count3->address);
fwrite(&length,sizeof(int),1,fp);
//Write passenger address to file
fwrite(count3->address,length,1,fp);
//Determine length of passenger city and write to file
length = strlen(count3->city);
fwrite(&length,sizeof(int),1,fp);
//Write passenger city to file
fwrite(count3->city,length,1,fp);
//Determine length of passenger gender and write to file
length = strlen(count3->gender);
fwrite(&length,sizeof(int),1,fp);
//Write passenger gender to file
fwrite(count3->gender,length,1,fp);
//Determine length of passenger data of birth and write to file
length = strlen(count3->data_of_birth);
fwrite(&length,sizeof(int),1,fp);
//Write passenger data of birth to file
fwrite(count3->data_of_birth,length,1,fp);
//Determine length of passenger weight and write to file
length = strlen(count3->weight);
fwrite(&length,sizeof(int),1,fp);
//Write passenger weight to file
fwrite(count3->weight,length,1,fp);
//------------------------------------------------------------------------------
//Determine number of reservation for this flight and write to file
for( count4 = count2->node3; count4 != NULL;
count4 = count4->next) ++reservation_count;
fwrite(&reservation_count,sizeof(int),1,fp);
//Loop through and write reservation data for the flight to file
for( count4 = count2->node3; count4 != NULL; count4 = count4->next)
{
//Determine length of reservation ID and write to file
length = strlen(count4->reservation_id);
fwrite(&length,sizeof(int),1,fp);
//Write reservation id to file
fwrite(count4->reservation_id,length,1,fp);
//Determine length of passenger ID and write to file
length = strlen(count4->passenger_id);
fwrite(&length,sizeof(int),1,fp);
//Write passenger ID to file
fwrite(count4->passenger_id,length,1,fp);
//Determine length of flight_number and write to file
length = strlen(count4->flight_number);
fwrite(&length,sizeof(int),1,fp);
//Write flight number to file
fwrite(count4->flight_number,length,1,fp);
//Determine length of cost and write to file
length = strlen(count4->cost);
fwrite(&length,sizeof(int),1,fp);
//Write passenger cost to file
fwrite(count4->cost,length,1,fp);*/
//------------------------------------------------------------------------------
//Write seat assignment to file
fwrite(count5->seat_assignment,length,1,fp);
//Determine length of seat assignment and write to file
length = strlen(count5->cost);
fwrite(&length,sizeof(int),1,fp);
//Write seat_assignment to file
fwrite(count5->seat_assignment,length,1,fp);
}
}
}
fclose(fp);
}
engine reservation * read_from_file() //read from file airline.txt
{
FILE *fp;
engine reservation *start, *curr, *temp;
int length = 0;
int airline_count= 0;
int flight_count = 0;
int passenger_count = 0;
int reservation_count = 0;
int seat_assignment_count = 0;
//Initialize pointers
start = curr = NULL;
//Open file for reading
fp = fopen("airline.txt","rb");
while(!feof(fp))
{
//Read in number of airlines stored in file
if( fp == NULL)
airline_count = 0;
else
fread(&airline_count,sizeof(int),1,fp);
//Loop through "airline_count" airlines
for( ; airline_count > 0; --airline_count )
{
//allocate room for a single airline structure and flight link to NULL
temp = (engine reservation *)malloc(sizeof(engine reservation ));
temp->next = NULL;
temp->node1 = NULL;
//read airline name length
fread(&length,sizeof(int),1,fp);
//allocate sufficent memory for the airline name
temp->airlinename = (char *)malloc(length+1);
//read in airline's name and NULL terminate
fread(temp->airlinename,length,1,fp);
temp->airlinename[length] = 0;
//Add current airline to end of growing list of airlines
if( start == NULL )
{
start = curr = temp;
}
else
{
curr->next = temp;
curr = curr->next;
}
//------------------------------------------------------------------------------
//Read in number of flights stored for the airline in file
fread(&flight_count,sizeof(int),1,fp);
//Loop through "flight_count" flight
for( ; flight_count > 0; --flight_count )
{
//allocate room for a single flight structure and set passenger link to NULL
curr->node1 = (flight *)malloc(sizeof(flight));
curr->node1->next = NULL;
curr->node1->node2 = NULL;
//read flight number length
fread(&length,sizeof(int),1,fp);
//allocate sufficent memory for the flight number
curr->node1->flightnumber = (char *)malloc(length+1);
//read in flight number and NULL terminate
fread(curr->node1->flightnumber,length,1,fp);
curr->node1->flightnumber[length] = 0;
//read date of flight length
fread(&length,sizeof(int),1,fp);
//allocate sufficent memory for the flight name
curr->node1->date_of_flight = (char *)malloc(length+1);
//read in date_of_flight and NULL terminate
fread(curr->node1->date_of_flight,length,1,fp);
curr->node1->date_of_flight[length] = 0;
//read date_of_flight length
fread(&length,sizeof(int),1,fp);
//allocate sufficent memory for the departure location
curr->node1->departure_location = (char *)malloc(length+1);
//read in departure location and NULL terminate
fread(curr->node1->departure_location,length,1,fp);
curr->node1->departure_location[length] = 0;
//read arrival location length
fread(&length,sizeof(int),1,fp);
//allocate sufficent memory for the arrival location
curr->node1->arrival_location = (char *)malloc(length+1);
//read in arrival location and NULL terminate
fread(curr->node1->arrival_location,length,1,fp);
curr->node1->arrival_location[length] = 0;
//read take off time length
fread(&length,sizeof(int),1,fp);
//allocate sufficent memory for the take off time
curr->node1->take_off_time = (char *)malloc(length+1);
//read in take off time and NULL terminate
fread(curr->node1->take_off_time,length,1,fp);
curr->node1->take_off_time[length] = 0;
//read in arrival time length
fread(&length,sizeof(int),1,fp);
//allocate sufficent memory for the arrival time
curr->node1->arrival_time = (char *)malloc(length+1);
//read in arrival time and NULL terminate
fread(curr->node1->arrival_time,length,1,fp);
curr->node1->arrival_time[length] = 0;
//Add current flight to end of growing list of flights
if( start->node1 == NULL )
{
start->node1 = curr->node1 = temp->node1;
}
else
{
curr->node1->next = temp->node1;
curr->node1 = curr->node1->next;
}
//------------------------------------------------------------------------------
//Read in number of passengers stored for that file
fread(&passenger_count,sizeof(int),1,fp);
//Loop through "passenger_count" passengers for this flight
for( ; passenger_count > 0; --passenger_count )
{
//allocate room for a single passenger structure
curr->node1->node2 = (passenger *)malloc(sizeof(passenger));
curr->node1->node2->next = NULL;
//read passenger name suffix length
fread(&length,sizeof(int),1,fp);
//allocate sufficent memory for passenger name suffix
curr->node1->node2->name_suffix = (char *)malloc(length+1);
//read in passenger name suffix and NULL terminate
fread(curr->node1->node2->name_suffix ,length,1,fp);
curr->node1->node2->name_suffix [length] = 0;
//read passenger name length
fread(&length,sizeof(int),1,fp);
//allocate sufficent memory for the passenger name
curr->node1->node2->name = (char *)malloc(length+1);
//read in passenger name and NULL terminate
fread(curr->node1->node2->name,length,1,fp);
curr->node1->node2->name[length] = 0;
//read passenger id length
fread(&length,sizeof(int),1,fp);
//allocate sufficent memory for the passenger id
curr->node1->node2->passenger_id = (char *)malloc(length+1);
//read in passenger id and NULL terminate
fread(curr->node1->node2->passenger_id,length,1,fp);
curr->node1->node2->passenger_id[length] = 0;
//read passenger address length
fread(&length,sizeof(int),1,fp);
//allocate sufficent memory for passenger address
curr->node1->node2->address = (char *)malloc(length+1);
//read in passenger address and NULL terminate
fread(curr->node1->node2->address,length,1,fp);
curr->node1->node2->address[length] = 0;
//read passenger city length
fread(&length,sizeof(int),1,fp);
//allocate sufficent memory for passenger city
curr->node1->node2->city = (char *)malloc(length+1);
//read in passenger city and NULL terminate
fread(curr->node1->node2->city ,length,1,fp);
curr->node1->node2->city [length] = 0;
//read passenger gender length
fread(&length,sizeof(int),1,fp);
//allocate sufficent memory for passenger gender
curr->node1->node2->gender = (char *)malloc(length+1);
//read in passenger gender and NULL terminate
fread(curr->node1->node2->gender ,length,1,fp);
curr->node1->node2->gender [length] = 0;
//read passenger data of birth length
fread(&length,sizeof(int),1,fp);
//allocate sufficent memory for passenger gender
curr->node1->node2->data_of_birth = (char *)malloc(length+1);
//read in passenger data of birth and NULL terminate
fread(curr->node1->node2->data_of_birth ,length,1,fp);
curr->node1->node2->data_of_birth [length] = 0;
//read passenger weight length
fread(&length,sizeof(int),1,fp);
//allocate sufficent memory for passenger weight
curr->node1->node2->weight = (char *)malloc(length+1);
//read in passenger weight and NULL terminate
fread(curr->node1->node2->weight ,length,1,fp);
curr->node1->node2->weight [length] = 0;
//Add current passenger to end of growing list of passengers for this flight
if( start->node1->node2 == NULL )
{
start->node1->node2 = curr->node1->node2 = temp->node1->node2;
}
else
{
curr->node1->node2->next = temp->node1->node2;
curr->node1->node2 = curr->node1->node2->next;
}
//------------------------------------------------------------------------------
//Read in number of reservation stored for that file
fread(&reservation_count,sizeof(int),1,fp);
//Loop through "reservation_count" reservation for this flight
for( ; reservation_count > 0; --reservation_count )
{
//allocate room for a single reservation structure
curr->node1->node2 = (passenger *)malloc(sizeof(reservation));
curr->node1->node2->next = NULL;
//read reservation id length
fread(&length,sizeof(int),1,fp);
//allocate sufficent memory for the reservation id
curr->node1->node3->reservation_id = (char *)malloc(length+1);
//read in reservation id and NULL terminate
fread(curr->node1->node3->reservation_id,length,1,fp);
curr->node1->node3->reservation_id[length] = 0;
//read passenger id lenght
fread(&length,sizeof(int),1,fp);
//allocate sufficent memory for the passenger id
curr->node1->node3->passenger_id = (char *)malloc(length+1);
//read in passenger_id and NULL terminghte
fread(curr->node1->node3->passenger_id,length,1,fp);
curr->node1->node3->passenger_id[length] = 0;
//read flight number lenght
fread(&length,sizeof(int),1,fp);
//allocate sufficent memory for the flight number
curr->node1->node3->flight_number = (char *)malloc(length+1);
//read in flight number and NULL termighte
fread(curr->node1->node3->flight_number,length,1,fp);
curr->node1->node3->flight_number[length] = 0;
//read cost lenght
fread(&length,sizeof(int),1,fp);
//allocate sufficent memory for the cost
curr->node1->node3->cost = (char *)malloc(length+1);
//read in cost and NULL termighte
fread(curr->node1->node3->cost,length,1,fp);
curr->node1->node3->cost[length] = 0;
//Add current reservation to end of growing list of reservation for this flight
if( start->node1->node2 == NULL )
{
start->node1->node2 = curr->node1->node2 = temp->node1->node2;
}
else
{
curr->node1->node2->next = temp->node1->node2;
curr->node1->node2 = curr->node1->node2->next;
}
//------------------------------------------------------------------------------
//Read in number of seat assignment stored for that file
fread(&seat_assignment_count,sizeof(int),1,fp);
//Loop through "seatassignment_count" seat assignment for this flight
for( ; seat_assignment_count > 0; --seat_assignment_count )
{
//allocate room for a single seat assignment structure
curr->node1->node2 = (seat_assignment *)malloc(sizeof(seat_assignment));
curr->node1->node2->next = NULL;
//read seat assignment length
fread(&length,sizeof(int),1,fp);
//allocate sufficent memory for the seat assignment
curr->node1->node3->reservation_id = (char *)malloc(length+1);
//read in seat_assignment and NULL terminate
fread(curr->node1->node3->seat_assignment,length,1,fp);
curr->node1->node3->seat_assignment[length] = 0;
//Add current seat_assignment to end of growing list of seat assignment for this flight
if( start->node1->node2 == NULL )
{
start->node1->node2 = curr->node1->node2 = temp->node1->node2;
}
else
{
curr->node1->node2->next = temp->node1->node2;
curr->node1->node2 = curr->node1->node2->next;
}
}
}
}
fclose(fp);
return start;
}
engine reservation * airline_menu(engine reservation *start) //Menu Function which is handles the airlinelist
{
int choice;
printf("Welcome to the Unknow Name Airline System Main Menu\n");
printf("Please enter your choice from the menu shown below\n");
printf("1: Add a new airline to this airport\n");
printf("2: Delete an airline from the airport\n");
printf("3: Display the Airlines List at this Airport\n");
printf("4: Enter Flight menu for an airline\n");
printf("5: Exit the program\n");
printf("To Save exit the program from system main menu\n");
scanf ("%d", &choice);
switch(choice)
{
case 1:
{
start1 = create_airline_node(start1);
} break;
case 2:
{
start1 = delete_airline_node(start1);
} break;
case 3:
{
print_airline_list(start1);
} break;
case 4:
{
start1 = enter_flight_menu(start1);
} break;
case 5:
{
write_to_file(start1);
exit(1);
} break;
default:
{
start1 = airline_menu(start1);
} break;
}
printf("\n");
start1 = airline_menu(start1);
return start1;
}
//--------------------------------------------------------------------------------
//Member Functions To Manipulate The Flight Linked List
flight* create_flight_node(flight *start2) // Creates a sorted list of flights (default entry sort condition by flight no.)
{ // by entering the flight node at the sorted position,
printf("\n"); // it calls the function "enter_flight_info() to ask the
if (start2 == NULL) // user for its information
{
start2 = (flight *) malloc(sizeof(flight));
start2 = enter_flight_info(start2);
start2->next = NULL;
}
else
{
flight *count_node1, *count_node2, *node;
node = (flight *) malloc(sizeof(flight));
node = enter_flight_info(node);
for (count_node1 = start2;
(count_node1 != NULL) && (strcmp(count_node1->flightnumber, node->flightnumber) <= 0);
count_node2 = count_node1, count_node1 = count_node1->next);
if(count_node1 == start2)
{
node->next = start2;
start2 = node;
}
else if (count_node1 == NULL)
{
count_node2->next = node;
node->next = NULL;
}
else
{
count_node2->next = node;
node->next = count_node1;
}
}
return start2;
}
flight* enter_flight_info(flight *node) // Function to enter the information about the flight, this function is
{ // called from the function create_flight_node(flight *start)by itself.
printf(" Welcome to the Flight List\n");
printf("Please enter the Flight number\n"); //Flight Number (unique key)
fflush(stdin);
node->flightnumber = new char [80];
gets(node->flightnumber);
printf("Please enter the Date of Flight\n"); //Date of Flight
fflush(stdin);
node->date_of_flight = new char [80];
gets(node->date_of_flight);
printf("Please enter the Departure Location\n"); //Departure From City
fflush(stdin);
node->departure_location = new char [80];
gets(node->departure_location);
printf("Please enter the Arrival Location\n"); //Arrival At City
fflush(stdin);
node->arrival_location = new char [80];
gets(node->arrival_location);
printf("Please enter the Take off time\n"); //Departuare time
fflush(stdin);
node->take_off_time = new char [80];
gets(node->take_off_time);
printf("Please enter the Arrival time\n"); //Arrival time
fflush(stdin);
node->arrival_time = new char [80];
gets(node->arrival_time);
node->node2 = NULL;
return node;
}
flight* delete_flight_node(flight *start2) // Function to delete the name of a flight, function
{ // searches for the name and deletes if it is found.
printf("\n");
if(start2 == NULL)
{
printf("Sorry, no available Flights today\n");
}
else
{
char flightnumber[80];
printf("Please enter the flight number you want to delete\n");
fflush(stdin);
gets(flightnumber);
flight *count_node1, *count_node2;
flight *temp;
for(count_node1 = start2;
(count_node1 != NULL) && (strcmp(count_node1->flightnumber, flightnumber)!= 0);
count_node2 = count_node1, count_node1 = count_node1->next);
if(count_node1!= NULL)
{
if (count_node1 == start2)
{
temp = start2;
start2 = start2->next;
free(temp);
}
else if(count_node1->next == NULL && count_node1 != start2)
{
temp = count_node1;
count_node2->next = NULL;
free (temp);
}
else
{
temp = count_node1;
count_node2->next = count_node1->next;
free (temp);
}
}
else
{
printf("\n");
printf("Sorry, this name was not found in this list\n");
}
}
return start2;
}
void print_flight_list(flight *start2)
{
printf("\n");
if (start2 == NULL)
{
printf("Sorry, the Flight List is empty\n");
}
else
{
flight *count;
for (count = start2; count != NULL; count = count->next)
{
printf("Flight Number : %s\n", count->flightnumber);
printf("Data of Flight : %s\n", count->date_of_flight);
printf("Departure Location : %s\n", count->departure_location);
printf("Arrival Location : %s\n", count->arrival_location);
printf("Take off Time : %s\n", count->take_off_time);
printf("Arrival Time : %s\n", count->arrival_time);
printf("\n");
}
}
}
flight* enter_passenger_menu(flight *start2) // Function to search for the flight entered and enter its passenger list menu
{
printf("\n");
char flightnumber[80];
printf("Welcome to the passenger list Menu\n");
printf("Enter the Flight Number you wish to check\n");
fflush(stdin);
gets(flightnumber);
flight *count;
for(count = start2; (count != NULL) && (strcmp(count->flightnumber, flightnumber) != 0);
count = count->next);
if(count == NULL)
{
printf("Sorry, this flight is not available\n");
return start2;