コード例 #1
0
        // Create a custom data structure to store airfare in a graph-like structure and retrieve airfare based on nodes
        // Takes departure airport and arrival airport as arguments
        public static void StoreAirfare(IRIS irisNative)
        {
            // Store routes and distance between airports
            // This API sets the value, for a global, with the following keys
            // For example, ^AIRPORT("BOS","AUS") = 1698
            irisNative.Set("1698", "^AIRPORT", "BOS", "AUS");
            irisNative.Set("450", "^AIRPORT", "BOS", "AUS", "AA150");
            irisNative.Set("550", "^AIRPORT", "BOS", "AUS", "AA290");
            irisNative.Set("200", "^AIRPORT", "BOS", "PHL", "UA110");
            irisNative.Set("700", "^AIRPORT", "BOS", "BIS", "AA330");
            irisNative.Set("710", "^AIRPORT", "BOS", "BIS", "UA208");

            // Start interactive prompt
            Console.WriteLine("Enter departure airport: ");
            String fromAirport = Console.ReadLine();

            Console.WriteLine("Enter destination airport: ");
            String toAirport = Console.ReadLine();

            // Query for routes based on input
            String hasRoutes = "This path has no routes";
            int    isDefined = irisNative.IsDefined("^AIRPORT", fromAirport, toAirport);

            if (isDefined == 11 || isDefined == 1)
            {
                hasRoutes = "This path has routes";
            }
            Console.WriteLine("");
            Console.WriteLine("Printed to ^AIRPORT global. The distance in miles between " + fromAirport + " and " + toAirport +
                              " is: " + irisNative.GetString("^AIRPORT", fromAirport, toAirport) + ". " + hasRoutes);
        }
コード例 #2
0
        // Simple interactive method using IRIS native API to consult the data structure populated in storeAirfare()
        public static void checkAirfare(IRIS irisNative)
        {
            // Prompt for input
            Console.Write("Enter departure airport: (e.g. BOS)");
            String fromAirport = Console.ReadLine();

            Console.Write("Enter destination airport: (e.g. AUS)");
            String toAirport = Console.ReadLine();

            // ^airport(from, to) = distance
            Console.WriteLine("");
            Console.WriteLine("The distance in miles between " + fromAirport + " and " + toAirport +
                              " is: " + irisNative.GetString("^airport", fromAirport, toAirport) + ".");

            // Now loop through routes: ^airport(from, to, flight) = fare
            int isDefined = irisNative.IsDefined("^airport", fromAirport, toAirport);

            if (isDefined == 11)
            {
                Console.WriteLine("The following routes exist for this path:");
                IRISIterator iterator = irisNative.GetIRISIterator("^airport", fromAirport, toAirport);
                while (iterator.MoveNext())
                {
                    String fare         = (String)iterator.Current;
                    String flightNumber = (String)iterator.CurrentSubscript;
                    Console.WriteLine("  - " + flightNumber + ": " + fare + " USD");
                }
            }
            else
            {
                Console.WriteLine("No routes exist for this path.");
            }
        }