Skip to content

OCR A-Level Computer Science: Programming & OOP

6 exam-style questions with full mark schemes and model answers. Write your own answer and the AI examiner marks it against the mark scheme.

Question 112 marksDesign

The following scenario was written for this exercise.

A public library runs a lending system that must model its members. Every LibraryMember has a name, a library-card number, and a running count of how many items they currently have on loan. The system enforces two rules:

  • a member may have at most 5 items on loan at once (any attempt to borrow a sixth must be refused);
  • the system must always be able to report how many members in total have been registered.

The library later introduces a special kind of member, the StudentMember, who is allowed a higher loan limit and who also records the name of the school or college they attend.

Answer in OCR-style OOP pseudocode (using CLASS … END CLASS, PRIVATE/PUBLIC, PUBLIC PROCEDURE new(…) for the constructor, INHERITS and SUPER.new(…)). A high-level language is acceptable, but the mark scheme assumes the OCR convention.

(a) Design the LibraryMember class. It must use encapsulation (private attributes accessed through public methods), provide a constructor that initialises every attribute, include a getter for the on-loan count and a borrowItem method that enforces the limit of 5, and maintain a class-level counter of every member registered. [6 marks]

(b) Design a subclass StudentMember that inherits from LibraryMember. Its constructor must take the school name as an extra parameter, call the superclass constructor, and the subclass must override the loan limit so that a student may have up to 10 items on loan. [4 marks]

(c) Explain what is meant by encapsulation in this class — private attributes accessed only through getters/setters — and give one benefit of designing the class this way. [2 marks]

AI examiner · marked against the mark scheme
Question 29 marksEvaluate

A company is building a large e-commerce platform — products, customers, shopping baskets, orders, payments and a recommendation engine — that a team of developers will extend and maintain for many years as the catalogue and feature set grow. The lead developer wants to build it using the object-oriented paradigm; a colleague argues the procedural style they used on earlier scripts would be quicker to start and "does the job".

Evaluate the use of the object-oriented paradigm rather than the procedural paradigm for a project of this kind, reaching a justified conclusion. [9 marks]

AI examiner · marked against the mark scheme
Question 36 marksTrace

The following algorithm was written for this exercise.

The recursive function below returns the sum of the decimal digits of a non-negative integer. DIV is integer division and MOD is the remainder:

// OCR-style pseudocode
FUNCTION sumDigits(n)
    IF n == 0 THEN
        RETURN 0
    ELSE
        RETURN (n MOD 10) + sumDigits(n DIV 10)
    ENDIF
ENDFUNCTION

The function is called as sumDigits(2547).

(a) Trace the chain of recursive calls for sumDigits(2547). Show, as a table, each call made (the winding phase) and the value each call returns as the recursion unwinds. [4 marks]

(b) State the value finally returned by sumDigits(2547). [1 mark]

(c) Identify the base case of this function and explain why, without it, the call to sumDigits(2547) would not terminate. [1 mark]

AI examiner · marked against the mark scheme
Question 45 marksWrite

A text-processing routine needs to count how many vowels (the letters a, e, i, o, u, in either case) appear in a string.

Write an algorithm, as a subroutine countVowels(text) in OCR-style pseudocode, that takes a string text and returns the number of vowels it contains. Your algorithm must work whether the letters are upper- or lower-case, and must return 0 for a string that contains no vowels (including the empty string). You may use LEN(s) for the length of a string and index a character as s[i] (0-indexed). [5 marks]

AI examiner · marked against the mark scheme
Question 54 marksDistinguish

Programming paradigms can be divided into imperative (which includes the procedural paradigm) and declarative (which includes the functional and logic paradigms).

Distinguish between the imperative/procedural and the declarative approaches, and give one example of a task to which each is well suited. [4 marks]

AI examiner · marked against the mark scheme
Question 63 marksExplain

Within a program, a variable has a scope that determines where it can be accessed. A variable may be local or global.

Explain the difference between a local variable and a global variable, and give one reason why local variables are generally preferred over global variables. [3 marks]

AI examiner · marked against the mark scheme