Advanced programming: modularisation and data structures (Grade 11 focus) – 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: 3rd 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.
Welcome, Grade 11 IT learners, to the exciting world of advanced programming! This week, we're diving into modularisation and data structures – fundamental concepts that will transform the way you think about and write code. These aren’t just theoretical concepts; they are the backbone of almost every software application you use daily, from banking apps managing millions of accounts to social media platforms connecting people across the globe. Think about the EskomSePush app (popular in South Africa), which needs to efficiently store and manage load shedding schedules for the entire country.
2.1 Modularisation: Divide and Conquer Modularisation is the process of breaking down a large, complex program into smaller, self-contained modules (also known as functions, procedures, or subroutines). Each module performs a specific task, making the overall program easier to understand, debug, and maintain. Think of it like building a house – you don't build everything at once; you break it down into smaller tasks like laying the foundation, building walls, installing plumbing, etc. Each of these tasks can be considered a module.
Benefits of Modularisation: Reusability: Modules can be reused in different parts of the program or even in different programs altogether, saving time and effort.
Maintainability: Changes to one module are less likely to affect other parts of the program, making it easier to fix bugs and add new features.
Readability: Smaller modules are easier to understand than a single large block of code.
Collaboration: Multiple programmers can work on different modules simultaneously, speeding up the development process.
Testing: Modules can be tested independently, making it easier to identify and fix errors.
Example: Let's say you're writing a program to calculate the final marks for students in a class. You could break this down into modules like: `get_student_name()`: Gets the name of a student. `get_test_marks()`: Gets the marks for the test components. `calculate_final_mark()`: Calculates the final mark based on the test marks. `display_results()`: Displays the student's name and final mark.
Code Example (Python): ```python def get_student_name(): """Gets the name of a student from the user.""" name = input("Enter student name: ") return name def get_test_marks(): """Gets the marks for the different tests.""" test1 = float(input("Enter mark for Test 1: ")) test2 = float(input("Enter mark for Test 2: ")) return test1, test2 def calculate_final_mark(test1, test2): """Calculates the final mark based on the test marks (50% each).""" final_mark = (test1 0.5) + (test2 0.5) return final_mark def display_results(name, final_mark): """Displays the student's name and final mark.""" print(f"Student: {name}, Final Mark: {final_mark:.2f}") Main program student_name = get_student_name() mark1, mark2 = get_test_marks() final_mark = calculate_final_mark(mark1, mark2) display_results(student_name, final_mark) ``` 2.2 Data Structures: Arrays (Lists) A data structure is a way of organizing and storing data in a computer so that it can be used efficiently. Arrays (often called lists in Python) are one of the simplest and most fundamental data structures. An array is a collection of elements of the same data type, stored in contiguous memory locations.
Key Concepts: Index: Each element in an array is accessed using its index, which is a number representing its position in the array. Indices usually start at
0. Element: Each item stored in the array is called an element.
Data Type: All elements in a traditional array (in languages like Pascal or C++) must be of the same data type. Python lists are more flexible and can contain elements of different data types, but using the same data type is generally recommended for efficiency and clarity.
Example: Imagine you want to store the ages of 5 students in an array. ```python student_ages = [16, 17, 15, 18, 16] ``` In this array: `student_ages[0]` is 16 (the age of the first student). `student_ages[1]` is 17 (the age of the second student). `student_ages[2]` is 15 (the age of the third student). `student_ages[3]` is 18 (the age of the fourth student). `student_ages[4]` is 16 (the age of the fifth student).
Common Array Operations: Accessing Elements: Retrieving the value of an element at a specific index (e.g., `student_ages[2]`).
Modifying Elements: Changing the value of an element at a specific index (e.g., `student_ages[2] = 16`).
Adding Elements: Adding a new element to the array (using methods like `append()` in Python lists).
Deleting Elements: Removing an element from the array (using methods like `remove()` or `pop()` in Python lists).
Iterating through Elements: Looping through all the elements in the array to perform some operation on each element.
Code Example (Python): ```python Creating an array (list) student_names = ["Thando", "Ayanda", "Sipho", "Zanele", "Bongani"] Accessing elements print(f"The first student is: {student_names[0]}") print(f"The third student is: {student_names[2]}") Modifying an element student_names[1] = "Amanda" # Corrected the name Ayanda to Amanda print(f"The second student is now: {student_names[1]}") Adding an element student_names.append("Lerato") print(f"The list of students is now: {student_names}") Deleting an element student_names.remove("Sipho") print(f"The list of students is now: {student_names}") Iterating through the array print("List of students:") for name in student_names: print(name) ``` 2.3 Local vs. Global Variables Understanding the scope of variables is crucial in modularised programs.