-- Nome del Programma: contalettere.adb -- Autore: Stefano Candolfi -- Data: 18.01.2001 -- Scopo: Inserisci un testo ed il programma conta quante volte -- sono comparse le varie lettere che compongono il testo with Ada.Text_IO; use Ada.Text_IO; with Ada.INTEGER_Text_IO; use Ada.INTEGER_Text_IO; procedure contalettere is type ALFABETO is array(65..122) of NATURAL; Conta :ALFABETO; Testo :String(1..100); lung, Setaccio :INTEGER; begin Conta := (others => 0); Put( Item => "Ciao, inserisci un testo:"); New_Line(spacing => 2); Get_Line(Item => Testo, Last => lung); Setaccio := 1; while Setaccio < Lung+1 loop if Character'pos(Testo(Setaccio)) >= 65 and Character'pos(Testo(Setaccio)) <= 90 then Conta(Character'pos(Testo(Setaccio))) := Conta(Character'pos(Testo(Setaccio))) +1; elsif Character'pos(Testo(Setaccio)) >= 97 and Character'pos(Testo(Setaccio)) <= 122 then Conta(Character'pos(Testo(Setaccio))) := Conta(Character'pos(Testo(Setaccio))) +1; end if; Setaccio := Setaccio +1; end loop; for i in 65..122 loop if Conta(i) /= 0 then New_Line; Put( Item => "la lettera "); Put( Item => Character'Val(i)); Put( Item => " e' comparsa "); Put( Item => Conta(i), Width => 2); if Conta(i)> 1 then Put( Item => " volte !"); else Put( Item => " volta !"); end if; end if; end loop; end contalettere;