Solution development: structured programming and control structures – Week 1 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: 1
Theme: General lesson support
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.
This week, we begin our exploration of solution development using structured programming techniques and control structures. This is a fundamental skill in IT, allowing us to create programs that solve problems logically and efficiently. In South Africa, the ability to develop effective software solutions is crucial for addressing challenges in various sectors, from healthcare and education to business and government services. Imagine developing an app that helps farmers in rural areas access market prices, or a system that manages patient records more efficiently in public hospitals. The skills you learn this week will lay the groundwork for creating such impactful solutions.
2.1 Structured Programming: Structured programming is a programming paradigm aimed at improving code clarity, quality, and development time by using a disciplined approach to organizing code.
Its core principles are: Modularity: Breaking down a large problem into smaller, manageable sub-problems (modules or functions). Each module performs a specific task and can be developed and tested independently. This promotes reusability and simplifies debugging.
Top-Down Design: Starting with the overall problem and gradually refining it into smaller and smaller components. This helps in understanding the problem comprehensively before starting to code.
Think of designing a house: you start with the overall layout and then focus on the details of each room.
Control Structures: Using only three basic control structures: sequence, selection, and repetition. These structures provide a clear and predictable flow of execution, making the code easier to understand and maintain.
Avoidance of 'goto' statements: 'goto' statements allow uncontrolled jumps in the code, making it difficult to follow the program's logic. Structured programming discourages their use in favor of well-defined control structures. 2.2 Control Structures: Control structures determine the order in which statements in a program are executed. There are three fundamental control structures: Sequence: Statements are executed in the order they appear in the code, one after another. This is the simplest control structure.
Example (Python): ```python Sequence example num1 = 10 num2 = 5 sum = num1 + num2 print("The sum is:", sum) ``` Explanation: The code first assigns values to `num1` and `num2`, then calculates their sum, and finally prints the result. Each statement is executed in the order it appears.
Selection (Conditional Statements): Selection structures allow the program to execute different blocks of code based on a condition. The most common selection structures are `if`, `if-else`, and `if-elif-else`. `if` statement: Executes a block of code only if a condition is true.
Example (Python): ```python if statement example age = 18 if age >= 18: print("You are eligible to vote.") ``` Explanation: The code checks if the value of `age` is greater than or equal to
1
8. If it is, the message "You are eligible to vote." is printed. Otherwise, nothing happens. `if-else` statement: Executes one block of code if a condition is true and another block of code if the condition is false.
Example (Python): ```python if-else statement example age = 16 if age >= 18: print("You are eligible to vote.") else: print("You are not eligible to vote.") ``` Explanation: The code checks if the value of `age` is greater than or equal to
1
8. If it is, the message "You are eligible to vote." is printed. Otherwise, the message "You are not eligible to vote." is printed. `if-elif-else` statement: Allows for multiple conditions to be checked sequentially. The `elif` (else if) keyword allows you to specify additional conditions. The `else` block is executed only if none of the preceding conditions are true.
Example (Python): ```python if-elif-else statement example score = 75 if score >= 80: grade = "A" elif score >= 70: grade = "B" elif score >= 60: grade = "C" else: grade = "D" print("Your grade is:", grade) ``` Explanation: The code checks the value of `score` against multiple conditions. If `score` is 80 or more, `grade` is assigned "A". If `score` is between 70 and 79, `grade` is assigned "B", and so on. If none of the conditions are met, `grade` is assigned "D". This is used for multiple possible outcomes. 2.3 Worked Examples with South African Context: Example 1: Calculating electricity bill based on usage (if-elif-else) Let's say Eskom charges different rates for electricity consumption.
The rate structure is as follows: 0-50 kWh: R1.50 per kWh 51-200 kWh: R2.00 per kWh 201+ kWh: R2.50 per kWh Write a program to calculate the electricity bill based on the number of kWh consumed. ```python Electricity bill calculator kwh_consumed = float(input("Enter the number of kWh consumed: ")) if kwh_consumed = 70: print("Congratulations! You qualify for the bursary.") else: print("Unfortunately, you do not qualify for the bursary.") ``` Explanation: This example uses an `if-else` statement to check if the learner's mark meets the eligibility criteria for the bursary. This is a relevant scenario for many learners in South Africa. Guided Practice (With Solutions)
Question 1: Write a program that takes a learner's age as input and determines whether they are old enough to obtain a driver's license (age 18 or older).
Solution: ```python age = int(input("Enter your age: ")) if age >= 18: print("You are eligible to obtain a driver's license.") else: print("You are not yet eligible to obtain a driver's license.") ```
Commentary: This problem uses a simple `if-else` statement to check if the learner's age meets the minimum requirement for obtaining a driver's license.