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

  1.                                        -- Chapter 20 - Program 1
  2. with Text_IO;
  3. use Text_IO;
  4.  
  5. procedure Discrim1 is
  6.  
  7.    package Int_IO is new Text_IO.Integer_IO(INTEGER);
  8.    use Int_IO;
  9.  
  10.    type SQUARE is array(INTEGER range <>,
  11.                         INTEGER range <>) of INTEGER;
  12.  
  13.    type LINEAR_TYPE is array(INTEGER range <>) of POSITIVE;
  14.  
  15.    type STUFF(List_Size : POSITIVE) is
  16.       record
  17.          Matrix   : SQUARE(1..List_Size,1..List_Size);
  18.          Elements : INTEGER := List_Size * List_Size;
  19.          Linear   : LINEAR_TYPE(1..List_Size);
  20.          Number   : INTEGER := List_Size;
  21.       end record;
  22.  
  23.    type ANOTHER_STUFF is new STUFF;
  24.  
  25.    subtype STUFF_5 is STUFF(5);
  26.  
  27.    Data_Store  : STUFF(5);
  28.    Big_Store   : STUFF(12);
  29.    Extra_Store : ANOTHER_STUFF(5);
  30.    More_Store  : STUFF(5);
  31.    Five_Store  : STUFF_5;
  32.    Name_Store  : STUFF(List_Size => 5);
  33.  
  34. begin
  35.  
  36.    for Index1 in Data_Store.Matrix'RANGE(1) loop
  37.       Data_Store.Linear(Index1) := Index1;
  38.       for Index2 in Data_Store.Matrix'RANGE(2) loop
  39.          Data_Store.Matrix(Index1,Index2) := Index1 * Index2;
  40.       end loop;
  41.    end loop;
  42.  
  43.    Five_Store := Data_Store;
  44.    More_Store := Five_Store;
  45.  
  46.    Put("The number of elements in More_Store.Matrix is");
  47.    Put(More_Store.Elements);
  48.    New_Line;
  49.  
  50. end Discrim1;
  51.  
  52.  
  53.  
  54.  
  55. -- Result of execution
  56.  
  57. -- The number of elements in More_Store.Matrix is    25
  58.  
  59.