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

  1.                        -- Chapter 22 - Programming exercise 1
  2. with Text_IO;
  3. use Text_IO;
  4. with Sequential_IO;
  5.  
  6. procedure CH22_1 is
  7.  
  8.    type MY_REC is
  9.       record
  10.          Age     : INTEGER;
  11.          Sex     : CHARACTER;
  12.          Initial : CHARACTER;
  13.       end record;
  14.  
  15.    package Seq_IO is new Sequential_IO(MY_REC);
  16.    use Seq_IO;
  17.  
  18.    Myself      : MY_REC;
  19.    My_Out_File : Seq_IO.FILE_TYPE;
  20.    Other_File  : Seq_IO.FILE_TYPE;
  21. begin
  22.  
  23.    Create(My_Out_File, Out_File, "NAMEFILE.TXT");
  24.    Create(Other_File, Out_File,  "OTHRFILE.TXT");
  25.  
  26.    Myself.Sex := 'M';
  27.    for Index in 1..100 loop
  28.       Myself.Age := Index;
  29.       Myself.Initial := 'X';
  30.       Write(My_Out_File, Myself);
  31.       if (Myself.Age >= 50) and (Myself.Age <= 60) then
  32.          Myself.Initial := 'O';
  33.          Write(Other_File, Myself);
  34.       else
  35.          Write(Other_File, Myself);
  36.       end if;
  37.    end loop;
  38.  
  39.    Close(My_Out_File);
  40.    Close(Other_File);
  41.  
  42. end CH22_1;
  43.  
  44.  
  45.  
  46.  
  47. -- Result of Execution
  48.  
  49. --   (The output is a binary file named NAMEFILE.TXT,
  50. --              and a binary fiel named OTHRFILE.TXT.)
  51.  
  52.