Level:
Correct: 0
Incorrect: 0
Marks: 0/0
Exam Practice
Course:
Topics:
AQA GCSE Computer Science (Paper 1) Smart practice A mixed round aimed at your weak spots
Unit 1
3.1 Fundamentals of algorithms
Unit 2
3.2 Programming
Data types
Data types
Arithmetic operations in a programming language
Arithmetic operations, DIV and MOD
Relational operations in a programming language
Relational operations
Boolean operations in a programming language
Boolean operations in conditions
Data structures
Arrays and records
Input/output
Input and output
String handling operations in a programming language
String handling
Random number generation in a programming language
Random number generation
Structured programming and subroutines (procedures and functions)
Subroutines and structured programming
Avg
score:
–
Topics
done:
0/15

Subroutines and structured programming

Practise 35 exam-style questions on Subroutines and structured programming for AQA GCSE Computer Science (Paper 1). Write your answer as you would in the exam and get it marked in seconds against the mark scheme, point by point, with the Study Helper on hand if you get stuck.

  • 35 questions
  • 1–11 marks each
  • Instant marking
  • No sign-up needed
20 questions, marked as you go

Sample questions with model answers

Here are 4 of the questions in this topic, each with a model answer, an explanation of why it earns the marks and the mark scheme an examiner would use.

Question 1

1 mark

A library program contains the four pseudo-code statements below.

Which one of the statements calls a subroutine?

Choose your answer.

  • SUBROUTINE lateFee(days)
  • RETURN days * 20
  • fee ← lateFee(days)
  • total ← total + fee

Model answer

fee ← lateFee(days)

Explanation

A subroutine is called by writing its name with any parameters in a statement, and fee ← lateFee(days) calls lateFee and stores the value it returns. SUBROUTINE lateFee(days) defines the subroutine but does not run it, and RETURN days * 20 is inside the subroutine. The last statement is an ordinary assignment.

Mark scheme
  1. 1 mark

    fee ← lateFee(days)

    If more than one option is given, 0 marks. Mark is for AO2 (apply).

Question 2

2 marks

A programmer writes a subroutine that works with values stored in variables that can be accessed from anywhere in the program (global variables), instead of having the values passed to it.

Explain two reasons why it would be better to pass the values to the subroutine as parameters.

Model answer

With parameters the subroutine is self-contained, so it can be called with different values or reused in another program. Global variables can be changed by any part of the program, so an unexpected change could cause a logic error that is hard to track down.

Explanation

Parameters give a subroutine a clear interface: the data it needs is passed in at the call, so it does not depend on the rest of the program. Global variables can be altered from anywhere, which makes errors hard to find. 'Parameters are faster' is not a valid reason.

Mark scheme
  1. 1 mark

    The subroutine is self-contained, so it can be reused (in other programs / called with different values)

    2 marks for AO1 (understanding). Max 2 marks from the four points; each mark must be for a different idea.

  2. 1 mark

    A global variable could be changed (accidentally) by any part of the program, causing logic errors that are hard to find

  3. 1 mark

    The interface is clear: it is obvious from the call / definition what data the subroutine uses

  4. 1 mark

    The subroutine can be tested on its own by passing it test values

Question 3

3 marks

The algorithm below is written in pseudo-code.

01SUBROUTINE greet(name, times)
02  FOR i ← 1 TO times
03    OUTPUT 'Hello ' + name
04  ENDFOR
05ENDSUBROUTINE
06OUTPUT 'Start'
07greet('Tomasz', 2)
08OUTPUT 'End'

Describe what happens when line 7 is executed.

Model answer

Line 7 calls greet, so execution passes to line 1. The parameter name is given the value 'Tomasz' and times the value 2, and the FOR loop runs twice, outputting Hello Tomasz twice. At ENDSUBROUTINE, execution returns to the line after the call, line 8, which outputs End.

Explanation

A subroutine is 'out of line' code: a call transfers control to it, passes the values into its parameters, runs its statements and then returns to the point after the call. Here the whole output is Start, Hello Tomasz, Hello Tomasz, End. Answers that just say 'greet runs' do not describe the call and the return.

Mark scheme
  1. 1 mark

    Execution jumps / passes to the subroutine greet (line 1)

    3 marks for AO2 (apply). Max 3 marks from the four points. NE. 'the subroutine runs' on its own.

  2. 1 mark

    The parameter name is given the value 'Tomasz' and times the value 2

    Both values needed.

  3. 1 mark

    The loop in greet runs twice, outputting Hello Tomasz twice

  4. 1 mark

    When the subroutine ends (ENDSUBROUTINE), execution returns to the statement after the call / line 8 (so End is output)

