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

  1.                        -- Chapter 22 - Programming exercise 3
  2. with Text_IO;
  3. use Text_IO;
  4. with Sequential_IO;
  5.  
  6. procedure CH22_3 is
  7.  
  8.    type MY_REC is
  9.       record
  10.          Age     : INTEGER;
  11.          Sex     : CHARACTER;
  12.          Initial : CHARACTER;
  13.       end record;
  14.  
  15.    package Int_IO is new Text_IO.Integer_IO(INTEGER);
  16.    use Int_IO;
  17.    package Seq_IO is new Sequential_IO(MY_REC);
  18.    use Seq_IO;
  19.  
  20.    Myself      : MY_REC;
  21.    My_Out_File : Seq_IO.FILE_TYPE;
  22.    My_In_File  : Seq_IO.FILE_TYPE;
  23.  
  24. begin
  25.  
  26.    Create(My_Out_File, Out_File, "NAMEFILE.TXT");
  27.  
  28.    Myself.Sex := 'M';
  29.    Myself.Initial := 'X';
  30.  
  31.    for Index in 1..100 loop
  32.       Myself.Age := Index;
  33.       Write(My_Out_File, Myself);
  34.    end loop;
  35.  
  36.    Close(My_Out_File);
  37.  
  38.    Open(My_In_File, In_File, "NAMEFILE.TXT");
  39.  
  40.    for Index in 1..100 loop
  41.       Read(My_In_File, Myself);
  42.       if Myself.Age >= 82 then
  43.          Put("Record number");
  44.          Put(Myself.Age);
  45.          Put(" ");
  46.          Put(Myself.Sex);
  47.          Put(" ");
  48.          Put(Myself.Initial);
  49.          New_Line;
  50.       end if;
  51.    end loop;
  52.  
  53.    Close(My_In_File);
  54.  
  55. end CH22_3;
  56.  
  57.  
  58.  
  59.  
  60. -- Result of Execution
  61.  
  62. -- Record number    82 M X
  63. -- Record number    83 M X
  64. -- Record number    84 M X
  65. -- Record number    85 M X
  66. -- Record number    86 M X
  67. -- Record number    87 M X
  68. -- Record number    88 M X
  69. -- Record number    89 M X
  70. -- Record number    90 M X
  71. -- Record number    91 M X
  72. -- Record number    92 M X
  73. -- Record number    93 M X
  74. -- Record number    94 M X
  75. -- Record number    95 M X
  76. -- Record number    96 M X
  77. -- Record number    97 M X
  78. -- Record number    98 M X
  79. -- Record number    99 M X
  80. -- Record number   100 M X
  81.  
  82.