Programming Lesson Notes
Programming Lesson Notes
Programming
Lesson Notes — from problems to Pascal code
Page 1 of 25
ICT · Grade 11 · Programming — Lesson Notes
How to use these notes: Each section below ends with a short Practice box. Work through it before moving to the
next section — programming is learned by doing, not just reading.
SECTION 1.1
Analyzing a Problem
Breaking a problem into Input, Process and Output
Notice: Steps 4 and 5 can swap order without changing the result, but steps 1–3 must stay in that exact order.
Process Put leaves in a strainer and pour hot water over them, add
sugar, stir, then taste — if it isn't sweet enough, add more
sugar and stir again
Page 2 of 25
ICT · Grade 11 · Programming — Lesson Notes
Part Details
Look closer: "Taste, and repeat if needed" is a Repetition hiding inside this problem — you will meet this control
structure properly in section 1.2.
Alternative Solutions
Most problems can be solved in more than one way. Every possible way of solving a problem together makes up its
solution space. A good programmer compares the alternatives and picks the most efficient one — usually the one
with the fewest steps or calculations.
Solution 1: Solution 2:
IF mark < 35 THEN IF mark >= 35 THEN
Result = Fail Result = Pass
ELSE ELSE
Result = Pass Result = Fail
✎ PRACTICE — 1.1
Analysing problems and comparing solutions
1. For the problem "sharing 100 toffees equally among 20 people", write down the Input, the Process and the
Output.
2. Identify the Input, Process and Output for the task of making a paper kite.
3. Write two different formulas (alternative solutions) that could calculate the area of a square, and say which
one is simplest.
4. A shop gives a 10% discount on bills over Rs. 2000. Write two alternative ways of expressing this rule using
words.
5. Explain, in your own words, why comparing alternative solutions is useful before you start programming.
Page 3 of 25
ICT · Grade 11 · Programming — Lesson Notes
SECTION 1.2
What is an Algorithm?
An algorithm is a step-by-step procedure for solving a problem. It is written in plain language, independent of any
computer or programming language, so that anyone reading it can follow exactly what to do and in what order.
Key idea: Steps 1–3 must be followed in strict order. Steps 4 and 5 may be swapped without affecting the outcome
— this is what we mean by a sequential vs. a flexible step.
↓ ↓
YES NO
Step 2 Done?
Path A Path B
↓ NO → repeat "Do step"
↓ YES — continue
Step 3
1. Sequence
Steps are carried out one after another, from beginning to end, in a fixed order.
– Climbing a staircase, one step at a time.
– A student progressing from Grade 1 through to Grade 13.
2. Selection
A condition is tested, and exactly one of two possible actions is carried out depending on whether it is True or False.
– Passing a subject: IF mark ≥ 35 → Pass, ELSE → Fail.
– Buying a book: IF you have enough money → buy it, ELSE → you cannot.
3. Repetition
One or more steps are repeated until a condition is satisfied.
– Marking an attendance register: call each name and mark it, repeating until the last name is called.
Page 4 of 25
ICT · Grade 11 · Programming — Lesson Notes
– Counting the words in a paragraph: read a word and add 1 to the count, repeating until the paragraph ends.
✎ PRACTICE — 1.2
Identifying control structures
1. State which control structure (Sequence, Selection or Repetition) best describes: "Ask every student in the
class, one by one, whether they want rice or noodles for lunch."
2. Write a short algorithm (in numbered steps) to decide whether a person can vote, given that the voting age
is 18.
3. Write an algorithm using repetition to print the 5-times table from 5 to 50.
4. Give one real-life example (not from these notes) of each control structure: Sequence, Selection,
Repetition.
5. Explain why almost every useful computer program needs all three control structures, not just one.
Page 5 of 25
ICT · Grade 11 · Programming — Lesson Notes
SECTION 1.3
Flowchart Symbols
A flowchart presents an algorithm visually, using standard shapes to show what kind of action each step performs.
Start / End (rounded shape) Marks the beginning or end of the algorithm
Input / Output (slanted box) Data going into or out of the process
Start
↓
Every box here runs exactly once, from top to bottom,
Input radius with no decisions and no repeats — that makes this a
pure sequence.
↓
Area = pi × r × r BEGIN
INPUT Radius
↓ Area = 22/7 * Radius * Radius
DISPLAY Area
Output area END.
↓
End
Start
The diamond checks a single condition. Exactly one of
the two branches runs, depending on whether the
↓ remainder is 0.
Page 6 of 25
ICT · Grade 11 · Programming — Lesson Notes
YES NO
END.
"Even number" "Odd number"
Start
↓
Total = 0 While the answer to "More numbers?" is YES, the flow
loops back and repeats the same two steps. It only
↓ continues onward once the condition becomes NO.
Get number N
BEGIN
↓ Total = 0
REPEAT
Total = Total + N READ Number as N
Total = Total + N
↓ UNTIL numbers are over
DISPLAY Total
More numbers?
END.
YES → repeat from "Get number N"
↓ NO
Output Total
Page 7 of 25
ICT · Grade 11 · Programming — Lesson Notes
Pseudocode Keywords
Pseudocode expresses an algorithm in plain English, independent of any specific programming language, which
makes it easy to translate later into Pascal, Python, or any other language.
Keyword(s) Meaning
BEGIN
Total = 0
Average = 0
n = 1
WHILE n <= 10
READ Number
Total = Total + Number
n = n + 1
ENDWHILE
Average = Total / (n - 1)
DISPLAY Total, Average
END.
1 12 12
2 15 27
… … …
10 — final sum
BEGIN
Put tea bag in cup
WHILE (not water boiled)
Boil water
ENDWHILE
Pour water in cup
WHILE (sugar needed)
Add sugar
Page 8 of 25
ICT · Grade 11 · Programming — Lesson Notes
Stir tea
ENDWHILE
END.
Conversion rule: Every diamond with a loop-back becomes a WHILE…ENDWHILE. Every plain rectangle becomes one
pseudocode instruction line.
✎ PRACTICE — 1.3
Flowcharts and pseudocode
1. Draw a flowchart to find the perimeter and area of a rectangle, given its length and width.
2. Draw a flowchart for: "a company adds Rs. 5000 to the basic salary of every employee."
3. Write pseudocode to find the smallest of three numbers entered by the user.
4. Convert this flowchart idea into pseudocode: Start → Input a mark → IF mark ≥ 35 THEN show "Pass" ELSE
show "Fail" → End.
5. Write pseudocode (using FOR) to display the first 12 multiples of 7.
Page 9 of 25
ICT · Grade 11 · Programming — Lesson Notes
SECTION 1.4
Pascal Programming
Turning pseudocode into a real, running program
1.4.1 Identifiers
An identifier is the name you give to a variable, constant or program.
– Must start with a letter (A–Z, a–z)
– After the first letter, only letters, digits (0–9) and underscore ( _ ) are allowed
– No spaces or special symbols ( ! @ # $ % etc.)
– Not case sensitive — Art, art and ART are treated as the same identifier
– Cannot be a reserved word (e.g. BEGIN, END, IF)
Valid identifiers Invalid identifiers
Important: Values of char and string type are always written inside single quotation marks, e.g. 'k' or 'ICT'.
1.4.5 Operators
Arithmetic operators
Operator Meaning Example Result
+ Addition 6+3 9
- Subtraction 7-5 2
* Multiplication 2*5 10
/ Division 10 / 4 2.50
DIV & MOD: 20 ÷ 6 goes in 3 whole times with 2 left over, so 20 DIV 6 = 3 and 20 MOD 6 = 2.
Comparison operators
Comparisons always produce a Boolean result — True or False.
1 (highest) NOT
Page 11 of 25
ICT · Grade 11 · Programming — Lesson Notes
Priority Operators
3 + - OR
Page 12 of 25
ICT · Grade 11 · Programming — Lesson Notes
program LargeNo(input,output);
var N1, N2, Large : integer;
begin
writeln('Enter Two Numbers'); read(N1, N2);
if N1 > N2 then
Large := N1
else
Large := N2;
writeln('Large Number is ', Large);
end.
if M >= 75 then
Grade := 'A'
else
if M >= 65 then
Grade := 'B'
else
if M >= 50 then
Grade := 'C'
else
if M >= 35 then
Grade := 'S'
else
Grade := 'F';
Why "nested"?: Each ELSE contains another whole IF statement inside it. Only one branch ever runs, chosen from
the top down.
Page 13 of 25
ICT · Grade 11 · Programming — Lesson Notes
program FindGrade(input,output);
var Marks : integer; Grade : char;
begin
writeln('Enter Marks'); read(Marks);
case Marks of
0..34 : Grade := 'W';
35..49 : Grade := 'S';
50..64 : Grade := 'C';
65..74 : Grade := 'B';
75..100 : Grade := 'A';
else writeln('Invalid Marks');
end;
writeln('Grade is ', Grade);
end.
Page 14 of 25
ICT · Grade 11 · Programming — Lesson Notes
WHILE … DO vs. REPEAT … UNTIL — when repeats are not known in advance
WHILE … DO REPEAT … UNTIL
Condition checked BEFORE the loop body runs Condition checked AFTER the loop body runs
If false at the start, the body never runs The body always runs at least once
Stops when the condition becomes FALSE Stops when the condition becomes TRUE
number := 1; count := 0;
while number <= 10 do repeat
number := number + 1; writeln('Pascal');
count := count + 1;
until count > 5;
for count := 1 to 10 do
begin
read(num);
if num mod 2 = 0 then
Page 15 of 25
ICT · Grade 11 · Programming — Lesson Notes
e_count := e_count + 1
else
o_count := o_count + 1;
end;
Page 16 of 25
ICT · Grade 11 · Programming — Lesson Notes
1.4.9 Arrays
An array stores many values of the same data type under a single variable name, instead of needing a separate
identifier for each value.
45 75 36 81 60
num[0] num[1] num[2] num[3] num[4]
program ictMarks(input,output);
var marks : array[0..34] of integer;
i, tot, max : integer; avg : real;
begin
for i := 0 to 34 do
begin
read(marks[i]);
tot := tot + marks[i];
end;
avg := tot / 35;
max := marks[0];
for i := 1 to 34 do
if marks[i] > max then max := marks[i];
writeln('Maximum marks = ', max);
writeln('Average marks = ', avg);
end.
Input Input
↓ ↓
PROCEDURE FUNCTION
No value returned
↓
Returns a value
Procedure Function
Performs a task but does NOT return a value Performs a task and DOES return a value to the caller
Page 17 of 25
ICT · Grade 11 · Programming — Lesson Notes
var area:real;
begin
area := pi * radius * radius;
processArea := area; { the function's own name carries the return value }
end;
Page 18 of 25
ICT · Grade 11 · Programming — Lesson Notes
SECTION 1.5
✎ PRACTICE — 1.5
1. In your own words, explain why writing directly in 1s and 0s would be impractical for most programmers.
2. Name one advantage of using pseudocode before writing code in any specific programming language.
Page 19 of 25
ICT · Grade 11 · Programming — Lesson Notes
The problem
A teacher enters a student's ICT mark. The program should display "Pass" if the mark is 35 or above, and "Fail"
otherwise.
Input · Process · Output
Algorithm
1. Get the mark, M
2. If M is 35 or more, the result is Pass
3. Otherwise, the result is Fail
4. Show the result
Pseudocode
BEGIN
READ mark as M
IF M >= 35 THEN
DISPLAY "Pass"
ELSE
DISPLAY "Fail"
ENDIF
END.
Pascal code
program passFail(input,output);
var M : integer;
begin
writeln('Enter Mark');
read(M);
if M >= 35 then
writeln('Pass')
else
writeln('Fail');
end.
Sample run
Input: M = 42 → Output: Pass
Page 20 of 25
ICT · Grade 11 · Programming — Lesson Notes
The problem
A user will enter exactly 5 numbers, one at a time. The program should calculate and display their total and
their average.
Input · Process · Output
5 numbers, one at a time Add each number to a running Total; Total and Average
after all 5, divide by 5
Algorithm
1. Set Total to 0 and count to 1
2. While count is 5 or less: read a Number, add it to Total, add 1 to count
3. Once the loop ends, calculate Average = Total / 5
4. Show Total and Average
Pseudocode
BEGIN
Total = 0
count = 1
WHILE count <= 5
READ Number
Total = Total + Number
count = count + 1
ENDWHILE
Average = Total / 5
DISPLAY Total, Average
END.
Pascal code
program sumAvg(input,output);
var total, num, count : integer;
avg : real;
begin
total := 0;
for count := 1 to 5 do
begin
writeln('Enter a number');
read(num);
total := total + num;
end;
avg := total / 5;
writeln('Total = ', total);
writeln('Average = ', avg);
end.
Sample run
Input: 10, 20, 15, 25, 30 → Output: Total = 100, Average = 20.00
Page 21 of 25
ICT · Grade 11 · Programming — Lesson Notes
WORKED EXAMPLE 3: Highest mark from a class, using an array and a function
The problem
A class of 8 students sit an ICT test. Store all 8 marks in an array, then use a function to find and return the
highest mark.
Input · Process · Output
8 marks, stored in an array Scan every element, keeping track of The highest mark in the class
the largest seen so far
Algorithm
1. Read 8 marks into an array called marks
2. Assume the first element is the largest so far
3. Compare every other element against the current largest; update it whenever a bigger mark is found
4. Once all elements are checked, the current largest is the answer
5. Show the highest mark
Pseudocode
BEGIN
FOR i = 0 TO 7
READ marks[i]
ENDFOR
max = marks[0]
FOR i = 1 TO 7
IF marks[i] > max THEN
max = marks[i]
ENDIF
ENDFOR
DISPLAY max
END.
program highestMark(input,output);
var marks : array[0..7] of integer;
i : integer;
begin
for i := 0 to 7 do
begin
writeln('Enter mark ', i+1);
read(marks[i]);
Page 22 of 25
ICT · Grade 11 · Programming — Lesson Notes
end;
writeln('Highest mark = ', findMax(marks));
end.
Sample run
Input: 65, 78, 92, 54, 88, 71, 60, 83 → Output: Highest mark = 92
Page 23 of 25
ICT · Grade 11 · Programming — Lesson Notes
Input / Process / Output The raw material, the ordered steps, and the result of
solving a problem
Array A single variable name that stores many values of the same
type
Study tip: Cover the right-hand column with a sheet of paper and try to explain each term in your own words — if
you can, you know it.
Page 24 of 25
ICT · Grade 11 · Programming — Lesson Notes
Practice 1.1
– Input: 100 toffees & 20 people. Process: repeatedly give 5 toffees to each person until none remain. Output:
each person holding 5 toffees.
– 3rd formula, (l + w) × 2, is simplest — the fewest operations.
Practice 1.2
– Repetition — the same question is repeated for every student in the class.
Practice 1.3
– Pass/Fail pseudocode: BEGIN → READ mark → IF mark >= 35 THEN DISPLAY "Pass" ELSE DISPLAY "Fail" → ENDIF
→ END.
Page 25 of 25