Пример #1
0
// Inserts flight into LinkedList based on string parameters for Flight attributes
void addFlight(string FlightNumber, double price, string departure, int duration, string sourceAirportName, string destinationAirportName, string company) {
	
	FlightNode *newFlightNode;					
	if (company.compare("USAirway") == 0) {
		newFlightNode = new FlightUSAirway();	// Inhertiance
	} else if (company.compare("Delta") == 0) {
		newFlightNode = new FlightDelta();		// Inhertiance 
	} else {
		newFlightNode = new FlightSouthWest();	// Inhertiance 
	}
	

	Date_Time *departureTime = new Date_Time(departure);		// create pointer to date_time class and use the ptr to access the date and time values
	Date_Time *arrivalTime = new Date_Time(departure);
	HubNode* sourceHub = searchHub(sourceAirportName, headHub);  
	HubNode* destinationHub = searchHub(destinationAirportName, headHub);  

	newFlightNode->flightCompany = company;
	newFlightNode->flightNumber = FlightNumber;
	newFlightNode->price = price;
	newFlightNode->departure = departureTime; 
	newFlightNode->departure->AddMinutes(newFlightNode->getDelay());
	newFlightNode->duration = duration;
	newFlightNode->source = sourceHub;
	newFlightNode->destination = destinationHub;
	arrivalTime->AddMinutes(duration + newFlightNode->getDelay());
	newFlightNode->arrival = arrivalTime;

	// Insert new flight node into linked list
	newFlightNode->next = sourceHub->headFlights;
	sourceHub->headFlights = newFlightNode;

};
Пример #2
0
/* Recursive function that searches for the cheapest flight.
	Parameters:
		HubNode* source => a pointer to the hubNode that the function is currently iterating through
		string destination => the string name of the destination city (e.g. Phoenix)
		FlightPlan* lowest => a pointer to the FlightPlan holding the currently cheapest flight
		FlightPlan* tracking => a pointer to the FlightPlan holding the current path
		int depth => an integer tracking the current number of flights in the tracking path
*/
void searchForCheapest(HubNode* source, string destination, FlightPlan* lowest, FlightPlan* tracking, int depth, Date_Time *startDate, Date_Time *endDate, int bags) {
	if (tracking->endHub->location.compare(destination) == 0 && timeBetween(startDate, tracking->startTime) >= 0 && timeBetween(tracking->calculateArrivalTime(), endDate) >=0 ) {
		/* If the tracking FlightPlan ends at our desired location, we need to check if it is cheaper than
			the lowest flight plan, and then return. */
		if (lowest->calculateCost(bags) < 0 || tracking->calculateCost(bags) < lowest->calculateCost(bags)) {
			// If the tracking FlightPlan is cheaper than the lowest FlightPlan, transfer all data to lowest
			for (int i = 0; i < 2; i++) {
				lowest->path[i] = tracking->path[i];
			}
			lowest->startTime = tracking->startTime;
			lowest->endHub = tracking->endHub;
		}

		return;
	} else if (depth == 2) {
		/* If the depth has reached 2 without arriving to the desired destination, return */
		return;
	} else {
		/* If we have only 0 or 1 flights, we must iterate through the sourceHub's flights, adding the flight
			to the tracking FlightPlan and calling the recursive function again on that flight's destination */
		FlightNode* tempFlight = source->headFlights;

		while (tempFlight != NULL) {
			/* Iterates through all of the flights, adding the flight to the FlightPlan's path, and setting the
				FlightPlan's endHub equal to the flight's destination. */

			/* Conditional check to see if second flight starts after first. */
			if (tracking->path[0] == NULL || timeBetween(tracking->calculateArrivalTime(), tempFlight->departure) >= 0 ) {
				tracking->path[depth] = tempFlight;
				tracking->endHub = tempFlight->destination;
				tracking->startTime = tempFlight->departure;
				tracking->startTime->AddMinutes(tempFlight->getDelay());
				searchForCheapest(tempFlight->destination,destination, lowest, tracking, (depth + 1), startDate, endDate, bags);
			}


			tempFlight = tempFlight->next;
		}
	}
};