Level:
Correct: 0
Incorrect: 0
Marks: 0/0
Exam Practice
Subject:
Topics:
Avg
score:
–
Topics
done:
0/32

Maintainable programs

Practise 24 exam-style questions on Maintainable programs for Cambridge IGCSE 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 an AI tutor on hand if you get stuck.

  • 24 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

2 marks

State two features that a programmer can include in a program to make it easier to maintain.

Model answer

Meaningful identifiers, such as TotalCost instead of X, and comments that explain the purpose of each section of code.

Explanation

A maintainable program is one that another programmer can understand and change easily. The main techniques are meaningful identifiers, relevant comments, procedures and functions, and constants. Each makes the purpose of the code clear without having to work it out line by line.

Mark scheme
  1. 1 mark

    Meaningful identifiers (for variables, constants, arrays, procedures and functions)

    max 2; 1 mark per feature

  2. 1 mark

    Comments (explaining the purpose of the code)

  3. 1 mark

    Procedures and functions / splitting the program into subroutines (modules)

  4. 1 mark

    Constants for fixed values

  5. 1 mark

    Consistent indentation / white space

Question 2

2 marks

A team of programmers is working on a large program, and each programmer writes different procedures and functions.

Explain how using the commenting feature of the programming language helps the team.

Model answer

Comments explain the purpose of each procedure and function, what its parameters are for and what it returns. Other members of the team can then understand and use each other's subroutines, and find and fix errors in them, without having to work out every line of the code.

Explanation

In a team, most of the code a programmer reads was written by someone else. Comments, ignored when the program runs, act as built-in documentation; a short comment at the top of each subroutine is particularly useful.

Mark scheme
  1. 1 mark

    Comments explain what each section/procedure/function does (its purpose, parameters, return value)

    max 2

  2. 1 mark

    so team members can quickly understand code written by someone else / can use, test, debug or update each other's subroutines

  3. 1 mark

    Comments can record who wrote or changed each part and when

Question 3

3 marks

This pseudocode calculates the cost of hiring a bike for a number of days from 1 to 30, at £7.50 per day. It works correctly, but it is difficult to maintain:

INPUT A
IF A > 0 AND A <= 30
THEN
B ← A * 7.5
OUTPUT B
ELSE
OUTPUT "Error"
ENDIF

Identify three ways in which this pseudocode could be made easier to maintain.

Model answer

Use meaningful identifiers instead of A and B, for example Days and HireCost.
Declare a constant for the daily rate, for example CONSTANT DailyRate ← 7.50, and use it in the calculation.
Add comments explaining the purpose of the program and that the IF statement validates the number of days.

Explanation

None of these changes alters what the program does, but each makes it quicker for someone else to understand and change. If the daily rate rises, a constant means one edit; meaningful identifiers and comments explain the purpose; indentation shows the structure of the IF statement.

Mark scheme
  1. 1 mark

    Use meaningful identifiers instead of A and B, e.g. Days and HireCost

    max 3; 1 mark per improvement

  2. 1 mark

    Use a constant for the daily rate 7.5, e.g. CONSTANT DailyRate ← 7.50

  3. 1 mark

    Use a constant for the maximum number of days, 30

    Accept with the previous point as one improvement if only 'use constants' is given.

  4. 1 mark

    Add comments, e.g. to explain the purpose of the program and that the IF validates the number of days

  5. 1 mark

    Indent the THEN and ELSE clauses and the statements inside them

Question 4

5 marks

This pseudocode calculates and outputs the areas of three circles:

Area1 ← 3.142 * Radius1 * Radius1
OUTPUT Area1
Area2 ← 3.142 * Radius2 * Radius2
OUTPUT Area2
Area3 ← 3.142 * Radius3 * Radius3
OUTPUT Area3

Rewrite this pseudocode so that it is easier to maintain. Use a constant, a function with a parameter, and at least one comment.

Model answer

CONSTANT Pi ← 3.142

// Returns the area of a circle with the given radius
FUNCTION CircleArea(Radius : REAL) RETURNS REAL
    RETURN Pi * Radius * Radius
ENDFUNCTION

OUTPUT CircleArea(Radius1)
OUTPUT CircleArea(Radius2)
OUTPUT CircleArea(Radius3)

Explanation

The calculation now appears once, inside a function, so a correction (for example using a more accurate value of Pi) is made in one place only. The constant names the fixed value and the comment explains what the function does. The function returns the area, so it is used inside the OUTPUT statements.

Mark scheme
  1. 1 mark

    MP1 a constant declared for 3.142 with a meaningful identifier, e.g. CONSTANT Pi ← 3.142, and used in the calculation

    max 5

  2. 1 mark

    MP2 function header with a meaningful identifier and one REAL parameter, RETURNS REAL, e.g. FUNCTION CircleArea(Radius : REAL) RETURNS REAL

  3. 1 mark

    MP3 the function returns Pi * Radius * Radius, and ends with ENDFUNCTION

  4. 1 mark

    MP4 the function is called for each of the three radii, in an expression or output (not with CALL)

  5. 1 mark

    MP5 the three areas are output

  6. 1 mark

    MP6 at least one relevant comment, e.g. explaining what the function returns

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

AI Tutor Hints first, answers after you try

Hi! Stuck? Ask me for a hint and I’ll help you work it out. Once you’ve checked your answer I can explain exactly where the marks are.