LearnStanmorephysics

Grade 12 · Matric Mastery

2D processing: totals & the wettest

Grade 12 · Two-dimensional arrays · Lesson and coding task · about 16 minutes

Open this task in the Delphi workspace →

Processing a 2D array is 1D patterns aimed along a row or a column:

Row total — reset inside the outer loop, accumulate in the inner:

for iRow := 1 to 3 do
begin
  iRowTot := 0;                       // reset PER ROW
  for iCol := 1 to 4 do
    iRowTot := iRowTot + arrRain[iRow, iCol];
  // … use iRowTot …
end;

Where you reset the total decides what it measures: before the outer loop = grand total; inside it = row total. That placement question is worth marks nearly every year.

Biggest row — the highest-value pattern from Grade 11, applied to row totals: keep the best total and its row number so you can name the province.

Your task

Same rainfall grid. Report each province's total, the grand total, and crown the wettest province.

What you will do

Hints
  1. iGrand resets once before the outer loop; iRowTot resets at the top of every outer lap.
  2. After the inner loop you have the row total — memo it, add it to iGrand, and challenge the current wettest.
  3. Track iWet (best total) and iWetRow (which row) together, like top-learner in Grade 11.
Model solution
const
  arrProv : array[1..3] of String = ('Gauteng', 'KwaZulu-Natal', 'Western Cape');
  arrRain : array[1..3, 1..4] of Integer = ((12, 0, 5, 20), (3, 8, 0, 11), (25, 14, 7, 0));

procedure TfrmRainStats.btnStatsClick(Sender: TObject);
var
  iRow, iCol, iRowTot, iGrand, iWet, iWetRow : Integer;
begin
  iGrand := 0;
  iWet := -1;
  iWetRow := 1;
  for iRow := 1 to 3 do
  begin
    iRowTot := 0;
    for iCol := 1 to 4 do
      iRowTot := iRowTot + arrRain[iRow, iCol];
    memOutput.Lines.Add(arrProv[iRow] + ': ' + IntToStr(iRowTot) + ' mm');
    iGrand := iGrand + iRowTot;
    if iRowTot > iWet then
    begin
      iWet := iRowTot;
      iWetRow := iRow;
    end;
  end;
  memOutput.Lines.Add('Total: ' + IntToStr(iGrand) + ' mm');
  memOutput.Lines.Add('Wettest: ' + arrProv[iWetRow] + ' (' + IntToStr(iWet) + ' mm)');
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.