Quiz 0

Statistics:

mean     21.429 (300.000/14)
stddev   6.044
median   24.500
midrange 14.000-27.000

#   avg
1   7.29 / 10
2   6.79 / 10
3   7.36 / 10

Question 0-1

Complete the following Ada program to read 30~numbers from the user into an array and then echo back to the screen all that exceed 50.

with Text_IO; use Text_IO;
procedure Print_Large is
    package Int_IO is new Integer_IO(Integer); use Int_IO;


begin




end Print_Large;

Question 0-2

Assume that the following Ada program compiled successfully.

with Text_IO; use Text_IO;

procedure Test is
    I : Integer;
    J : Integer;

    procedure Y(A : Integer; B : Integer) is
    begin
        A := 5;
        I := 6;
        B := A + I;
    end Y;
begin
    I := 4;
    J := 8;
    Y(I, J);
    Put_Line(Integer'Image(I) & " " & Integer'Image(J));
    Y(I, I); -- Note: I is passed for both parameters!
    Put_Line(Integer'Image(I) & " " & Integer'Image(J));
end Test;

Question 0-3

Use the following grammar in answering the questions below.

S -> N 0 N 1 N
N -> 0 N | 1 N | eps

Solutions

Solution 0-1

with Text_IO; use Text_IO;
procedure Print_Large is
    package Int_IO is new Integer_IO(Integer); use Int_IO;
    Nums : array (1..30) of Integer;
begin
    for I in Nums'Range loop
        Get(Nums(I));
    end loop;
    for I in Nums'Range loop
        if Nums(I) > 50 then
            Put(Nums(I)); New_Line;
        end if;
    end loop;
end Print_Large;

Solution 0-2

Solution 0-3

  • a.
    S -> N 0 N 1 N
      ->   0 N 1 N
      ->   0   1 N
      ->   0   1 0 N
      ->   0   1 0
    

  • b.