CS262 Project 3: Cruise Ship Manifest
Due 11:59 P.M., April 25, 2015
Modifications and Errata:
April 2, 2015: Initial posting
April 6, 2015: Corrected copy snafu in section 4.G of implementation steps
April 7, 2015: Modified 4.E in implementation steps to allow parameters. Remove reference to Global variable in 4.C
Introduction:
Gilligan’s Cruise Company (GCC) is planning to modernize their ship, the SS Minnow, with the latest technology. One aspect of their upgrades is how they keep track of passenger shipboard accounts and whether they are on or off the ship.
In the past, they kept track of customer embarking and disembarking by having a security person look at the passenger ID and letting them on or off the ship. With their new upgrade, they will have a computer program keep track of each passenger’s location (whether they are on or off the ship), as well as each passenger’s ship accounts (bar bills, gift shop purchases, island tours, etc.). Passengers will carry a cruise card that they will use when embarking, disembarking and making a purchase. All cruise itineraries will include a stop at Gilligan’s Island, the cruise line’s private island, for a three hour tour. While on the island, and at other ports of call, passengers may also use their shipboard accounts to buy coconuts and other souvenirs.
Your company has been selected by GCC to write this computer program, and you have been selected by your boss to design and code it. GCC has given the following specifications for their new system:
- Information for each passenger will be kept in a single data type (struct) and will consist of:
- A unique passenger ID (integer)
- Passenger First Name (char string of 25 characters)
- Passenger Last Name (char string of 35 characters)
- Current balance of passenger shipboard account (double)
- Passenger Location (char)
- If passenger is on-board, the value of this data will be 1
- If the passenger is visiting the current island, the value of this data will be 0
- The passenger data will be read from an ASCII file at the start of the program. The data will consist of the unique ID, and the passenger’s first and last name. Each line in the file will contain a single data item. When the data is read, the balance of the passenger’s account will be set to 0.00, and the passenger will be considered to be off the ship (Location value is 0).
- Passengers will be identified by their unique ID. Thus when a passenger embarks, disembarks or makes an on-board purchase, their ID card is scanned, and the unique id is read from the magnetic strip on their cruise card. This ID will be used to search for the customer information so that it can be updated.
- As passengers arrive on the ship, the passenger location value will be set to 1. If the passenger location value indicates that they are already on the ship, a message will be printed stating that the passenger must have slipped off the ship without going through security.
- Similar to #3, when a passenger leaves the ship, the location value will be set to 0. If the location value indicates that they are currently off the ship, a message will be printed stating that the passenger must have gotten on the ship without going through security.
- When a passenger makes an on-board purchase, the amount of the purchase will be added to their shipboard account. If the location value of the passenger indicates they are currently off the ship, a message will be printed stating that the passenger location is incorrect. The location value will be set to 1 and the amount of the purchase will be added to their shipboard account.
- Similar to #6, when a passenger makes an off-board purchase, the amount of the purchase will be added to their shipboard account. If the location value of the passenger indicates they are currently on the ship, a message will be printed stating that the passenger location is incorrect. The location value will be set to 0 and the amount of the purchase will be added to their shipboard account.
- The program must have the ability to print:
- Information for a single passenger (identified by the unique ID)
- Passenger information for all passengers currently on board
- Passenger information for all passengers currently on shore
- When printing passenger information, the passenger’s Unique ID, First and Last name, and current shipboard account balance is printed
- At the end of the cruise, all passengers will exit the ship. The program will then calculate the total amount of money the passengers spent on the cruise, compute the average amount of money spent per passenger, and print this information.
Implementation:
The specifications for this project have a great deal of detail. However, the fact that they are detailed can be used to your advantage, in that you can break the project into smaller units and work on them separately to create the complete project.
- You will implement this program using singly Linked Lists. You will create a linked list node struct that will contain a passenger struct, and a pointer to a linked list node.
- You will have, at a minumum, two linked lists. One for passengers on board the ship (onShip), and one for passengers that are not on the ship (offShip).
- The nodes in the linked lists will always be ordered by Passenger ID.
- Your program will be menu driven. The program will contain a main menu, and several choices from this menu will bring up a sub-menu. See the Menu Specifications below.
- A sample script and output will be provided that you may test with your program. Your program must respond to inputs in the same manner that the sample script responds. In other words, your program should not add unnecessary prompts for user input, nor should it skip prompts for input (or prompt for multiple data items with a single prompt).
- Two input files containing Names and Passenger IDs are provided, one for testing, and one for a more realistic number of passengers.
Menu Specifications:
- Main Menu: The main menu will contain the following choices and functionality:
- Read Passenger Mainfest
- Prompt the user for a filename containing the “Passenger Manifest.”
- Open this file and read the information from the file, creating Passengers and adding them to the offShip list
- If the file cannot be found, print a message stating this fact, and return to the Main Menu.
- Embark all passengers
- Move all passengers from the offShip list to the onShip list
- Passenger Information
- Display the Passenger Information Menu (See below)
- Print Menu
- Display the Print Menu (See below)
- Debark all passengers
- Move all passengers from the onShip list to the offShip list
- Quit
- Remove all nodes from both the onShip and offShip lists and free the memory.
- Exit the program
- Passenger Information Menu:
- Embark Passenger
- The program prompts for the passenger ID. The passenger node is removed from the offShip list and added in the proper position to the the onShip list. The passenger location is set to be on board.
- If the passenger ID is not found in the offShip list, the onShip list is searched. If the passenger is found in the onShip list, a message stating so is written to the console, and the program returns to the main menu.
- If the passenger is not found in either list, a message stating an incorrect ID was entered is written to the console, and the program returns to the Passenger Information menu.
- Debark Passenger
- The program prompts for the passenger ID. The passenger node is removed from the onShip list and added in the proper position to the the offShip list. The passenger location is set to be of the ship.
- If the passenger ID is not found in the onShip list, the offShip list is searched. If the passenger is found in the offShip list, a message stating so is written to the console, and the program returns to the main menu.
- If the passenger is not found in either list, a message stating an incorrect ID was entered is written to the console, and the program returns to the Passenger Information menu.
- Passenger OnBoard Purchase
- The program prompts for the passenger ID. The program then prompts for the amount of purchase as a floating point value.
- The program searches for the passenger node, first in the onShip list, then (if it is not found in the onShip list) the offShip list is searched.
- Once the node is found, the purchase amount is added to the current balance of the shipboard account for that passenger. Also, the Passenger location is set to 1 if it is not already (if the passenger was in the offShip list).
- If the passenger ID is not found, a message stating an incorrect ID was entered is written to the console, and the program returns to the Passenger Information menu.
- Passenger OffBoard Purchase
- The program prompts for the passenger ID. The program then prompts for the amount of purchase as a floating point value.
- The program searches for the passenger node, first in the offShip list, then (if it is not found in the offShip list) the onShip list is searched.
- Once the node is found, the purchase amount is added to the current balance of the shipboard account for that passenger. Also, the Passenger location is set to 0 if it is not already (if the passenger was in the onShip list).
- If the passenger ID is not found, a message stating an incorrect ID was entered is written to the console, and the program returns to thePassenger Information menu.
- Synchronize Passenger Lists
- The program traverse through the two passenger lists. Any passenger in the onShip list with the location set to 0 will be removed from the onShip list and moved to the offShip list. Any passenger in the offShip list with the location set to 1 will be removed from the offShip list and moved to the onShip list.
- Return to Main Menu
- Print Menu:
- Print Account for Single Passenger
- Prompt the user for the Passenger ID.
- Search both onShip and offShip lists until the passenger is found
- Print the information for that passenger.
- If the Passenger ID is not found, write a message to the console stating that fact and return to the Print Menu.
- Print All Passenger Accounts
- Print Accounts for onShip Passengers
- Print Accounts for offShip Passengers
- Return to Main Menu
Additional Specifications:
- Your program will have at least two source files
- Source file 1 will be named Project3_main_<username>_<lab_section>.c
- This file will contain your main() function as well as the functions to handle the menus
- Source file #2 will be named Project3_llist_<username>_<lab_section>.c
- This file will contain your linked list functions and other functions necessary to complete the project.
- Source file 1 will be named Project3_main_<username>_<lab_section>.c
- You will provide a Makefile that will compile your source files into object files, and link them into a single executable
- You may not use global variables for the linked lists. You must pass the heads of your lists as parameters to the functions.
- You may implement your linked lists using either a dummy node or using a pointer to the head of the list.
- It is suggested that you create separate generic linked list functions that perform insertions, deletions, searches, etc. These functions are then used by specific functions(Passenger_Onboard_Purchase() for example) to retrieve references to the desired nodes where they will be modified.
Submission Instructions:
You will submit a tar file containing your source code files, your Passenger Manifest file, and Makefile. To do this, perform the following steps:
- On zeus, make a directory to hold your files for submission. This directory must be named “Project3_<username>_<lab_section>”
- Copy or move your source file, manifest file, and Makefile to this directory.
- Perform the following command to create your tar file:
            tar -cvf Project3_<username>_<lab_section>.tar Project3_<username>_<lab_section>
