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

  1.                         -- Chapter 22 - Programming exercise 2
  2. with Text_IO;
  3. use Text_IO;
  4. with Sequential_IO;
  5.  
  6. procedure CH22_2 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, Other : MY_REC;
  21.    My_In_File    : Seq_IO.FILE_TYPE;
  22.    Other_File    : Seq_IO.FILE_TYPE;
  23.  
  24. begin
  25.  
  26.    Open(My_In_File, In_File, "NAMEFILE.TXT");
  27.    Open(Other_File, In_File, "OTHRFILE.TXT");
  28.  
  29.    for Index in 1..100 loop
  30.       Read(My_In_File, Myself);
  31.       Read(Other_File, Other);
  32.       if (Myself.Age     /= Other.Age) or
  33.          (Myself.Sex     /= Other.Sex) or
  34.          (Myself.Initial /= Other.Initial) then
  35.  
  36.          Put("Record number");
  37.          Put(Myself.Age);
  38.          Put(" ");
  39.          Put(Myself.Sex);
  40.          Put(" ");
  41.          Put(Myself.Initial);
  42.  
  43.          Put(Other.Age,12);
  44.          Put(" ");
  45.          Put(Other.Sex);
  46.          Put(" ");
  47.          Put(Other.Initial);
  48.          New_Line;
  49.       end if;
  50.    end loop;
  51.  
  52.    Close(My_In_File);
  53.    Close(Other_File);
  54.  
  55. end CH22_2;
  56.  
  57.  
  58.  
  59.  
  60. -- Result of Execution
  61.  
  62. -- Record number    50 M X          50 M O
  63. -- Record number    51 M X          51 M O
  64. -- Record number    52 M X          52 M O
  65. -- Record number    53 M X          53 M O
  66. -- Record number    54 M X          54 M O
  67. -- Record number    55 M X          55 M O
  68. -- Record number    56 M X          56 M O
  69. -- Record number    57 M X          57 M O
  70. -- Record number    58 M X          58 M O
  71. -- Record number    59 M X          59 M O
  72. -- Record number    60 M X          60 M O
  73.  
  74.