Lesson Notes By Weeks and Term v3 - Senior Secondary 3

BASIC programme III (Onedimentional array)

Download the Lessonotes Mobile Nigeria 2025 app for faster lesson access on Android and iPhone.

Subject: Computer & IT

Class: Senior Secondary 3

Term: 2nd Term

Week: 4

Theme: Problems - Solving Skills

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

Array: An array is a collection of variables of the same data type, stored under a single common name. Each item in the array is called an element. Elements are typically stored in contiguous memory locations, allowing for efficient access. To distinguish between elements, each element is assigned a unique number called an index or subscript. In BASIC, array indices usually start from 0 or 1, depending on the specific BASIC interpreter or explicit declaration (using `OPTION BASE`). For simplicity and common practice, assume 0-based indexing unless specified.

One-Dimensional Array: A one-dimensional array is like a list or a row of items. It has only one index to identify each element.

Lesson notes

Phase 1: Introduction and Concept Definition (15 minutes)

Teacher Activity: Introduce the problem of managing large sets of similar data (e.g., 50 student scores, 100 daily market prices). Ask students how they would typically store these using variables. Guide them to understand the inefficiency of using `score1, score2, ..., score50`. Introduce the concept of an "array" as a more efficient solution – a single name for a collection of related data. Define "array," "element," and "index" clearly, using analogies relevant to local context (e.g., a row of numbered stalls in a market, a list of names for a community meeting, numbered compartments in a medicine cabinet). Explain specifically what a "one-dimensional array" is and how it functions as a linear list. Display a chart or write on the board the conceptual representation of an array `SCORES(0) ... SCORES(9)`.

Student Activity: Participate in discussion, suggest methods for data storage. Listen attentively, take notes on definitions. Ask clarifying questions about the analogies used.

Phase 2: Array Declaration and Basic Operations (20 minutes)

Teacher Activity: Introduce the `DIM` statement for declaring arrays. Explain its syntax and how `upperBound` determines the number of elements (emphasize `N+1` for 0-based indexing). Provide simple examples of `DIM` statements: `DIM Age(19)`, `DIM ProductPrices(49)`. Explain how to assign values to specific elements (e.g., `Age(0) = 15`) and access values (e.g., `PRINT Age(5)`). List and explain other basic array operations: initialization, input, output, and the idea of processing. Demonstrate on the board how to declare, input into, and print elements of a small array (e.g., 3 elements).

Student Activity: Practice writing `DIM` statements for different array sizes. Work through examples of assigning and accessing array elements verbally or on paper. Ask questions regarding array bounds and index numbering.

Phase 3: Looping with Arrays (FOR-NEXT, WHILE-END) (30 minutes)

Teacher Activity: Emphasize that manually assigning/accessing elements for large arrays is impractical. Introduce loops as the solution. Focus on `FOR-NEXT` loop for its suitability in iterating through arrays with known sizes. Walk through Worked Example 2 (summing 5 numbers) step-by-step, explaining each line of code. Trace the values of `i` and `Total` during execution. Provide a brief overview of `WHILE-END` loop's syntax and its use case (e.g., when the exact number of elements is unknown, using a sentinel value). Walk through Worked Example 3 (reading until a negative number). Explain the role of the sentinel value and the loop condition. Highlight the difference in application compared to `FOR-NEXT`.

Discuss common errors: array out of bounds, off-by-one errors in loop limits.

Student Activity: Copy and analyze `FOR-NEXT` and `WHILE-END` examples. Participate in tracing the execution of the example programs. Practice modifying loop bounds for arrays of different sizes. Engage in a quick "debug this snippet" activity if time permits, identifying potential errors.

Phase 4: Practical Application and Review (25 minutes)

Teacher Activity: Present simple problems that require array usage, focusing on the performance objectives. Guide students through Guided Practice questions, encouraging collaborative problem-solving. Circulate to observe student progress and provide immediate feedback.

Summarize key takeaways: definition of array, `DIM` statement, `FOR-NEXT` for fixed iterations, `WHILE-END` for conditional iterations.

Student Activity: Attempt Guided Practice questions individually or in pairs. Present solutions to the class and explain their logic. Participate in a class discussion for review and clarification.

Instruction: Students should attempt to write the BASIC programs for the following problems.

Question 1: Write a BASIC program that uses a `DIM` statement to declare an array named `Temperatures` to store the daily average temperatures for a week (7 days). Then, use a `FOR-NEXT` loop to accept 7 temperature values from the user and store them in the array. Finally, use another `FOR-NEXT` loop to print all the stored temperatures.

Solution 1: ```BASIC 10 REM Program to store and print weekly temperatures 20 DIM Temperatures(6) ' Array for 7 days (indices 0 to 6) 30 40 REM Input temperatures 50 FOR Day = 0 TO 6 60 PRINT "Enter temperature for Day "; Day + 1; " (in Celsius):" 70 INPUT Temperatures(Day) 80 NEXT Day 90 100 PRINT "--- Weekly Temperature Report ---" 110 REM Output temperatures 120 FOR Day = 0 TO 6 130 PRINT "Day "; Day + 1; ": "; Temperatures(Day); " degrees Celsius" 140 NEXT Day 150 END ```

