Skip to content
Marlbridge

Revision Notes

OxfordAQA IGCSE Computer Science (9210): Structured programming – Revision Notes

Revision notes for OxfordAQA IGCSE Computer Science 9210 section 3.2.11: modules, interfaces, local variables, parameters, return values and a self-test.

Level
IGCSE
Topic
Topic 2 – Programming
Updated

Aligned to OxfordAQA IGCSE Computer Science (9210), For teaching from September 2017, exams from May/June 2019. Official specification .

Syllabus page (what it covers and how it is assessed): OxfordAQA IGCSE Computer Science.

Syllabus points this page covers

9210

  • 3.2.11 Structured programming

Found an error? Report a correction.

Need help with this topic? Request a free trial class for IGCSE Computer Science (9210).

Condensed notes for section 3.2.11 Structured programming of OxfordAQA International GCSE Computer Science (9210). The restructuring example and library plan are in the structured programming study guide.

What the specification asks

  • Describe the structured approach, including modularised programming, clear, well documented interfaces (local variables, parameters) and return values.
  • Explain the advantages of the structured approach.
  • Exam material uses “parameter” for both parameters and arguments.

The approach in five points

  1. Decompose the problem into sub-problems.
  2. Write each sub-problem as a module (subroutine) with one task.
  3. Pass data in through parameters.
  4. Pass results out through return values.
  5. Keep working data in local variables and document each interface.
A module carries out one clearly defined task. Data goes in through parameters and the result comes out as a return value; working data is kept in local variables that nothing else can see or change; and the interface is documented. The main program becomes a short sequence of calls to modules.
Modules with one task, parameters in, a return value out, local variables inside and a documented interface.
A structure chart. The main program shows a menu and calls LoanBook, ReturnBook or ShowOverdue. LoanBook uses IsMemberValid and IsBookAvailable, which return True or False; ReturnBook uses DaysLate, which returns an integer, and Fine, which returns a real.
Decomposition: each sub-problem becomes a small module with one job.

What an interface documents

Part Example for Fine(daysLate)
Name Fine
Purpose Calculates the fine for a late book
Parameters (order, type, meaning) daysLate: integer, days past the due date
Return value (type, meaning) Real: fine in dollars, 0.0 if not late

A programmer should be able to use a module from its interface alone, without reading the code.

The comment block for the Fine subroutine gives its name, what it does, its parameter daysLate (integer, days after the due date) and its return value (real, the fine in dollars, 0.0 if not late). Treated as a black box, Fine(8) returns 2.0 without the caller reading its code.
The interface tells a caller everything needed to use a module without reading its code.

Local variables

Local variable Program-wide (global) variable
Declared inside a subroutine Declared for the whole program
Exists only while the subroutine runs Exists for the whole run
Only that subroutine can use or change it Any part of the program can change it
Same name can be reused in other subroutines safely A change in one place can break another
The main program and SumArray each have their own variable called total; SumArray’s total and i are local and are discarded when it finishes, so they do not interfere. Below, if subroutines A and B share one program-wide counter i and A calls B inside its loop, B changes i and breaks A’s loop.
Local variables stop one module accidentally changing another module’s data.

Advantages, with reasons

Advantage Because…
Easier to understand Each module is small with one job; the main program reads like a plan
Easier testing and debugging Modules are tested separately, so an error can be traced to one module
Easier maintenance Change one module; if its interface is unchanged, nothing else needs editing
Reuse A documented module can be used in other programs
Teamwork Programmers work on separate modules using agreed interfaces
Fewer unintended effects Local variables cannot be changed by other modules
Three features linked to six advantages. Modules with one job make a program easier to understand, easier to test and debug, and suit team development. Documented interfaces make it easier to maintain, allow reuse and let a team rely on agreed interfaces. Local variables mean fewer side effects.
For each advantage, say which feature causes it and what it allows or prevents.

Model description (4 points)

“The program is split into modules, each a subroutine with a single task. Data is passed into each module through parameters and results are passed back with return values. Each module uses local variables, so it cannot affect data in other modules. Every module has a documented interface stating its parameters and return value.”

Mini example

-- Area: returns the area of a rectangle (real)
-- Parameters: length, width (real, metres)
SUBROUTINE Area(length, width)
  result ← length * width        -- local variable
  RETURN result
ENDSUBROUTINE

OUTPUT Area(3.5, 2.0)            -- 7.0

The comment documents the interface; result is local; data enters through parameters and leaves through the return value.

Before, input checking, adding and averaging are mixed in one block. After, input checking lives in GetMark, which asks until a mark from 0 to 100 is entered and returns it, and Mean returns total / count; the main program just loops NumMarks times adding GetMark() and outputs Mean(sum, NumMarks). GetMark can be tested alone with −1, 0, 100 and 101.
Pull each job into its own module and the main program becomes a readable plan.

Key terms

Term Meaning
Structured programming Building a program from modules with clear interfaces, using sequence, selection and iteration
Module A self-contained subroutine that carries out one task
Decomposition Breaking a problem into smaller sub-problems
Interface The name, parameters and return value of a module, which other code relies on
Local variable A variable that exists and can be used only inside the subroutine where it is declared
Parameter A value passed into a subroutine (the exam’s term for arguments too)
Return value The value passed back from a function to its caller

Exam traps

  • A description that only says “use subroutines” misses interfaces, parameters, return values and local variables.
  • “Local variables can be accessed by any subroutine”: false; that describes a program-wide variable.
  • “Easier to debug” without a reason earns little: add “because each module can be tested on its own”.
  • Interface ≠ code: it is what the module needs and returns.
  • Repeating the same advantage in different words scores once.

Self-test

  1. Define the term module.
  2. Name the four features the specification lists for the structured approach.
  3. State what is meant by a local variable.
  4. Give two items that should be documented in a module’s interface.
  5. Explain how a structured approach makes testing easier.
  6. Explain how local variables reduce errors.
  7. Explain why a clear interface helps a team of programmers.
  8. Explain why changing the code inside a module need not affect the rest of the program.
  9. Two subroutines each declare a local variable called count. Do they interfere? Explain.
  10. Which term does the exam use for the values given in a subroutine call?
  11. Give one advantage of a main program made mostly of subroutine calls.
  12. A function returns a value. Explain why this is better than storing the result in a program-wide variable.

Answers:

  1. A self-contained subroutine that performs one specific task.
  2. Modularised programming; clear, well documented interfaces; local variables and parameters; return values.
  3. A variable declared inside a subroutine that exists only while it runs and can only be used inside it.
  4. Any two: name, purpose, parameters (with types), return value (with type).
  5. Each module can be tested on its own with chosen parameters, so errors are found in a small piece of code.
  6. They cannot be changed by other parts of the program, so modules cannot accidentally overwrite each other’s data.
  7. Each programmer only needs the agreed parameters and return values to use another’s module, so modules can be written at the same time.
  8. Other code depends only on the interface; if the parameters and return value stay the same, callers are unaffected.
  9. No; each count is local to its own subroutine and exists separately.
  10. Parameter.
  11. It is easy to read, because the calls describe the steps of the solution.
  12. The caller decides what to do with the value, and no other module can change it unexpectedly; the function stays independent and reusable.

More resources on this topic

Related resources

Get free revision emails (optional)

Occasional emails with practice questions, worked explanations and links to free resources for the qualification and subjects you choose. No spam, and you can unsubscribe from any email. The free tools on this site never need an email.