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

// Declare some variables
  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


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

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

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

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

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

  // Cleanup


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

Toggle menu