Advertisement
Guest User

Untitled

a guest
Jul 1st, 2017
468
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Eiffel 2.26 KB | None | 0 0
  1.  
  2. indexing
  3.     author: "Stephen Shaw <shawsd@tcd.ie>"
  4.     description: "Root class for the anagram dictionary program"
  5.  
  6. class
  7.     ANAGRAM
  8.  
  9. creation
  10.     make
  11.  
  12. feature
  13.     anagram_dictionary : ANAGRAM_DICTIONARY
  14.  
  15.     make is
  16.         local
  17.             input : STRING
  18.             anagrams : HASHED_SET[STRING]
  19.             words : ARRAY[STRING]
  20.         do
  21.             words := << "teals", "stela", "Tesla", "tales", "Stael", "least","tesla", "taels", "stale", "steal", "slate" >>
  22.             create anagram_dictionary.from_array(words)
  23.             io.put_string("Dictionary successfully read%N")
  24.  
  25.             from
  26.             until
  27.                 False
  28.             loop
  29.                 io.put_string("Word: ")
  30.                 io.read_line
  31.                 input := io.last_string
  32.                
  33.                 anagrams := anagram_dictionary.get_anagrams(input)
  34.                 show_anagrams(anagrams)
  35.             end
  36.         end -- make
  37.        
  38.         read_filename : STRING is
  39.             local
  40.                 filename : STRING
  41.             do
  42.  
  43.                 io.put_string("Location of dictionary file: ")
  44.                 io.read_line
  45.                 filename := io.last_string
  46.             rescue
  47.                 retry
  48.             end -- read_filename
  49.  
  50.         show_anagrams(anagrams : HASHED_SET[STRING]) is
  51.             require
  52.                 anagrams /= Void
  53.             local
  54.                 index : INTEGER
  55.             do
  56.                 if anagrams.is_empty then
  57.                     io.put_string("Sorry, no anagrams found")
  58.                 else
  59.                     io.put_integer(anagrams.count)
  60.                     io.put_string(" anagrams found:")
  61.                     from
  62.                         index := anagrams.lower
  63.                     until
  64.                         index = anagrams.upper
  65.                     loop
  66.                         io.put_string(anagrams.item(index))
  67.                         index := index + 1
  68.                         if index < anagrams.upper then
  69.                             io.put_string(", ")
  70.                         else
  71.                             io.put_string(".")
  72.                         end
  73.                     end
  74.                 end
  75.             end -- show_anagrams
  76.  
  77.  
  78. end -- class ANAGRAM
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement