Lesson Notes By Weeks and Term v5 - Grade 11

Solution development: structured programming and control structures – Week 3 focus

Download the Lessonotes Mobile South Africa app for faster lesson access on Android and iPhone.

Subject: Information Technology

Class: Grade 11

Term: 1st Term

Week: 3

Theme: General lesson support

Lesson Video

This page supports the lesson note with a companion video and a short classroom-ready summary.

For class groups and homework, share this lesson page so learners also get the summary, objectives, and full lesson context.

Performance objectives

Lesson summary

Structured programming is a fundamental approach to software development that emphasizes clarity, efficiency, and maintainability. This week, we delve deeper into structured programming principles, focusing particularly on control structures, which are the building blocks of program logic. Understanding control structures is crucial for creating programs that solve real-world problems in a systematic and predictable manner. In the South African context, these skills are vital for developing innovative solutions tailored to our specific needs, from managing water resources in drought-stricken areas to improving the efficiency of our healthcare system.

Lesson notes

2.1 Structured Programming Principles Structured programming is a programming paradigm aimed at improving the clarity, quality, and development time of a computer program by making extensive use of subroutines, block structures, for and while loops—in contrast to using simple and potentially unstructured control flow into and out of blocks of code, as with assembly language.

Modularity: Breaking down a large, complex problem into smaller, manageable sub-problems or modules. Each module performs a specific task, making the overall program easier to understand, test, and maintain. Think of it like building a house; you don't build the entire house at once, you break it down into smaller tasks like laying the foundation, building the walls, and installing the roof.

Top-Down Design: Starting with the overall problem and progressively refining it into smaller, more detailed steps. This approach helps to organize the development process and ensures that the final program addresses the core requirements. This is like planning a trip. You start with your destination, then figure out the route, mode of transport, and accommodation details. Avoidance of Unrestricted "goto" Statements: "goto" statements allow direct jumps to arbitrary points in the code, making it difficult to follow the program's flow and introduce potential errors. Structured programming favors control structures (selection and repetition) to manage program flow in a more controlled and predictable manner. 2.2 Selection Control Structures Selection structures allow the program to make decisions based on certain conditions.

IF-THEN-ELSE: Executes one block of code if a condition is true, and another block of code if the condition is false. ```pseudocode IF condition THEN // Code to execute if condition is true ELSE // Code to execute if condition is false ENDIF ```

Example: A program to determine if a student has passed or failed based on their score. ```pseudocode INPUT score IF score >= 50 THEN DISPLAY "Pass" ELSE DISPLAY "Fail" ENDIF ``` Nested IFs: Placing one IF-THEN-ELSE statement inside another. This allows for more complex decision-making. ```pseudocode IF condition1 THEN IF condition2 THEN // Code to execute if both condition1 and condition2 are true ELSE // Code to execute if condition1 is true but condition2 is false ENDIF ELSE // Code to execute if condition1 is false ENDIF ```

Example: A program to determine the discount a customer receives based on their age and purchase amount. ```pseudocode INPUT age INPUT purchaseAmount IF age >= 60 THEN IF purchaseAmount > 500 THEN DISPLAY "Discount: 15%" ELSE DISPLAY "Discount: 10%" ENDIF ELSE IF purchaseAmount > 500 THEN DISPLAY "Discount: 5%" ELSE DISPLAY "No Discount" ENDIF ENDIF ``` CASE (or SWITCH)

Statements: Allows selecting one block of code to execute from a set of possible blocks, based on the value of a variable. ```pseudocode CASE variable OF value1: // Code to execute if variable = value1 value2: // Code to execute if variable = value2 ...

OTHERWISE: // Code to execute if variable does not match any of the above values ENDCASE ```

Example: A program to display the day of the week based on a number entered (1 for Monday, 2 for Tuesday, etc.). ```pseudocode INPUT dayNumber CASE dayNumber OF 1: DISPLAY "Monday" 2: DISPLAY "Tuesday" 3: DISPLAY "Wednesday" 4: DISPLAY "Thursday" 5: DISPLAY "Friday" 6: DISPLAY "Saturday" 7: DISPLAY "Sunday" OTHERWISE: DISPLAY "Invalid day number" ENDCASE ``` 2.3 Repetition Control Structures (Loops) Repetition structures allow a block of code to be executed repeatedly until a certain condition is met.

FOR Loop: Executes a block of code a specific number of times. ```pseudocode FOR counter = startValue TO endValue STEP increment // Code to execute repeatedly NEXT counter ```

Example: A program to display the numbers from 1 to 10. ```pseudocode FOR i = 1 TO 10 DISPLAY i NEXT i ``` WHILE Loop: Executes a block of code as long as a condition is true. The condition is checked before each execution of the loop. ```pseudocode WHILE condition // Code to execute repeatedly ENDWHILE ```

Example: A program to calculate the sum of numbers entered by the user until the user enters 0. ```pseudocode sum = 0 INPUT number WHILE number != 0 sum = sum + number INPUT number ENDWHILE DISPLAY "Sum = ", sum ``` REPEAT-UNTIL Loop: Executes a block of code repeatedly until a condition is true. The condition is checked after each execution of the loop. This guarantees that the loop will execute at least once. ```pseudocode REPEAT // Code to execute repeatedly UNTIL condition ```

Example: A program to ask the user to enter a positive number, and keeps asking until a positive number is entered. ```pseudocode REPEAT INPUT number UNTIL number > 0 DISPLAY "You entered a positive number: ", number ``` 2.4 Nested Control Structures: Control structures can be nested within each other to create more complex logic.