//FlightDatabase.h -- assignment 3, summer 2001 //author: Rebecca Price, id: XXXXXXX, section: AA, TA: Man Chun Liu #ifndef FLIGHTDATABASE_H #define FLIGHTDATABASE_H #include "flightinfo.h" class FDatabase{ public: FDatabase(); //Default Constructor. Sets private data members to zero/empty values. FDatabase(const FDatabase& other); //Copies one Flight Database array into a new variable. //Precondition: the passed in FDatabase variable must have been // initialized. //Postcondition: The two instances of FDatabase contain the same info // as other. FDatabase& operator= (const FDatabase& other); //Allows the info of one instance of FDatabase to be copied into // another instance of FDatabase. //Precondition: the two instances have been declared. //Postcondition: the two instances contain the same info as other. ~FDatabase(); bool OpenFlightFile(); //Function that will open the file that contains // the flight info. If thefile is not read in properly // an error message will be printed and the user will be // returned to the menu. If the file is read correctly the // function will return true and the information will be // contained in the class Flight. void EnsureCapacity(int requireSize); //Makes sure that the array is capable of containing all the info // being passed into the flightArray. //Precondition: the size needed is passed into the function. The // current capacity has a value. //Postcondition: the array capacity is enlargened if the required size is // greater than that of the current capapcity. void AddFlight(Flight& other, int size); //Adds the info stored in other into the next indice(size) of the given flightArray. //Precondition: there is currently an instance of Flight opened. The size is allowed // or the capacity of the array is large enough. //Postcondition: the info of other is now stored in the sizeth element of an instance // of Flight. void SetCapacity(int current); //Sets the capacity to a given value. //Precondition: the value passed into the function is an int. //Postcondition: the capacity is equal to the value of current. int GetCapacity() const; //Returns the value of capacity. //Precondition: capacity has been intialized. //Postcondition: the value of capacity is returned. No values are changed. void SetSize(int arraySize); //Sets the size to the value of arraySize. //Precondition: The value passed into the function is an int. //Postcondition: size is equal to the value of arraySize. int GetSize() const; //Returns the value of size without changing the value. //Precondition: Size has been initialized. //Postcondition: the value of size is returned without changing the value. void CancelFlight(); //Asks the user for the number next to the flight they want to cancel from the // database. The it stores that value and copies the over that indice by moving // all the flights above the given one into the spot before it. Cover over values and // decreases the size by one. //Precondition: the user has selected the value 'c or C' from the main menu. //Postcondition: the flight the user selected has been removed and the size has // decreased by one. int SearchFlight(string number); //Searches the current flight database for any flights that have the same flight // number as the one passed in the parameter. //Preconditions: There is currently a flight array database and there is a string // passed in the parameter. //Postconditions: Returns the index of the flight that contains a flight number // matching the value of the passed parameter. void SortFlight(Flight* fArray, int fCount); //Sorts the current flight array according to price in acsending order. //Precondtions: A valid array of flights is passed and an int is passed for fCount. //Postconditions: The array is sorted in ascending order by price. void PrintFlightInfo(); //Prints out the information in a Flight array. //Preconditions: none. //Postconditions: Prints out all the flights in the database. void PrintFlightInfo(Flight* fArray, int fCount, string title); //Prints out the information contained in the passed flight array according to its // current size. //Preconditions: The proper parameters are passed into the function. //Postconditions: The flight contained in the flight array are printed out. void FlightReserve(); //Deals with asking the user for a flight they want to reserve. Then searched the database // for any matches. When a match is found it is stored in a new Flight* reservedMatches. // This new, local, Flight array is then sent to PrintFlight Info with the necessary // parameters so that it prints out only the flights in reservedMatches. //Preconditions: There is a database for the flight the user wants to be compared to. //Postconditions: The flights that match the user's request are printed out. At the end of // the function the Flight array reservedMatches is removed. void PrintReservationInfo(Flight* fArray, int fCount, string title); private: Flight* flightArray; //Variable to hold the info pretaining to Flight of several flights. int size; //Current number of flights in the array. int capacity; //Current capacity of array, flightArray. void cleanup(); //Deletes any allocated memory. void copy(const FDatabase& other); // Copies the information of instance other into another instance of FDatabase. //Preconditions: the function is called with a declared instance of FDatabase. //Postconditions: the new instance contains the same info as instance other. bool updateInfo(Flight& other); //If there flight numbers are the same during reading of the file the latest info // for the flight number replaces the older info. //Precondition: the flight numbers of the twoi instances are equal. //Postcondtion: the info in the flight database now contains the update for that flight number. void CompactFlightDataBase(int spareCapacityCount); //Compacts the array by copying the non-canceled flight (those whose variable canceledFlight is false) // into a new array and then deallocates the old array and resets it to the new one, with spare capacity. //Preconditions: there is a flightArray, database. //Postconditions: the flights that have their variable canceledFlight set to true are no longer in the // database. Those that have not been canceled are still there, with no empty spaces between them and // there is extra capacity set at the end of the array. }; #endif