Level:
Correct: 0
Incorrect: 0
Marks: 0/0
Exam Practice
Course:
Topics:
OCR GCSE Computer Science (Paper 2) Smart practice A mixed round aimed at your weak spots
Unit 1
Algorithms
Unit 2
Programming fundamentals
Unit 3
Producing robust programs
Unit 4
Boolean logic
Unit 5
Programming languages and IDEs
Unit 6
Practical programming (Section B)
Avg
score:
–
Topics
done:
0/31

Maintainability: sub programs, naming, indentation and comments

Practise 27 exam-style questions on Maintainability: sub programs, naming, indentation and comments for OCR GCSE Computer Science (Paper 2). 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.

  • 27 questions
  • 1–6 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

State the term used for the name that a programmer gives to a variable, constant or sub program.

Model answer

Identifier

Explanation

An identifier is the name used to refer to a variable, constant, array or sub program, for example totalCost or calculateFine. Choosing meaningful identifiers and following a naming convention are two of the main ways of making a program easier to maintain.

Mark scheme
  1. 1 mark

    identifier

    Accept 'identifier name'. Do not accept 'name' or 'label' on their own, or 'variable name' (the term asked for also covers constants and sub programs).

Question 2

2 marks

A team of programmers is writing a large program together.

Explain one reason why the team agrees to use the same naming convention for all identifiers.

Model answer

If everyone uses the same naming convention, all of the code is written in a consistent style. This means any programmer in the team can read and update code written by someone else, and is less likely to get an identifier wrong, for example typing total_cost when the variable is called totalCost.

Explanation

A naming convention is an agreed set of rules for writing identifiers, such as camelCase for variables. Consistency matters in a team because each programmer has to read and change code written by others. Mixing styles leads to confusion and errors such as referring to a variable that does not exist.

Mark scheme
  1. 1 mark

    All the code is consistent / every programmer writes identifiers in the same style

  2. 1 mark

    So any member of the team can read, understand and update code written by the others more easily // programmers are less likely to mistype or misuse an identifier (e.g. totalCost and total_cost)

    The second mark expands the first. Accept another valid reason with an expansion, e.g. the convention shows what kind of item a name refers to (such as constants in capitals), so programmers can tell variables and constants apart (1 + 1).

Question 3

3 marks

Here is a function:

01// Returns the price after a percentage discount has been taken off
02function discountPrice(price, percent)
03    saving = price * percent / 100
04    // take away
05    newPrice = price - saving
06    return newPrice
07endfunction

Explain why the comment on line 04 is less useful than the comment on line 01, and write a more useful comment for line 04.

Model answer

The comment 'take away' just repeats the minus sign in line 05 and does not say what is taken away from what or why. The comment on line 01 explains what the whole function does and what it returns, which helps another programmer use and maintain it.

Better comment for line 04:
// subtract the amount saved from the original price to get the discounted price

Explanation

Good comments explain purpose - what a section of code is for and why - rather than describing each symbol. A comment such as 'take away' adds nothing, because any programmer can already see the subtraction. Writing comments appropriately means commenting the parts that are not obvious from the code itself.

Mark scheme
  1. 1 mark

    The comment on line 04 only repeats what the code already shows / does not say what is being taken away from what, or why

  2. 1 mark

    The comment on line 01 explains the purpose of the whole function / what it returns, which cannot easily be seen from one line of code

  3. 1 mark

    A more useful comment for line 04, e.g. // subtract the amount saved from the original price to get the discounted price

    The comment must explain the purpose (that the saving is subtracted from the original price / this gives the new price). Do not accept 'subtract' or 'minus' on its own.

Question 4

4 marks

The structure diagram shows how a cinema booking program has been broken down into sub programs. The program will be written by a team of three programmers.

Explain how writing each part as a separate sub program helps the team to develop and maintain the program.

Structure diagram (top-down design) with 11 boxes on 3 levels, joined by plain lines (no arrows). The top box is "Cinema booking". "Cinema booking" is broken down into 4 sub-systems, from left to right: "Choose film", "Choose seats", "Take payment" and "Print tickets". "Choose film" is broken down into 2 sub-systems, drawn as a column under it from top to bottom: "Show film list" and "Select showing". "Choose seats" is broken down into 2 sub-systems, drawn as a column under it from top to bottom: "Show seat plan" and "Reserve seats". "Take payment" is broken down into 2 sub-systems, drawn as a column under it from top to bottom: "Calculate total" and "Process card".

Model answer

The team can share out the sub programs, for example one programmer writes Choose film, one writes Choose seats and one writes Take payment, so all three are developed at the same time. Each sub program can be tested on its own before they are joined together, so errors are found in a small section of code and are easier to fix. Later, if the way cards are processed changes, only Process card needs updating, without changing the rest of the program. Each sub program is small with a clear purpose, so it is easier for any member of the team to understand.

Explanation

Breaking a program into sub programs (decomposition) lets a team divide the work, test each part separately and change one part without breaking the others. This is why large programs are built from many small procedures and functions. In an answer, link each benefit to the team or to a part of the diagram rather than listing words.

Mark scheme
  1. 1 mark

    Different programmers can write different sub programs at the same time (so the program is finished sooner)

    max 4. Credit answers that use sub programs from the diagram as examples.

  2. 1 mark

    Each sub program can be tested on its own before the parts are combined

  3. 1 mark

    Errors are easier to find and fix because they are in one small sub program

  4. 1 mark

    A sub program can be changed / updated without affecting or rewriting the rest of the program (as long as its parameters and return value stay the same)

    e.g. the card payment method can change without touching Choose seats.

  5. 1 mark

    A sub program can be called from more than one place / reused, so its code is written only once

  6. 1 mark

    Each sub program is small with one clear purpose, so it is easier to understand

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.