LearnStanmorephysics

Grade 11 · Powering Up

Meet arrays

Grade 11 · One-dimensional arrays · Lesson and coding task · about 12 minutes

Open this task in the Delphi workspace →

An array is a row of variables sharing one name, numbered from a low to a high index. In SA schools we almost always start at 1:

var
  arrMarks : array[1..5] of Integer;
begin
  arrMarks[1] := 78;      // first box
  arrMarks[5] := 67;      // last box

Arrays and FOR loops are inseparable — the loop variable becomes the index:

for i := 1 to 5 do
  memOutput.Lines.Add(IntToStr(arrMarks[i]));

Parallel arrays hold related data at matching positions: arrNames[3] and arrMarks[3] describe the same learner. Exam papers give you data as constant arrays exactly as in this exercise's starter code.

Go outside the range (like index 6 in a 1..5 array) and your program crashes — try it and read the error we give you.

What you will do

Hints
  1. for i := 1 to 5 do — the same i indexes both arrays.
  2. The line is arrNames[i] + ': ' + IntToStr(arrMarks[i])
Model solution
const
  arrNames : array[1..5] of String = ('Thabo', 'Lerato', 'Anele', 'Sipho', 'Zanele');
  arrMarks : array[1..5] of Integer = (78, 45, 90, 33, 67);

procedure TfrmClass.btnListClick(Sender: TObject);
var
  i : Integer;
begin
  for i := 1 to 5 do
    memOutput.Lines.Add(arrNames[i] + ': ' + IntToStr(arrMarks[i]));
end;

About this material

This platform provides original CAPS-aligned practice material and study tools. Content is machine-verified and has not been reviewed by subject specialists. It is not affiliated with or endorsed by the Department of Basic Education. Learners should also use official past papers and consult their teachers where uncertain.