// // This is an implementation of the Air Gourmet product written in C++ // // This application was developed using Microsoft Visual C++ 5.0 // #include #include #include #include #include #include #include using namespace std; // // Boolean values // #define BOOL short #define FALSE 0 #define TRUE 1 // // field lengths // #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 // // lengths of strings // typedef char ID_TYPE[ID_LENGTH + 1]; typedef char NAME_TYPE[NAME_LENGTH + 1]; typedef char SUFFIX_TYPE[SUFFIX_LENGTH + 1]; typedef char ADDR_TYPE[ADDR_LENGTH + 1]; typedef char CITY_STATE_TYPE[CITY_STATE_LENGTH + 1]; typedef char POSTAL_CODE_TYPE[POSTAL_CODE_LENGTH + 1]; typedef char COUNTRY_TYPE[COUNTRY_LENGTH + 1]; typedef char RES_ID_TYPE[RES_ID_LENGTH + 1]; typedef char FLIGHT_NUM_TYPE[FLIGHT_NUM_LENGTH + 1]; typedef char SEAT_NUM_TYPE[SEAT_NUM_LENGTH + 1]; // // special meal enumerated type and string values // enum SP_MEAL_TYPE {child, Halaal, Kosher, lactose_free, low_cal, low_cholesterol, low_fat, low_protein, low_sodium, sea_food, vegan, vegetarian, regular}; string SP_MEAL_VALUES[13] = {"Child ", "Halaal ", "Kosher ", "Lactose Free ", "Low Calories ", "Low Cholesterol", "Low Fat ", "Low Protein ", "Low Sodium ", "Sea Food ", "Vegan ", "Vegetarian ", "Regular Meal "}; // // functions declared outside of any object // void clear_screen (void); void press_enter (void); void display_main_menu (void); void display_report_menu (void); //---------------------------------------------------------------------------------------- class CDate { private: // // class data members // short month; // integer month value of date, 1 <= month <= 12 char monthname[4]; // 3-letter abbreviation of month, "JAN".."DEC" short day; // integer day value of date, range based on month short year; // 4 digit year component of date char strdate[12]; // string value of complete date, in form "mmm/dd/yyyy" // // private method // void breakup_date (); // breaks up strdate into month, day, year public: CDate () {month = 1; day = 1; year = 1900;}; // default date constructor // // data member access methods // short getMonth () { return month; } char* getMonthname () { return monthname; } short getDay () { return day; } short getYear () { return year; } void setMonth (short m) { month = m; } void setMonthname (char* m) { strcpy(monthname, m); } void setDay (short d) { day = d; } void setYear (short y) { year = y; } BOOL isLeapYear (); // return TRUE iff a leap-year short days_in_month (); // return the # of days in month BOOL valid_date (); // return TRUE iff strdate is well-formed // // date comparison and stream operators // BOOL operator > (CDate d); BOOL operator == (CDate d); friend std::ostream& operator << (ostream& aStream, CDate aDate); friend std::istream& operator >> (istream& aStream, CDate& aDate); }; // class CDate //---------------------------------------------------------------------------------------- class CPassenger { private: // // class data members // ID_TYPE passenger_id; // id of passenger (9 digits) NAME_TYPE first_name; // first name of passenger (15 chars) char middle_init; // middle initial of passenger [1 char] NAME_TYPE last_name; // last name of passenger (15 chars) SUFFIX_TYPE suffix; // suffix of passenger [5 chars] ADDR_TYPE address1; // first line of passenger address (25 chars) ADDR_TYPE address2; // second line of passenger address [25 chars] CITY_STATE_TYPE city; // city that passenger lives in (14 chars) CITY_STATE_TYPE state; // state that passenger lives in [14 chars] POSTAL_CODE_TYPE postal_code; // postal code of passenger [10 anythings] COUNTRY_TYPE country; // country that passenger lives in (20 chars) // // private method // BOOL already_exists (); // is this passenger already in file? public: // // data member access methods // char* get_passenger_id () { return passenger_id; } char* get_first_name () { return first_name; } char get_middle_init () { return middle_init; } char* get_last_name () { return last_name; } char* get_suffix () { return suffix; } char* get_address1 () { return address1; } char* get_address2 () { return address2; } char* get_city () { return city; } char* get_state () { return state; } char* get_postal_code () { return postal_code; } char* get_country () { return country; } void set_passenger_id (char* s){ strcpy(passenger_id, strupr(s)); } void set_first_name (char* f) { strcpy(first_name, f); } void set_middle_init (char m) { middle_init = m; } void set_last_name (char* l) { strcpy(last_name, l); } void set_suffix (char* s) { strcpy(suffix, s); } void set_address1 (char* a1) { strcpy(address1, a1); } void set_address2 (char* a2) { strcpy(address2, a2); } void set_city (char* c) { strcpy(city, c); } void set_state (char* s) { strcpy(state, s); } void set_postal_code (char* p) { strcpy(postal_code, p); } void set_country (char* c) { strcpy(country, c); } // // public methods // BOOL get_passenger (ID_TYPE search_id); // if exists, get passenger where // passenger_id = search_id void get_description (); // get all of the passenger record info // // file and stream operators // void insert (); // place record in proper location in file void write (ofstream& file_name); // write the object to a stream BOOL read (ifstream& file_name); // read an object from a stream friend ostream& operator << (ostream& aStream, CPassenger aPassenger); }; // class CPassenger //---------------------------------------------------------------------------------------- class CFlight_Record { private: // // class data members // ID_TYPE passenger_id; // id of passenger (9 digits) RES_ID_TYPE reservation_id; // reservation id of flight (6 uppercase) FLIGHT_NUM_TYPE flight_num; // flight number (3 digits, right just.) CDate flight_date; // date of flight SEAT_NUM_TYPE seat_num; // seat number (3 digits + char, right just.) SP_MEAL_TYPE meal_type; // enumerated value of SP_MEAL_TYPE short perceived_quality; // perceived meal quality (1 through 5) BOOL checked_in; // indicates if passenger has checked in BOOL meal_loaded; // indicates if a passengers meal was loaded // // private methods // BOOL check_reservation_id (); // is the reservation id entered correctly? BOOL check_flight_num (); // is the flight number entered correctly? BOOL check_seat_num (); // is the seat number entered correctly? BOOL already_exists (); // is this flight record already in file? BOOL seat_reserved (); // is the seat number already reserved? public: // // data member access methods // char* get_passenger_id () { return passenger_id; } char* get_reservation_id () { return reservation_id; } char* get_flight_num () { return flight_num; } CDate get_flight_date () { return flight_date; } char* get_seat_num () { return seat_num; } SP_MEAL_TYPE get_meal_type () { return meal_type; } short get_perceived_quality () { return perceived_quality; } BOOL get_checked_in () { return checked_in; } BOOL get_meal_loaded () { return meal_loaded; } void set_passenger_id (char* s) { strcpy(passenger_id, strupr(s)); } void set_reservation_id (char* r) { strcpy(reservation_id, strupr(r)); } void set_flight_num (char* f) { strcpy(flight_num, strupr(f)); } void set_flight_date (CDate d) { flight_date = d; } void set_seat_num (char* s) { strcpy(seat_num, strupr(s)); } void set_meal_type (SP_MEAL_TYPE m) { meal_type = m; } void set_perceived_quality (short p) { perceived_quality = p; } void set_checked_in (BOOL c) { checked_in = c; } void set_meal_loaded (BOOL m) { meal_loaded = m; } // // public methods // void get_reservation (); // get all of the flight record info void check_in_passenger (); // update checked_in for a particular // passenger void scan_special_meals (); // for a particular flight, update // meal_loaded for each passenger void scan_postcard (); // update perceived_quality for a // particular passenger // // file methods // void insert (); // place record in proper location in file void write (ofstream& file_name); // write the object to a stream BOOL read (ifstream& file_name); // read an object from a stream }; // class CFlight_Record //---------------------------------------------------------------------------------------- class CReport { protected: // // class data members // CDate from_date; // from_date and to_date represent the CDate to_date; // range of dates used in the report short recs_per_screen; // # of records in a report per screen BOOL print_header; // indicates if the_header is always printed string the_header; // title of the report // // overriden methods // // Description: // - get_qualifications: this method retrieves from the user any values // that are needed to determine if a record // qualifies for inclusion in the report // - qualifies_for_report: this method applies the qualifications to a // flight record to see if it should be in the report // - print_record: this will print a flight record to the screen // based on the type of report // virtual void get_qualifications (); virtual BOOL qualifies_for_report (CFlight_Record aFlight_Record) = 0; virtual void print_record (CFlight_Record aFlight_Record) = 0; public: // // data member access methods // CDate get_from_date () { return from_date; } CDate get_to_date () { return to_date; } void set_from_date (CDate f) { from_date = f; } void set_to_date (CDate t) { to_date = t; } // // public method // void print (); // this method iterates through all flight records // if a flight record qualifies for the report // it will call print_record }; // class CReport //---------------------------------------------------------------------------------------- class CCaterer_Report: public CReport { private: // // data member access methods // FLIGHT_NUM_TYPE flight_num; // the report is for a specific // flight number int special_meal_tally[13]; // used to keep track of all the // different types of special // meals needed on a flight void get_qualifications (); BOOL qualifies_for_report (CFlight_Record aFlight_Record); void print_record (CFlight_Record aFlight_Record); public: // // default constructor // CCaterer_Report () { recs_per_screen = 1; print_header = FALSE; the_header = " Caterer Special Meals List";}; void print (); }; // class CCaterer_Report //---------------------------------------------------------------------------------------- class COn_Board_Report: public CReport { private: // // data member access methods // FLIGHT_NUM_TYPE flight_num; // the report is for a specific flight number void get_qualifications (); BOOL qualifies_for_report (CFlight_Record aFlight_Record); void print_record (CFlight_Record aFlight_Record); public: // // default constructor // COn_Board_Report () { recs_per_screen = 10; print_header = TRUE; the_header = " On Board Meals List\n";}; }; // class COn_Board_Report //---------------------------------------------------------------------------------------- class CNot_Loaded_Report: public CReport { private: BOOL qualifies_for_report (CFlight_Record aFlight_Record); void print_record (CFlight_Record aFlight_Record); BOOL already_encountered (ID_TYPE search_id); BOOL not_loaded_more_than_once(CFlight_Record aFlight_Record); void mark_encountered (ID_TYPE encountered_id); public: // // default constructor // CNot_Loaded_Report () { recs_per_screen = 2; print_header = TRUE; the_header = " Meals Not Loaded Report\n";}; void print (); }; // class CNot_Loaded_Report //---------------------------------------------------------------------------------------- class CPoor_Quality_Report: public CReport { private: BOOL qualifies_for_report (CFlight_Record aFlight_Record); void print_record (CFlight_Record aFlight_Record); public: // // default constructor // CPoor_Quality_Report () { recs_per_screen = 2; print_header = TRUE; the_header = " Poor Quality Report\n";}; }; // class CPoor_Quality_Report //---------------------------------------------------------------------------------------- class CLow_Sodium_Report: public CReport { private: BOOL qualifies_for_report (CFlight_Record aFlight_Record); void print_record (CFlight_Record aFlight_Record); public: // // default constructor // CLow_Sodium_Report () { recs_per_screen = 3; print_header = TRUE; the_header = " Low Sodium Report\n";}; }; // class CLow_Sodium_Report //---------------------------------------------------------------------------------------- class CPercentage_Report: public CReport { private: // // data member access methods // // the following are used to keep track of the different kinds of totals // needed to display the various percentages // int loaded_as_specified_found[13], on_board_found[13]; int on_board_not_loaded[13], total_encountered[13]; BOOL qualifies_for_report (CFlight_Record aFlight_Record); void print_record (CFlight_Record aFlight_Record); public: // // default constructor // CPercentage_Report () { recs_per_screen = 2; print_header = FALSE; the_header = " Percentages Report\n";}; void print (); }; // class CPercentage_Report //---------------------------------------------------------------------------------------- BOOL CPassenger::already_exists () // // determines if the passenger id of the current object already exists in the file // if the id exists, then the user is asked if the values stored in the file // are to be used // { ifstream in_file; // stream object used for file input char ch; // holds user response to Y/N question BOOL found; // indicates if passenger already exists ID_TYPE search_id; // the passenger id to search for strcpy(search_id, passenger_id); found = FALSE; in_file.open ("passenger.dat", ios::in); if (in_file) { // // determine if the passenger object already exists // while (!in_file.eof ()) { if (read (in_file)) // // check if there is a match with the search id // if (strcmp (passenger_id, strupr(search_id)) == 0) { found = TRUE; break; } } // while (!in_file.eof ()) } // if (in_file) in_file.close (); // // a record was found that has the same passenger id // ask the users if they want to use this record in the current // reservation (if the user answers 'N', then a new name/address may be // given to this passenger id // if (found) { cout << endl << endl; cout << "The following passenger exists: \n\n"; cout << *this << endl << endl; cout << "Do you want to use this name and address to make a " << endl << "reservation for this passenger (Y/N)? "; cin >> ch; cout << endl << endl; found = FALSE; if ((ch == 'Y') || (ch == 'y')) found = TRUE; } strcpy(passenger_id, search_id); return found; } // CPassenger::already_exists //---------------------------------------------------------------------------------------- BOOL CPassenger::get_passenger (ID_TYPE search_id) // // load the passenger from the file that has passenger_id equal to search_id // return TRUE if the passenger was found and loaded // { ifstream in_file; // stream object used for file input BOOL found; // indicates if passenger already exists found = FALSE; in_file.open ("passenger.dat", ios::in); if (in_file) { // // determine if the passenger object already exists // while (!in_file.eof ()) { if (read (in_file)) // // check if there is a match with the search_id // if (strcmp (search_id, strupr(passenger_id)) == 0) { found = TRUE; break; } } // while (!in_file.eof ()) } // if (in_file) in_file.close (); return found; } // CPassenger::get_passenger //---------------------------------------------------------------------------------------- void CPassenger::get_description () // // retrieves passenger information // { clear_screen (); cout << "Please enter the following information about the passenger.\n\n"; cout << "Note: - Use an underscore in place of any spaces.\n"; cout << " - Do not leave any request blank.\n\n\n"; cout << "Enter the PASSENGER ID assigned to this passenger" << endl; cout << "(9 numbers only - no spaces or dashes): "; cin >> passenger_id; if (!already_exists ()) { cout << "Enter the FIRST name of the passenger: "; cin >> first_name; cout << "Enter the MIDDLE INITIAL of the passenger: "; cin >> middle_init; cout << "Enter the LAST name of the passenger: "; cin >> last_name; cout << "Enter the SUFFIX used by the passenger: "; cin >> suffix; cout << "Enter the ADDRESS (first line) of the passenger: "; cin >> address1; cout << "Enter the ADDRESS (second line) of the passenger: "; cin >> address2; cout << "Enter the CITY where the passenger lives: "; cin >> city; cout << "Enter the STATE where the passenger lives: "; cin >> state; cout << "Enter the POSTAL CODE where the passenger lives: "; cin >> postal_code; cout << "Enter the COUNTRY where the passenger lives: "; cin >> country; } } // CPassenger::get_description //---------------------------------------------------------------------------------------- void CPassenger::insert () // // inserts a passenger object in the proper place // { ifstream in_tmp, in_copy; // stream objects used for file input ofstream out_tmp, out_copy; // stream objects used for file output BOOL found; // indicates if object insertion point found CPassenger temp_passenger; // temporary object used for file copying found = FALSE; out_tmp.open ("temp_p.dat", ios::out); in_tmp.open ("passenger.dat", ios::in); if (in_tmp) { // // copy the current passenger file to a temporary file // while (!in_tmp.eof ()) // // read/write the temporary passenger object from the passenger file // if (temp_passenger.read (in_tmp)) temp_passenger.write (out_tmp); } // if (in_tmp) in_tmp.close (); out_tmp.close (); out_copy.open ("passenger.dat", ios::out); in_copy.open ("temp_p.dat", ios::in); if (in_copy) { // // copy the temporary file to new passenger file // while inserting the passenger object in the proper location // while (!in_copy.eof ()) { if (temp_passenger.read (in_copy)) { // // check if there is already a passenger with the current id // if one exists, it means a change of address so write the new // passenger object into the file // if (strcmp (temp_passenger.passenger_id, strupr(passenger_id)) == 0) { write (out_copy); found = TRUE; } else temp_passenger.write (out_copy); } // if (temp_passenger.read (in_copy)) } // while (!in_copy.eof ()) } // if (in_copy) if (!found) write (out_copy); in_copy.close (); out_copy.close (); } // CPassenger::insert //---------------------------------------------------------------------------------------- void CPassenger::write (ofstream& file_name) // stream object where passenger information is written // // writes a passenger object to file_name // { file_name << strupr(passenger_id) << endl; file_name << first_name << endl; file_name << middle_init << endl; file_name << last_name << endl; file_name << suffix << endl; file_name << address1 << endl; file_name << address2 << endl; file_name << city << endl; file_name << state << endl; file_name << postal_code << endl; file_name << country << endl; } // CPassenger::write //---------------------------------------------------------------------------------------- BOOL CPassenger::read (ifstream& file_name) // stream object where gallery information is read // // reads a passenger object from file_name // { file_name >> passenger_id; file_name >> first_name; file_name >> middle_init; file_name >> last_name; file_name >> suffix; file_name >> address1; file_name >> address2; file_name >> city; file_name >> state; file_name >> postal_code; file_name >> country; return (strlen (passenger_id) != 0); } // CPassenger::read //---------------------------------------------------------------------------------------- ostream& operator << (ostream& aStream, CPassenger aPassenger) // // writes a passenger object to a stream // { aStream << aPassenger.passenger_id << endl << aPassenger.first_name << " " << aPassenger.middle_init << " " << aPassenger.last_name << " " << aPassenger.suffix << endl << aPassenger.address1 << endl << aPassenger.address2 << endl << aPassenger.city << " " << aPassenger.state << " " << aPassenger.postal_code << " " << aPassenger.country << endl; return aStream; } //---------------------------------------------------------------------------------------- BOOL CFlight_Record::check_reservation_id () // // determines if the reservation_id is valid // { BOOL valid; // indicates if the reservation_id is valid short i; // used to iterate through chars in reservation_id strcpy(reservation_id, strupr(reservation_id)); valid = TRUE; // // make sure that the reservation_id is composed of exactly 6 chars // if ((strlen(reservation_id) == 6)) { for (i=0; i<6; i++) if (!isalpha(reservation_id[i])) valid = FALSE; } else valid = FALSE; return valid; } // CFlight_Record::check_reservation_id //---------------------------------------------------------------------------------------- BOOL CFlight_Record::check_flight_num () // // determines if the flight_num is valid // { BOOL valid; // indicates if the flight_num is valid short i; // used to iterate through chars in flight_num FLIGHT_NUM_TYPE temp_flt_num; // used in right justification valid = TRUE; // // the flight_num must be composed of digits only // for (i=0; i> reservation_id; if (check_reservation_id ()) if (!already_exists ()) reservation_ok = TRUE; else { cout << "\n\tThis RESERVATION ID already exists.\n"; cout << "\tPlease try again...\n\n"; } else { cout << "\n\tA RESERVATION ID must be 6 letters.\n"; cout << "\tPlease try again...\n\n"; } } // // retrieves and validates a value for flight_num // while (!flight_num_ok) { cout << "Enter the FLIGHT NUMBER: "; cin >> flight_num; if (check_flight_num ()) flight_num_ok = TRUE; else { cout << "\n\tA FLIGHT NUMBER must be 3 digits.\n"; cout << "\tPlease try again...\n\n"; } } // // retrieves and validates a value for flight_date // while (!date_ok) { cout << "Enter the DATE of the flight: "; cin >> flight_date; if (flight_date.valid_date() == 0) date_ok = TRUE; else { cout << "\n\tYou entered the date incorrectly.\n"; cout << "\tPlease use the format mmm/dd/yyyy.\n\n"; } } // // retrieves and validates a value for seat_num // while (!seat_ok) { cout << "Enter the SEAT NUMBER assigned to this passenger: "; cin >> seat_num; if (check_seat_num ()) if (!seat_reserved ()) seat_ok = TRUE; else { cout << "\n\tThis seat is already reserved.\n"; cout << "\tPlease choose another seat.\n\n"; } else { cout << "\n\tA SEAT NUMBER must be 3 digits followed by an uppercase letter.\n"; cout << "\tPlease try again...\n\n"; } } // // retrieves and validates a value for meal_type // while (!meal_ok) { cout << endl << endl; cout << "List of available special meals: " << endl << endl; cout << " 0 - Child 1 - Halaal 2 - Kosher" << endl; cout << " 3 - Lactose Free 4 - Low Cal 5 - Low Cholesterol" << endl; cout << " 6 - Low Fat 7 - Low Protein 8 - Low Sodium" << endl; cout << " 9 - Sea Food 10 - Vegan 11 - Vegetarian" << endl; cout << " 12 - REGULAR MEAL" << endl << endl; short tmp_meal_type; cout << "Enter the SPECIAL MEAL for this reservation: "; cin >> tmp_meal_type; meal_type = static_cast(tmp_meal_type); if ((meal_type >= child) && (meal_type <= regular)) meal_ok = TRUE; else { cout << endl << "Invalid response!" << endl; cout << "Please enter a value from the following list:"; } } // // get passenger information and insert the passenger to the passenger file // aPassenger.get_description(); aPassenger.insert (); // // copy the passenger_id from the passenger object to the flight record object // initialize the values for perceived_quality, checked_in, meal_loaded // strcpy(passenger_id, aPassenger.get_passenger_id()); perceived_quality = 0; checked_in = FALSE; meal_loaded = FALSE; insert (); // insert the reservation into the reservation file } // CFlight_Record::get_reservation //---------------------------------------------------------------------------------------- void CFlight_Record::check_in_passenger () // // this will set checked_in to TRUE for a specific reservation // { BOOL reservation_ok; // indicates if reservation id is valid clear_screen (); // // retrieves and validates a value for reservation_id // reservation_ok = FALSE; while (!reservation_ok) { cout << "Enter the RESERVATION ID: "; cin >> reservation_id; if (check_reservation_id ()) reservation_ok = TRUE; else { cout << "\n\tA RESERVATION ID must be 6 letters.\n"; cout << "\tPlease try again...\n\n"; } } // // search for the reservation, set checked_in to TRUE, and then insert the // change // if (already_exists ()) { checked_in = TRUE; insert (); cout << "\n\n\tThe passenger has been checked in." << endl; cout << "\tPlease check their identification." << endl; cout << endl << endl << "Press to return to main menu..."; press_enter (); } else { cout << "\n\n\tThere is no reservation with this id..."; cout << endl << endl << "Press to return to main menu..."; press_enter (); } } // CFlight_Record::check_in_passenger //---------------------------------------------------------------------------------------- void CFlight_Record::scan_special_meals () // // for all of the reservations on a specific flight (flight_num+flight_date), // query the user about whether the meal was loaded and update the file // { ifstream in_tmp, in_copy; // stream objects used for file input ofstream out_tmp, out_copy; // stream objects used for file output CFlight_Record temp_flt_rec; // temporary object used for file copying BOOL date_ok; // indicates if flight date properly entered BOOL flight_num_ok; // indicates if flight_num id is valid char ch; // holds user response to Y/N question date_ok = FALSE; flight_num_ok = FALSE; clear_screen (); // // retrieves and validates a value for flight_date // while (!date_ok) { cout << "Enter the date of this flight: "; cin >> flight_date; if (flight_date.valid_date() == 0) date_ok = TRUE; else { cout << "\n\tYou entered the date incorrectly.\n"; cout << "\tPlease use the format mmm/dd/yyyy.\n\n"; } } // // retrieves and validates a value for flight_num // while (!flight_num_ok) { cout << "Enter the FLIGHT NUMBER: "; cin >> flight_num; if (check_flight_num ()) flight_num_ok = TRUE; else { cout << "\n\tA FLIGHT NUMBER must be 3 digits.\n"; cout << "\tPlease try again...\n\n"; } } clear_screen (); out_tmp.open ("temp_f.dat", ios::out); in_tmp.open ("flt_rec.dat", ios::in); if (in_tmp) { // // copy the current flight record file to a temporary file // while (!in_tmp.eof ()) if (temp_flt_rec.read (in_tmp)) temp_flt_rec.write (out_tmp); } // if (in_tmp) in_tmp.close (); out_tmp.close (); out_copy.open ("flt_rec.dat", ios::out); in_copy.open ("temp_f.dat", ios::in); if (in_copy) { // // copy the temporary file to new flight record file // while inserting the passenger object in the proper location after // updating meal_loaded // while (!in_copy.eof ()) { if (temp_flt_rec.read (in_copy)) { if ((flight_date == temp_flt_rec.get_flight_date ()) && (strcmp(strupr(flight_num), temp_flt_rec.get_flight_num ()) == 0)) { cout << endl << endl << "PASSENGER: " << temp_flt_rec.get_passenger_id () << " SEAT: " << temp_flt_rec.get_seat_num () << " MEAL TYPE: " << SP_MEAL_VALUES[temp_flt_rec.get_meal_type()] << endl << endl << "Was the meal for this passenger loaded (Y/N) ? "; cin >> ch; if ((ch == 'Y') || (ch == 'y')) temp_flt_rec.set_meal_loaded (TRUE); } temp_flt_rec.write (out_copy); } // if (temp_flt_rec.read (in_copy)) } // while (!in_copy.eof ()) } // if (in_copy) in_copy.close (); out_copy.close (); } // CFlight_Record::scan_special_meals //---------------------------------------------------------------------------------------- void CFlight_Record::scan_postcard () // // for a specific reservation this will set perceived_quality to a value entered // by the user and insert the change // { BOOL reservation_ok; // indicates if reservation id is valid clear_screen (); // // retrieves and validates a value for reservation_id // reservation_ok = FALSE; while (!reservation_ok) { cout << "Enter the RESERVATION ID: "; cin >> reservation_id; if (check_reservation_id ()) reservation_ok = TRUE; else { cout << "\n\tA RESERVATION ID must be 6 letters.\n"; cout << "\tPlease try again...\n\n"; } } // // if the reservation exists, get the perceived_quality and then // write the change back to the file // if (already_exists ()) { cout << "Enter perceived meal quality (1 thru 5):"; cin >> perceived_quality; insert (); cout << "\n\n\tThe passenger record has been updated." << endl; cout << endl << endl << "Press to return to main menu..."; press_enter (); } else { cout << "\n\n\tThere is no reservation with this id..."; cout << endl << endl << "Press to return to main menu..."; press_enter (); } } // CFlight_Record::scan_postcard //---------------------------------------------------------------------------------------- void CFlight_Record::insert () // // inserts a flight record object in the proper place // { ifstream in_tmp, in_copy; // stream objects used for file input ofstream out_tmp, out_copy; // stream objects used for file output BOOL found; // indicates if object insertion point found CFlight_Record temp_flt_rec; // temporary object used for file copying found = FALSE; out_tmp.open ("temp_f.dat", ios::out); in_tmp.open ("flt_rec.dat", ios::in); if (in_tmp) { // // copy the current flight record file to a temporary file // while (!in_tmp.eof ()) if (temp_flt_rec.read (in_tmp)) temp_flt_rec.write (out_tmp); } // if (in_tmp) in_tmp.close (); out_tmp.close (); out_copy.open ("flt_rec.dat", ios::out); in_copy.open ("temp_f.dat", ios::in); if (in_copy) { // // copy the temporary file to new flight record file // while inserting the flight record object in the proper location // while (!in_copy.eof ()) { if (temp_flt_rec.read (in_copy)) if (strcmp (temp_flt_rec.reservation_id, strupr(reservation_id)) == 0) { write (out_copy); found = TRUE; } else temp_flt_rec.write (out_copy); } // while (!in_copy.eof ()) } // if (in_copy) if (!found) write (out_copy); in_copy.close (); out_copy.close (); } // CFlight_Record::insert //---------------------------------------------------------------------------------------- void CFlight_Record::write (ofstream& file_name) // stream object where passenger information is written // // writes a flight record object to file_name // { file_name << strupr(passenger_id) << endl; file_name << strupr(reservation_id) << endl; file_name << strupr(flight_num) << endl; file_name << flight_date << endl; file_name << strupr(seat_num) << endl; file_name << meal_type << endl; file_name << perceived_quality << endl; file_name << checked_in << endl; file_name << meal_loaded << endl; } // CFlight_Record::write //---------------------------------------------------------------------------------------- BOOL CFlight_Record::read (ifstream& file_name) // stream object where gallery information is read // // reads a flight record object from file_name // { short tmp_meal_type; file_name >> passenger_id; file_name >> reservation_id; file_name >> flight_num; file_name >> flight_date; file_name >> seat_num; file_name >> tmp_meal_type; meal_type = static_cast(tmp_meal_type); file_name >> perceived_quality; file_name >> checked_in; file_name >> meal_loaded; return (strlen (passenger_id) != 0); } // CFlight_Record::read //---------------------------------------------------------------------------------------- void CReport::get_qualifications () // // this is the default method for get_qualifications // it will obtain the start and ending dates that define the range of the report // { BOOL date_ok; // indicates if a date was properly entered BOOL range_ok; // indicates if report range properly entered clear_screen (); range_ok = FALSE; while (!range_ok) { // // retrieves and validates a value for the start date of the report // date_ok = FALSE; while (!date_ok) { cout << "Enter the start date for the report: "; cin >> from_date; if (from_date.valid_date() == 0) date_ok = TRUE; else { cout << "\n\tYou entered the date incorrectly.\n"; cout << "\tPlease use the format mmm/dd/yyyy.\n\n"; } } // while (!date_ok) // // retrieves and validates a value for the end date of the report // date_ok = FALSE; while (!date_ok) { cout << "Enter the end date for the report: "; cin >> to_date; if (to_date.valid_date() == 0) date_ok = TRUE; else { cout << "\n\tYou entered the date incorrectly.\n"; cout << "\tPlease use the format mmm/dd/yyyy.\n\n"; } } // while (!date_ok) // // retrieves and validates the report date range // if ((to_date > from_date) || (to_date == from_date)) range_ok = TRUE; else { cout << "\n\tThe 'end' date is less than the 'start' date.\n"; cout << "\tPlease enter a valid date range.\n\n"; } } // while (!range_ok) } // CReport::get_qualifications //---------------------------------------------------------------------------------------- void CReport::print () // // this is the default method for printing a report // it will iterate through all of the records in the flight record file // for each record that qualifies for the report, the print_record // function is invokd // { ifstream in_file; // stream object used for file input int num_recs; // count of total flight records CFlight_Record temp_flight_record; // used to iterate through all // flight records in the file get_qualifications (); clear_screen (); in_file.open ("flt_rec.dat", ios::in); num_recs = 0; if (in_file) { // // read in all flight records and determine if they are // candidates for the report // while (!in_file.eof ()) { if (temp_flight_record.read (in_file)) { // // check if the flight date is within the given range // and that this the record qualifies for the report // if (qualifies_for_report(temp_flight_record)) { if (print_header) { // // pause the screen after every recs_per_screen flight records // if (((num_recs % recs_per_screen) == 0) && (num_recs != 0)) { cout << endl << endl; cout << " Press to view the next screen..."; press_enter (); } // // display a header message after every third flight record // if ((num_recs % recs_per_screen) == 0) { clear_screen (); cout << endl << endl; cout << "\t\t Air Gourmet\n"; cout << "\t\t\t" << the_header; } } // if (print_header) // // call the method to handle this record // print_record(temp_flight_record); num_recs++; } // if ((from_date < temp_flight_record.get_flight_date ()) && } // if (qualifies_for_report(temp_flight_record)) } // while (!in_file.eof ()) } // if (in_file) in_file.close (); // // print the report trailer // if (print_header) { if (num_recs == 0) cout << endl << endl << "\tThere were no records to print..." << endl << endl; cout << endl << endl << "Press to return to main menu..."; press_enter (); } } // CReport::print //---------------------------------------------------------------------------------------- void CCaterer_Report::get_qualifications () // // the caterer report requires a flight date and a flight number // { BOOL date_ok; // indicates if flight date properly entered clear_screen (); date_ok = FALSE; // // retrieves and validates a value for the flight date used in the report // while (!date_ok) { cout << "Enter the date of this flight: "; cin >> from_date; if (from_date.valid_date() == 0) date_ok = TRUE; else { cout << "\n\tYou entered the date incorrectly.\n"; cout << "\tPlease use the format mmm/dd/yyyy.\n\n"; } } // // retrieves a value for flight_num // cout << "Enter the FLIGHT NUMBER: "; cin >> flight_num; } // CCaterer_Report::get_qualifications //---------------------------------------------------------------------------------------- BOOL CCaterer_Report::qualifies_for_report (CFlight_Record aFlight_Record) // // a record qualifies for this report by having the same flight date // and flight number as that specified by the user // { return ((aFlight_Record.get_flight_date () == from_date) && (strcmp(aFlight_Record.get_flight_num (), flight_num) == 0)); } // CCaterer_Report::qualifies_for_report //---------------------------------------------------------------------------------------- void CCaterer_Report::print_record (CFlight_Record aFlight_Record) // // this method does not print any information // it updates an array that keeps track of the different kinds of meals that // need to be delivered by the caterer // { ++special_meal_tally[aFlight_Record.get_meal_type ()]; } // CCaterer_Report::print_record //---------------------------------------------------------------------------------------- void CCaterer_Report::print () // // this overrides the print method in the base class // it initializes an array that keeps track of meals, calls the base // class print method, and then prints out the array // { int i; for (i=0; i < 13; i++) special_meal_tally[i] = 0; CReport::print (); cout << "\t\t Air Gourmet\n"; cout << "\t\t\t" << the_header << endl << endl; cout << "MEAL TYPE\t\t NUMBER OF MEALS NEEDED" << endl; cout << "-----------------------------------------------------------------------------\n"; for (i=0; i < 13; i++) cout << SP_MEAL_VALUES[i] << "\t\t\t " << special_meal_tally[i] << endl; cout << endl << endl << "Press to return to main menu..."; press_enter (); } // CCaterer_Report::print //---------------------------------------------------------------------------------------- void COn_Board_Report::get_qualifications () // // the on-board report requires a flight date and a flight number // { BOOL date_ok; // indicates if flight date properly entered clear_screen (); date_ok = FALSE; // // retrieves and validates a value for the flight date used in the report // while (!date_ok) { cout << "Enter the date of this flight: "; cin >> from_date; if (from_date.valid_date() == 0) date_ok = TRUE; else { cout << "\n\tYou entered the date incorrectly.\n"; cout << "\tPlease use the format mmm/dd/yyyy.\n\n"; } } // // retrieves a value for flight_num // cout << "Enter the FLIGHT NUMBER: "; cin >> flight_num; } // COn_Board_Report::get_qualifications //---------------------------------------------------------------------------------------- BOOL COn_Board_Report::qualifies_for_report (CFlight_Record aFlight_Record) // // a record qualifies for this report by having the same flight date // and flight number as that specified by the user // { return ((aFlight_Record.get_flight_date () == from_date) && (strcmp(aFlight_Record.get_flight_num (), flight_num) == 0)); } // COn_Board_Report::qualifies_for_report //---------------------------------------------------------------------------------------- void COn_Board_Report::print_record (CFlight_Record aFlight_Record) // // output the passenger, seat number, meal type, and checkbox for this record // { cout << "-----------------------------------------------------------------------------\n"; cout << "PASSENGER: " << aFlight_Record.get_passenger_id () << " SEAT: " << aFlight_Record.get_seat_num () << " MEAL TYPE: " << SP_MEAL_VALUES[aFlight_Record.get_meal_type()] << " |__|" << endl; } // COn_Board_Report::print_record //---------------------------------------------------------------------------------------- BOOL CNot_Loaded_Report::qualifies_for_report (CFlight_Record aFlight_Record) // // a record qualifies for this report by being within the date range // of the report and having more than one meal not loaded within the date range // { return (((aFlight_Record.get_flight_date () > from_date) || (aFlight_Record.get_flight_date () == from_date)) && ((to_date > aFlight_Record.get_flight_date ()) || (to_date == aFlight_Record.get_flight_date ())) && (!already_encountered(aFlight_Record.get_passenger_id ())) && (not_loaded_more_than_once(aFlight_Record))); } // CNot_Loaded_Report::qualifies_for_report //---------------------------------------------------------------------------------------- void CNot_Loaded_Report::print_record (CFlight_Record aFlight_Record) // // output the passenger name/address and the dates when a meal was not loaded // { ifstream in_file; // stream object used for file input CFlight_Record temp_flt_rec; // temporary record used for reading in // all reservations CPassenger temp_passenger; // represents the passenger assigned to // this reservation if (temp_passenger.get_passenger (aFlight_Record.get_passenger_id ())) { mark_encountered (temp_passenger.get_passenger_id ()); cout << "-----------------------------------------------------------------------------\n"; cout << "PASSENGER: " << temp_passenger << endl; cout << "DATES: "; } in_file.open ("flt_rec.dat", ios::in); if (in_file) { // // loop through all flight records // while (!in_file.eof ()) { temp_flt_rec.read (in_file); // // check if there is a match with the current flight record object // must have the same passenger_id and be within report date range // if ((strcmp (temp_flt_rec.get_passenger_id (), aFlight_Record.get_passenger_id ()) == 0) && ((temp_flt_rec.get_flight_date () > from_date) || (temp_flt_rec.get_flight_date () == from_date)) && ((to_date > temp_flt_rec.get_flight_date ()) || (to_date == temp_flt_rec.get_flight_date ()))) cout << temp_flt_rec.get_flight_date () << " "; } // while (!in_file.eof ()) cout << endl; } // if (in_file) in_file.close (); } // CNot_Loaded_Report::print_record //---------------------------------------------------------------------------------------- BOOL CNot_Loaded_Report::already_encountered (ID_TYPE search_id) // // determine if a passenger id has already been encountered by this report // { ifstream in_file; // stream object used for file input BOOL found; // indicates if passenger already encountered ID_TYPE temp_id; // temporary passenger id read from file found = FALSE; in_file.open ("not_loaded.dat", ios::in); if (in_file) { // // loop through all previously processed passenger ids // while (!in_file.eof ()) { in_file >> temp_id; // // check if there is a match // if (strcmp (temp_id, search_id) == 0) { found = TRUE; break; } } // while (!in_file.eof ()) } // if (in_file) in_file.close (); return found; } // CNot_Loaded_Report::already_encountered //---------------------------------------------------------------------------------------- BOOL CNot_Loaded_Report::not_loaded_more_than_once(CFlight_Record aFlight_Record) // // determine if a passenger has had more than one meal not loaded // { ifstream in_file; // stream object used for file input short not_loaded_count; // count of not loadeds CFlight_Record temp_flt_rec; // temporary record used for reading in // and comparing all reservations not_loaded_count = 0; in_file.open ("flt_rec.dat", ios::in); if (in_file) { // // loop through all flight records // while (!in_file.eof ()) { temp_flt_rec.read (in_file); // // check if there is a match with the current flight record object // must have the same passenger_id and be within report date range // if ((strcmp (temp_flt_rec.get_passenger_id (), aFlight_Record.get_passenger_id ()) == 0) && ((temp_flt_rec.get_flight_date () > from_date) || (temp_flt_rec.get_flight_date () == from_date)) && ((to_date > temp_flt_rec.get_flight_date ()) || (to_date == temp_flt_rec.get_flight_date ()))) { not_loaded_count++; if (not_loaded_count > 1) break; } } // while (!in_file.eof ()) } // if (in_file) in_file.close (); return (not_loaded_count > 1); } // CNot_Loaded_Report::not_loaded_more_than_once //---------------------------------------------------------------------------------------- void CNot_Loaded_Report::mark_encountered(ID_TYPE encountered_id) // // add the current passenger id to the not_loaded file // { ifstream in_tmp, in_copy; // stream objects used for file input ofstream out_tmp, out_copy; // stream objects used for file output ID_TYPE temp_passenger_id; // temporary object used for file copying out_tmp.open ("temp_not.dat", ios::out); in_tmp.open ("not_loaded.dat", ios::in); if (in_tmp) { // // copy the current not_loaded file to a temporary file // while (!in_tmp.eof ()) { in_tmp >> temp_passenger_id; out_tmp << temp_passenger_id << endl; } } // if (in_tmp) in_tmp.close (); out_tmp.close (); out_copy.open ("not_loaded.dat", ios::out); in_copy.open ("temp_not.dat", ios::in); if (in_copy) { // // copy the temporary file to new not_loaded file // while inserting the new passenger id in the proper location // while (!in_copy.eof ()) { in_copy >> temp_passenger_id; out_copy << temp_passenger_id << endl; } } // if (in_copy) out_copy << encountered_id; in_copy.close (); out_copy.close (); } // CNot_Loaded_Report::mark_encountered //---------------------------------------------------------------------------------------- void CNot_Loaded_Report::print () // // initialize a needed file before calling the base class print method // { ofstream out_file; // stream object used to delete a file // // delete the not_loaded file before printing the report // out_file.open ("not_loaded.dat", ios::out); out_file.close (); CReport::print (); } // CNot_Loaded_Report::print () //---------------------------------------------------------------------------------------- BOOL CPoor_Quality_Report::qualifies_for_report (CFlight_Record aFlight_Record) // // a record qualifies for this report by being a special meal within the date // range of the report with a perceived quality less than 5 // { return (((aFlight_Record.get_flight_date () > from_date) || (aFlight_Record.get_flight_date () == from_date)) && ((to_date > aFlight_Record.get_flight_date ()) || (to_date == aFlight_Record.get_flight_date ())) && (aFlight_Record.get_perceived_quality() < 5) && (aFlight_Record.get_meal_type () < regular)); } // CPoor_Quality_Report::qualifies_for_report //---------------------------------------------------------------------------------------- void CPoor_Quality_Report::print_record (CFlight_Record aFlight_Record) // // output the passenger, flight date, and meal type // { CPassenger temp_passenger; // represents the passenger assigned to // this reservation if (temp_passenger.get_passenger (aFlight_Record.get_passenger_id ())) { cout << "-----------------------------------------------------------------------------\n"; cout << "PASSENGER: " << temp_passenger << endl; cout << "FLIGHT DATE: " << aFlight_Record.get_flight_date() << " MEAL TYPE: "; if (aFlight_Record.get_meal_loaded () == FALSE) cout << "(not loaded) "; cout << SP_MEAL_VALUES[aFlight_Record.get_meal_type()] << endl; } } // CPoor_Quality_Report::print_record //---------------------------------------------------------------------------------------- BOOL CLow_Sodium_Report::qualifies_for_report (CFlight_Record aFlight_Record) // // a record qualifies for this report by being a loaded low-sodium meal within // the date range of the report // { return (((aFlight_Record.get_flight_date () > from_date) || (aFlight_Record.get_flight_date () == from_date)) && ((to_date > aFlight_Record.get_flight_date ()) || (to_date == aFlight_Record.get_flight_date ())) && (aFlight_Record.get_meal_type () == low_sodium) && (aFlight_Record.get_meal_loaded () == TRUE)); } // CLow_Sodium_Report::qualifies_for_report //---------------------------------------------------------------------------------------- void CLow_Sodium_Report::print_record (CFlight_Record aFlight_Record) // // output the flight number, flight date, and perceived quality // { cout << "-----------------------------------------------------------------------------\n"; cout << "FLIGHT NUMBER: " << aFlight_Record.get_flight_num() << endl; cout << "FLIGHT DATE: " << aFlight_Record.get_flight_date() << endl; cout << "PERCEIVED QUALITY: " << aFlight_Record.get_perceived_quality() << endl; } // CLow_Sodium_Report::print_record //---------------------------------------------------------------------------------------- BOOL CPercentage_Report::qualifies_for_report (CFlight_Record aFlight_Record) // // a record qualifies for this report by being a special meal within the date // range of the report // { return (((aFlight_Record.get_flight_date () > from_date) || (aFlight_Record.get_flight_date () == from_date)) && ((to_date > aFlight_Record.get_flight_date ()) || (to_date == aFlight_Record.get_flight_date ())) && (aFlight_Record.get_meal_type () < regular)); } // CPercentage_Report::qualifies_for_report //---------------------------------------------------------------------------------------- void CPercentage_Report::print_record (CFlight_Record aFlight_Record) // // this method does not print any information // it updates several arrays that keep track of the different kinds of // percentages // { ++total_encountered[aFlight_Record.get_meal_type ()]; ++total_encountered[12]; if (aFlight_Record.get_meal_loaded () == TRUE) { ++loaded_as_specified_found[aFlight_Record.get_meal_type ()]; ++loaded_as_specified_found[12]; } if (aFlight_Record.get_checked_in () == TRUE) { ++on_board_found[aFlight_Record.get_meal_type ()]; ++on_board_found[12]; } if ((aFlight_Record.get_checked_in () == TRUE) && (aFlight_Record.get_meal_loaded () == FALSE)) { ++on_board_not_loaded[aFlight_Record.get_meal_type ()]; ++on_board_not_loaded[12]; } } // CPercentage_Report::print_record //---------------------------------------------------------------------------------------- void CPercentage_Report::print () // // this overrides the print method in the base class // it initializes an array that keeps track of meals, calls the base // class print method, and then prints out the array // { int i; for (i=0; i < 13; i++) { loaded_as_specified_found[i] = 0; on_board_found[i] = 0; on_board_not_loaded[i] = 0; total_encountered[i] = 0; } CReport::print (); // // print header // cout << "\t\t Air Gourmet\n"; cout << "\t\t\t" << the_header << endl << endl; cout << "MEAL TYPE\t % LOADED\t % ON BOARD" << "\t % ON BOARD, NOT LOADED" << endl; cout << "-----------------------------------------------------------------------------\n"; // // print the percentages for each meal type // for (i=0; i < 12; i++) { cout << SP_MEAL_VALUES[i] << "\t "; if (total_encountered[i] == 0) cout << " NA\t\t"; else cout << float(loaded_as_specified_found[i]) / float(total_encountered[i]) * 100 << " \t\t"; if (total_encountered[i] == 0) cout << " NA\t\t "; else cout << float(on_board_found[i]) / float(total_encountered[i]) * 100 << "\t\t "; if (total_encountered[i] == 0) cout << " NA"; else cout << float(on_board_not_loaded[i]) / float(total_encountered[i]) * 100; cout << endl; } // // print the totals // cout << endl << "TOTALS: \t "; if (total_encountered[12] == 0) cout << " NA\t\t"; else cout << float(loaded_as_specified_found[12]) / float(total_encountered[12]) * 100 << " \t\t"; if (total_encountered[12] == 0) cout << " NA\t\t "; else cout << float(on_board_found[12]) / float(total_encountered[12]) * 100 << "\t\t "; if (total_encountered[12] == 0) cout << " NA"; else cout << float(on_board_not_loaded[12]) / float(total_encountered[12]) * 100; cout << endl << endl << "Press to return to main menu..."; press_enter (); } // CPercentage_Report::print //---------------------------------------------------------------------------------------- BOOL CDate::isLeapYear () // // this function determines if the current year is a leap year // { if ( year % 4 != 0 ) return FALSE; else { if ( year % 100 != 0 ) return TRUE; else if ( year % 400 != 0 ) return FALSE; else return TRUE; } } // CDate::isLeapYear //---------------------------------------------------------------------------------------- short CDate::days_in_month () // // this functions returns the number of days that are in a given month // { switch (month) { case 2: if ( isLeapYear() ) return 29; else return 28; case 4: case 6: case 9: case 11: return 30; default: return 31; } } // CDate::days_in_month //---------------------------------------------------------------------------------------- BOOL CDate::operator > (CDate d) // // return TRUE if this > d.date, 0 otherwise // { return year == d.getYear() ? (month == d.getMonth() ? day > d.getDay() : month > d.getMonth()) : year > d.getYear(); } //---------------------------------------------------------------------------------------- BOOL CDate::operator == (CDate d) // // return TRUE if this = d.date, 0 otherwise // { return ((year == d.getYear()) && (month == d.month) && (day == d.day)); } //---------------------------------------------------------------------------------------- ostream& operator << (ostream& aStream, CDate aDate) // // output the date to a stream in the format of "mmm/dd/yyyy" // { aStream << aDate.monthname << '/' << (aDate.getDay() < 10 ? "0" : "") << aDate.getDay() << '/' << aDate.getYear(); return aStream; } istream& operator >> (istream& aStream, CDate& aDate) // // to input a date, read a string into strdate and then validate it // { aStream >> aDate.strdate; aDate.valid_date(); return aStream; } //---------------------------------------------------------------------------------------- void CDate::breakup_date () // // given a valid date in the format MMM/DD/YYYY, returns the // integer components of the respective year and day, and the // abbreviation of the month // { char tempyear[5], tempday[3]; // for storing parts of date // // retrieve the monthname component from the date string // monthname[0] = strdate[0]; monthname[1] = strdate[1]; monthname[2] = strdate[2]; strcpy(monthname, strupr(monthname)); // // retrieve the day component from the date string // tempday[2] = '\0'; tempday[0] = strdate[4]; tempday[1] = strdate[5]; day = atoi (tempday); // // retrieve the year component from the date string // tempyear[4] = '\0'; tempyear[0] = strdate[7]; tempyear[1] = strdate[8]; tempyear[2] = strdate[9]; tempyear[3] = strdate[10]; year = atoi (tempyear); } // CDate::breakup_date //---------------------------------------------------------------------------------------- short CDate::valid_date () // // determines if the string contained in date corresponds to a valid date // of the form mmm/dd/yyyy, where 1 <= mm <= 12, 1 <= dd <= 31, 0 <= yyyy <= ???? // return 0 iff the date is valid // { int i; static char monthAbbrev[12][4] = {"JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","NOV","OCT","DEC"}; // // ensure that the slashes are in the proper place // if ((strdate[3] != '/') || (strdate[6] != '/')) return -1; monthname[3] = '\0'; month = 0; // // obtain all the integer components of date // breakup_date (); // // convert the three-letter month to a numeric equivalent // for (i=0; i < 12; i++) if (strcmp(monthAbbrev[i], strupr(monthname)) == 0) { month = i + 1; break; } // // check that the year component makes sense // if ((year < 0) || (year > 2999)) return -1; // // check that the month component makes sense // if ((month < 1) || (month > 12)) return -1; // // check that the day component makes sense // if ((day < 1) || (day > days_in_month())) return -1; else return 0; } // CDate::valid_date //---------------------------------------------------------------------------------------- void main (void) { // // initialize float output to two digits after the decimal point // cout.precision (2); cout.setf (ios::showpoint); cout.setf (ios::fixed); display_main_menu (); } // main //---------------------------------------------------------------------------------------- void clear_screen (void) // // // clears the screen // { int i; // loop counter representing number of blank lines to be printed // // implementation-dependent code to clear the screen should replace // the code given below // for (i = 0; i < 26; i++) cout << endl; } // clear_screen //---------------------------------------------------------------------------------------- void press_enter (void) // // waits until the user presses the key // { char ch; // dummy variable used to induce keyboard input fflush (stdin); cout << endl; ch = getchar (); } // press_enter //---------------------------------------------------------------------------------------- void display_main_menu (void) // // displays the main menu containing all the options available to the user // { int done; // terminates do-loop char choice; // user's choice CFlight_Record flight_record; // tempoary flight record used to // invoke flight record operations done = FALSE; while (!done) { clear_screen (); cout << "\t MAIN MENU\n\n"; cout << "\t Air Gourmet\n\n"; cout << "\t 1. Enter a Reservation\n\n"; cout << "\t 2. Check-in a Passenger\n\n"; cout << "\t 3. Scan the Special Meals List\n\n"; cout << "\t 4. Scan a Returned Postcard\n\n"; cout << "\t 5. Produce a Report\n\n"; cout << "\t 6. Quit\n\n\n"; cout << "\t Enter your choice and press : "; cin >> choice; switch (choice) { case '1': flight_record.get_reservation (); break; case '2': flight_record.check_in_passenger (); break; case '3': flight_record.scan_special_meals (); break; case '4': flight_record.scan_postcard (); break; case '5': display_report_menu (); break; case '6': cout << endl << endl << "Thank you for using Air Gourmet!!" << endl; done = TRUE; break; default: cout << endl << endl << "Choice is out of range\n\n"; cout << " Press to return to menu..."; press_enter (); break; } // switch (choice) } // while (!done) } // display_main_menu //---------------------------------------------------------------------------------------- void display_report_menu (void) // // allows user to select the type of report to be displayed // { int done; // terminates do-loop char choice; // user's choice // // report objects // CCaterer_Report caterer_report; COn_Board_Report on_board_report; CPercentage_Report percentage_report; CNot_Loaded_Report not_loaded_report; CPoor_Quality_Report poor_quality_report; CLow_Sodium_Report low_sodium_report; done = FALSE; while (!done) { clear_screen (); cout << "\t REPORT MENU\n\n"; cout << "\t Air Gourmet\n\n"; cout << "\t 1. 24 Hour Caterer List\n\n"; cout << "\t 2. On Board Meals List\n\n"; cout << "\t 3. Report on Percentages\n\n"; cout << "\t 4. Report on Meals not Loaded\n\n"; cout << "\t 5. Report on Poor Quality\n\n"; cout << "\t 6. Report on Low Sodium\n\n"; cout << "\t 7. Return to Main Menu\n\n\n"; cout << "\t Enter your choice and press : "; cin >> choice; switch (choice) { case '1': caterer_report.print (); break; case '2': on_board_report.print (); break; case '3': percentage_report.print (); break; case '4': not_loaded_report.print (); break; case '5': poor_quality_report.print (); break; case '6': low_sodium_report.print (); break; case '7': done = TRUE; break; default: cout << endl << endl << "Choice is out of range\n\n"; cout << " Press to return to menu..."; press_enter (); break; } // switch (choice) } // while (!done) } // display_report_menu //----------------------------------------------------------------------------------------