Further programming: paradigms, OOP, files and exceptions – A Level Computer Science (9618)
36 questions · page 3 of 3 · Clear filters
Question text
1
Data types can be defined using pseudocode.
The data type, BuildingRecord, is defined in pseudocode as:
TYPE BuildingRecord
DECLARE BuildingID : INTEGER
DECLARE BuildingGroup : STRING
DECLARE OwnerName : STRING
DECLARE BuildingAddress : STRING
DECLARE DateLastSold : DATE
DECLARE PriceLastSold : REAL
ENDTYPE
A variable, BuildingRegister, is declared in pseudocode as:
DECLARE BuildingRegister : BuildingRecord
(a) Write pseudocode statements to assign:
•
1067 to the BuildingID of BuildingRegister
•
house to the BuildingGroup of BuildingRegister
…
…
…
… [2]
(b) The type definition for BuildingRecord is changed. The data type for BuildingGroup is
changed to an enumerated type, BuildingType, with values of house, bungalow, apartment
and farm.
(i)
Write the type declaration for BuildingType in pseudocode.
…
…
…
… [2]
(ii)
Write the new declaration for BuildingGroup in pseudocode.
…
… [1]
(iii)
Write the new pseudocode statement to assign house to BuildingGroup of
BuildingRegister.
…
… [1]
(c) The program is to be rewritten using Object-Oriented Programming (OOP). The data type
BuildingRecord is to be changed to a class, BuildingClass.
The properties for BuildingClass are BuildingID, BuildingGroup, OwnerName,
BuildingAddress, DateLastSold and PriceLastSold.
All the properties are set to PRIVATE, for example:
PRIVATE PriceLastSold : REAL
(i)
Write the declaration in pseudocode for OwnerName as PRIVATE.
������������������������������������������������������������������������������������������������������������������������������������������������������������
����������������������������������������������������������������������������������������������������������������������������������������������������� [1]
(ii)
Explain why the properties have been set to PRIVATE.
������������������������������������������������������������������������������������������������������������������������������������������������������������
������������������������������������������������������������������������������������������������������������������������������������������������������������
������������������������������������������������������������������������������������������������������������������������������������������������������������
��������������������������������������������������������������
Question text
2
A declarative language is used to represent the following facts about a school.
01
teaches(alan, mathematics).
02
teaches(ioana, geography).
03
teaches(nina, history).
04
teaches(alan, statistics).
05
06
studies(ahmed, history).
07
studies(freya, history).
08
studies(kim, history).
09
studies(freya, geography).
10
studies(hua, mathematics).
11
studies(hua, statistics).
12
studies(hua, geography).
13
14
tutors(alan,
kim).
15
tutors(alan,
hua).
16
tutors(alan,
freya).
17
tutors(nina,
ahmed).
These clauses have the following meaning:
Clause
Meaning
01
Alan teaches mathematics.
06
Ahmed studies history.
14
Alan is Kim’s tutor.
(a) More facts are to be included. Sam studies history and Nina is his tutor.
Write the additional clauses to record these facts.
18 …
19 …
[2]
(b) Using the variable Student, the goal:
studies(Student, history)
returns
Student = freya, ahmed, kim
Write the result returned by the goal:
studies(Student, geography)
Student = … [1]
(c) Write the goal, using the variable X, to find all the students who have a tutor that teaches
them. For example, Hua has Alan for a tutor and is also taught mathematics by Alan.
…
…
…
… [4]
Question text
9
State the reasons for including exception handling routines when writing a program.
Include an example of an exception in your answer.
…
…
…
…
…
…
…
… [4]
Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every
publisher will be pleased to make amends at the earliest possible opportunity.
To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge
Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download
at www.cambridgeinternational.org after the live examination series.
Cambridge Assessment International Education is part of Cambridge Assessment. Cambridge Assessment is the brand name of the University of Cambridge
Question text
2
Draw one line from each programming paradigm to its most appropriate description.
Programming paradigm
Description
Programs using the instruction set of a
processor
Declarative
Programs based on events such as user
actions or sensor outputs
Imperative
Programs using the concepts of class,
inheritance, encapsulation and
polymorphism
Low-level
Programs with an explicit sequence of
commands that update the program state,
with or without procedure calls
Object-oriented
Programs that specify the desired result
rather than how to get to it
[4]
Question text
5
(a) Compare sequential and serial methods of file organisation.
…
…
…
…
…
…
…
…
… [4]
(b) State the most suitable method of file access when a record is referenced by a unique
address on a disk-type storage medium.
… [1]
(c) State the most suitable method of file access when a bank stores its data records in ascending
order of account number.
… [1]
Question text
9
(a) Describe what is meant by an imperative (procedural) programming language.
…
…
…
… [2]
(b) Describe what is meant by a declarative programming language.
…
…
…
… [2]
(c) Identify the programming paradigm for each of these program code examples.
Program code example
Programming paradigm
male(john).
female(ethel).
parent(john, ethel).
FOR Counter = 1 TO 20
X = X * Counter
NEXT Counter
Start: LDD Counter
INC ACC
STO Counter
public class Vehicle
{
private speed;
public Vehicle()
{
speed = 0;
}
}
[4]
Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every
publisher will be pleased to make amends at the earliest possible opportunity.
To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge
Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download
at www.cambridgeinternational.org after the live examination series.
Cambridge Assessment International Education is part of the Cambridge Assessment Group. Cambridge Assessment is the brand name of the University of