Lesson Notes By Weeks and Term v5 - Grade 11

Advanced programming: modularisation and data structures (Grade 11 focus) – Week 2 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: 2

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

This week, we delve deeper into two crucial aspects of advanced programming: modularisation and data structures. Modularisation is about breaking down a large, complex program into smaller, more manageable, and reusable components (modules or functions).

Think of it like building a house: you wouldn't build the entire house at once; you'd build the foundation, walls, roof, etc., separately and then assemble them. Similarly, modularisation allows us to create well-organized and maintainable code. Data structures, on the other hand, are ways of organizing and storing data so that we can use it efficiently.

Lesson notes

2.1 Modularisation: Definition: Modularisation is the process of dividing a program into smaller, independent modules (functions or procedures) that perform specific tasks.

Advantages: Code Reusability: Modules can be reused in different parts of the same program or even in different programs, saving time and effort. Imagine creating a function to calculate the average rainfall for a specific region; you could reuse this function in multiple agricultural applications.

Maintainability: When changes are needed, it's easier to locate and modify the specific module responsible for the task. If the formula for calculating crop yield changes, you only need to update the 'calculate_yield' function.

Reduced Complexity: Breaking down a large problem into smaller, manageable modules makes the overall program easier to understand and develop. Think of it as tackling a large puzzle one small section at a time.

Collaboration: Modular programming facilitates teamwork, as different developers can work on different modules simultaneously. Functions vs.

Procedures: A function is a block of code that performs a specific task and returns a value. A procedure (sometimes called a subroutine) is a block of code that performs a specific task but does not necessarily return a value. In some languages, the distinction is less clear, and all subprograms are called functions. Python uses the `def` keyword to define both functions and procedures (functions that don't explicitly return a value implicitly return `None`).

Example (Python): ```python def calculate_area_rectangle(length, width): # Function to calculate rectangle area """Calculates the area of a rectangle.""" # Docstring - good practice! area = length * width return area def display_message(message): # Procedure to display a message """Displays a message to the user.""" print(message) Example Usage length = 10 width = 5 rectangle_area = calculate_area_rectangle(length, width) display_message(f"The area of the rectangle is: {rectangle_area}") ``` 2.2 Data Structures: Definition: A data structure is a particular way of organizing and storing data in a computer so that it can be used efficiently.

Common Data Structures (Grade 11 focus): Arrays/Lists: An ordered collection of elements of the same data type, stored in contiguous memory locations. In Python, lists are more flexible than traditional arrays as they can hold elements of different data types.

Characteristics: Elements are accessed using an index (starting from 0). Elements can be added, removed, or modified. Fixed size (in some languages like C++, but dynamically sized in Python lists).

Example (Python): ```python List of student names student_names = ["Thando", "Sipho", "Aisha", "David"] print(student_names[0]) # Accessing the first element (Thando) student_names.append("Zanele") # Adding a new student print(student_names) ``` Records/Dictionaries: A collection of fields (or keys) each containing one item of information. In Python, dictionaries are used to implement records.

Characteristics: Elements are accessed using a key (a unique identifier). Elements can be added, removed, or modified. Unordered (the order in which elements are added is not guaranteed).

Example (Python): ```python Dictionary representing a student's information student = { "name": "Thando Dlamini", "age": 17, "grade": 11, "subjects": ["IT", "Maths", "English"] } print(student["name"]) # Accessing the student's name student["city"] = "Johannesburg" # Adding a new field print(student) ``` 2.3 Choosing the Right Data Structure: The choice of data structure depends on the specific problem you are trying to solve.

Arrays/Lists: Use when you need to store an ordered collection of items and access them by their position (index). Good for storing sequences of numbers, names, or other data where order matters.

Records/Dictionaries: Use when you need to store data associated with specific keys (labels). Good for representing objects with attributes, such as student records, product information, or configuration settings.

Example: If you're writing a program to store and process the results of a class test, a list of numbers (the scores) would be a suitable data structure. If you're writing a program to store information about each student (name, ID, score), a dictionary would be more appropriate. Guided Practice (With Solutions)

Question 1: Write a Python function called `calculate_average` that takes a list of numbers as input and returns the average of those numbers. If the list is empty, it should return 0.