CPSC 120 LAB 13 Back to Lab index page

Lab must be completed and reviewed by Peer Instructor Seth Peery no later than Fri, Nov 30 during lab class.

You will write a nicely documented Ada program that will read names from a file using a Get_Line statement. Assign these names to an array of records, then print the names in order of their length. In other words, print the shortest name first and the longest name last. You should employ a loop that utilizes an Ada.Text_IO.End_of_File function to read the names and count the number of names read. You should find and save the length of the shortest name and the length of the longest name.

Sample input data

John
Mary
Joseph
Tom
Dorothy
Kathleen
Abe

Output of the program based on the sample input should look like:

Length of the shortest name = 3
Length of the longest name = 8

Tom
Abe
John
Mary
Joseph
Dorothy
Kathleen

Hints:

Store the names and their lengths in an array of records:

Type nameleng is record
    name:string(1..10);
    length:natural;
End record;

Type namearray is array (1..15) of nameleng;

namelist: namearray;

For the output section:

Once you know the number of names, the shortest length, and the longest length, use nested for loops and an if statement to ouput the names shortest to longest order.

for i in shortest to longest
      for j in 1 to number of names
            if the length of the name(j) is i, output it