----------------------------------------------------------- -- letters.ada - count lower-case letters read from user -- -- written by: Lawrie Brown / 29 Jul 94 ----------------------------------------------------------- with TEXT_IO; procedure lc_letter_freq is package int_io is new TEXT_IO.INTEGER_IO (INTEGER); use TEXT_IO, int_io; subtype lc_letters is CHARACTER range 'a' .. 'z'; type freq_table is array (lc_letters) of INTEGER; count : freq_table := (others => 0); -- freq counts char : CHARACTER; -- letter just read begin -- lc_letter_freq -- give some instructions PUT_LINE ("This program will count lc letters"); PUT_LINE ("Enter lines of text, finish with '.'"); -- get some characters from the user loop GET(char); exit when char = '.'; if char in lc_letters then count(char) := count(char) + 1; end if; end loop; -- now show how many letters were read NEW_LINE; PUT_LINE("Letter Freq"); NEW_LINE; for t in lc_letters loop PUT(t); PUT(count(t), width=>11); NEW_LINE; end loop; end lc_letter_freq;