Revise Computingrevisecomputing.co.uk
Free student revisionSee questionsFor schoolsSchool enquiry
Free revisionSee questionsFor schoolsSchool enquiry
Knowledge/A Level/H446/02 Algorithms and programming/Thinking Procedurally/Identify sub-procedures necessary to solve…

Identify sub-procedures necessary to solve a problem

Identify sub-procedures necessary to solve a problem.

2.1.3 Thinking Procedurally

Thinking Procedurally — Note 4 of 4

Candidates need to understand the use and purpose of sub-procedures in a program and identify where they may be used. Candidates should be able to write pseudocode, code and/or flowcharts for sub-procedures, using parameters where appropriate, and interpret or complete structure diagrams.

What you need to know

Sub-procedures (subroutines) are named blocks of code that carry out a specific task. Identifying where they are needed makes programs modular, easier to test and easier to maintain.

What to know

  • Look for tasks that are repeated, or that form a distinct, self-contained part of the solution.
  • Use parameters to pass in the data a sub-procedure needs and return values to pass results back.
  • Sub-procedures can be shown on a structure diagram, with each box representing a subroutine.

Key terms

Exam tipCommon mistake

Sub-proceduresubroutine

A named, self-contained block of code that performs a specific task and can be called from elsewhere in the program.

  • Exam tip: When writing sub-procedures, use parameters rather than global variables, and use the parameters that are passed in rather than asking for new input.

Code examples

Identifying sub-procedures for a quiz program
text
procedure runQuiz()
    score = 0
    for q = 1 to 10
        question = getQuestion(q)
        answer = askUser(question)
        if checkAnswer(q, answer) then
            score = score + 1
        endif
    next q
    showResult(score)
endprocedure
← Previous noteDetermine the order of the steps needed to solve a problem2.1.3 Thinking ProcedurallyNext topic →Identify the points in a solution where a decision has to be taken2.1.4 Thinking Logically

Back to Thinking Procedurally

Thinking Procedurally

Note 4 of 4

  1. 1Identify the components of a problem
  2. 2Identify the components of a solution to a problem
  3. 3Determine the order of the steps needed to solve a problem
  4. 4Identify sub-procedures necessary to solve a problem
Topic overview