Commentary: This program demonstrates the declaration of a one-dimensional array using `DIM`, and the use of `FOR-NEXT` loops for both inputting values into the array and displaying them, addressing performance objectives 1, 2, and 3.i & 3.iii. The index `Day + 1` is used to display user-friendly day numbers (1-7) while actual array indexing remains 0-

6. Question 2: Modify the program from Question 1 to also calculate and print the average weekly temperature after all values have been entered and displayed.

Solution 2: ```BASIC 10 REM Program to store, print, and average weekly temperatures 20 DIM Temperatures(6) ' Array for 7 days (indices 0 to 6) 30 TotalTemp = 0 ' Initialize variable for sum 40 50 REM Input temperatures 60 FOR Day = 0 TO 6 70 PRINT "Enter temperature for Day "; Day + 1; " (in Celsius):" 80 INPUT Temperatures(Day) 90 NEXT Day 100 110 PRINT "--- Weekly Temperature Report ---" 120 REM Output temperatures and calculate sum 130 FOR Day = 0 TO 6 140 PRINT "Day "; Day + 1; ": "; Temperatures(Day); " degrees Celsius" 150 TotalTemp = TotalTemp + Temperatures(Day) ' Add to total 160 NEXT Day 170 180 AverageTemp = TotalTemp / 7 ' Calculate average 190 PRINT "---------------------------------" 200 PRINT "Total Temperature: "; TotalTemp; " C" 210 PRINT "Average Weekly Temperature: "; AverageTemp; " degrees Celsius" 220 END ```

Commentary: This solution expands on Question 1 by introducing a variable `TotalTemp` to accumulate the sum of temperatures within the output loop. After the loop, the `AverageTemp` is calculated by dividing `TotalTemp` by the number of days (7). This demonstrates further array processing, addressing performance objective

2. Question 3: Write a BASIC program that declares an array `Prices` of size

5. Use a `WHILE-END` loop to read prices from the user into this array. The loop should stop if a price of 0 is entered (as a sentinel value) or if 5 prices have been entered. Print the number of valid prices entered and then print all valid prices.

Solution 3: ```BASIC 10 REM Program to read prices into an array using WHILE-END loop 20 DIM Prices(4) ' Array for 5 prices (indices 0 to 4) 30 i = 0 ' Initialize index for array 40 Count = 0 ' Initialize counter for valid prices 50 60 PRINT "Enter 5 prices (enter 0 to stop early):" 70 WHILE i <= 4 ' Loop as long as index is within bounds 80 INPUT "Price: ", CurrentPrice 90 IF CurrentPrice = 0 THEN GOTO 140 ' Sentinel value check 100 Prices(i) = CurrentPrice 110 Count = Count + 1 120 i = i + 1 130 WEND 140 150 PRINT "---------------------------------" 160 PRINT "Number of valid prices entered: "; Count 170 PRINT "Valid Prices:" 180 FOR j = 0 TO Count - 1 190 PRINT Prices(j) 200 NEXT j 210 END ```

Commentary: This program effectively uses a `WHILE-END` loop to handle variable input, stopping either when the array is full or a sentinel value (0) is entered. It correctly tracks the number of valid inputs using the `Count` variable, and then uses a `FOR-NEXT` loop to display only the valid elements. i = i + 1 130 WEND 140 150 PRINT "---------------------------------" 160 PRINT "Number of valid prices entered: "; Count 170 PRINT "Valid Prices:" 180 FOR j = 0 TO Count - 1 190 PRINT Prices(j) 200 NEXT j 210 END ```

Commentary: This program effectively uses a `WHILE-END` loop to handle variable input, stopping either when the array is full or a sentinel value (0) is entered. It correctly tracks the number of valid inputs using the `Count` variable, and then uses a `FOR-NEXT` loop to display only the valid elements. This addresses performance objectives 1, 2, 3.ii & 3.iii. Problems - Solving Skills

Real-life applications

Market Price Tracking and Analysis: In Nigeria, market prices for agricultural produce (e.g., yam, tomatoes, rice, maize) fluctuate daily across different markets (e.g., Bodija, Mile 12, Onitsha Main Market). An array can be used to store these daily prices over a week or month. Programs can then be written to calculate average prices, identify the highest/lowest prices, or track price trends, which is valuable for farmers, traders, and consumers to make informed decisions.

Census Data and Demographic Analysis: Government agencies collect vast amounts of demographic data during census exercises (e.g., population by age group, literacy rates by state, household sizes). Arrays can be used to store and process such data. For instance, an array could hold the population figures for each of Nigeria's 36 states, allowing for quick calculations of total population, or identifying the most populous states. This supports national planning and resource allocation.

Local Weather Monitoring: Community environmental groups or even local schools can collect daily rainfall measurements or temperature readings over a period. Storing these values in a one-dimensional array allows for easy calculation of monthly averages, identification of the wettest/driest days, or monitoring seasonal patterns crucial for local agriculture and flood prevention.

Teacher activity

Evaluation guide

Reference guide