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

  1.                                        -- Chapter 10 - Program 1
  2. with Text_IO;
  3. use Text_IO;
  4.  
  5. procedure Array1 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.  
  17.    Total        : MY_ARRAY;
  18.    First        : MY_ARRAY;
  19.    Second       : MY_ARRAY;
  20.    Funny        : array(1..5) of INTEGER;
  21.    X,Y          : array(12..27) of INTEGER;
  22.    Fourth_Value : INTEGER renames First(4);
  23.  
  24. begin
  25.    First(1) := 12;
  26.    First(2) := 16;
  27.    First(3) := First(2) - First(1);
  28.    Fourth_Value := -13;
  29.    First(5) := 16 - 2*First(2);
  30.  
  31.    for Index in 1..5 loop
  32.       Second(Index) := 3 * Index + 77;
  33.    end loop;
  34.  
  35.    Total := First;
  36.    if Total = First then
  37.       Put("Both arrays are the same size and contain ");
  38.       Put_Line("the same values in all elements.");
  39.    end if;
  40.  
  41.    for Index in 1..5 loop
  42.       Total(Index) := Total(Index) + Second(Index);
  43.       Funny(Index) := Total(Index) + First(6 - Index);
  44.       Put("The array values are");
  45.       Put(Total(Index));
  46.       Put(Funny(Index));
  47.       New_Line;
  48.    end loop;
  49. end Array1;
  50.  
  51.  
  52.  
  53.  
  54. -- Result of execution
  55.  
  56. -- Both arrays are the same size and contain the same values in...
  57. -- The array values are    92    76
  58. -- The array values are    99    86
  59. -- The array values are    90    94
  60. -- The array values are    76    92
  61. -- The array values are    76    88
  62.  
  63.