with ada.text_io; use ada.text_io; -- This program will print a list of "words" in the input. -- Each unique word will appear only once -- For the purposes of this program, a "word" is a line of input procedure group3 is Maxwordsize: constant Natural := 200; Maxwordlistsize: constant Natural := 100; -- Let's define a type for arrays -- This does not create any instances of the array type WordList is array (1 .. Maxwordlistsize) of string(1 .. Maxwordsize); type WordLengthList is array (1 .. Maxwordlistsize) of Natural; procedure addWord(w: in String; wl:in out WordList; wll:in out WordLengthList; n: in out Natural) is found: Boolean := false; i: Natural := 0; len: constant Natural := w'length; begin -- Find out if the word is in the array loop exit when found or i >= n; i := i + 1; found := wl(i)(1..len) = w; end loop; -- Add the word if it's not there if not found then n := n + 1; wl(n)(1..len) := w; wll(n) := len; end if; end addWord; -- Now declare an instance of the words array -- Remember that the type declaration does not create an instance of the type theWordList: wordList; -- Now declare an instance of the word lengths array theWordLengthList: wordLengthList; theWord, tempWord: String(1 .. Maxwordsize); len, NumEntered, tempLen: Natural := 0; -- Let's do some bottom up testing of addWord begin -- theWord(1..9) := ("Firstword"); -- addWord(theWord, theWordList, theWordLengthList, NumEntered); -- theWord(1..10) := ("secondword"); -- addWord(theWord, theWordList, theWordLengthList, NumEntered); while not end_of_file loop get_line(theWord, len); -- Only pass the slice containing the characters read in to addWord addWord(theWord(1..len), theWordList, theWordLengthList, NumEntered); end loop; for i in 1 .. NumEntered loop -- Output each word, but only a slice of the word tempWord := theWordList(i); tempLen := theWordLengthList(i); put_line(tempWord(1 .. tempLen)); -- Another way to print it, all in one line -- put_line( theWordList(i) (1 .. theWordLengthList(i)) ); end loop; -- If this program is run with its source as input, -- this line should appear only once -- this line should appear only once end group3;