1  (* This program illustrates the use of input and output files *)
 2  (* NOTE: Remember to close your files at the end of the program *)
 3  (*       If you do not, you MAY find that your output file is empty *)
 4 PROGRAM eofFile(input, output, infile, outfile);
 5 VAR     sideA, sideB, height , area : real;
 6         infile, outfile : textfile;
 7         infilename, outfilename : String;
 8 BEGIN
 9     writeln  (' Please enter the name of your input file and hit return ');
10     readln  ( infilename);
11     assign (infile, infilename); (* associates logical file with disk file *)
12     reset (infile);           (* moves cursor to beginning of input file *)
13                           (* note that reset will fail if disk file doesn't exist *)
14     writeln (' Please enter the name of your output file and hit return ');
15     readln   (outfilename);
16     assign (outfile, outfilename); (* associates logical file with disk file *)
17     rewrite (outfile);    (* moves cursor to beginning of output file *)
18                   (* note that rewrite is destructive of previously existing file *)
19     writeln('This program computes the area of a trapezoid');
20     writeln('Enter 3 numbers, separated by a space, for the sides and height:'); 
21     REPEAT
22        readln(infile, sideA, sideB, height);
23        writeln (' The numbers you entered are: ', sideA:5:2, sideB:7:3, height:8:2);
24        writeln (outfile, 'The numbers you entered are: ', sideA:5:2, sideB:7:3, height:8:2);
25        area := ((sideA + sideB)/2)*height;
26        writeln('Area: ', area:5:2);
27        writeln(outfile, 'Area: ', area:5:2);
28        writeln('Enter 3 numbers, separated by a space, for the sides and height:'); 
29     UNTIL eof (infile);
30     writeln (' The end of file was found so the program is ending normally ');
31     writeln (' This program has completed normally ');
32     writeln (' The input came from ', infilename);
33     writeln (' The output went to  ', outfilename);
34     close (infile);     (* be sure to do this *)
35     close (outfile);    (* output file MAY be empty if you forget this  *)
36     END.