Submit this tar file to Blackboard for the Project 3 assignment.
Suggested Implementation Steps:
Below is a step by step guide you can use to create your program for this project. You do not have to follow this procedure, but you will likely have greater success in completing your project on time if you do so. Breaking the creation of the program into smaller portions will make your code easier to maintain and debug.
- Create separate void functions with no parameters to print each menu (one for the Main Menu, one for the Passenger Information Menu, one for the Print Menu, etc.). Use these functions only to print the menus (do not prompt for a menu choice in these functions).
- Create the logic to use the menus.
- In the main() function, create a loop to print the Main Menu (by calling its print function) and prompt for user input.
- Use switch statements based on user input to call other functions (don’t put other functionality in the switch statements – just call other functions).Also break out of the loop if the user chooses to end the program.
- Create the other functions based on user input.
- If the function is to print a submenu, add functionality print the submenu, prompt the user for input, then add a switch statement to call “stub functions” based on user input.
- If the other functions are not submenu functions, create a “stub function.” A stub function has no parameters or functionality other than to print an informational message, such as “In Function PassengerPurchase.” You will add parameters and functionality to it later.
- Test the logic of your menus by checking each combination of input from the Main Menu through the submenus and stub functions to ensure that each stub function is reached correctly.
- Once you have the menus working, add the linked list functions.
- Create the struct for the Passenger Information
- Create a Linked List struct. This struct will contain a Passenger Information struct and a reference (usually called Next) to a Linked List struct.
- Create two linked list head nodes in your main() function, one for the onShip list and one for the offShip list.
- Add parameters to your functions (where needed) to pass the linked list head nodes to the stub functions.
- Write a function that creates a Linked List node. This function will likely have a file descriptor as a parameter. It will use memory allocation to create a Linked List node, prompt for all information required for a passenger struct (reading it in from the file referenced by the file descriptor), initialize the Passenger struct portion of the Linked List node with this information,set the Next pointer to NULL, and return a pointer to this newly created node.
- Create a function that takes a pointer to a Linked List node as a parameter and returns the Passenger ID.
- Create a Linked List function that will return a pointer to a node in a linked list, without removing that node. This function takes the head of a linked list and an integer value (the Passenger ID) as parameters. If the node containing the Passenger ID is not found in the linked list, a void pointer is returned.
- Create a Linked List function that will add a node to a linked list. This function takes the head of a linked list and a pointer to the node to add as parameters. The function will use the function created in Step F to determine where the node will be added.
- Create a Linked List function that will remove a node from a linked list, and return a pointer to the removed node. This function takes the head of a linked list and an integer value (the Passenger ID) as parameters. If the node containing the Passenger ID is not found in the linked list, a void pointer is returned.
- The Linked List functions created in the previous step are difficult to test on their own. You will test them by gradually adding functionality to your program.
- Implement the Main Menu function to Embark all Passengers
- Implement the Print Menu function to Print onShip Passengers
- Create a function that takes the head of a Linked List as a parameter and prints the information contained all nodes of that list
- Call this function with the onShip list as the parameter.
- Test these two functions to see if the program can add all the passengers to the onShip list and then print them.
- Implement the Main Menu function to Debark all Passengers
- Implement the Print Menu function to Print offShip Passengers.
- Note that this is the same function created for #2 above. It just takes the offShip list as a parameter.
- Test the Debark and Print offShip Passengers functions.
- Implement and test the Print All Passengers function
- This is trivial – just call the Print onShip Passengers and the Print offShip Passengers functions.
- Implement and test the Print Single Passenger function
- You will use the function created in step 5.9 above
- Now implement and test the functions for the Passenger Information Menu
- There is not much advantage to the order that these functions are implemented, although the Synchronize Passenger Lists functions might be best to implement after the Purchase functions are implemented.
- Test your code thoroughly
A suggested timeframe to complete the steps is as follows:
Week 1: Items 1-3. Start on Item 4
Week 2: Items 4-5 (possibly Item 6 also)
Week 3: (First half):Â Item 6 (if not already completed). Start Item 7
Week 3: (Second half): Complete Item 7 and submit