/* * This is a rapid prototype of the Air Gourmet product. It is written in C */ #include #include #include #define NUM_FLIGHT_RECORDS 20 #define NUM_PASSENGER_RECORDS 10 #define BOOL short #define FALSE 0 #define TRUE 1 #define ID_LENGTH 9 #define NAME_LENGTH 15 #define SUFFIX_LENGTH 5 #define ADDR_LENGTH 25 #define CITY_STATE_LENGTH 14 #define POSTAL_CODE_LENGTH 10 #define COUNTRY_LENGTH 20 #define RES_ID_LENGTH 6 #define FLIGHT_NUM_LENGTH 3 #define SEAT_NUM_LENGTH 4 struct passenger_type { char passenger_id[10]; char first_name[16]; char middle_init; char last_name[16]; char suffix[6]; char address1[26]; char address2[26]; char city[15]; char state[15]; char postal_code[11]; char country[21]; }; struct flight_record_type { char passenger_id[10]; char reservation_id[7]; char flight_num[4]; char flight_date[9]; char seat_num[5]; char meal_type[11]; short perceived_quality; BOOL checked_in; BOOL meal_loaded; }; /* * Because this is a rapid prototype, an array of records has been used to * keep track of the number of flight records and passenger records */ short flight_record_count; short passenger_count; struct passenger_type passenger_records[NUM_PASSENGER_RECORDS]; struct flight_record_type flight_records[NUM_FLIGHT_RECORDS]; /*------------------------------------------------------------------------------------------------------------------------------------------------*/ void clear_screen (void) /* * The following code will clear the screen */ { int i; /* * Implementation-dependent code to clear the screen should replace * the code given below. */ for (i = 0; i < 26; i++) printf ("\n"); } /* clear_screen */ /*------------------------------------------------------------------------------------------------------------------------------------------------*/ void press_enter (void) /* * Wait until the user presses the key */ { char ch; fflush (stdin); ch = getchar (); } /* press_enter */ /*------------------------------------------------------------------------------------------------------------------------------------------------*/ char *stringupr (char *s) /* * This function converts characters of string s to uppercase */ { int i; for (i = 0; i <= strlen (s); i++) /* * change the current character to lowercase if needed */ if (islower (s[i])) s[i] = toupper (s[i]); return s; } /* stringupr */ /*------------------------------------------------------------------------------------------------------------------------------------------------*/ void initialize (void) /* *This function initializes records */ { short count; flight_record_count = -1; passenger_count = -1; for (count = 0; count < NUM_FLIGHT_RECORDS; count++) { flight_records[count].perceived_quality = 0; flight_records[count].checked_in = FALSE; flight_records[count].meal_loaded = FALSE; } } /* initialize */ /*------------------------------------------------------------------------------------------------------------------------------------------------*/ int date_compare (char *date1, char *date2) /* * This function determines the temporal order of two dates. It returns * -1 if date1 < date2; * 0 if the dates are the same; and * 1 if date2 < date1 */ { int year1, year2, month1, month2, day1, day2; char temp[2]; temp[0] = date1[6]; temp[1] = date1[7]; year1 = atoi (temp); temp[0] = date2[6]; temp[1] = date2[7]; year2 = atoi (temp); temp[0] = date1[3]; temp[1] = date1[4]; day1 = atoi (temp); temp[0] = date2[3]; temp[1] = date2[4]; day2 = atoi (temp); temp[0] = date1[0]; temp[1] = date1[1]; month1 = atoi (temp); temp[0] = date2[0]; temp[1] = date2[1]; month2 = atoi (temp); if (year1 < year2) return -1; if (year1 > year2) return 1; if (month1 < month2) return -1; if (month1 > month2) return 1; if (day1 < day2) return -1; if (day1 > day2) return 1; else return 0; } /* date_compare */ /*------------------------------------------------------------------------------------------------------------------------------------------------*/ void check_in_passenger (void) /* * This function sets the checked-in field for a particular * passenger to TRUE, if the passenger has a reservation. */ { int i; BOOL found; char reservation_id[7]; clear_screen (); fflush (stdin); printf ("\n\n"); printf ("Enter the RESERVATION ID: "); gets (reservation_id); found = FALSE; for (i=0; i <= flight_record_count; i++) if (strcmp (flight_records[i].reservation_id, reservation_id) == 0) { found = TRUE; flight_records[i].checked_in = TRUE; printf ("\n\n\tThe passenger has been checked in.\n"); printf ("\tPlease check their identification.\n\n"); printf ("Press to return to main menu..."); press_enter (); break; } if (!found) { printf ("\n\n\tThere is no reservation with this id...\n\n"); printf ("Press to return to main menu..."); press_enter (); } } /* check_in_passenger */ /*------------------------------------------------------------------------------------------------------------------------------------------------*/ void scan_special_meals (void) /* * For each passenger on a particular flight, this function asks if the passengeršs special meal was loaded */ { int i; char ch, flight_num[4], flight_date[9]; BOOL found; clear_screen (); fflush (stdin); printf ("\n\n"); printf ("Enter the date of this flight: "); gets (flight_date); printf ("Enter the FLIGHT NUMBER: "); gets (flight_num); found = FALSE; for (i=0; i <= flight_record_count; i++) if ((date_compare (flight_date, flight_records[i].flight_date) == 0) && (strcmp (stringupr (flight_num), flight_records[i].flight_num) == 0)) { found = TRUE; printf ("\n\nPASSENGER: %s SEAT: %s \n\n", flight_records[i].passenger_id, flight_records[i].seat_num); printf ("Was the meal for this passenger loaded (Y/N) ? "); fflush (stdin); ch = getchar (); if ((ch == 'Y') || (ch == 'y')) flight_records[i].meal_loaded = TRUE; } if (!found) printf ("\n\n\tThere are no passengers on this flight..."); printf ("\n\nPress to return to main menu..."); press_enter (); } /* scan_special_meals */ /*------------------------------------------------------------------------------------------------------------------------------------------------*/ void scan_postcard (void) /* * For a particular passenger, obtain the perceived meal * quality from a postcard */ { int i, meal_quality; BOOL found; char reservation_id[7]; clear_screen (); fflush (stdin); printf ("\n\n"); printf ("Enter the RESERVATION ID: "); gets (reservation_id); found = FALSE; for (i=0; i <= flight_record_count; i++) if (strcmp (flight_records[i].reservation_id, reservation_id) == 0) { printf ("Enter perceived meal quality(1 thru 5): "); scanf ("%d", meal_quality); found = TRUE; flight_records[i].perceived_quality = meal_quality; printf ("\n\n\tThe meal quality has been recorded.\n\n"); printf ("Press to return to main menu..."); press_enter (); break; } if (!found) { printf ("\n\n\tThere is no reservation with this id...\n\n"); printf ("Press to return to main menu..."); press_enter (); } } /* scan_postcard */ /*------------------------------------------------------------------------------------------------------------------------------------------------*/ BOOL already_exists (char search_id[9]) /* * This determines if a passenger already exists and, if so, * whether the found passenger is to be assigned to the * current flight record */ { int i; BOOL found; char ch; found = FALSE; for (i=0; i <= passenger_count; i++) if (strcmp (passenger_records[i].passenger_id, search_id) == 0) { found = TRUE; break; } if (found) { printf ("\n\nThis passenger id already exists.\n\n"); printf ("\n\nDo you want to use this name and address to make a\n"); printf ("reservation for this passenger (Y/N)? "); fflush (stdin); ch = getchar (); found = FALSE; if ((ch == 'Y') || (ch == 'y')) found = TRUE; } return found; } /* already_exists */ /*------------------------------------------------------------------------------------------------------------------------------------------------*/ void get_passenger_description (void) /* * This function retrieves information about a passenger */ { char new_passenger_id[10]; clear_screen (); fflush (stdin); printf ("\n\n"); printf ("Please enter the following information about the passenger:\n"); printf ("Enter the PASSENGER ID assigned to this passenger\n"); printf (" (9 numbers only--no spaces or dashes): "); gets (new_passenger_id); if (!already_exists (new_passenger_id)) { if (passenger_count >= NUM_PASSENGER_RECORDS) { printf ("The maximum number of allowed passengers for this\n"); printf ("prototype has been exceeded...No new passengers are allowed.\n\n"); printf ("Press to return to main menu..."); press_enter (); } else { passenger_count++; printf ("Enter the FIRST name of the passenger: "); gets (passenger_records[passenger_count].first_name); fflush (stdin); printf ("Enter the MIDDLE INITIAL of the passenger: "); passenger_records[passenger_count].middle_init = getchar (); fflush (stdin); printf ("Enter the LAST name of the passenger: "); gets (passenger_records[passenger_count].last_name); printf ("Enter the SUFFIX used by the passenger: "); gets (passenger_records[passenger_count].suffix); printf ("Enter the ADDRESS (first line) of the passenger: "); gets (passenger_records[passenger_count].address1); printf ("Enter the ADDRESS (second line) of the passenger: "); gets (passenger_records[passenger_count].address2); printf ("Enter the CITY where the passenger lives: "); gets (passenger_records[passenger_count].city); printf ("Enter the STATE where the passenger lives: "); gets (passenger_records[passenger_count].state); printf ("Enter the POSTAL CODE where the passenger lives: "); gets (passenger_records[passenger_count].postal_code); printf ("Enter the COUNTRY where the passenger lives: "); gets (passenger_records[passenger_count].country); } } strcpy (flight_records[flight_record_count].passenger_id, new_passenger_id); } /* get_passenger_description */ /*------------------------------------------------------------------------------------------------------------------------------------------------*/ void enter_reservation (void) /* * This function retrieves information regarding a flight reservation */ { if (flight_record_count >= NUM_FLIGHT_RECORDS) { printf ("The maximum number of reservations for this\n"); printf ("prototype has been exceeded...No new reservations are allowed.\n\n"); printf (" Press to return to main menu..."); press_enter (); } else { flight_record_count++; clear_screen (); printf ("Please enter the following information about the reservation:\n"); fflush (stdin); printf ("\n\n"); printf ("Enter the RESERVATION ID: "); gets (flight_records[flight_record_count].reservation_id); printf ("Enter the FLIGHT NUMBER: "); gets (flight_records[flight_record_count].flight_num); printf ("Enter the DATE of the flight (mm/dd/yy): "); gets (flight_records[flight_record_count].flight_date); printf ("Enter the SEAT NUMBER assigned to this passenger: "); gets (flight_records[flight_record_count].seat_num); printf ("Menu of available special meals:\n\n "); printf (" CHILD, DIABETIC, HALAAL, KOSHER, LACTOSE FREE, LOW CAL\n"); printf (" LOW CHOLESTEROL, LOW FAT, LOW PROTEIN, LOW SODIUM,\n"); printf (" SEA FOOD, VEGAN, VEGETARIAN\n\n"); printf ("Enter the SPECIAL MEAL for this reservation: "); gets (flight_records[flight_record_count].meal_type); get_passenger_description (); } } /* enter_reservation */ /*------------------------------------------------------------------------------------------------------------------------------------------------*/ void low_sodium_report (void) /* * This function displays a report of the flight number, flight date, and perceived quality for all * low-sodium meals */ { short i, record_count; char from_date[9], to_date[9]; clear_screen (); fflush (stdin); printf ("Enter the start date for this report: "); gets (from_date); printf ("Enter the end date for this report: "); gets (to_date); clear_screen (); record_count = 0; for (i = 0; i <= flight_record_count; i++) { if (((record_count % 3) == 0) && (record_count != 0)) { printf ("\n\n"); printf (" Press to view the next screen..."); press_enter (); } if ((record_count % 3) == 0) { clear_screen (); printf ("\n\n"); printf (" Air Gourmet\n"); printf (" LOW SODIUM REPORT\n\n"); } if ((date_compare (from_date, flight_records[i].flight_date) <= 0) && (date_compare (to_date, flight_records[i].flight_date) >= 0) && (strcmp ("LOW SODIUM", flight_records[i].meal_type) == 0)) { printf ("-------------------------------------------------------------------\n"); printf ("FLIGHT NUMBER: %s\n", flight_records[i].flight_num); printf ("FLIGHT DATE: %s\n", flight_records[i].flight_date); printf ("PERCEIVED QUALITY: %s\n", flight_records[i].perceived_quality); record_count++; } } if (record_count == 0) printf ("There are no passengers on this flight."); printf ("\n\n"); printf (" Press to return to main menu..."); press_enter (); } /* low_sodium_report */ /*------------------------------------------------------------------------------------------------------------------------------------------------*/ void on_board_report (void) /* * This function displays a report of all passenger ids, seat numbers, and meal type for all meals * that should be loaded on board */ { short i, record_count; char flight_date[9], flight_num[4]; clear_screen (); fflush (stdin); printf ("Enter the date of this flight: "); gets (flight_date); fflush (stdin); printf ("Enter the FLIGHT NUMBER: "); gets (flight_num); clear_screen (); record_count = 0; for (i = 0; i <= flight_record_count; i++) { if (((record_count % 10) == 0) && (record_count != 0)) { printf ("\n\n"); printf (" Press to view the next screen..."); press_enter (); } if ((record_count % 10) == 0) { clear_screen (); printf ("\n\n"); printf (" Air Gourmet\n"); printf (" ON BOARD REPORT\n\n"); } if ((date_compare (flight_date, flight_records[i].flight_date) == 0) && (strcmp (flight_num, flight_records[i].flight_num) == 0)) { printf ("-------------------------------------------------------------------\n"); printf ("PASSENGER: %s\t", flight_records[i].passenger_id); printf ("SEAT: %s\t", flight_records[i].seat_num); printf ("MEAL TYPE: %s\n", flight_records[i].meal_type); record_count++; } } if (record_count == 0) printf ("There are no passengers on this flight."); printf ("\n\n"); printf (" Press to return to main menu..."); press_enter (); } /* on_board_report */ /*------------------------------------------------------------------------------------------------------------------------------------------------*/ void report_menu (void) /* * This function allows user to select the type of report to be displayed */ { int done, choice; done = FALSE; while (!done) { clear_screen (); printf ("\t REPORT MENU\n\n\n"); printf ("\t Air Gourmet\n\n\n"); printf ("\t 1. *24 Hour Caterer List\n\n"); printf ("\t 2. On Board Meals List\n\n"); printf ("\t 3. *Report on Percentages\n\n"); printf ("\t 4. *Report on Meals not Loaded\n\n"); printf ("\t 5. *Report on Poor Quality\n\n"); printf ("\t 6. Report on Low Sodium\n\n"); printf ("\t 7. Return to Main Menu\n\n\n"); printf ("\t (* denotes not implemented)\n\n\n"); printf ("\t Enter your choice and press : "); scanf ("%d", &choice); switch (choice) { case 1: clear_screen (); printf ("\t\t 24 HOUR CATERER LIST\n\n"); printf ("\t\t This report is not implemented in the prototype\n\n\n"); printf (" Press to return to the menu "); press_enter (); break; case 2: on_board_report (); break; case 3: clear_screen (); printf ("\t\t REPORT ON PERCENTAGES\n\n"); printf ("\t\t This report is not implemented in the prototype\n\n\n"); printf (" Press to return to the menu..."); press_enter (); break; case 4: clear_screen (); printf ("\t\t REPORT ON MEALS NOT LOADED\n\n"); printf ("\t\t This report is not implemented in the prototype\n\n\n"); printf (" Press to return to the menu..."); press_enter (); break; case 5: clear_screen (); printf ("\t\t REPORT ON POOR QUALITY\n\n"); printf ("\t\t This report is not implemented in the prototype\n\n\n"); printf (" Press to return to the menu..."); press_enter (); break; case 6: low_sodium_report (); break; case 7: done = TRUE; break; default: printf ("\n\nChoice is out of range\n\n"); printf (" Press to return to menu..."); press_enter (); break; } } } /* report */ /*------------------------------------------------------------------------------------------------------------------------------------------------*/ void main_menu (void) /* * This function displays the main menu containing all the options available */ { int done, choice; done = FALSE; while (!done) { clear_screen (); printf ("\t MAIN MENU\n\n\n"); printf ("\t Air Gourmet Prototype\n\n\n"); printf ("\t 1. Enter a Reservation\n\n"); printf ("\t 2. Check-in a Passenger\n\n"); printf ("\t 3. Scan the Special Meals List\n\n"); printf ("\t 4. Scan a Returned Postcard\n\n"); printf ("\t 5. Produce a Report\n\n"); printf ("\t 6. Quit \n\n\n"); printf ("\t Enter your choice and press : "); scanf ("%d", &choice); switch (choice) { case 1: enter_reservation (); break; case 2: check_in_passenger (); break; case 3: scan_special_meals (); break; case 4: scan_postcard (); break; case 5: report_menu (); break; case 6: done = TRUE; break; default: printf ("\n\nChoice is out of range\n\n"); printf (" Press to return to menu..."); press_enter (); break; } } } /* main_menu */ /*------------------------------------------------------------------------------------------------------------------------------------------------*/ void main (void) { initialize (); main_menu (); } /* main */ /*------------------------------------------------------------------------------------------------------------------------------------------------*/