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

  1.                                        -- Chapter 22 - Program 3
  2. with Text_IO;
  3. use Text_IO;
  4. with Direct_IO;
  5.  
  6. procedure BiRandIO 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 Ran_IO is new Direct_IO(MY_REC);
  18.    use Ran_IO;
  19.  
  20.    Myself     : MY_REC;
  21.    My_In_Out_File : Ran_IO.FILE_TYPE;
  22.  
  23.    procedure Display_Record(In_Rec : MY_REC) is
  24.    begin
  25.       Put("Record number");
  26.       Put(In_Rec.Age);
  27.       Put(" ");
  28.       Put(In_Rec.Sex);
  29.       Put(" ");
  30.       Put(In_Rec.Initial);
  31.       New_Line;
  32.    end Display_Record;
  33.  
  34. begin
  35.  
  36.    Open(My_In_Out_File, InOut_File, "NAMEFILE.TXT");
  37.  
  38.    Read(My_In_Out_File, Myself, 37);
  39.    Display_Record(Myself);
  40.    Read(My_In_Out_File, Myself, 25);
  41.    Display_Record(Myself);
  42.    Read(My_In_Out_File, Myself);
  43.    Display_Record(Myself);
  44.    New_Line;
  45.  
  46.    Myself.Age := 33;
  47.    Myself.Sex := 'F';
  48.    Myself.Initial := 'Z';
  49.    Write(My_In_Out_File, Myself, 91);
  50.    Write(My_In_Out_File, Myself, 96);
  51.    Write(My_In_Out_File, Myself);
  52.  
  53.    Set_Index(My_In_Out_File, 88);
  54.    while not End_Of_File(My_In_Out_File) loop
  55.       Read(My_In_Out_File, Myself);
  56.       Display_Record(Myself);
  57.    end loop;
  58.  
  59.    Close(My_In_Out_File);
  60.  
  61. end BiRandIO;
  62.  
  63.  
  64.  
  65.  
  66. -- Result of Execution
  67.  
  68. -- Record number    37 M X
  69. -- Record number    25 M X
  70. -- Record number    26 M X
  71.  
  72. -- Record number    88 M X
  73. -- Record number    89 M X
  74. -- Record number    90 M X
  75. -- Record number    33 F Z
  76. -- Record number    92 M X
  77. -- Record number    93 M X
  78. -- Record number    94 M X
  79. -- Record number    95 M X
  80. -- Record number    33 F Z
  81. -- Record number    33 F Z
  82. -- Record number    98 M X
  83. -- Record number    99 M X
  84. -- Record number   100 M X
  85.  
  86.