PROGRAM TYPEFILE;

{ This turbo pascal program shows how to read, and write a file. }
{ MALCOLM MCCORQUODALE III, HOUSTON, TEXAS  JUNE 1984}

VAR
     FILE1, FILE2 : TEXT;          { File variables }
     PRTLINE      : STRING[78];    { Read into this variable and print it }
     FILENAME1,
     FILENAME2    : STRING[14];    { Name of source and dest files }

{1------------------------------------------------}

PROCEDURE GET_FILE_NAMES;
{ Ask the user what file to read from and write to, }
{ then open those files. }
BEGIN
     WRITELN ('Enter name of file to read');   { Ask question  }
     READLN (FILENAME1);                       { Get answer    }
     ASSIGN (FILE1,FILENAME1);     { Tell computer the answer  }
     RESET (FILE1);                { Open the file for reading }

     WRITELN ('Enter name of file to write');  { Ask question  }
     READLN (FILENAME2);                       { Get answer    }
     ASSIGN (FILE2,FILENAME2);     { Tell computer the answer  }
     REWRITE (FILE2);              { Open the file for writing }
END;

{1------------------------------------------------}

PROCEDURE READ_AND_PRINT_FILE;
{ Read and print each record read along with it's record number }
VAR
     RECCNT,                  { Record counter }
     SCRCNT : INTEGER;        { Counts records on screen }

{2------------------------------------------------}

PROCEDURE NEW_PAGE;
VAR
     CH : CHAR;
BEGIN
       WRITELN ('Hit ENTER to continue');
       READLN (CH);             { Wait until a key is hit }
       CLRSCR;                  { Clear the screen }
       SCRCNT := 0;
END;

{2------------------------------------------------}

BEGIN
     RECCNT := 1;
     SCRCNT := 0;
     WHILE NOT EOF (FILE1) DO      { As long as there are records DO }
     BEGIN
          READLN (FILE1,PRTLINE);    { Read the file }
          WRITELN (RECCNT,PRTLINE);  { Write record and number on screen }
          WRITELN (FILE2,PRTLINE);   { Write record to other disk file }
          RECCNT := RECCNT + 1;      { Increment record counter }
          SCRCNT := SCRCNT + 1;
          IF SCRCNT = 20 THEN NEW_PAGE;
          END;
END;

{1------------------------------------------------}

PROCEDURE CLOSE_FILES;
{ Close the files we have opened }
BEGIN
     CLOSE(FILE1);
     CLOSE(FILE2);
END;

{1------------------------------------------------}

BEGIN
     GET_FILE_NAMES;
     READ_AND_PRINT_FILE;
     CLOSE_FILES;
END.
 * K3) + (Z * K4));
    Q:= trunc(GR + (H / 2));
 