CS Airline Current version: 1.0.9 Welcome to CS Airline! COVID is becoming a thing of the past, we are beginning to be a
Posted: Tue Jul 12, 2022 8:09 am
QUESTION FOR STAGE 1
END OF QUESTION FOR STAGE 2
END OF QUESTION FOR STAGE 3
END OF QUESTION FOR STAGE 4
MUCH APPRECIATED FOR SOMEONE WHO COULD HELP ME WITH THIS QUESTION!!!!!
CS Airline Current version: 1.0.9 Welcome to CS Airline! COVID is becoming a thing of the past, we are beginning to be able to travel again (how exciting!). As part of this, naturally all the Sydneysiders now want to be able to fly overseas and interstate, but there's a problem! The old airline booking system is out of date. The airline, 'CS-Airline' has contracted you, a new software developer, to build them a new one! In this assignment, you will build a booking system capable of managing a single flight with multiple stops. You will do this using a Linked List and all the skills you have learnt in this course. Assignment Structure The primary purpose of this assignment is to test your ability to create, use and manipulate a linked list. As such, each flight route is implemented as a linked list of airports, with a flight storing the location of origin and destination airport. Airport's names are stored as ICAO Codes, which is an international system for identifying airports by a 4 letter code. See the list of terminology for more details.
that fight dest airport OxDF12 origin airport-OFA3 strict airport code YSSY arrival me 0000 optime-0100 next aport struct airport • Purpose: code YUML arival time 0000 deptime-0230 next airport 74AC The CS-Airline program makes use of the following structs: • Contains: 0 0 struct airport 6 codew YPAD arrival time 054 dept time 700 next airport DDF12 struct airport To store information about a specific airport on the flight route. char code [ICAO_CODE_LEN • The ICAO airport code. int arrival time • The time the plane would arrive at this airport int departure time The time the plane would depart from this airport struct airport snext_airport • A pointer to the next airport in the route struct airport char code(ICAO CODE LEN int arrival time struct airport code YPPH aival time 1135 dept time-1340 next airport NALL NULL 1 CS Airline Stage 11 Stage 2 Stage 3 Stage 4 Appendix Rationales Assessment
. ● struct airport char code(ICAO_CODE_LEN] struct flight • Purpose: • To store where the origin and destination of the flight it and any metadata about the flight as a whole • Contains: int arrival time int dept time HINT: struct airport "next_airport; struct airport #origin_airport A pointer to the first airport on the route struct airport dest_airport A pointer to the last airport on the route Representing Time NOTE: You should not need to modify the definition of these structs until Stage 4! struct flight struct airport "origin_airport; struct airport "dest airport; Remember to initialize all the fields of your struct when you create them, not just the ones you're using. CS A Sta Sta Star Stag App Rati Asses
Representing Time To match the industry standard of time management, your CS-Airline program will use 24-Hour time. Things to note: • This time should always be stored in an int variable • E.g. 15:00 would be stored as 1500 • The range of the entire flight will always reside within the range 0000 to 2359, inclusive. • I.e. A flight will never extend over more than 1 day. • Times will never have more than 59 minutes in them. • L.e. You will never have times like 8860-0099 or 1368-1399 How to get started There are a few steps to getting started with CS Airline. 1. Create a new folder for your assignment work and move into it. $ mkdir ass2 $ cd ass2 2. Download the starter code (cs_airline.c) here or use this command on your CSE account to copy the file into your current directory: $ cp -n /web/dp1091/2272/activities/cs_airtine/cs_airline v 3. Run 1091 autotest to make sure you have correctly downloaded the file -- $ 1091 autotest cs_airline 4. Spend a few minutes playing with the reference solution--get a feel for how the assignment works. $ 1091 cs_airline 5. Read through Stage 1. CS Air Stage Stage Stage Stage Appe Ration Assess
NOTE: Each task has an 'Overview' & 'Requirements' section. Overview = A top level description of what is involved in this task. Requirements = Everything you must consider to be able to complete this stage. 6. Think about your solution, draw a diagram of what you need to do to help you get started. 7. Note down when the livestream is, and attend (or watch the recording)! 8. Start coding! Stage 100 Stage 2 00 Stage 3 Stage 1 Stage 4 You can run the autotests for Stage 1 by running the following command: 1091 autotest-stage 01 cs_airline Appendix Modes Similar to assignment 1-CS-Airline operates in two modes, setup and operational mode. The setup mode must be completed first, then the program moves into operational mode. The program cannot move back into setup mode. Setup mode: • Ask the user how many airports will be enroute . Read in the details of that many airports 1 CS Airlin Stage 1 Stage 2 Stage 3 Stage 4 Appendi Rationale Assessme
Read in the details of that many airports For each airport, append them to the flight route in the order they are entered. I.e. Origin to destination. Operational mode: • Given a specific single character command, apply that command to the flight. This may require the program to read in extra information • The program should continue to read commands until EOF is pressed NOTE: This structure is very similar to assignment 1 and we suggest reviewing your assignment 1 code to accelerate your implementation of these first few steps. Stage 1 will see you implement the setup mode and then display the flight route back to the user. You will also cover a lot of the code and logic needed to complete the first Stage in Week 7 lectures. 1.1 Initialisation Overview This stage is implementing the setup mode of CS-Airline as described above. You should: • Ask the user how many stops will be enroute • Read in the details of all these stops For each stop, create a new linked list node (a struct airport) and append it to the end of the flight route. Remember: the head of the linked list is stored in flight->origin_airport Your program must also do some error checking for each airport. You should check the following requirements: Should give the following error if the departure time is 'before' arrival time and not add the airport to the list. The arrival time and departure time can be the same with no errors. CS Airl Stage Stage Stage Stage Appene Rationa Assessm
• Should give the following error if the departure time is "before" arrival time and not add the airport to the list. The arrival time and departure time can be the same with no errors. • "Departure time cannot be before the arrival time!" • Should give the following error if the arrival time of new airport is before the last departure time. I.e. if you arrive at the next stop, before you have left. o "New arrival time cannot be before the previous departure time" The starter code includes some code to get started. You will will implement the provided setup_flight function. This function has some suggested TODO comments. HINT: You should create functions for creating airports and appending airports to the flight route. HINT: To help with error checking, you should remember the departure time of the last airport you added. After setting up the flight route, the program should prompt the user to enter a commands until EOF. When EOF is entered, print the following. Enter Command: Ctrl-D Goodbye! Requirements This should always happen first, when the program is first run, with no command needed from the user. • Program should never go back into setup mode. • Program should automatically go into operational mode after X number of airport details have been read (regardless of if they were valid or not). Format must match sample solution. • Should give the following error if the departure time is 'before' arrival time and not add the airport to the CS Air Stag Stage Stage Stage Appe Ration Assess
Should give the following error if the departure time is 'before' arrival time and not add the airport to the list o "Departure time cannot be before the arrival time!" • The arrival time and departure time can be the same with no errors. • Should give the following error if the arrival time of new airport is before departure time of previous airport • "New arrival time cannot be before the previous departure time" . You can assume you the number of airport details will always match the number of airports . An airport code will always be exactly 4 characters • You can assume that during the setup phase, every inputted airport will have a unique ICAO code - i.e. you DO NOT have to check the codes are unique. • You should assume you will always be given at least 1 valid airport. Example 1.1.1: Basic Initialisation $ ./cs_airline How many stops will be enroute? 3 0000 0100 yssy 0200 0230 ymml 0545 0700 ypad Enter Command: Ctrl-D Goodbye! - Example 1.1.2: Arrival Time Check $ ./cs_airline How many stops will be enroute? 2. 0200 0400 yssy 0400 0200 ymml CS Airline Stage 11 Stage 2 Stage 3 Stage 4 Appendix Rationales Assessment
$ ./cs_airline How many stops will be enroute? 2 ezee 0400 yssy 0400 0200 ymml Departure time cannot be before the arrival time! Enter Command: Ctrl-D Goodbye! - Example 1.1.3: Depature Time Check $ ./cs_airline How many stops will be enroute? 21 0100 0200 yssy 0130 0200 ymml New arrival time cannot be before the previous departure time Enter Command: Ctrl-D Goodbye! 1.2 Print Route Command Format PRINT ROUTE Enter command: print Overview | CS F Sta Sta Sta Star App Rati Asses
Overview Now that we have entered all the airport details and created our linked list, it is time to review them! To do this, we need a method to be able to display the current flight route to the terminal. When the PRINT ROUTE command is entered, the program should display the current flight route in the following format: ROUTE: YSSY: YMML: WSSS: 0100 - 0200 0300-> 0500 1000 1100 In order to do this, you will need to loop through the linked list based inside the flight struct. For each of these airports, print out the airport. To match the sample solution and autotests, you should use the provided print_one_airport function in the starter code. HINT: You should implement this task within the provided do_print_airports stub function. Requirements • The print route function should be triggered when the 'print' command is given • The route should be printed in order from origin to destination, with the origin being at the top of the list. • Each airport should have its arrival & departure time next to it. The print route function should not modify the route Example 1.2.1: Print Route CS Ai Stag Stag Stag Stage Appe Ratio Assess
Tn Course: DPST1091 Introduction to Programming 2022 T2 PST1091 22T2 Forum Submissions History Assignment 1 Assignment 2 starter code. HINT: You should implement this task within the provided do_print_airports stub function. - Requirements • The print route function should be triggered when the 'print' command is given • The route should be printed in order from origin to destination, with the origin being at the top of the list. Each airport should have its arrival & departure time next to it. The print route function should not modify the route Example 1.2.1: Print Route 1sw.edu.au $ ./cs_airline How many stops will be enroute? 4 0000 0100 yssy 0200 0230 ymml 0545 0700 ypad 1350 1340 ypph Departure time cannot be before the arrival time! Enter Command: print ROUTE: yssy: 00000100 ymml: 0200 - 0230 ypad: 0545 0700 Enter Command: Ctrl-D Goodbye DPST1091 22T2
Stage 2 You can run the autotests for Stage 2 by running the following command: 1091 autotest-stage 02 cs_airline Stage 2 will implement functionality, which will begin to calculate some parameters concerning the linked list, and also modify the linked list. Command Format. SUBROUTE Enter command: subroute Enter airport code: [AIRPORT CODE] 2.1 Calculate Subroute Overview The airline has asked for a new piece of functionality you have not previously implemented; A passenger has come to them and asked how long it will take to get from the origin to a specific airport within the route - your task is to be able to tell them! When the SUBROUTE command is given, read an airport code and if the airport is in the route, your program should calculate the number of hours and minutes between the origin airport's departure time, and the given airport's arrival time in the following format:
Time for subroute: 1 hrs & 35 mins. If the airport does not exist within the flight route, the program should produce the following error message: Desired subroute destination does not exist! The following diagram gives an example of a subroute to the YPAD airport in the flight route. This example is shown in action in example 2.1.1 struct fight dest airport 0xDF 12 origin, arport A IF struct aport code YSSY aival time 0000 dept time 0100 next airport 001 D-FAM YPAD Subroute 0130 struct aport code YMML amval time 0000 dept time-0230 next airport 0x74AC 001 studarport code YPAD amival time 0541 dept_time=0700 next airport DDF12 0x74AC Nos (349 tapo code-YPPH anival time 1135 dept time 1340 next airport NULL 0-DF12 HINT: Refer to the command index for the format of the command and it's parameters. TY NULL HINT: You should use the provided #define s for checking input to commands. You may choose to use this logic (or 'pseudo code') to calculate the hours and minutes between two 24hr
You may choose to use this logic (or 'pseudo code') to calculate the hours and minutes between two 24hr times. start= start time of time period end end time of time period hours (end / 100) (start / 100) mins (end 100) (start 100) minute_diff hours * 60 + mins if (minute_diff < 0) { minute_diff *= -1; hours minute_diff / 60 mins minute_diff % 60 HINT: You should implement the provided the do_subroute stub function. Requirements This functionality should also read in the subroute destination airport code The time period should always be calculated from the origin airports departure time • The time period should always be calculate to the specified airport's arrival time • The program should print out the number of hours and minutes for the subroute. • You will never asked to calculate a subroute to the origin airport (i.e. you will never be asked to calculate a subroute to yourself • The program should produce the following error message if the desired airport doesn't exist within the route:
- Desired subroute destination does not exist! Example 2.1.1: Subroute $ ./cs_airline How many stops will be enroute? 3 eeee 0100 yssy 0200 0230 ymml 0545 0700 ypad Enter Command: subroute Enter airport code: ypad Time for subroute: 4 hrs & 45 mins Enter Command: Ctrl-D Goodbye! Example 2.1.2: Subroute checks $ ./cs_airline How many stops will be enroute? 3 eeee 0100 yssy 0200 0230 ymml 0545 0700 ypad Enter Command: subroute Enter airport code: wsss Desired subroute destination does not exist! Enter Command: [Ctrl-D Goodbye!
2.2 Change Origin Command. CHANGE ORIGIN Format Enter command: change_origin Enter new origin info: [ARRIVAL TIME] [DEPARTURE TIME] [AIRPORT CODE] There has been a change to the plan and the route must now start from an earlier airport. This task will implement the ability to add an airport before the existing origin (not replace the origin). Overview When the CHANGE ORIGIN command is given, the program should read in: • ICAO airport code • Arrival time • Departure time With this new information, the program should create a new airport and insert it at the beginning of the flight route. HINT: The new airport ICAO code must be unique. Unlike stage 1, you cannot assume the scanned in airport code will be unique, and you must check if it is. If the new airport code is not unique, you should display the following message: New airport code is not unique! Your program should do some basic error checking and display if successful as stated in the requirements.
HINT: You should implement the provided the do_change origin stub function. Requirements • The arrival time should be chronologically before or the same as the departure time of the new origin. Otherwise the following error message should be displayed and the new origin not added. Departure time cannot be before the arrival time! The departure time of the new origin should be before or the same as the arrival time of the old-origin (the next airport in the route). Otherwise the following error message should be produced and the new origin not added. Departure of new origin cannot be after the arrival time of the next airport! • The new origin airport's ICAO code must be unique and the program should check this. If it is not unique, the program should produce the following error message and new origin not be added. New airport code is not unique! • If the new origin is successfully added, the program should code of the added airport in the following format; Added: [AIRPORT CODE] Changing the origin should not remove the existing origin, but should add the new origin before it in the route. • The validity of the new departure time should be checked before the code uniqueness. i.e. If the departure time is before the arrival time and the airport code is not unique, display only the timing error message. HINT: You may want to check the reference solution for the correct error messages. Your program must match these error messages exactly in order to pass auto testing. CS A Ra Ass
HINT: You may want to check the reference solution for the correct error messages. Your program must match these error messages exactly in order to pass auto testing. - Example 2.2.1: Change Origin $ ./cs_airline How many stops will be enroute? 3 0300 8400 yssy 0800 0930 ymml 1045 1200 ypad Enter Command: print ROUTE: yssy: 03000400 ymml: 08000930 ypad: 1045-1200 Enter Command: change origin Enter new origin info: 0200 0230 ybcg Added: ybcg Enter Command: print ROUTE: ybcg: 0200 - 0230 yssy: 03000400 ymml: 0800 8930 ypad: 1045 1200 Enter Command: Ctrl-D Goodbye! I
Example 2.2.2: Check Change Origin $ ./cs_airline How many stops will be enroute? 3 0300 0400 yssy 0800 0930 ymml 1045 1200 ypad Enter Command: print ROUTE: yssy: 03000400 ymml: 08000930 ypad: 1045 1200 Enter Command: change origin Enter new origin info: 0200 0230 ymml New airport code is not unique! Enter Command: print ROUTE: yssy: ymml: ypad: 1045 1200 Enter Command: Ctrl-DGoodbye! 03000400 08000930 2.3 Bypass Airport Command Format BYPASS Enter command: bypass Enter airport code: [AIRPORT CODE]
2.3 Bypass Airport Command Format. BYPASS Enter command: bypass Enter airport code: [AIRPORT CODE] For this stage, we will imagine there has been an issue at a specific airport and we can no longer land there - as such, we must be able to by-pass an airport enroute given its ICAO code. Overview When the BYPASS command is read, the program should read in the ICAO code of the airport to bypass, and remove it from the flight route. This functionality should do the relevant updating of the flight route linked list to ensure the flight route remains intact. Requirements The airports before and after the airport to be removed, should not be removed from the route and should be linked together in the same order, only the airport that needs to be bypassed should be removed. • If the bypassed airport is the origin, the next airport in the route should become the new origin • If the bypassed airport is the destination, the new destination should become the airport before the bypassed airport • If the inputted airport code is not in the flight route, the following error message should be displayed; No airport of that code exists! Bypassing the last remaining airport (i.e, when there is only one airport in the list) is undefined behavior and should not be implemented. | 1
• If the inputted airport code is not in the flight route, the following error message should be displayed; No airport of that code exists! . Bypassing the last remaining airport (i.e, when there is only one airport in the list) is undefined behavior and should not be implemented. Example 2.3.1: Bypass Airport $ ./cs_airline How many stops will be enroute? 3 0300 0400 yssy 0800 0930 ymml 1045 1200 ypad Enter Command: print ROUTE: - yssy: 03000400 ymml: 08000930 ypad: 1045 1200 Enter Command: bypass Enter airport code: ymml Enter Command: print ROUTE: yssy: 03000400 ypad: 1045-1200 Enter Command: Ctrl-DGoodbye! Example 2.3.2: Check Bypass Airport
Enter airport code: ymml Enter Command: print ROUTE: 03000400 yssy: ypad: 1045 1200 Enter Command: (Ctrl-D Goodbye! Example 2.3.2: Check Bypass Airport $ ./cs_airline How many stops will be enroute? 3 0300 0400 yssy 0800 0930 ymml 1045 1200 ypad Enter Command: print ROUTE: yssy: 03000400 ymml: 08000930 I ypad: 1045 1200 Enter Command: bypass Enter airport code: wsss No airport of that code exists! Enter Command: print ROUTE: yssy: 03000400 ymml: 08000930 ypad: 1045-1200 Enter Command: Ctrl-D Goodbye!
Stage 3 You can run the autotests for Stage 3 by running the following command: 1891 autotest-stage 03 cs_airline Fun fact: There have been no fatalities in scheduled commercial air transport in Australia since 2005 according to The Australian Transport Safety Bureau (ATSB). So in essence, commercial flight is very safe! However, this is mainly because pilots have strict processes and regulations which allow them to make precautionary and emergency landings. This stage will implement functionality to allow the user to reflect these route changes in the CS-Airline. 3.1 Emergency Landing Command Format EMERGENCY Enter command: emergency How long until emergency: [TIME IN HOURS] Although flying is typically very safe, components on aircraft have a limited service life (i.e. they fail after a specific period of time). This stage will implement an emergency landing at a new airport after a specified time period. Overview St Se St St Ap Ra Ass
Overview When the EMERGENCY command is input, the program should read in the number of hours until an emergency landing. The time of the emergency landing will be the departure time of the origin airport, plus the number of hours that was just read in. The EMERGENCY command should insert an airport, in chronological order, at the time of the emergency landing and remove all airports after the landing. In other words, for a given emergency the following occurs: 1. Insert an airport in chronological order into the flight route. a. The arrival time should be exactly the origin departure time + the hours until emergency. b. The airport code should be "ALT". c. The airport departure time should be 0000 as the aircraft is now out of service. 2. All remaining airports in the flight after the alternate should be removed from the route. Original Flight dest airport DDF12 origin, airport FAS struct airport code VSSY valme0000 deptime-0100 next airport-OSOF OXFA34 struct airport code=YMM ame=0200 deptime-0230 next airport 74AC ONEOFY struct airport code VIAD amval sme 0545 deptime-0700 next airport OxDF 12 Ox74AC struct airport code YPPH arrival time 1135 dept time-1340 next airport NULL CADF12 | CS A Star Stag Star Stag App Rati Asses
struct flight dest airport DDF12 origin airport OxFA34 struct airport code=YSSY arrival time 0000 dept time 0100 next airport Ox0F1 OxFA34 Emergency after 2 hours struct airport code YMML arrival time 0200 dept time=0230 next airport Ox815 OxGDF1 struct airport code=ALTO arrival time 0000 dept time 0000 next airport NULL OxE815 NULL Every time an aircraft is about to take off, the captain and co-pilot must do pre-flight checks. If any of these checks presents an error, the flight may be canceled. To represent this in the program, we say the hours until emergency is 0. If the hours until the emergency is exactly 0, there is different behavior. • The origin airport arrival time should remain unchanged • The origin airport departure time should be set to 0000 The origin airport code should remain unchanged • Every airport except the origin should be removed from the flight route. HINT: When reading in the then use the atoi() For an example of how to do do this, look at lines 145-150 of the provided starter code. ITIME IN HOURS], you should use fgets to read in the number as a string, and function to convert it to a number.
Requirements • You can assume there will not be an emergency after reversing the flight route (Only relevant if completed stage 3.3) • If the time of emergency is after the destination arrival time, the program should print the following message saying the flight was safe: • Flight was safe! You can assume the time of emergency will not be any later than 2359 The time of an emergency is calculated as emergency_time = origin_airport->departure_time + [HOURS] • The code of the emergency landing airport should be "ALTO" • The departure time of the emergency landing airport should be 0000 • the arrival time of the emergency landing airport should be exactly the time of the emergency.(see above requirement) • There should be no other airports in the flight route after the emergency landing airport • If the time of emergency is exactly the arrival time of an existing airport, the program should still remove the existing airport and replace with the new "ALTO" airport and associated data. • You can assume emergencies will always be after at least 1 airport • If the hours until emergency is exactly 0, all airports except the origin should be removed. • If the hours until emergency is exactly 0, the origin's departure time should be set to 0000. • If the plane is on the ground at the time of the emergency, add the alternate airport after existing airport but with the times. (This is to simplify the implementation). Check the reference implementation for examples Example 3.1.1: Emergency $ ./cs_airline How many stops will be enroute? 4 eeee 0100 yssy 0200 8230 ymml
Example 3.1.1: Emergency $ ./cs_airline How many stops will be enroute? 4 0000 0100 yssy 0200 0230 ymml 0545 0700 ypad 1025 1355 ypph Enter Command: print ROUTE: 00000100 0200 - 0230 ypad: 0545 -> 0700 ypph: 10351355 - yssy: ymml: Enter Command: emergency How long until emergency: 3 Enter Command: print ROUTE: yssy: ymml: ALTO: 04000000 Enter Command: Ctrl-DGoodbye! 0000-> 0100 0200 - 0230 Example 3.1.2: Safe Flight $ ./cs_airline How many stops will be enroute? 4 eeee 0100 yssy 8288 0230 mm1.
Example 3.1.2: Safe Flight $ ./cs_airline How many stops will be enroute? 41 0000 0100 yssy 0200 0230 ymml 0545 0700 ypad 1055 1355 ypph Enter Command: print ROUTE: 00000100 02000230 0545 - 0700 10351355 Enter Command: emergency How long until emergency: 15 yssy: ymml: ypad: ypph: Flight was safe! Enter Command: print ROUTE: yssy: 00000100 ymml: 0200 - 0230 ypad: 0545 0700 ypph: 10351355 Enter Command: Ctrl-D Goodbye! Example 3.1.3: Emergency Before Departure $ ./cs_airline
- Example 3.1.3: Emergency Before Departure $ ./cs_airline How many stops will be enroute? 4 0030 0100 yssy 0200 0230 ymml 0545 0700 ypad 1035 1355 ypph Enter Command: p ROUTE: yssy: 0030 - 0100 ymml: 02000230 ypad: 0545 - 0700 ypph: 10351355 Enter Command: emergency How long until emergency: 0 Enter Command: print ROUTE: yssy: 0030 -> 0000 Enter Command: Ctrl-DGoodbye! 3.2 Cancel Flight Command Format CANCEL Enter command: cancel
3.2 Cancel Flight Command Format CANCEL Enter command: cancel Unfortunately in the commercial airline industry, things do not always go to plan. It could be weather, technical problems or financial reasoning - but sometimes, airlines will have to cancel a flight. Overview In this stage, you will implement the ability for your program to cancel a flight. When the CANCEL command is entered, your program should delete all airports from the route and then accept a new flight. Additionally, the program must now free() all malloc'd memory throughout the program. This will require you to add logic to your previous stages (2.3 & 3.1) to free any memory which is being deleted from the linked list. i.e You must now free() the airports which were after the emergency landing airport. NOTE: When the program ends due to the user inputting Ctrl+D, you should still ensure that all malloc'd memory is cleaned up! HINT: Remember to free the flight struct as well! Requirements
Requirements • After the CANCEL command, your program should print the following message: Flight cancelled. Now accepting a new flight: • Your program should then accept information for a new flight, in the same manner as Stage 1. • Your program should remove all airports from the flight route • For every task from now on, your program must clean up all memory that was malloc'd throughout the program - including in other stages. Example 3.2.1: Cancel Flight - $ ./cs_airline How many stops will be enroute? 4 0000 0100 yssy 0200 0230 ymml 0545 0700 ypad 1035 1355 ypph Enter Command: print ROUTE: yssy: 00000100 ymml: 02000230 ypad: 0545 0700 ypph: 1035 -> 1355 Enter Command: cancel Flight cancelled. Now accepting a new flight: How many stops will be enroute? 1 0000 0100 abcd Enter Command: Ctrl-D) Goodbye!
3.3 Reverse Flight Command Format REVERSE Enter command: reverse Good news, the flight successfully got to its destination airport and all the passengers have left the plane. Now we want to fly back to the origin! Overview This stage will require you to implement the REVERSE functionality. This functionality reverses the order of the airports in the flight route - i.e. The destination becomes the origin and the origin becomes the destination. You must change the next_airport pointer in each airport to point to the new airport that will come after. However, since the plane is now flying back through the timezones, the departure times will now be 'after' the arrival time of the next airport. This is the intended behavior. For further clarification, please review the diagrams & examples below. struct flight dest airport xDF12 origin, airport DFAS struct airport code VSSY amival time 0000 struct airport code YMML arrival time-0200 struct airport code YPAD arrival time 0545 struct airport code - YPPH arrival time 1135 NULL
struct fight dest airport w DxDF 12 origin airport OFA34 struct airport code YSSY arrival time-0000 dept time 0100 next airport 0x80F1 struct fight dest airport DDF12 origin, airport the FAM OxFA34 struct airport code VPP arrival time 1135 dept Sime-1340 next airport 0x74AC OXDF12 Requirements struct airport code YMML arrival time-0200- dept time 0230 next airport Dx74AC OF struct airport code YPAD Reversed arrival time 0545 dept time-0200 next, airport OF 0x74AC struct airport code YPAD arrival time-0545 dept time 0700 next airport OxDF12 Ox74AC struct airport code YMML arrival time 0000 dept me 0230 next airport DA OSOFI struct airport code VPPH arrival time 1135 dept time 1340 next airport NULL OXDF12 struct airport code VSSY anival time 0000 dept time 0100 next airport NULL CFA34 NULL NULL
Requirements • When the REVERSE command is entered, the order of airports in the flight route should be reversed • When the REVERSE command is entered, the origin and destination airport should be swapped • When the REVERSE command is entered, the arrival and departure times of each airport in the flight route should not be modified • After the REVERSE command, you can assume the program will not be asked to make an emergency landing. I.e After reversing the flight, you will not be given any EMERGENCY commands from stage 3.1. • After the REVERSE command, the program could still be asked to calculate a subroute. In this case, the resultant subroute time should still be positive numbers. Example 3.3.1: Reverse Flight $ ./cs_airline How many stops will be enroute? 4 0000 0100 yssy 0200 0230 ymml 0545 0700 ypad 1035 1355 ypph Enter Command: print ROUTE: yssy: 00000100 ymml: 82000230 ypad: 0545 - 0700 ypph: 10351355 Enter Command: reverse Enter Command: print ROUTE: ypph: 10351355 ypad: 0545-0700 ymml: 02000230 yssy: 00000100 C: F As
Example 3.3.1: Reverse Flight $ ./cs_airline How many stops will be enroute? 4 0000 0100 yssy 0200 0230 ymml 0545 0700 ypad 1035 1355 ypph Enter Command: print ROUTE: yssy: ymml: ypad: 0545 0700 ypph: 10351355 00000100 02000230 Enter Command: reverse Enter Command: print ROUTE: ypph: ypad: ymml: 10351355 0545 0700 0200 - 0230 yssy: 00000100 Enter Command: [Ctrl-D] Goodbye! MacBook Air
Stage 4 You can run the autotests for Stage 4 by running the following command: 1891 autotest-stage 04 cs_airline Well done - You now have all the essential functionality to run cs_airline! I look forward to joining you for a flight! This stage will see you continue to add some cool functionality to your program to allow you to manage your flights more effectively with more advanced functionality. Additionally, for this stage, we have provided a partially complete Abstract Data Type (ADT). This stage will require you to use and finish the implementation of this ADT. Stage 4.1 & 4.2 only require you to use the provided parts, however stage 4.3 requires you to finish the implementation of some ADT functions. Manifest ADT The remaining stages of this assignment require you to make use of, and complete the implementation of a new ADT called 'Manifest'. Please review the 'Key Terminology' table for a definition and explanation of a manifest in this context. Using the Manifest ADT Before you can start using the manifest ADT, you must get setup with the new Manifest ADT files. Most of the ADT functionality has already been completed for you and is sufficient for stages 4.1 and 4.2. However there are 2 functions you must implement before you can use them in stage 4. You should review the manifest.h file to see what functions are available and how they work. The manifest ADT uses the following structs;
struct manifest • Purpose: o To store a pointer to the first person on the manifest • Contains: O struct person • Purpose: struct person people • A pointer to the first person on the manifest • Contains: 0 • To store the details about an individual person O struct manifest struct person "people; char name [MAX_NAME_LEN] • Store the name of the person . Note: MAX_NAME_LEN is #defined in the manifest.h file. double weight • Store the weight of the person struct person next • Store a pointer to the next person on the manifest struct manifest struct person "people=0x34DE struct person char name[MAX NAME_LEN]: double weight; struct person "next: The structure of the manifest ADT is shown in the diagram below;
The structure of the manifest ADT is shown in the diagram below; struct manifest struct person "people=0x34DE OxB528 struct person char name Anosua double weight 1.03 struct person "next=0x703F . 0x34DE struct person char name Sasha double weight 0.92 struct person "next Ox5C42 Ox703F struct person char name Tom double weight 8.24 struct person "next ULL What You're Provided You are provided with: manifest.h • Defines all the structs and functions available with the Manifest ADT o Shows the interface between the main CS-Airline program and the internal Manifest ADT implementation You cannot change manifest.h 0x5042 manifest.c Defines the implementation for all the manifest functionality This is where you will have to implement the 2 remaining functions You can download the manifest by running the commands below; $ cp /web/dp1091/22T2/activities/cs_airline/manifest.c. $ 1n-s/web/dp1091/22T2/activities/cs_airline/manifest.h. NULL I C: As
Remember: • Ensure these files are in the same working directory as your cs_airline.c file • Ensure to #include "manifest.h" into your cs_airline.c file • When compiling, ensure to add manifest.c in your dcc command • E.g. $ dcc cs_airline.c manifest.c-o cs_airline What you have to do • For Stages 4.1 & 4.2 • Use the provided and fully implemented functions in manifest.h • For Stage 4.3 • Implement the following functions in manifest.c manifest_weight() join_manifest() • Use the functions in cs_airline.c 4.1 Add People to Airport Command ADD PERSON Format Enter command: add_person Enter the airport code: [AIRPORT CODE] Enter the passenger name: [NAME] Enter the passenger weight: [WEIGHT] What is a flight without a manifest! Making use of the Manifest ADT, your CS-Airline program will now be able to manage a manifest of people at each airport which describes who is getting on the flight at this airport. The manifest will describe the name & weight of each person.
What is a flight without a manifest! Making use of the Manifest ADT, your CS-Airline program will now be able to manage a manifest of people at each airport which describes who is getting on the flight at this airport. The manifest will describe the name & weight of each person. You should add the person into the manifest of the airport that matches the given code. Overview When the ADD PERSON command is entered, the program should read in: • ICAO Code . 0 Which airport's manifest the person should be added to Name • The name of the person to be added Weight The weight of the person to be added To implement the use of the manifest ADT, you will need to modify struct airport to be able to store a manifest. The diagram below shows how a manifest should be implemented into the CS-Airline program structure. HINT: You should use fgets to read in all information, including the weight. You may like to use the atof() function to convert your string into a double. destport DDF12 ongin, arport DA ONESAF
struct fight dest airport OxDF12 origin airport OxFA34 OXES4F struct airport code YSSY arrival time 0000 dept time 0100 next airport OvOF1 manifest Ox528 OxFA34 struct manifest struct person "people=0x34DE Ov528 struct person char name An double weight 100 struct person "next0x703 OXIDE struct airport code YMML arrival time 200 dept time 02:30 next airport 0x740 manifest 777 OSOF1 struct person char name Sasha double weight 0.92 struct person "next0x5042 Ox7D3F struct airport code YPAD arrival time 0545 dept time w 0700 next airport OxDF12 manifest777 Ox74AC Requirements: • CS-Airline must make use of the provided Manifest ADT • A person's name does not have to be unique struct person char name Tom double weight-824 struct person next=NULL Ox5042 struct airport code YPPH arrival time 1135 dept time-1340 next arport NULL manifest-777 ONDF12 NULL NULL
NOTE: If you are unsure of the program's behavior, check the sample solutions result. NOTE: We won't be able to check how you have implemented this functionality until you implement stage 4.2 4.2 Print Airport Manifest Command PRINT MANIFEST Format Enter command: print_manifest Enter the airport code: [AIRPORT CODE] After adding people to an airport manifest, it is important to be able to review the state of a manifest and the details of people in that manifest. Overview When the PRINT MANIFEST command is executed, the program should read in the name of the airport to print the manifest of and then display the manifest of people and their weight in the following format. Manifest: For example [weight] [name] [weight] [name] [weight] [name]
For example; Manifest: 91.22- person3 77.23 - person4 Requirements • When the PRINT MANIFEST command is executed, the program should print out the name and weights of all people at a specific airport . When the •. When the PRINT MANIFEST command is executed, it should not modify the list of people at each airport PRINT MANIFEST command is executed, the program should use the predefined manifest ADT function. • If the given airport code is not in the list, the program should output the following error message. No airport of that code exists! Example 4.2.1: View Manifest Example 4.2.1 - View Manifest $ ./cs_airline How many stops will be enroute? 3 eeee 0100 yssy 0200 0230 ymml 0545 0700 ypad Enter Command: print ROUTE: yssy: 00000100 ymml: 02000230 ypad: 8545 0700 | с As
Example 4.2.1 - View Manifest $ ./cs_airline How many stops will be enroute? 3 eeee elee yssy 0200 0230 ymml 0545 0700 ypad Enter Command: print ROUTE: 00000100 0200 - 0230 0700 yssy: ymml: ypad: 0545 Enter Command: add_person Enter the airport code: yssy Enter the passenger name: personl Enter the passenger weight: 84.55 Enter Command: add_person Enter the airport code: ymml Enter the passenger name: person2 Enter the passenger weight: 72.45 Enter Command: add_person Enter the airport code: ypad Enter the passenger name: person3 Enter the passenger weight: 91.22 Enter Command: print manifest Enter the airport code: yssy Manifest: 84.55 - personl Enter Command: print_manifest Enter the airport code: yaml Manifest: 72.45 person2 Enter Command: print manifest Enter the airport code: ypad Manifest:
Enter the airport code: ypad Manifest: 91.22 person3 Enter Command: (Ctrl-D) Goodbye! 4.3 Flight Statistics Command FLIGHT STATISTICS Enter command: stats Format CS-Airline is now a fully fledged flight management and planning system, cool! This final stage will see you display and calculate some statistics and views of the flight for when the flight makes it to the final destination. Overview When the FLIGHT STATISTICS command is given, the program should merge all the manifests together at the destination airport. Next, it should display the list of all people now at the destination airport and the total weight of everyone. Before the statistics, your data structure might look like: dest, aporta engin airport M Ose
structi destaport Ov origin airport DAM DESAF tarport code YSRY avalime 0000 dete-0106 next airport DFY manifest OXFA34 me et person people-4DE des sport DDF12 origin airport FAM ONE SAF OBS wat person cher name Arc doute weight 1. eta person next MAL ONDADE att sport sode Y valm deptime-30 next airport 74 manifest OF ut aut person people- CHED mujere char mech u poned 0x70SF code AD aival me 0645 dept fine 3700 next aport DDF12 mantestOVEDOS DETRAC After the statistics, your data structure might look like: ut me et person people ODOS ther name T duble weight 1.34 pared OSCA code YPPH avali113s dept Sime 1340 next airport NULL manifesta AF OF12 man struct person people OAKF ther name the die weight 1.79 struct person neet LL DIFE NULL | c= As
struct sport code-YSSY anival Sime 0000 dept Sime-0100 next portr manifest D OXFA34 struct person "people=NULL Ox529 ha aport code YMM avival Time 0000 deptime=0230 next airport DAC manestO82 COF stut mande struct person "people NULL 082 code YPAD aival Sime 0545 dept time 0700 nevt airport OvDF12 manifest OxED29 Ox74AC struct person people NULL OVED29 ut airport code YPPH arrival time-1135 dept time 1340 next airport NULL mandest DAK OxOF 12 struct person "people FE OxA82F char name Shrey double weight-079 struct person "next NULL C82FE person char name Tom double weight-8.24 struct person next NULL 05042 person char name Basha struct person nest MULL 0X703F struct person double weight 100 struct person next-NULL NULL
You should output the final manifest in the format following format (similar to 4.2). Final manifest: Manifest: 66.32 person5 75.92- person6 91.22- person3 77.23- person4 84.55- person1 72.45 person2 Total weight: 467.690000 Note the additional line Final manifest: and the calculation of Total weight. Requirements • After the FLIGHT_STATISTICS command, every airport except the destination airport should have an empty manifest • After the FLIGHT_STATISTICS command, the destination airport should have every person on the manifest that existed anywhere in the route • After the FLIGHT_STATISTICS command, the order of people in the final manifest should not be modified from the original flight route. See sample solution for desired ordering of people - Example 4.3.1: Flight Statistics $ ./cs_airline How many stops will be enroute? 3 0000 0100 yssy 0200 0230 ymml 0545 0700 ypad Enter Command: print ROUTE: yssy: 00000100 | c As
yssy: 00000100 ymml: 0200 - 0230 ypad: 0545 - 0700 Enter Command: add_person Enter the airport code: yssy Enter the passenger name: personl Enter the passenger weight: 84.55 Enter Command: add_person Enter the airport code: ymml Enter the passenger name: person2 Enter the passenger weight: 72.45 Enter Command: add_person Enter the airport code: ypad Enter the passenger name: person3 Enter the passenger weight: 91.22 Enter Command: print_manifest Enter the airport code: yssy Manifest: 84.55- personl Enter Command: print_manifest Enter the airport code: ymml Manifest: 72.45 - person2 Enter Command: print_manifest Enter the airport code: ypad Manifest: 91.22 - person3 Enter Command: stats Final manifest: Manifest: 91.22 person3 72.45 person2 84.55- personl Total weight: 248.220000 Enter Command: print_manifest Enter the airport code: yssy
Enter the passenger name: person3 Enter the passenger weight: 91.22 Enter Command: print_manifest Enter the airport code: yssy Manifest: 84.55 - personl Enter Command: print_manifest Enter the airport code: ymml Manifest: 72.45 - person2 Enter Command: print_manifest Enter the airport code: ypad Manifest: 91.22 person3 Enter Command: stats Final manifest: Manifest: 91.22- person3 72.45- person2 84.55- personl Total weight: 248.220000 Enter Command: print_manifest Enter the airport code: yssy Manifest: Enter Command: print_manifest Enter the airport code: ymml Manifest: Enter Command: print_manifest Enter the airport code: ypad Manifest: 91.22 person3 72.45 person2 84.55 person1 Enter Command: Ctrl-D Goodbye! -
Appendix Command Index Command PRINT ROUTE SUBROUTE CHANGE ORIGIN BYPASS EMERGENCY CANCEL REVERSE Format Enter command: print Enter command: subroute Enter airport code: [AIRPORT CODE] Enter command: change origin Enter new origin info: [ARRIVAL TIME] [DEPARTURE TIME] [AIRPORT CODE] Enter command: bypass Enter airport code: [AIRPORT CODE] Enter command: emergency How long until emergency: [TIME IN HOURS] Enter command: cancel Enter command: reverse
ADD PERSON PRINT MANIFEST FLIGHT STATISTICS Term Flight Terminology The below table outlines the command characters and input format. You should refer back to this table to understand what command executes which bit of functionality. Airplane /Plane Flight Route / Route Enter command: add_person Enter the airport code: [AIRPORT CODE] Enter the passenger name: [NAME] Enter the passenger weight: [WEIGHT] Meaning Enter command: print_manifest Enter the airport code: [AIRPORT CODE] Enter command: stats Refers to the overarching structure The airplane that would fly along this route. Note, this mechanism is not implemented until Stage 4. Refers to the ordered list of airports
Airplane The airplane that would fly along this route. Note, this mechanism is not implemented until / Plane Stage 4. Flight Route / Route Airport Person ICAO Code Refers to the ordered list of airports NOTE: A single place along the route Manifest In this context, it refers to a "Flight Manifest" - an ordered list of people where each person has a set of associate details. A single individual with details Each airport in the world has a unique 4 character code to identify it - this is called an ICAO code. For example, you can see all the Australian airports and their ICAO codes here. Throughout the specification, the [] bracketing refers to placeholders. For example, [AIRPORT CODE] would be replaced with WSSS The entire [AIRPORT CODE] has been replaced with wss
// CS Airline // cs_airline.c // // This program was written by YOUR-NAME-HERE (25555555) // on INSERT-DATE-HERE // // Version 1.0.0 2022-04-02: Initial Release. // Version 1.0.1 2022-04-06: Fixed style issue with help function. // // TODO: Description of your program. #include #include #include // The buffer length is used for reading a single line #define MAX_STRING_LEN 100 CONSTANTS #define COMMAND PRINT HELP "help" #define COMMAND PRINT_ROUTE "print" #define COMMAND SUBROUTE "subroute" #define COMMAND CHANGE ORIGIN "change_origin" #define COMMAND BYPASS "bypass" #define COMMAND EMERGENCY "emergency" #define COMMAND CANCEL "cancel" #define COMMAND REVERSE "reverse" #define COMMAND ADD PERSON "add_person" #define COMMAND PRINT MANIFEST "print_manifest" #define COMMAND FLIGHT_STATS "stats" // TODO: you may choose to add additional #defines here. char code [MAX_STRING_LEN]; "// STRUCTS /// // Airports represent 'stops' along the flight path // These are the 'nodes' of the linked list struct airport { int arrival time; int departure_time; struct airport *next_airport; }; // Root flight structure // This stores the state of the current flight // (i.e. the head and tail of the linked list) struct flight ( struct airport origin airport.
}; struct airport origin_airport; struct airport *dest_airport; // FUNCTION PROTOTYPES // Helper Functions. void remove_newline (char input [MAX_STRING_LEN]); void do print_help (void); void interpret_line ( char buffer[MAX_STRING_LEN], int *val0, int *vall, char word [MAX_STRING_LEN] // Stage 1 Functions struct flight setup_flight (void); void do print airports (struct flight flight); void print_one_airport (struct airport *ap); struct airport *create_airport ( char code [MAX_STRING_LEN), int arrival time, int departure ); // Stage 2 Functions void do subroute (struct flight flight); void do change origin(struct flight flight); // TODO: Your functions prototypes here. // FUNCTION IMPLEMENTATIONS int main(void) { // Stage 1.1 // TODO: Complete the setup flight function below struct flight flight setup_flight(); // TODO: Fill out the while loop with relevant commands & functions // Move into and stay in operational mode until CTRL+D printf("Enter Command: "); char command line [MAX_STRING_LEN]; while (fgets (command_line, MAX_STRING_LEN, stdin) != NULL) { remove_newline (command line);
} remove_newline (command line); if (stremp (COMMAND PRINT HELP, command line) == 0) { // A help command we have implemented for you. do print_help(); } else if (stremp (COMMAND PRINT_ROUTE, command line) == 0) { // Stage 1.2- TODO: Complete this function below do_print_airports (flight); } else if (strcmp (COMMAND SUBROUTE, command line) == 0) ( // Stage 2.1 - TODO: Complete this function below do subroute (flight); } else if (strcmp(COMMAND_CHANGE_ORIGIN, // Stage 2.2 - TODO: Complete this function below do_change_origin (flight); // TODO: Add more conditions here for the remaining commands printf("Enter Command: "); printf("Goodbye!\n"); return 0; } // Stage 1.1 // Creates and initialises a flight by asking the user for input. // Parameters: // None // Returns: // Pointer to the malloc'd flight struct flight setup_flight (void) { // Create a new, empty flight struct flight new flight new flight->origin_airport new flight->dest airport = NULL; NULL; malloc(sizeof(struct flight)); // Read number of stops using fgets printf("How many stops will be enroute? "); char input_line [MAX_STRING_LEN) (0); fgets (input_line, MAX_STRING_LEN, stdin); command line) == 0) { // Convert the string to a number int num_stops = 0; num_stops atoi (input_line); // TODO: For each airport Use fgets to read a line and then use the // provided interpret_line () function to extract information // TODO: For each airport, check conditions and 11 add it to the end of the flight route // TODO: Change the next line
// TODO: Change the next line. return NULL; } // Stage 1.2 // Given a pointer to a flight struct, prints all the info about the route // Parameters: // flight the flight which contains the flight route to print // Returns: // None void do print_airports (struct flight flight) { // TODO: Loop through the flight route and call 11 the provided print_one_airport function } // Stage 1.2 // PROVIDED FUNCTION DO NOT CHANGE // Given a pointer to an airport struct, // prints all the info about the airport // Parameters: ap the airport to print // // Returns: // None void print_one_airport (struct airport ap) ( ( printf( *886: 804d -> 804d\n", ap->code, ap->arrival time, ap->departure time // Stage 1.1 // Given the information about a new airport, // Uses malloc to create memory for it and returns a pointer to // that memory. // Parameters: 11 code arrival time departure time the airport ICAO code the arrival time of the new airport the departure time of the new airport 11 // // Returns: // A pointer to the malloc'd struct airport struct airport *create_airport ( char code [MAX_STRING_LEN), int arrival time, int departure_time) // Malloc new struct struct airport new airport malloc(sizeof(struct airport)); // initialise airport fields strcpy(new_airport->code, code);
strcpy (new_airport->code, new_airport->arrival_time new_airport->departure_time new_airport->next_airport = NULL; return new airport; code); = arrival time; departure_time; } // TODO void do subroute (struct flight flight) { return; } // TODO void do_change_origin(struct flight flight) { return; /// HELPER FUNCTIONS // Helper Function // You likely do not need to change this function. // // Given a raw string will remove and first newline it sees. // The newline character wil be replaced with a null terminator ('\0') // Parameters: 1/ flight the flight to move people along of // Returns: // None void remove_newline (char input [MAX_STRING_LEN]) { // Find the newline or end of string int index = 0; while (input[index] != '\n' && input[index] != '\0') { index++; } // Goto the last position in the array and replace with '\0' // Note: will have no effect if already at null terminator input[index] = '\0'; // Belper Function // You DO NOT NEED TO UNDERSTAND THIS FUNCTION, and will not need to change it. // // Given a raw string in the following foramt: [integer0] [integerl] [string] // This function will extract the relevant values into the given pointer variables. // The function will also remove any newline characters. // // For example, if given: "0135 0545 YSSY" // The function will put the integer values // 135 into the vall pointer Far
// 11 // And 135 into the vall pointer 545 into the val2 pointer will copy a null terminated string "YSSY" into the 'word' array 11 // If you are interested, strtok is a function which takes a string, // and splits it up into before and after a "token" (the second argument) // // Parameters: buffer 11 11 // // // // Returns: // None > { valo vall word void interpret_line ( A null terminated string in the following format [integer0] [integerl] [string] A pointer to where [integer0] should be stored = A pointer to where [integerl] should be stored An array for the [string] to be copied into char buffer (MAX_STRING_LEN], int *val0, int *vall, char word [MAX_STRING_LEN] // Remove extra newline remove_newline (buffer); // Extract value 1 as int char val0_str strtok (buffer, " "); if (val0_str = NULL) { *valo atoi (val0_str); - } else { } // Extract value 2 as int char *vall_str = strtok (NULL," "); if (vall str != NULL) { *vallatoi (vall_str); } else { } *val0 = -1; *vall= -1; char *word_str = strtok (NULL, " "); if (word_str != NULL) { // Extract word strcpy(word, word_str); } if (val0_str = NULL || vall_str == NULL || word_str == NULL) { // If any of these are null, there were not enough words. printf("Could not properly interpret line: ts.\n", buffer);
char *vall str strtok (NULL, if (vall str != NULL) { *vallatoi (vall_str); } else { } char *word_str = strtok (NULL," "); if (word_str != NULL) ( // Extract word strcpy(word, word_str); *vall= -1; } if (val0_str == NULL || vall_str = NULL || word_str == NULL) { // If any of these are null, there were not enough words. printf("Could not properly interpret line: s.\n", buffer); > void do_print_help (void) { printf("+ printf("Command Name printf("+.. printf("|PRINT ROUTE printf("+en die printf("SUBROUTE printf(" printf(" printf("CHANGE ORIGIN printf(" printf(" printf("+ printf("BYPASS printf(" printf("+ printf("EMERGENCY printf(" printf(" printf("CANCEL printf(" printf("REVERSE printf("+- printf(" printf("ADD PERSON printf(" printf(" printf("+ printf("|PRINT MANIFEST How to Use Enter command: print Enter command: subroute Enter airport code: [AIRPORT CODE] Enter command: change origin Enter new origin info: [ARRIVAL TIME)... ... [DEPARTURE TIME] [AIRPORT CODE] Enter command: bypass Enter airport code: [AIRPORT CODE] ---+\n"); |\n"); +\n"); |\n"); Enter command: print manifest Enter the airport code: [AIRPORT CODE] printf(" printf("+- printf("FLIGHT STATISTICS Enter command: stats printf(" -+\n"); |\n"); |\n"); -+\n"); |\n"); \n"); \n"); -+\n"); Enter command: emergency |\n"); How long until emergency: [TIME IN HOURS) \n"); Enter command: cancel Enter command: reverse Enter command: add_person Enter the airport code: [AIRPORT CODE] Enter the passenger name: [NAME] Enter the passenger weight: [WEIGHT] --+\n"); |\n"); |\n"); ---+\n"); |\n"); -+\n"); |\n"); -+\n"); |\n"); \n"); \n"); \n"); +\n"); |\n"); |\n"); -+\n"); |\n"); +\n");
END OF END OF QUESTION FOR STAGE 2
END OF QUESTION FOR STAGE 3
END OF QUESTION FOR STAGE 4
MUCH APPRECIATED FOR SOMEONE WHO COULD HELP ME WITH THIS QUESTION!!!!!
CS Airline Current version: 1.0.9 Welcome to CS Airline! COVID is becoming a thing of the past, we are beginning to be able to travel again (how exciting!). As part of this, naturally all the Sydneysiders now want to be able to fly overseas and interstate, but there's a problem! The old airline booking system is out of date. The airline, 'CS-Airline' has contracted you, a new software developer, to build them a new one! In this assignment, you will build a booking system capable of managing a single flight with multiple stops. You will do this using a Linked List and all the skills you have learnt in this course. Assignment Structure The primary purpose of this assignment is to test your ability to create, use and manipulate a linked list. As such, each flight route is implemented as a linked list of airports, with a flight storing the location of origin and destination airport. Airport's names are stored as ICAO Codes, which is an international system for identifying airports by a 4 letter code. See the list of terminology for more details.
that fight dest airport OxDF12 origin airport-OFA3 strict airport code YSSY arrival me 0000 optime-0100 next aport struct airport • Purpose: code YUML arival time 0000 deptime-0230 next airport 74AC The CS-Airline program makes use of the following structs: • Contains: 0 0 struct airport 6 codew YPAD arrival time 054 dept time 700 next airport DDF12 struct airport To store information about a specific airport on the flight route. char code [ICAO_CODE_LEN • The ICAO airport code. int arrival time • The time the plane would arrive at this airport int departure time The time the plane would depart from this airport struct airport snext_airport • A pointer to the next airport in the route struct airport char code(ICAO CODE LEN int arrival time struct airport code YPPH aival time 1135 dept time-1340 next airport NALL NULL 1 CS Airline Stage 11 Stage 2 Stage 3 Stage 4 Appendix Rationales Assessment
. ● struct airport char code(ICAO_CODE_LEN] struct flight • Purpose: • To store where the origin and destination of the flight it and any metadata about the flight as a whole • Contains: int arrival time int dept time HINT: struct airport "next_airport; struct airport #origin_airport A pointer to the first airport on the route struct airport dest_airport A pointer to the last airport on the route Representing Time NOTE: You should not need to modify the definition of these structs until Stage 4! struct flight struct airport "origin_airport; struct airport "dest airport; Remember to initialize all the fields of your struct when you create them, not just the ones you're using. CS A Sta Sta Star Stag App Rati Asses
Representing Time To match the industry standard of time management, your CS-Airline program will use 24-Hour time. Things to note: • This time should always be stored in an int variable • E.g. 15:00 would be stored as 1500 • The range of the entire flight will always reside within the range 0000 to 2359, inclusive. • I.e. A flight will never extend over more than 1 day. • Times will never have more than 59 minutes in them. • L.e. You will never have times like 8860-0099 or 1368-1399 How to get started There are a few steps to getting started with CS Airline. 1. Create a new folder for your assignment work and move into it. $ mkdir ass2 $ cd ass2 2. Download the starter code (cs_airline.c) here or use this command on your CSE account to copy the file into your current directory: $ cp -n /web/dp1091/2272/activities/cs_airtine/cs_airline v 3. Run 1091 autotest to make sure you have correctly downloaded the file -- $ 1091 autotest cs_airline 4. Spend a few minutes playing with the reference solution--get a feel for how the assignment works. $ 1091 cs_airline 5. Read through Stage 1. CS Air Stage Stage Stage Stage Appe Ration Assess
NOTE: Each task has an 'Overview' & 'Requirements' section. Overview = A top level description of what is involved in this task. Requirements = Everything you must consider to be able to complete this stage. 6. Think about your solution, draw a diagram of what you need to do to help you get started. 7. Note down when the livestream is, and attend (or watch the recording)! 8. Start coding! Stage 100 Stage 2 00 Stage 3 Stage 1 Stage 4 You can run the autotests for Stage 1 by running the following command: 1091 autotest-stage 01 cs_airline Appendix Modes Similar to assignment 1-CS-Airline operates in two modes, setup and operational mode. The setup mode must be completed first, then the program moves into operational mode. The program cannot move back into setup mode. Setup mode: • Ask the user how many airports will be enroute . Read in the details of that many airports 1 CS Airlin Stage 1 Stage 2 Stage 3 Stage 4 Appendi Rationale Assessme
Read in the details of that many airports For each airport, append them to the flight route in the order they are entered. I.e. Origin to destination. Operational mode: • Given a specific single character command, apply that command to the flight. This may require the program to read in extra information • The program should continue to read commands until EOF is pressed NOTE: This structure is very similar to assignment 1 and we suggest reviewing your assignment 1 code to accelerate your implementation of these first few steps. Stage 1 will see you implement the setup mode and then display the flight route back to the user. You will also cover a lot of the code and logic needed to complete the first Stage in Week 7 lectures. 1.1 Initialisation Overview This stage is implementing the setup mode of CS-Airline as described above. You should: • Ask the user how many stops will be enroute • Read in the details of all these stops For each stop, create a new linked list node (a struct airport) and append it to the end of the flight route. Remember: the head of the linked list is stored in flight->origin_airport Your program must also do some error checking for each airport. You should check the following requirements: Should give the following error if the departure time is 'before' arrival time and not add the airport to the list. The arrival time and departure time can be the same with no errors. CS Airl Stage Stage Stage Stage Appene Rationa Assessm
• Should give the following error if the departure time is "before" arrival time and not add the airport to the list. The arrival time and departure time can be the same with no errors. • "Departure time cannot be before the arrival time!" • Should give the following error if the arrival time of new airport is before the last departure time. I.e. if you arrive at the next stop, before you have left. o "New arrival time cannot be before the previous departure time" The starter code includes some code to get started. You will will implement the provided setup_flight function. This function has some suggested TODO comments. HINT: You should create functions for creating airports and appending airports to the flight route. HINT: To help with error checking, you should remember the departure time of the last airport you added. After setting up the flight route, the program should prompt the user to enter a commands until EOF. When EOF is entered, print the following. Enter Command: Ctrl-D Goodbye! Requirements This should always happen first, when the program is first run, with no command needed from the user. • Program should never go back into setup mode. • Program should automatically go into operational mode after X number of airport details have been read (regardless of if they were valid or not). Format must match sample solution. • Should give the following error if the departure time is 'before' arrival time and not add the airport to the CS Air Stag Stage Stage Stage Appe Ration Assess
Should give the following error if the departure time is 'before' arrival time and not add the airport to the list o "Departure time cannot be before the arrival time!" • The arrival time and departure time can be the same with no errors. • Should give the following error if the arrival time of new airport is before departure time of previous airport • "New arrival time cannot be before the previous departure time" . You can assume you the number of airport details will always match the number of airports . An airport code will always be exactly 4 characters • You can assume that during the setup phase, every inputted airport will have a unique ICAO code - i.e. you DO NOT have to check the codes are unique. • You should assume you will always be given at least 1 valid airport. Example 1.1.1: Basic Initialisation $ ./cs_airline How many stops will be enroute? 3 0000 0100 yssy 0200 0230 ymml 0545 0700 ypad Enter Command: Ctrl-D Goodbye! - Example 1.1.2: Arrival Time Check $ ./cs_airline How many stops will be enroute? 2. 0200 0400 yssy 0400 0200 ymml CS Airline Stage 11 Stage 2 Stage 3 Stage 4 Appendix Rationales Assessment
$ ./cs_airline How many stops will be enroute? 2 ezee 0400 yssy 0400 0200 ymml Departure time cannot be before the arrival time! Enter Command: Ctrl-D Goodbye! - Example 1.1.3: Depature Time Check $ ./cs_airline How many stops will be enroute? 21 0100 0200 yssy 0130 0200 ymml New arrival time cannot be before the previous departure time Enter Command: Ctrl-D Goodbye! 1.2 Print Route Command Format PRINT ROUTE Enter command: print Overview | CS F Sta Sta Sta Star App Rati Asses
Overview Now that we have entered all the airport details and created our linked list, it is time to review them! To do this, we need a method to be able to display the current flight route to the terminal. When the PRINT ROUTE command is entered, the program should display the current flight route in the following format: ROUTE: YSSY: YMML: WSSS: 0100 - 0200 0300-> 0500 1000 1100 In order to do this, you will need to loop through the linked list based inside the flight struct. For each of these airports, print out the airport. To match the sample solution and autotests, you should use the provided print_one_airport function in the starter code. HINT: You should implement this task within the provided do_print_airports stub function. Requirements • The print route function should be triggered when the 'print' command is given • The route should be printed in order from origin to destination, with the origin being at the top of the list. • Each airport should have its arrival & departure time next to it. The print route function should not modify the route Example 1.2.1: Print Route CS Ai Stag Stag Stag Stage Appe Ratio Assess
Tn Course: DPST1091 Introduction to Programming 2022 T2 PST1091 22T2 Forum Submissions History Assignment 1 Assignment 2 starter code. HINT: You should implement this task within the provided do_print_airports stub function. - Requirements • The print route function should be triggered when the 'print' command is given • The route should be printed in order from origin to destination, with the origin being at the top of the list. Each airport should have its arrival & departure time next to it. The print route function should not modify the route Example 1.2.1: Print Route 1sw.edu.au $ ./cs_airline How many stops will be enroute? 4 0000 0100 yssy 0200 0230 ymml 0545 0700 ypad 1350 1340 ypph Departure time cannot be before the arrival time! Enter Command: print ROUTE: yssy: 00000100 ymml: 0200 - 0230 ypad: 0545 0700 Enter Command: Ctrl-D Goodbye DPST1091 22T2
Stage 2 You can run the autotests for Stage 2 by running the following command: 1091 autotest-stage 02 cs_airline Stage 2 will implement functionality, which will begin to calculate some parameters concerning the linked list, and also modify the linked list. Command Format. SUBROUTE Enter command: subroute Enter airport code: [AIRPORT CODE] 2.1 Calculate Subroute Overview The airline has asked for a new piece of functionality you have not previously implemented; A passenger has come to them and asked how long it will take to get from the origin to a specific airport within the route - your task is to be able to tell them! When the SUBROUTE command is given, read an airport code and if the airport is in the route, your program should calculate the number of hours and minutes between the origin airport's departure time, and the given airport's arrival time in the following format:
Time for subroute: 1 hrs & 35 mins. If the airport does not exist within the flight route, the program should produce the following error message: Desired subroute destination does not exist! The following diagram gives an example of a subroute to the YPAD airport in the flight route. This example is shown in action in example 2.1.1 struct fight dest airport 0xDF 12 origin, arport A IF struct aport code YSSY aival time 0000 dept time 0100 next airport 001 D-FAM YPAD Subroute 0130 struct aport code YMML amval time 0000 dept time-0230 next airport 0x74AC 001 studarport code YPAD amival time 0541 dept_time=0700 next airport DDF12 0x74AC Nos (349 tapo code-YPPH anival time 1135 dept time 1340 next airport NULL 0-DF12 HINT: Refer to the command index for the format of the command and it's parameters. TY NULL HINT: You should use the provided #define s for checking input to commands. You may choose to use this logic (or 'pseudo code') to calculate the hours and minutes between two 24hr
You may choose to use this logic (or 'pseudo code') to calculate the hours and minutes between two 24hr times. start= start time of time period end end time of time period hours (end / 100) (start / 100) mins (end 100) (start 100) minute_diff hours * 60 + mins if (minute_diff < 0) { minute_diff *= -1; hours minute_diff / 60 mins minute_diff % 60 HINT: You should implement the provided the do_subroute stub function. Requirements This functionality should also read in the subroute destination airport code The time period should always be calculated from the origin airports departure time • The time period should always be calculate to the specified airport's arrival time • The program should print out the number of hours and minutes for the subroute. • You will never asked to calculate a subroute to the origin airport (i.e. you will never be asked to calculate a subroute to yourself • The program should produce the following error message if the desired airport doesn't exist within the route:
- Desired subroute destination does not exist! Example 2.1.1: Subroute $ ./cs_airline How many stops will be enroute? 3 eeee 0100 yssy 0200 0230 ymml 0545 0700 ypad Enter Command: subroute Enter airport code: ypad Time for subroute: 4 hrs & 45 mins Enter Command: Ctrl-D Goodbye! Example 2.1.2: Subroute checks $ ./cs_airline How many stops will be enroute? 3 eeee 0100 yssy 0200 0230 ymml 0545 0700 ypad Enter Command: subroute Enter airport code: wsss Desired subroute destination does not exist! Enter Command: [Ctrl-D Goodbye!
2.2 Change Origin Command. CHANGE ORIGIN Format Enter command: change_origin Enter new origin info: [ARRIVAL TIME] [DEPARTURE TIME] [AIRPORT CODE] There has been a change to the plan and the route must now start from an earlier airport. This task will implement the ability to add an airport before the existing origin (not replace the origin). Overview When the CHANGE ORIGIN command is given, the program should read in: • ICAO airport code • Arrival time • Departure time With this new information, the program should create a new airport and insert it at the beginning of the flight route. HINT: The new airport ICAO code must be unique. Unlike stage 1, you cannot assume the scanned in airport code will be unique, and you must check if it is. If the new airport code is not unique, you should display the following message: New airport code is not unique! Your program should do some basic error checking and display if successful as stated in the requirements.
HINT: You should implement the provided the do_change origin stub function. Requirements • The arrival time should be chronologically before or the same as the departure time of the new origin. Otherwise the following error message should be displayed and the new origin not added. Departure time cannot be before the arrival time! The departure time of the new origin should be before or the same as the arrival time of the old-origin (the next airport in the route). Otherwise the following error message should be produced and the new origin not added. Departure of new origin cannot be after the arrival time of the next airport! • The new origin airport's ICAO code must be unique and the program should check this. If it is not unique, the program should produce the following error message and new origin not be added. New airport code is not unique! • If the new origin is successfully added, the program should code of the added airport in the following format; Added: [AIRPORT CODE] Changing the origin should not remove the existing origin, but should add the new origin before it in the route. • The validity of the new departure time should be checked before the code uniqueness. i.e. If the departure time is before the arrival time and the airport code is not unique, display only the timing error message. HINT: You may want to check the reference solution for the correct error messages. Your program must match these error messages exactly in order to pass auto testing. CS A Ra Ass
HINT: You may want to check the reference solution for the correct error messages. Your program must match these error messages exactly in order to pass auto testing. - Example 2.2.1: Change Origin $ ./cs_airline How many stops will be enroute? 3 0300 8400 yssy 0800 0930 ymml 1045 1200 ypad Enter Command: print ROUTE: yssy: 03000400 ymml: 08000930 ypad: 1045-1200 Enter Command: change origin Enter new origin info: 0200 0230 ybcg Added: ybcg Enter Command: print ROUTE: ybcg: 0200 - 0230 yssy: 03000400 ymml: 0800 8930 ypad: 1045 1200 Enter Command: Ctrl-D Goodbye! I
Example 2.2.2: Check Change Origin $ ./cs_airline How many stops will be enroute? 3 0300 0400 yssy 0800 0930 ymml 1045 1200 ypad Enter Command: print ROUTE: yssy: 03000400 ymml: 08000930 ypad: 1045 1200 Enter Command: change origin Enter new origin info: 0200 0230 ymml New airport code is not unique! Enter Command: print ROUTE: yssy: ymml: ypad: 1045 1200 Enter Command: Ctrl-DGoodbye! 03000400 08000930 2.3 Bypass Airport Command Format BYPASS Enter command: bypass Enter airport code: [AIRPORT CODE]
2.3 Bypass Airport Command Format. BYPASS Enter command: bypass Enter airport code: [AIRPORT CODE] For this stage, we will imagine there has been an issue at a specific airport and we can no longer land there - as such, we must be able to by-pass an airport enroute given its ICAO code. Overview When the BYPASS command is read, the program should read in the ICAO code of the airport to bypass, and remove it from the flight route. This functionality should do the relevant updating of the flight route linked list to ensure the flight route remains intact. Requirements The airports before and after the airport to be removed, should not be removed from the route and should be linked together in the same order, only the airport that needs to be bypassed should be removed. • If the bypassed airport is the origin, the next airport in the route should become the new origin • If the bypassed airport is the destination, the new destination should become the airport before the bypassed airport • If the inputted airport code is not in the flight route, the following error message should be displayed; No airport of that code exists! Bypassing the last remaining airport (i.e, when there is only one airport in the list) is undefined behavior and should not be implemented. | 1
• If the inputted airport code is not in the flight route, the following error message should be displayed; No airport of that code exists! . Bypassing the last remaining airport (i.e, when there is only one airport in the list) is undefined behavior and should not be implemented. Example 2.3.1: Bypass Airport $ ./cs_airline How many stops will be enroute? 3 0300 0400 yssy 0800 0930 ymml 1045 1200 ypad Enter Command: print ROUTE: - yssy: 03000400 ymml: 08000930 ypad: 1045 1200 Enter Command: bypass Enter airport code: ymml Enter Command: print ROUTE: yssy: 03000400 ypad: 1045-1200 Enter Command: Ctrl-DGoodbye! Example 2.3.2: Check Bypass Airport
Enter airport code: ymml Enter Command: print ROUTE: 03000400 yssy: ypad: 1045 1200 Enter Command: (Ctrl-D Goodbye! Example 2.3.2: Check Bypass Airport $ ./cs_airline How many stops will be enroute? 3 0300 0400 yssy 0800 0930 ymml 1045 1200 ypad Enter Command: print ROUTE: yssy: 03000400 ymml: 08000930 I ypad: 1045 1200 Enter Command: bypass Enter airport code: wsss No airport of that code exists! Enter Command: print ROUTE: yssy: 03000400 ymml: 08000930 ypad: 1045-1200 Enter Command: Ctrl-D Goodbye!
Stage 3 You can run the autotests for Stage 3 by running the following command: 1891 autotest-stage 03 cs_airline Fun fact: There have been no fatalities in scheduled commercial air transport in Australia since 2005 according to The Australian Transport Safety Bureau (ATSB). So in essence, commercial flight is very safe! However, this is mainly because pilots have strict processes and regulations which allow them to make precautionary and emergency landings. This stage will implement functionality to allow the user to reflect these route changes in the CS-Airline. 3.1 Emergency Landing Command Format EMERGENCY Enter command: emergency How long until emergency: [TIME IN HOURS] Although flying is typically very safe, components on aircraft have a limited service life (i.e. they fail after a specific period of time). This stage will implement an emergency landing at a new airport after a specified time period. Overview St Se St St Ap Ra Ass
Overview When the EMERGENCY command is input, the program should read in the number of hours until an emergency landing. The time of the emergency landing will be the departure time of the origin airport, plus the number of hours that was just read in. The EMERGENCY command should insert an airport, in chronological order, at the time of the emergency landing and remove all airports after the landing. In other words, for a given emergency the following occurs: 1. Insert an airport in chronological order into the flight route. a. The arrival time should be exactly the origin departure time + the hours until emergency. b. The airport code should be "ALT". c. The airport departure time should be 0000 as the aircraft is now out of service. 2. All remaining airports in the flight after the alternate should be removed from the route. Original Flight dest airport DDF12 origin, airport FAS struct airport code VSSY valme0000 deptime-0100 next airport-OSOF OXFA34 struct airport code=YMM ame=0200 deptime-0230 next airport 74AC ONEOFY struct airport code VIAD amval sme 0545 deptime-0700 next airport OxDF 12 Ox74AC struct airport code YPPH arrival time 1135 dept time-1340 next airport NULL CADF12 | CS A Star Stag Star Stag App Rati Asses
struct flight dest airport DDF12 origin airport OxFA34 struct airport code=YSSY arrival time 0000 dept time 0100 next airport Ox0F1 OxFA34 Emergency after 2 hours struct airport code YMML arrival time 0200 dept time=0230 next airport Ox815 OxGDF1 struct airport code=ALTO arrival time 0000 dept time 0000 next airport NULL OxE815 NULL Every time an aircraft is about to take off, the captain and co-pilot must do pre-flight checks. If any of these checks presents an error, the flight may be canceled. To represent this in the program, we say the hours until emergency is 0. If the hours until the emergency is exactly 0, there is different behavior. • The origin airport arrival time should remain unchanged • The origin airport departure time should be set to 0000 The origin airport code should remain unchanged • Every airport except the origin should be removed from the flight route. HINT: When reading in the then use the atoi() For an example of how to do do this, look at lines 145-150 of the provided starter code. ITIME IN HOURS], you should use fgets to read in the number as a string, and function to convert it to a number.
Requirements • You can assume there will not be an emergency after reversing the flight route (Only relevant if completed stage 3.3) • If the time of emergency is after the destination arrival time, the program should print the following message saying the flight was safe: • Flight was safe! You can assume the time of emergency will not be any later than 2359 The time of an emergency is calculated as emergency_time = origin_airport->departure_time + [HOURS] • The code of the emergency landing airport should be "ALTO" • The departure time of the emergency landing airport should be 0000 • the arrival time of the emergency landing airport should be exactly the time of the emergency.(see above requirement) • There should be no other airports in the flight route after the emergency landing airport • If the time of emergency is exactly the arrival time of an existing airport, the program should still remove the existing airport and replace with the new "ALTO" airport and associated data. • You can assume emergencies will always be after at least 1 airport • If the hours until emergency is exactly 0, all airports except the origin should be removed. • If the hours until emergency is exactly 0, the origin's departure time should be set to 0000. • If the plane is on the ground at the time of the emergency, add the alternate airport after existing airport but with the times. (This is to simplify the implementation). Check the reference implementation for examples Example 3.1.1: Emergency $ ./cs_airline How many stops will be enroute? 4 eeee 0100 yssy 0200 8230 ymml
Example 3.1.1: Emergency $ ./cs_airline How many stops will be enroute? 4 0000 0100 yssy 0200 0230 ymml 0545 0700 ypad 1025 1355 ypph Enter Command: print ROUTE: 00000100 0200 - 0230 ypad: 0545 -> 0700 ypph: 10351355 - yssy: ymml: Enter Command: emergency How long until emergency: 3 Enter Command: print ROUTE: yssy: ymml: ALTO: 04000000 Enter Command: Ctrl-DGoodbye! 0000-> 0100 0200 - 0230 Example 3.1.2: Safe Flight $ ./cs_airline How many stops will be enroute? 4 eeee 0100 yssy 8288 0230 mm1.
Example 3.1.2: Safe Flight $ ./cs_airline How many stops will be enroute? 41 0000 0100 yssy 0200 0230 ymml 0545 0700 ypad 1055 1355 ypph Enter Command: print ROUTE: 00000100 02000230 0545 - 0700 10351355 Enter Command: emergency How long until emergency: 15 yssy: ymml: ypad: ypph: Flight was safe! Enter Command: print ROUTE: yssy: 00000100 ymml: 0200 - 0230 ypad: 0545 0700 ypph: 10351355 Enter Command: Ctrl-D Goodbye! Example 3.1.3: Emergency Before Departure $ ./cs_airline
- Example 3.1.3: Emergency Before Departure $ ./cs_airline How many stops will be enroute? 4 0030 0100 yssy 0200 0230 ymml 0545 0700 ypad 1035 1355 ypph Enter Command: p ROUTE: yssy: 0030 - 0100 ymml: 02000230 ypad: 0545 - 0700 ypph: 10351355 Enter Command: emergency How long until emergency: 0 Enter Command: print ROUTE: yssy: 0030 -> 0000 Enter Command: Ctrl-DGoodbye! 3.2 Cancel Flight Command Format CANCEL Enter command: cancel
3.2 Cancel Flight Command Format CANCEL Enter command: cancel Unfortunately in the commercial airline industry, things do not always go to plan. It could be weather, technical problems or financial reasoning - but sometimes, airlines will have to cancel a flight. Overview In this stage, you will implement the ability for your program to cancel a flight. When the CANCEL command is entered, your program should delete all airports from the route and then accept a new flight. Additionally, the program must now free() all malloc'd memory throughout the program. This will require you to add logic to your previous stages (2.3 & 3.1) to free any memory which is being deleted from the linked list. i.e You must now free() the airports which were after the emergency landing airport. NOTE: When the program ends due to the user inputting Ctrl+D, you should still ensure that all malloc'd memory is cleaned up! HINT: Remember to free the flight struct as well! Requirements
Requirements • After the CANCEL command, your program should print the following message: Flight cancelled. Now accepting a new flight: • Your program should then accept information for a new flight, in the same manner as Stage 1. • Your program should remove all airports from the flight route • For every task from now on, your program must clean up all memory that was malloc'd throughout the program - including in other stages. Example 3.2.1: Cancel Flight - $ ./cs_airline How many stops will be enroute? 4 0000 0100 yssy 0200 0230 ymml 0545 0700 ypad 1035 1355 ypph Enter Command: print ROUTE: yssy: 00000100 ymml: 02000230 ypad: 0545 0700 ypph: 1035 -> 1355 Enter Command: cancel Flight cancelled. Now accepting a new flight: How many stops will be enroute? 1 0000 0100 abcd Enter Command: Ctrl-D) Goodbye!
3.3 Reverse Flight Command Format REVERSE Enter command: reverse Good news, the flight successfully got to its destination airport and all the passengers have left the plane. Now we want to fly back to the origin! Overview This stage will require you to implement the REVERSE functionality. This functionality reverses the order of the airports in the flight route - i.e. The destination becomes the origin and the origin becomes the destination. You must change the next_airport pointer in each airport to point to the new airport that will come after. However, since the plane is now flying back through the timezones, the departure times will now be 'after' the arrival time of the next airport. This is the intended behavior. For further clarification, please review the diagrams & examples below. struct flight dest airport xDF12 origin, airport DFAS struct airport code VSSY amival time 0000 struct airport code YMML arrival time-0200 struct airport code YPAD arrival time 0545 struct airport code - YPPH arrival time 1135 NULL
struct fight dest airport w DxDF 12 origin airport OFA34 struct airport code YSSY arrival time-0000 dept time 0100 next airport 0x80F1 struct fight dest airport DDF12 origin, airport the FAM OxFA34 struct airport code VPP arrival time 1135 dept Sime-1340 next airport 0x74AC OXDF12 Requirements struct airport code YMML arrival time-0200- dept time 0230 next airport Dx74AC OF struct airport code YPAD Reversed arrival time 0545 dept time-0200 next, airport OF 0x74AC struct airport code YPAD arrival time-0545 dept time 0700 next airport OxDF12 Ox74AC struct airport code YMML arrival time 0000 dept me 0230 next airport DA OSOFI struct airport code VPPH arrival time 1135 dept time 1340 next airport NULL OXDF12 struct airport code VSSY anival time 0000 dept time 0100 next airport NULL CFA34 NULL NULL
Requirements • When the REVERSE command is entered, the order of airports in the flight route should be reversed • When the REVERSE command is entered, the origin and destination airport should be swapped • When the REVERSE command is entered, the arrival and departure times of each airport in the flight route should not be modified • After the REVERSE command, you can assume the program will not be asked to make an emergency landing. I.e After reversing the flight, you will not be given any EMERGENCY commands from stage 3.1. • After the REVERSE command, the program could still be asked to calculate a subroute. In this case, the resultant subroute time should still be positive numbers. Example 3.3.1: Reverse Flight $ ./cs_airline How many stops will be enroute? 4 0000 0100 yssy 0200 0230 ymml 0545 0700 ypad 1035 1355 ypph Enter Command: print ROUTE: yssy: 00000100 ymml: 82000230 ypad: 0545 - 0700 ypph: 10351355 Enter Command: reverse Enter Command: print ROUTE: ypph: 10351355 ypad: 0545-0700 ymml: 02000230 yssy: 00000100 C: F As
Example 3.3.1: Reverse Flight $ ./cs_airline How many stops will be enroute? 4 0000 0100 yssy 0200 0230 ymml 0545 0700 ypad 1035 1355 ypph Enter Command: print ROUTE: yssy: ymml: ypad: 0545 0700 ypph: 10351355 00000100 02000230 Enter Command: reverse Enter Command: print ROUTE: ypph: ypad: ymml: 10351355 0545 0700 0200 - 0230 yssy: 00000100 Enter Command: [Ctrl-D] Goodbye! MacBook Air
Stage 4 You can run the autotests for Stage 4 by running the following command: 1891 autotest-stage 04 cs_airline Well done - You now have all the essential functionality to run cs_airline! I look forward to joining you for a flight! This stage will see you continue to add some cool functionality to your program to allow you to manage your flights more effectively with more advanced functionality. Additionally, for this stage, we have provided a partially complete Abstract Data Type (ADT). This stage will require you to use and finish the implementation of this ADT. Stage 4.1 & 4.2 only require you to use the provided parts, however stage 4.3 requires you to finish the implementation of some ADT functions. Manifest ADT The remaining stages of this assignment require you to make use of, and complete the implementation of a new ADT called 'Manifest'. Please review the 'Key Terminology' table for a definition and explanation of a manifest in this context. Using the Manifest ADT Before you can start using the manifest ADT, you must get setup with the new Manifest ADT files. Most of the ADT functionality has already been completed for you and is sufficient for stages 4.1 and 4.2. However there are 2 functions you must implement before you can use them in stage 4. You should review the manifest.h file to see what functions are available and how they work. The manifest ADT uses the following structs;
struct manifest • Purpose: o To store a pointer to the first person on the manifest • Contains: O struct person • Purpose: struct person people • A pointer to the first person on the manifest • Contains: 0 • To store the details about an individual person O struct manifest struct person "people; char name [MAX_NAME_LEN] • Store the name of the person . Note: MAX_NAME_LEN is #defined in the manifest.h file. double weight • Store the weight of the person struct person next • Store a pointer to the next person on the manifest struct manifest struct person "people=0x34DE struct person char name[MAX NAME_LEN]: double weight; struct person "next: The structure of the manifest ADT is shown in the diagram below;
The structure of the manifest ADT is shown in the diagram below; struct manifest struct person "people=0x34DE OxB528 struct person char name Anosua double weight 1.03 struct person "next=0x703F . 0x34DE struct person char name Sasha double weight 0.92 struct person "next Ox5C42 Ox703F struct person char name Tom double weight 8.24 struct person "next ULL What You're Provided You are provided with: manifest.h • Defines all the structs and functions available with the Manifest ADT o Shows the interface between the main CS-Airline program and the internal Manifest ADT implementation You cannot change manifest.h 0x5042 manifest.c Defines the implementation for all the manifest functionality This is where you will have to implement the 2 remaining functions You can download the manifest by running the commands below; $ cp /web/dp1091/22T2/activities/cs_airline/manifest.c. $ 1n-s/web/dp1091/22T2/activities/cs_airline/manifest.h. NULL I C: As
Remember: • Ensure these files are in the same working directory as your cs_airline.c file • Ensure to #include "manifest.h" into your cs_airline.c file • When compiling, ensure to add manifest.c in your dcc command • E.g. $ dcc cs_airline.c manifest.c-o cs_airline What you have to do • For Stages 4.1 & 4.2 • Use the provided and fully implemented functions in manifest.h • For Stage 4.3 • Implement the following functions in manifest.c manifest_weight() join_manifest() • Use the functions in cs_airline.c 4.1 Add People to Airport Command ADD PERSON Format Enter command: add_person Enter the airport code: [AIRPORT CODE] Enter the passenger name: [NAME] Enter the passenger weight: [WEIGHT] What is a flight without a manifest! Making use of the Manifest ADT, your CS-Airline program will now be able to manage a manifest of people at each airport which describes who is getting on the flight at this airport. The manifest will describe the name & weight of each person.
What is a flight without a manifest! Making use of the Manifest ADT, your CS-Airline program will now be able to manage a manifest of people at each airport which describes who is getting on the flight at this airport. The manifest will describe the name & weight of each person. You should add the person into the manifest of the airport that matches the given code. Overview When the ADD PERSON command is entered, the program should read in: • ICAO Code . 0 Which airport's manifest the person should be added to Name • The name of the person to be added Weight The weight of the person to be added To implement the use of the manifest ADT, you will need to modify struct airport to be able to store a manifest. The diagram below shows how a manifest should be implemented into the CS-Airline program structure. HINT: You should use fgets to read in all information, including the weight. You may like to use the atof() function to convert your string into a double. destport DDF12 ongin, arport DA ONESAF
struct fight dest airport OxDF12 origin airport OxFA34 OXES4F struct airport code YSSY arrival time 0000 dept time 0100 next airport OvOF1 manifest Ox528 OxFA34 struct manifest struct person "people=0x34DE Ov528 struct person char name An double weight 100 struct person "next0x703 OXIDE struct airport code YMML arrival time 200 dept time 02:30 next airport 0x740 manifest 777 OSOF1 struct person char name Sasha double weight 0.92 struct person "next0x5042 Ox7D3F struct airport code YPAD arrival time 0545 dept time w 0700 next airport OxDF12 manifest777 Ox74AC Requirements: • CS-Airline must make use of the provided Manifest ADT • A person's name does not have to be unique struct person char name Tom double weight-824 struct person next=NULL Ox5042 struct airport code YPPH arrival time 1135 dept time-1340 next arport NULL manifest-777 ONDF12 NULL NULL
NOTE: If you are unsure of the program's behavior, check the sample solutions result. NOTE: We won't be able to check how you have implemented this functionality until you implement stage 4.2 4.2 Print Airport Manifest Command PRINT MANIFEST Format Enter command: print_manifest Enter the airport code: [AIRPORT CODE] After adding people to an airport manifest, it is important to be able to review the state of a manifest and the details of people in that manifest. Overview When the PRINT MANIFEST command is executed, the program should read in the name of the airport to print the manifest of and then display the manifest of people and their weight in the following format. Manifest: For example [weight] [name] [weight] [name] [weight] [name]
For example; Manifest: 91.22- person3 77.23 - person4 Requirements • When the PRINT MANIFEST command is executed, the program should print out the name and weights of all people at a specific airport . When the •. When the PRINT MANIFEST command is executed, it should not modify the list of people at each airport PRINT MANIFEST command is executed, the program should use the predefined manifest ADT function. • If the given airport code is not in the list, the program should output the following error message. No airport of that code exists! Example 4.2.1: View Manifest Example 4.2.1 - View Manifest $ ./cs_airline How many stops will be enroute? 3 eeee 0100 yssy 0200 0230 ymml 0545 0700 ypad Enter Command: print ROUTE: yssy: 00000100 ymml: 02000230 ypad: 8545 0700 | с As
Example 4.2.1 - View Manifest $ ./cs_airline How many stops will be enroute? 3 eeee elee yssy 0200 0230 ymml 0545 0700 ypad Enter Command: print ROUTE: 00000100 0200 - 0230 0700 yssy: ymml: ypad: 0545 Enter Command: add_person Enter the airport code: yssy Enter the passenger name: personl Enter the passenger weight: 84.55 Enter Command: add_person Enter the airport code: ymml Enter the passenger name: person2 Enter the passenger weight: 72.45 Enter Command: add_person Enter the airport code: ypad Enter the passenger name: person3 Enter the passenger weight: 91.22 Enter Command: print manifest Enter the airport code: yssy Manifest: 84.55 - personl Enter Command: print_manifest Enter the airport code: yaml Manifest: 72.45 person2 Enter Command: print manifest Enter the airport code: ypad Manifest:
Enter the airport code: ypad Manifest: 91.22 person3 Enter Command: (Ctrl-D) Goodbye! 4.3 Flight Statistics Command FLIGHT STATISTICS Enter command: stats Format CS-Airline is now a fully fledged flight management and planning system, cool! This final stage will see you display and calculate some statistics and views of the flight for when the flight makes it to the final destination. Overview When the FLIGHT STATISTICS command is given, the program should merge all the manifests together at the destination airport. Next, it should display the list of all people now at the destination airport and the total weight of everyone. Before the statistics, your data structure might look like: dest, aporta engin airport M Ose
structi destaport Ov origin airport DAM DESAF tarport code YSRY avalime 0000 dete-0106 next airport DFY manifest OXFA34 me et person people-4DE des sport DDF12 origin airport FAM ONE SAF OBS wat person cher name Arc doute weight 1. eta person next MAL ONDADE att sport sode Y valm deptime-30 next airport 74 manifest OF ut aut person people- CHED mujere char mech u poned 0x70SF code AD aival me 0645 dept fine 3700 next aport DDF12 mantestOVEDOS DETRAC After the statistics, your data structure might look like: ut me et person people ODOS ther name T duble weight 1.34 pared OSCA code YPPH avali113s dept Sime 1340 next airport NULL manifesta AF OF12 man struct person people OAKF ther name the die weight 1.79 struct person neet LL DIFE NULL | c= As
struct sport code-YSSY anival Sime 0000 dept Sime-0100 next portr manifest D OXFA34 struct person "people=NULL Ox529 ha aport code YMM avival Time 0000 deptime=0230 next airport DAC manestO82 COF stut mande struct person "people NULL 082 code YPAD aival Sime 0545 dept time 0700 nevt airport OvDF12 manifest OxED29 Ox74AC struct person people NULL OVED29 ut airport code YPPH arrival time-1135 dept time 1340 next airport NULL mandest DAK OxOF 12 struct person "people FE OxA82F char name Shrey double weight-079 struct person "next NULL C82FE person char name Tom double weight-8.24 struct person next NULL 05042 person char name Basha struct person nest MULL 0X703F struct person double weight 100 struct person next-NULL NULL
You should output the final manifest in the format following format (similar to 4.2). Final manifest: Manifest: 66.32 person5 75.92- person6 91.22- person3 77.23- person4 84.55- person1 72.45 person2 Total weight: 467.690000 Note the additional line Final manifest: and the calculation of Total weight. Requirements • After the FLIGHT_STATISTICS command, every airport except the destination airport should have an empty manifest • After the FLIGHT_STATISTICS command, the destination airport should have every person on the manifest that existed anywhere in the route • After the FLIGHT_STATISTICS command, the order of people in the final manifest should not be modified from the original flight route. See sample solution for desired ordering of people - Example 4.3.1: Flight Statistics $ ./cs_airline How many stops will be enroute? 3 0000 0100 yssy 0200 0230 ymml 0545 0700 ypad Enter Command: print ROUTE: yssy: 00000100 | c As
yssy: 00000100 ymml: 0200 - 0230 ypad: 0545 - 0700 Enter Command: add_person Enter the airport code: yssy Enter the passenger name: personl Enter the passenger weight: 84.55 Enter Command: add_person Enter the airport code: ymml Enter the passenger name: person2 Enter the passenger weight: 72.45 Enter Command: add_person Enter the airport code: ypad Enter the passenger name: person3 Enter the passenger weight: 91.22 Enter Command: print_manifest Enter the airport code: yssy Manifest: 84.55- personl Enter Command: print_manifest Enter the airport code: ymml Manifest: 72.45 - person2 Enter Command: print_manifest Enter the airport code: ypad Manifest: 91.22 - person3 Enter Command: stats Final manifest: Manifest: 91.22 person3 72.45 person2 84.55- personl Total weight: 248.220000 Enter Command: print_manifest Enter the airport code: yssy
Enter the passenger name: person3 Enter the passenger weight: 91.22 Enter Command: print_manifest Enter the airport code: yssy Manifest: 84.55 - personl Enter Command: print_manifest Enter the airport code: ymml Manifest: 72.45 - person2 Enter Command: print_manifest Enter the airport code: ypad Manifest: 91.22 person3 Enter Command: stats Final manifest: Manifest: 91.22- person3 72.45- person2 84.55- personl Total weight: 248.220000 Enter Command: print_manifest Enter the airport code: yssy Manifest: Enter Command: print_manifest Enter the airport code: ymml Manifest: Enter Command: print_manifest Enter the airport code: ypad Manifest: 91.22 person3 72.45 person2 84.55 person1 Enter Command: Ctrl-D Goodbye! -
Appendix Command Index Command PRINT ROUTE SUBROUTE CHANGE ORIGIN BYPASS EMERGENCY CANCEL REVERSE Format Enter command: print Enter command: subroute Enter airport code: [AIRPORT CODE] Enter command: change origin Enter new origin info: [ARRIVAL TIME] [DEPARTURE TIME] [AIRPORT CODE] Enter command: bypass Enter airport code: [AIRPORT CODE] Enter command: emergency How long until emergency: [TIME IN HOURS] Enter command: cancel Enter command: reverse
ADD PERSON PRINT MANIFEST FLIGHT STATISTICS Term Flight Terminology The below table outlines the command characters and input format. You should refer back to this table to understand what command executes which bit of functionality. Airplane /Plane Flight Route / Route Enter command: add_person Enter the airport code: [AIRPORT CODE] Enter the passenger name: [NAME] Enter the passenger weight: [WEIGHT] Meaning Enter command: print_manifest Enter the airport code: [AIRPORT CODE] Enter command: stats Refers to the overarching structure The airplane that would fly along this route. Note, this mechanism is not implemented until Stage 4. Refers to the ordered list of airports
Airplane The airplane that would fly along this route. Note, this mechanism is not implemented until / Plane Stage 4. Flight Route / Route Airport Person ICAO Code Refers to the ordered list of airports NOTE: A single place along the route Manifest In this context, it refers to a "Flight Manifest" - an ordered list of people where each person has a set of associate details. A single individual with details Each airport in the world has a unique 4 character code to identify it - this is called an ICAO code. For example, you can see all the Australian airports and their ICAO codes here. Throughout the specification, the [] bracketing refers to placeholders. For example, [AIRPORT CODE] would be replaced with WSSS The entire [AIRPORT CODE] has been replaced with wss
// CS Airline // cs_airline.c // // This program was written by YOUR-NAME-HERE (25555555) // on INSERT-DATE-HERE // // Version 1.0.0 2022-04-02: Initial Release. // Version 1.0.1 2022-04-06: Fixed style issue with help function. // // TODO: Description of your program. #include #include #include // The buffer length is used for reading a single line #define MAX_STRING_LEN 100 CONSTANTS #define COMMAND PRINT HELP "help" #define COMMAND PRINT_ROUTE "print" #define COMMAND SUBROUTE "subroute" #define COMMAND CHANGE ORIGIN "change_origin" #define COMMAND BYPASS "bypass" #define COMMAND EMERGENCY "emergency" #define COMMAND CANCEL "cancel" #define COMMAND REVERSE "reverse" #define COMMAND ADD PERSON "add_person" #define COMMAND PRINT MANIFEST "print_manifest" #define COMMAND FLIGHT_STATS "stats" // TODO: you may choose to add additional #defines here. char code [MAX_STRING_LEN]; "// STRUCTS /// // Airports represent 'stops' along the flight path // These are the 'nodes' of the linked list struct airport { int arrival time; int departure_time; struct airport *next_airport; }; // Root flight structure // This stores the state of the current flight // (i.e. the head and tail of the linked list) struct flight ( struct airport origin airport.
}; struct airport origin_airport; struct airport *dest_airport; // FUNCTION PROTOTYPES // Helper Functions. void remove_newline (char input [MAX_STRING_LEN]); void do print_help (void); void interpret_line ( char buffer[MAX_STRING_LEN], int *val0, int *vall, char word [MAX_STRING_LEN] // Stage 1 Functions struct flight setup_flight (void); void do print airports (struct flight flight); void print_one_airport (struct airport *ap); struct airport *create_airport ( char code [MAX_STRING_LEN), int arrival time, int departure ); // Stage 2 Functions void do subroute (struct flight flight); void do change origin(struct flight flight); // TODO: Your functions prototypes here. // FUNCTION IMPLEMENTATIONS int main(void) { // Stage 1.1 // TODO: Complete the setup flight function below struct flight flight setup_flight(); // TODO: Fill out the while loop with relevant commands & functions // Move into and stay in operational mode until CTRL+D printf("Enter Command: "); char command line [MAX_STRING_LEN]; while (fgets (command_line, MAX_STRING_LEN, stdin) != NULL) { remove_newline (command line);
} remove_newline (command line); if (stremp (COMMAND PRINT HELP, command line) == 0) { // A help command we have implemented for you. do print_help(); } else if (stremp (COMMAND PRINT_ROUTE, command line) == 0) { // Stage 1.2- TODO: Complete this function below do_print_airports (flight); } else if (strcmp (COMMAND SUBROUTE, command line) == 0) ( // Stage 2.1 - TODO: Complete this function below do subroute (flight); } else if (strcmp(COMMAND_CHANGE_ORIGIN, // Stage 2.2 - TODO: Complete this function below do_change_origin (flight); // TODO: Add more conditions here for the remaining commands printf("Enter Command: "); printf("Goodbye!\n"); return 0; } // Stage 1.1 // Creates and initialises a flight by asking the user for input. // Parameters: // None // Returns: // Pointer to the malloc'd flight struct flight setup_flight (void) { // Create a new, empty flight struct flight new flight new flight->origin_airport new flight->dest airport = NULL; NULL; malloc(sizeof(struct flight)); // Read number of stops using fgets printf("How many stops will be enroute? "); char input_line [MAX_STRING_LEN) (0); fgets (input_line, MAX_STRING_LEN, stdin); command line) == 0) { // Convert the string to a number int num_stops = 0; num_stops atoi (input_line); // TODO: For each airport Use fgets to read a line and then use the // provided interpret_line () function to extract information // TODO: For each airport, check conditions and 11 add it to the end of the flight route // TODO: Change the next line
// TODO: Change the next line. return NULL; } // Stage 1.2 // Given a pointer to a flight struct, prints all the info about the route // Parameters: // flight the flight which contains the flight route to print // Returns: // None void do print_airports (struct flight flight) { // TODO: Loop through the flight route and call 11 the provided print_one_airport function } // Stage 1.2 // PROVIDED FUNCTION DO NOT CHANGE // Given a pointer to an airport struct, // prints all the info about the airport // Parameters: ap the airport to print // // Returns: // None void print_one_airport (struct airport ap) ( ( printf( *886: 804d -> 804d\n", ap->code, ap->arrival time, ap->departure time // Stage 1.1 // Given the information about a new airport, // Uses malloc to create memory for it and returns a pointer to // that memory. // Parameters: 11 code arrival time departure time the airport ICAO code the arrival time of the new airport the departure time of the new airport 11 // // Returns: // A pointer to the malloc'd struct airport struct airport *create_airport ( char code [MAX_STRING_LEN), int arrival time, int departure_time) // Malloc new struct struct airport new airport malloc(sizeof(struct airport)); // initialise airport fields strcpy(new_airport->code, code);
strcpy (new_airport->code, new_airport->arrival_time new_airport->departure_time new_airport->next_airport = NULL; return new airport; code); = arrival time; departure_time; } // TODO void do subroute (struct flight flight) { return; } // TODO void do_change_origin(struct flight flight) { return; /// HELPER FUNCTIONS // Helper Function // You likely do not need to change this function. // // Given a raw string will remove and first newline it sees. // The newline character wil be replaced with a null terminator ('\0') // Parameters: 1/ flight the flight to move people along of // Returns: // None void remove_newline (char input [MAX_STRING_LEN]) { // Find the newline or end of string int index = 0; while (input[index] != '\n' && input[index] != '\0') { index++; } // Goto the last position in the array and replace with '\0' // Note: will have no effect if already at null terminator input[index] = '\0'; // Belper Function // You DO NOT NEED TO UNDERSTAND THIS FUNCTION, and will not need to change it. // // Given a raw string in the following foramt: [integer0] [integerl] [string] // This function will extract the relevant values into the given pointer variables. // The function will also remove any newline characters. // // For example, if given: "0135 0545 YSSY" // The function will put the integer values // 135 into the vall pointer Far
// 11 // And 135 into the vall pointer 545 into the val2 pointer will copy a null terminated string "YSSY" into the 'word' array 11 // If you are interested, strtok is a function which takes a string, // and splits it up into before and after a "token" (the second argument) // // Parameters: buffer 11 11 // // // // Returns: // None > { valo vall word void interpret_line ( A null terminated string in the following format [integer0] [integerl] [string] A pointer to where [integer0] should be stored = A pointer to where [integerl] should be stored An array for the [string] to be copied into char buffer (MAX_STRING_LEN], int *val0, int *vall, char word [MAX_STRING_LEN] // Remove extra newline remove_newline (buffer); // Extract value 1 as int char val0_str strtok (buffer, " "); if (val0_str = NULL) { *valo atoi (val0_str); - } else { } // Extract value 2 as int char *vall_str = strtok (NULL," "); if (vall str != NULL) { *vallatoi (vall_str); } else { } *val0 = -1; *vall= -1; char *word_str = strtok (NULL, " "); if (word_str != NULL) { // Extract word strcpy(word, word_str); } if (val0_str = NULL || vall_str == NULL || word_str == NULL) { // If any of these are null, there were not enough words. printf("Could not properly interpret line: ts.\n", buffer);
char *vall str strtok (NULL, if (vall str != NULL) { *vallatoi (vall_str); } else { } char *word_str = strtok (NULL," "); if (word_str != NULL) ( // Extract word strcpy(word, word_str); *vall= -1; } if (val0_str == NULL || vall_str = NULL || word_str == NULL) { // If any of these are null, there were not enough words. printf("Could not properly interpret line: s.\n", buffer); > void do_print_help (void) { printf("+ printf("Command Name printf("+.. printf("|PRINT ROUTE printf("+en die printf("SUBROUTE printf(" printf(" printf("CHANGE ORIGIN printf(" printf(" printf("+ printf("BYPASS printf(" printf("+ printf("EMERGENCY printf(" printf(" printf("CANCEL printf(" printf("REVERSE printf("+- printf(" printf("ADD PERSON printf(" printf(" printf("+ printf("|PRINT MANIFEST How to Use Enter command: print Enter command: subroute Enter airport code: [AIRPORT CODE] Enter command: change origin Enter new origin info: [ARRIVAL TIME)... ... [DEPARTURE TIME] [AIRPORT CODE] Enter command: bypass Enter airport code: [AIRPORT CODE] ---+\n"); |\n"); +\n"); |\n"); Enter command: print manifest Enter the airport code: [AIRPORT CODE] printf(" printf("+- printf("FLIGHT STATISTICS Enter command: stats printf(" -+\n"); |\n"); |\n"); -+\n"); |\n"); \n"); \n"); -+\n"); Enter command: emergency |\n"); How long until emergency: [TIME IN HOURS) \n"); Enter command: cancel Enter command: reverse Enter command: add_person Enter the airport code: [AIRPORT CODE] Enter the passenger name: [NAME] Enter the passenger weight: [WEIGHT] --+\n"); |\n"); |\n"); ---+\n"); |\n"); -+\n"); |\n"); -+\n"); |\n"); \n"); \n"); \n"); +\n"); |\n"); |\n"); -+\n"); |\n"); +\n");