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

  1.                                        -- Chapter 13 - Program 5
  2. with Text_IO;
  3. use Text_IO;
  4.  
  5. procedure Access5 is
  6.  
  7.    package Int_IO is new Text_IO.Integer_IO(INTEGER);
  8.    use Int_IO;
  9.  
  10.    type MY_RECORD is
  11.       record
  12.          Age     : INTEGER;
  13.          Initial : CHARACTER;
  14.          Sex     : CHARACTER;
  15.       end record;
  16.  
  17.    type ACCESS_MY_DATA is access MY_RECORD;
  18.  
  19.    Myself  : ACCESS_MY_DATA;
  20.    Class   : array(1..10) of ACCESS_MY_DATA;
  21.  
  22. begin
  23.    Myself := new MY_RECORD;
  24.  
  25.    Myself.Age := 34;
  26.    Myself.Initial := 'D';
  27.    Myself.Sex := 'M';
  28.  
  29.    for Index in 1..10 loop
  30.       Class(Index) := new MY_RECORD;
  31.       Class(Index).all := Myself.all;
  32.    end loop;
  33.  
  34.    Class(3).Age := 30;
  35.    Class(3).Initial := 'A';
  36.    Class(5).Initial := 'Z';
  37.    Class(8).Initial := 'R';
  38.    Class(6).Sex := 'F';
  39.    Class(7).Sex := 'F';
  40.    Class(2).Sex := 'F';
  41.  
  42.    for Index in 1..10 loop
  43.       Put("The class members age is");
  44.       Put(Class(Index).Age,3);
  45.       if Class(Index).Sex = 'M' then
  46.          Put(" and his initial is ");
  47.       else
  48.          Put(" and her initial is ");
  49.       end if;
  50.       Put(Class(Index).Initial);
  51.       New_Line;
  52.    end loop;
  53.  
  54. end Access5;
  55.  
  56.  
  57.  
  58.  
  59. -- Result of execution
  60.  
  61. -- The class members age is 34 and his initial is D
  62. -- The class members age is 34 and her initial is D
  63. -- The class members age is 30 and his initial is A
  64. -- The class members age is 34 and his initial is D
  65. -- The class members age is 34 and his initial is Z
  66. -- The class members age is 34 and her initial is D
  67. -- The class members age is 34 and her initial is D
  68. -- The class members age is 34 and his initial is R
  69. -- The class members age is 34 and his initial is D
  70. -- The class members age is 34 and his initial is D
  71.  
  72.