This lab was developed by Prof. L. Felipe Perrone. Permission to reuse this material in parts or in its entirety is granted provided that this credits note is not removed. Additional students files associated with this lab, as well as any existing solutions can be provided upon request by e-mail to: perrone[at]bucknell[dot]edu
It should go without saying that all the work that you will turn in for this lab will be yours. You should try your best to debug your code on your own, but it’s fine to get help from a colleague as long as that means getting assistance to identify the problem and doesn’t go as far as receiving source code to fix it (in writing or orally).
Before you start, do the following on a terminal:
cd ~/csci307/Labs/Lab3
cp ~perrone/csci307/Labs/Lab3/* .
You will need to copy additional material from your Labs 1 and 2, as necessary.
In this assignment, you will continue to build up our flight reservation system. The code you were given before has been a bit refactored and extended. Take the time to get acquainted with the files and the functionality that each module provides. The executable flight_system.c contains functionality to offer the user a menu of six options, as shown in the figure below.
From this menu, the user enters their selection by pressing a key from 1 to 6 followed by return. This input is processed in a switch/case statement that dispatches each key press to the corresponding function. The options execute as follows:
Note: from now on, make an effort to have ALL your code compile without any warnings. In this lab, there will be no points deducted when warnings are left unaddressed, but in future labs that will happen.
Get acquainted with the new functionality provided for you in the slist module. You will find functions that will be helpful to you later. In particular, look at slist_iter_init and slist_iter_next, which you may choose to use to traverse a list without reaching directly into the data structure.
Merge the code you developed for the reservation module into the files given to you with this lab. In particular, you will want to copy over your functions reservation_add and reservation_compare. Use your completed program reservationtest.c from last time to verify that everything works as expected.
After you debug your code and get everything working correctly, add, commit and push your files to your gitlab as follows:
git add reservation.h
git add reservation.c
git add reservationtest.c
git commit -m "lab3-1 completed"
git push
In flight_system.c, you will find the complete code for function sys_save_flights. This function will first open a file whose name is read from the terminal as write-only, requesting the system to create the file if it does not already exist. Take time time to read the code given to you in this function. You will notice that it does the opening and closing of the file for you. Pay close attention to how it uses the system call open(2) and read the man page for the system call to understand the parameters used in this example.
Function sys_save_flights traverses a list of flights and for each node encountered, it saves the flight information encountered into a file whose name is read from the terminal. The real action in saving the system’s flight data to a file is done by function flight_traverse_save from the flights module, which you need to flesh out. Read the function prototype to see that it takes two parameters: the file descriptor for the file to save into and a pointer to the list of flights. Complete the code of function flight_traverse_save and use the flight_system program to verify that your implementation works as expected.
Once you get it to work without crashing, you will be able to have flight data in a file, but you won’t be sure if each flight was saved correctly because the contents of the file will not all be encoded as text. At this point, you can use the Unix program xxd(1) to take a peak into the file. You will only be sure that the data was correctly recorded once you read it back in, but that’s for the next problem. There is not test program for this function: you will need to “exercise” the system to verify that it is working as you expect it.
After you debug your code and get everything working correctly, add, commit and push your files to your gitlab as follows:
git add flight.c
git add flight_system.c
git commit -m "lab3-2 completed"
git push
In flight_system.c, flesh out the code for function sys_load_flights. This function will first open a file whose name is read from the terminal as read-only. Upon successful opening, the function will enter a loop in which you perform the following actions repeatedly until all the contents of the file have been read: read from the file enough bytes to fill a struct flight and insert it into the list passed to this function as a parameter. Read the man page for system call read(2) to understand how you will detect that the end of the file has been reached. Use this function to read the data you saved into a file with the solution to Problem 2 and verify that your saving functionality was indeed implemented correctly. Of course, if you realize that the file was not save as expected, you will need to go back to fix your implementation of flight_traverse_save. There is not test program for this function: you will need to “exercise” the system to verify that it is working as you expect it.
After you debug your code and get everything working correctly, add, commit and push your files to your gitlab as follows:
git add flight.c
git add flight_system.c
git commit -m "lab3-3 completed"
git push
For this problem you will flesh out the code for two functions in flight_system.c. First, work on sys_make_reservation to create a new reservation and insert it in the appropriate list. As in Lab 2, you will need to ensure that only non-existing reservations are added to the system, that is, no duplicates should be allowed. If you think for a moment, you already developed code for this, didn’t you? So, just use what you implemented before. Second, work on sys_display_reservations to traverse the list reservations and display all the reservations encountered on the screen. In both functions, do you best to create the same pattern of interactions with the user that you see in other menu options of the system to create a consistent experience. There is not test program for these functions: you will need to “exercise” the system to verify that it is working as you expect it.
After you debug your code and get everything working correctly, add, commit and push your files to your gitlab as follows:
git add flight_system.c
git commit -m “lab3-4 completed”
git push
The rubric below shows the number of points that will be earned for each item that compiles and runs correctly. If the item does not compile correctly, 60% of the total points will be deducted. If the item compiles correctly and runs with major errors, 40% of the total points will be deducted. If the item compiles correctly and runs with minor errors, 20% of the total points will be deducted.