Pascal Cheat Sheet

About the Pascal Cheat Sheet

FreePascal with Lazarus are Club Engineer's tools of choice for teaching object oriented programming. This cheat sheet demonstrates basic file access necessary necessary for solving the Australian Informatics Olympiad problems.

Australian Informatics Olympiad File Access

Starter Problem #1 - Addition

This code will solve the AIO Starter Problem #1 - Addition.

In the Lazarus IDE, select File | New from the menu, then choose Project | Program from the tree on the LH side.

Save the project with the name addition.

Delete the template code provided in the Lazarus Project File, addition.lpr and type the code below.

program Addition;

// Link the SysUtils file for access to file handling routines
uses
  SysUtils;

// Declare some variables
var
  LIn, LOut: Text;         // References to the input and output files
  LVar1, LVar2: integer;   // The two values that are to be added together
  LResult: integer;        // The result

begin

  // Open the input file
  Assign(LIn, 'addin.txt');
  Reset(LIn);

  // Read the input values
  ReadLn(LIn, LVar1, LVar2);

  // Open the output file
  Assign(LOut, 'addout.txt');
  ReWrite(LOut);

  // Calculate the result
  LResult:= LVar1 + LVar2;

  // Write to output file
  WriteLn(LOut, LResult);

  // Cleanup
  CloseFile(LIn);
  CloseFile(LOut);

end.

To test the code on the AIO training site, upload the file Addition.lpr

Toggle menu