EXAM QUESTIONS · A LEVEL 9618

Further Programming (A2) Exam-Style Questions with Answers (A Level 9618)

Original exam-style questions on programming paradigms, object-oriented programming, declarative programming with facts, rules and queries, random file handling and exception handling for Cambridge AS & A Level Computer Science 9618 (Paper 4). There are 22 marks in total. Try each question on paper first, then press Show answer to see the mark scheme. Answers that can be calculated mark themselves.

Question 1[4 marks]

Describe the four programming paradigms: low-level, imperative (procedural), object-oriented and declarative.

Show answer
  • Low-level: uses instructions close to machine code, e.g. assembly language. [1]
  • Imperative: a sequence of statements that change the program state, organised into procedures and functions. [1]
  • Object-oriented: programs are made of objects (instances of classes) that contain both data and methods. [1]
  • Declarative: the programmer states facts and rules (what is wanted), and the language works out how to find the answer, e.g. Prolog. [1]
Question 2[3 marks]

Explain what is meant by encapsulation and why getter and setter methods are used.

Show answer
  • Encapsulation: an object’s attributes and the methods that use them are kept together in one class. [1]
  • Attributes are made private, so they cannot be changed directly from outside the class. [1]
  • Getters and setters give controlled access, e.g. a setter can validate a value before storing it. [1]
Question 3[4 marks]

A class Vehicle has a method Describe(). Classes Car and Bus inherit from Vehicle, and each has its own Describe() method. Explain how this shows inheritance and polymorphism.

Show answer
  • Inheritance: Car and Bus are subclasses that take on the attributes and methods of Vehicle [1], so common code is written once. [1]
  • Polymorphism: Describe() has the same name in each class [1] but each subclass overrides it, so calling Describe() on a Car or a Bus object gives a different, suitable result. [1]
Question 4[3 marks]

Write a pseudocode constructor for a class Student with private attributes Name (string) and Mark (integer). The constructor takes the name as a parameter and sets the mark to 0.

Show answer
CLASS Student
   PRIVATE Name : STRING
   PRIVATE Mark : INTEGER
   PUBLIC PROCEDURE NEW(GivenName : STRING)
      Name ← GivenName
      Mark ← 0
   ENDPROCEDURE
ENDCLASS
  • 1 mark: private attributes with data types
  • 1 mark: constructor PROCEDURE NEW with a parameter
  • 1 mark: Name set from the parameter and Mark set to 0

For Questions 5 and 6, use these declarative (Prolog-style) facts and rule.

parent(ana, ben).
parent(ben, cara).
parent(ben, dev).
parent(cara, eli).
grandparent(X, Z) IF parent(X, Y) AND parent(Y, Z).
Question 5[2 marks]

State the result of the query grandparent(ana, Who).

Show answer

Who = cara, Who = dev [2]

ana is the parent of ben, and ben is the parent of cara and dev.

Question 6[2 marks]

Write a query to find all the grandchildren of ben, and state the result.

Show answer

grandparent(ben, G) [1] → G = eli [1]

Question 7[4 marks]

Write pseudocode that reads record number 5 from a random file Stock.dat into the variable Item, and handles the exception if the file cannot be opened.

Show answer
TRY
   OPENFILE "Stock.dat" FOR RANDOM
   SEEK "Stock.dat", 5
   GETRECORD "Stock.dat", Item
   CLOSEFILE "Stock.dat"
EXCEPT
   OUTPUT "The file could not be opened"
ENDTRY
  • 1 mark: OPENFILE … FOR RANDOM and CLOSEFILE
  • 1 mark: SEEK to record 5
  • 1 mark: GETRECORD into Item
  • 1 mark: TRY … EXCEPT … ENDTRY with a suitable message

Frequently asked questions

What is the difference between inheritance and polymorphism?

Inheritance lets a subclass take on the attributes and methods of its parent class. Polymorphism lets a method with the same name behave differently in different classes, for example when a subclass overrides it.

Are these past paper questions?

No. These are original exam-style questions written by a Computer Science teacher in the Cambridge style.

Revise the topic: 9618 further programming notes · 9618 flashcards · All exam-style questions