-- here's the program I wrote to determine the answers to the -- homework from chapter 2 on data types. WITH ada.text_io; WITH ada.Integer_text_io; PROCEDURE problem15 IS -- given type declarations TYPE B_array IS ARRAY (0..4) OF Boolean; TYPE Grade_Type IS (A,B,C,D,F); TYPE N_array IS ARRAY (Grade_Type) OF Natural; PACKAGE Grade_io IS NEW ada.text_io.enumeration_io (enum => grade_type); PACKAGE bool_io IS NEW ada.text_io.enumeration_io(enum => boolean); -- given variable declarations X : B_array := (0..2 => true, 3..4 => false); Y : B_array := (2..3 => true, OTHERS => false); G : N_Array := (24, 35, 41, 33, 18); H : N_Array := (24, 35, 40, 32, 19); L : N_Array; Z : B_array; result : boolean; BEGIN ada.integer_text_io.put (X'first); ada.text_io.put_line (" is X'first"); ada.integer_text_io.put (X'last); ada.text_io.put_line (" is X'last"); ada.integer_text_io.put (X'length); ada.text_io.put_line (" is X'length"); grade_io.put (G'first); ada.text_io.put_line (" is G'first" ); grade_io.put(G'last); ada.text_io.put_line (" is G'last" ); ada.integer_text_io.put (G'length); ada.text_io.put_line (" is G'length"); bool_io.put (X(2) AND Y(2)); ada.text_io.put_line (" is X(2) and Y(2)" ); -- x array ada.text_io.put (" X array "); FOR i IN x'first..x'last LOOP bool_io.put (x(i)); ada.text_io.put (" "); END LOOP; ada.text_io.new_line ; -- y array ada.text_io.put (" Y array "); FOR i IN y'first..y'last LOOP bool_io.put (y(i)); ada.text_io.put (" "); END LOOP; ada.text_io.new_line; -- and array x and array y and store result in Z Z := X AND Y; -- anded arrays ada.text_io.put (" X ANDED with Y array and stored in Z "); FOR i IN z'first..z'last LOOP bool_io.put (z(i)); ada.text_io.put (" "); END LOOP; ada.text_io.new_line; -- concatenate ada.text_io.put (" used slices with & - X(0..2)& Y(2..3) - result in Z "); Z := X(0..2)& Y(2..3); FOR i IN z'first..z'last LOOP bool_io.put (z(i)); ada.text_io.put (" "); END LOOP; ada.text_io.new_line; result := x(1) = y(1); bool_io.put (result); ada.text_io.put_line (" is X(1)= Y(1) "); -- compare two arrays result := X = Y; bool_io.put (result); ada.text_io.put_line (" is X = Y "); result := x(1) < y(1); bool_io.put (result); ada.text_io.put_line (" is X(1)< Y(1) "); result := X < Y; bool_io.put (result); ada.text_io.put_line (" is X < Y "); ada.text_io.put_line ("i g(i) h(i) "); FOR i IN A..F LOOP grade_io.put (i); ada.integer_text_io.put (g(i)); ada.integer_text_io.put (h(i)); ada.text_io.new_line; END LOOP; ada.text_io.new_line; result := g(A..B) < H(D..F); bool_io.put (result); ada.text_io.put_line (" g(A..B) < H(D..F) "); result := g < h; bool_io.put (result); ada.text_io.put_line (" is G < H "); result := g(a) < h(d); bool_io.put (result); ada.text_io.put_line (" is g(a) < h(d)"); result := g(b) < h(f); bool_io.put (result); ada.text_io.put_line (" is g(b) < h(f)"); ada.text_io.put_line ( " G(A..B) & H(C..F)is "); L := G(A..B) & H(C..F); FOR i IN A..F LOOP ada.integer_text_io.put (l(i)); END LOOP; ada.text_io.new_line; ada.text_io.put_line ( " G(F..F) & G(D..D) & G(C..C) & G(B..B) & G(A.A) "); L := G(F..F) & G(D..D) & G(C..C) & G(B..B) & G(A..A); FOR i IN A..F LOOP ada.integer_text_io.put (l(i)); END LOOP; ada.text_io.new_line; ada.text_io.put_line ( " G(A..B) & H(C..F) < H(A..B) & G(C..F) "); result := G(A..B) & H(C..F) < H(A..B) & G(C..F); bool_io.put(result); ada.text_io.new_line; -- assign one array to another not part of the problem l := h; FOR i IN A..F LOOP ada.integer_text_io.put (l(i)); END LOOP; ada.text_io.new_line; END problem15;