home *** CD-ROM | disk | FTP | other *** search
/ Chip 1995 March / CHIP3.mdf / programm / prog2 / answers / ch10_1.ada < prev    next >
Encoding:
Text File  |  1991-07-01  |  1.7 KB  |  70 lines

  1.                             -- Chapter 10 - Programming exercise 1
  2. with Text_IO;
  3. use Text_IO;
  4.  
  5. procedure CH10_1 is
  6.  
  7.    package Int_IO is new Text_IO.Integer_IO(INTEGER);
  8.    use Int_IO;
  9.  
  10.    N : INTEGER := 10;
  11.    Dummy1 : array(INTEGER range 1..7) of BOOLEAN;
  12.    Dummy2 : array(INTEGER range -21..N) of BOOLEAN;
  13.    Dummy3 : array(-21..N) of BOOLEAN;
  14.  
  15.    type MY_ARRAY is array(1..5) of INTEGER;
  16.    type NEW_ARRAY_TYPE is array(12..27) of INTEGER;
  17.  
  18.    Total        : MY_ARRAY;
  19.    First        : MY_ARRAY;
  20.    Second       : MY_ARRAY;
  21.    Funny        : array(1..5) of INTEGER;
  22.    X,Y          : NEW_ARRAY_TYPE;
  23.    Fourth_Value : INTEGER renames First(4);
  24.  
  25. begin
  26.    for Index in 12..27 loop
  27.       X(Index) := Index + 7;
  28.    end loop;
  29.  
  30.    Y := X;           -- These are now assignment compatible
  31.  
  32.    First(1) := 12;
  33.    First(2) := 16;
  34.    First(3) := First(2) - First(1);
  35.    Fourth_Value := -13;
  36.    First(5) := 16 - 2*First(2);
  37.  
  38.    for Index in 1..5 loop
  39.       Second(Index) := 3 * Index + 77;
  40.    end loop;
  41.  
  42.    Total := First;
  43.    if Total = First then
  44.       Put("Both arrays are the same size and contain ");
  45.       Put_Line("the same values in all elements.");
  46.    end if;
  47.  
  48.    for Index in 1..5 loop
  49.       Total(Index) := Total(Index) + Second(Index);
  50.       Funny(Index) := Total(Index) + First(6 - Index);
  51.       Put("The array values are");
  52.       Put(Total(Index));
  53.       Put(Funny(Index));
  54.       New_Line;
  55.    end loop;
  56. end CH10_1;
  57.  
  58.  
  59.  
  60.  
  61. -- Result of execution
  62.  
  63. -- Both arrays are the same size and contain the same values in...
  64. -- The array values are    92    76
  65. -- The array values are    99    86
  66. -- The array values are    90    94
  67. -- The array values are    76    92
  68. -- The array values are    76    88
  69.  
  70.