|
//file Flights002.cpp //date 12/04/2006 //author aou //csis250.tripod.com // Flights and Flights /////////////////////////////////////////////////////////// //includes /////////////////////////////////////////////////////////// #include <iostream> using namespace std; const int TEST_COUNT = 5; const int MAX_CHARS = 30; char *testCities[] = {"MCI", "LAX", "NYC", "CHI", "JAX", "SJC", "STL", "TUL", "PIT"}; const int CITIES_COUNT = sizeof(testCities)/4; class CFlight { private: char orig[MAX_CHARS]; char dest[MAX_CHARS]; int cost; CFlight *next; public: CFlight(void); CFlight(char orig[], char dest[], int cost); CFlight(char ch); friend class CFlights; friend ostream & operator << (ostream & bob, const CFlight &flight); }; class CFlights { private: int count; CFlight *first; CFlight *last; public: CFlights(void); CFlights(int n); CFlights(char ch); bool add(char orig[], char dest[], int cost); CFlight * findFlight(char orig[], char dest[]); CFlights * findFlights(char orig[], char dest[]); CFlight * findCheapestFlight(char orig[], char dest[]); CFlights * findFlightsOrderedByCost(char orig[], char dest[]); friend ostream & operator << (ostream & bob, const CFlights &flights); }; void test_CFlight_constructorDefault(void); void test_CFlight_constructorSecond(void); void main(void) { //test_CFlight_constructorDefault(); //test_CFlight_constructorSecond(); cout << CITIES_COUNT << endl; } void test_CFlight_constructorSecond(void) { cout << "======================\n"; cout << "test_CFlight_constructorSecond \n"; cout << "======================\n"; for (int i=1; i<=TEST_COUNT; i++) { CFlight myFlight("MCI", "LAX", 50); cout << myFlight << endl; CFlight yourFlight("LAX", "MCI", 90); cout << yourFlight << endl; cout << "----------------------\n"; } } CFlight::CFlight(char orig[], char dest[], int cost) { this->cost = cost; strcpy(this->orig, orig); strcpy(this->dest, dest); this->next = NULL; } void test_CFlight_constructorDefault(void) { cout << "======================\n"; cout << "test_CFlight_constructorDefault \n"; cout << "======================\n"; for (int i=1; i<=TEST_COUNT; i++) { CFlight myFlight; cout << myFlight << endl; CFlight yourFlight; cout << yourFlight << endl; cout << "----------------------\n"; } } CFlight::CFlight(void) { this->cost = 0; strcpy(this->orig, "??"); strcpy(this->dest, "??"); this->next = NULL; } ostream & operator << (ostream & bob, const CFlight &flight) { bob << "flight at " << &flight << "(" << flight.orig << ", " << flight.dest << ", " << flight.cost << ", " << flight.next << ")\n"; return bob; } |