LEARNING OBJECTIVES
What you will be able to do
- select data types, variables, constants and operators
- use sequence, selection and iteration
- manipulate strings, arrays and files
- design procedures and functions with appropriate scope
AT A GLANCE
INTRODUCTION · THE BIG IDEA
Build maintainable programs using data, control structures, arrays, files and modular design.
Programming translates an algorithm into precise statements a computer can execute. Correctness comes first, followed by readability, maintainability and robustness.
The syllabus expects practical experience writing, executing, testing and debugging programs as well as reading pseudocode.
SECTION 01
Data types, variables and operators
Common data types are integer, real, character, string and Boolean. A constant has a named value that does not change. Type choice affects valid operations, storage and input checking.
Arithmetic operators include +, −, *, /, integer division DIV and remainder MOD. Relational operators compare values and Boolean operators AND, OR and NOT combine conditions. Precedence matters, so parentheses improve clarity.
Using DIV and MOD
- Convert 367 seconds to minutes and seconds.
- Minutes = 367 DIV 60 = 6.
- Seconds = 367 MOD 60 = 7.
Answer: 367 seconds is 6 minutes 7 seconds.
SECTION 02
Selection and iteration
IF statements make one- or two-way decisions; nested IF handles dependent conditions; CASE selects among discrete values. Conditions should be mutually clear and cover required alternatives.
A count-controlled FOR loop repeats a known number of times. A pre-condition WHILE loop may run zero times; a post-condition REPEAT loop runs at least once. Choose the structure that matches the termination rule.
| Structure | Use when | Key feature |
|---|---|---|
| FOR | repeat count known | control variable changes automatically |
| WHILE | test before each pass | may execute zero times |
| REPEAT | test after each pass | executes at least once |
SECTION 03
Strings and arrays
String operations can find length, extract a substring, convert case and access characters. Index rules must match the pseudocode convention used in the question.
A one-dimensional array stores a list under one identifier; a two-dimensional array stores rows and columns. Arrays use loops for input, search, total and update. Parallel arrays use the same index for related values, though records are often clearer in real programs.
Average of an array
- Initialise Total to 0 before the loop.
- For each of 5 scores, add Scores[Index] to Total.
- After the loop, calculate Total / 5.
Answer: The accumulator must be initialised once, not reset during each iteration.
SECTION 04
Procedures, functions and scope
A procedure performs a task; a function returns a value. Parameters pass information and can be by value or by reference where specified. Local variables exist within one module; global variables are widely accessible but increase coupling.
Modules reduce duplication, support team development and can be tested independently. Interfaces should clearly state parameter types and returned results. Maintainable code uses meaningful identifiers, indentation and comments that explain purpose rather than repeat statements.
SECTION 05
Files, robustness and maintenance
Text files provide persistent sequential storage. A program opens a file in read or write mode, processes records and closes it. End-of-file checks prevent reading beyond available data; write mode may overwrite existing content.
Robust programs validate input, handle exceptional cases and give clear messages. Syntax errors break language rules, runtime errors occur during execution and logic errors produce incorrect results. Test, locate, correct and retest each fault.
Corrective maintenance fixes faults, adaptive maintenance responds to environment change and perfective maintenance improves performance or usability.
QUICK CHAPTER SUMMARY
The ideas to carry forward
- Choose types and operators deliberately.
- Control structures should mirror the algorithm's decision and repetition rules.
- Arrays and files organise repeated and persistent data.
- Modular programs are easier to test and maintain.
QUICK REVISION CHECKLIST
Can you do each of these without your notes?
- select data types, variables, constants and operators
- use sequence, selection and iteration
- manipulate strings, arrays and files
- design procedures and functions with appropriate scope