Question 4

5 marks

An online shop works out a delivery charge, in pence:
- the charge is 300 for a parcel that weighs 2 kg or less
- for a parcel that weighs more than 2 kg, the charge is 300 plus 100 for every kg over 2 kg
- 250 is added to the charge if the delivery distance is more than 50 miles.

Write a subroutine called deliveryCharge that:
- takes the weight in kg and the distance in miles, both whole numbers, as two parameters in that order
- returns the delivery charge.

The subroutine must not use any input or output statements.

You should write your answer in C#, Python or VB.NET.

Model answer

def deliveryCharge(weight, distance):
    charge = 300
    if weight > 2:
        charge = charge + (weight - 2) * 100
    if distance > 50:
        charge = charge + 250
    return charge

Explanation

The charge starts at 300 and two separate IF statements add the extra amounts, so a heavy parcel going a long way gets both. For more than 2 kg the extra is (weight - 2) * 100, so a 5 kg parcel costs 600, or 850 if it goes more than 50 miles. The subroutine must return the charge, not print it, and must use > 50 so that exactly 50 miles costs nothing extra.

Mark scheme
  1. 1 mark

    Mark A for the use of selection to decide whether each extra amount is added to the charge

    1 mark for AO3 (design), 4 marks for AO3 (program). Program Design. Note that AO3 (design) marks are for selecting appropriate techniques to use to solve the problem, so should be credited whether the syntax of programming language statements is correct or not and regardless of whether the solution works.

  2. 1 mark

    Mark B for defining a subroutine called deliveryCharge with two parameters, for the weight and the distance, in that order

    Program Logic. A. with or without static (C#).

  3. 1 mark

    Mark C for a weight charge that is correct in all cases: 300 for 2 kg or less, and 300 + (weight - 2) * 100 for more than 2 kg

    A. weight * 100 + 100 for more than 2 kg (equivalent). R. 300 + weight * 100.

  4. 1 mark

    Mark D for adding 250 only when the distance is more than 50

    R. distance >= 50.

  5. 1 mark

    Mark E for returning the charge after both checks have been made

    R. if the charge is output instead of (or as well as) being returned. R. if the weight or distance is input inside the subroutine.
    Maximum 4 marks if any errors in code. I. Case. I. Indentation. I. Messages or no messages with input statements. I. Gaps/spaces throughout the code, except where to do so would explicitly alter the logic of the code in a way that makes it incorrect. Minor syntax errors that do not affect the logic flow are not penalised (AQA marking guidance): missing colons or semicolons, the case of keywords and identifiers, missing import statements, = or == in a condition, <> or != or ≠ for not equal, ( ) instead of [ ] for list access, and misspelt keywords whose meaning is clear (e.g. whiel for while). Answers in C#, Python or VB.NET (or AQA-style pseudo-code where the question allows it) are marked on their logic, never on one language's syntax.
    Note to examiners: the C# and VB.NET examples include variable declarations so that they run; any correct variable declarations in student answers should be accepted, and (as in AQA's marking guidance for C# and VB.NET) a missing declaration that would make the code correct is marked as if the declaration were present.
    Test values: deliveryCharge(2, 10) returns 300; deliveryCharge(5, 10) returns 600; deliveryCharge(5, 60) returns 850; deliveryCharge(3, 50) returns 400.
    Python Example 1 (fully correct)
    All design marks are achieved (Mark A)
    def deliveryCharge(weight, distance):
    charge = 300
    if weight > 2:
    charge = charge + (weight - 2) * 100
    if distance > 50:
    charge = charge + 250
    return charge
    C# Example 1 (fully correct)
    All design marks are achieved (Mark A)
    static int deliveryCharge(int weight, int distance)
    {
    int charge = 300;
    if (weight > 2)
    {
    charge = charge + (weight - 2) * 100;
    }
    if (distance > 50)
    {
    charge = charge + 250;
    }
    return charge;
    }
    VB.NET Example 1 (fully correct)
    All design marks are achieved (Mark A)
    Function deliveryCharge(weight As Integer, distance As Integer) As Integer
    Dim charge As Integer = 300
    If weight > 2 Then
    charge = charge + (weight - 2) * 100
    End If
    If distance > 50 Then
    charge = charge + 250
    End If
    Return charge
    End Function

Ready to try the rest? Every answer you write is marked against the mark scheme, so you can see exactly where the marks are.

Study Helper Hints first, answers after you try

Stuck on this one? Ask for a hint and I’ll point you in the right direction, without giving the answer away. Once you’ve checked your answer, I’ll show you how the marks are awarded.