Further programming: paradigms, OOP, files and exceptions – A Level Computer Science (old syllabus, to 2021) (9608)

25 questions · page 1 of 2 · Clear filters

0 / 0Answer a question to start your score.
Quick quiz (10)Saved 0
Advertisement
1
9608/41/O/N/21 · Question 4Oct/Nov 2021Paper 419 marks
Loading question…
Question text

4
Teachers in a school may work on Mondays, Tuesdays and Wednesdays. There are three time
slots on each day: time slot 1, time slot 2 and time slot 3.
A teacher is either busy or free.
The school is using a declarative language to write a program to record which teachers are busy
in each time slot on each day.
The following knowledge base is used:
01 teacher(james).
02 teacher(jill).
03 teacher(karl).
04 teacher(kira).
05 day(monday).
06 day(tuesday).
07 day(wednesday).
08 timeSlot(1).
09 timeSlot(2).
10 timeSlot(3).
11 busy(james, monday, 1).
12 busy(james, tuesday, 2).
13 busy(karl, monday, 1).
14 busy(kira, wednesday, 3).
These clauses have the following meaning:
Clause
Explanation
01
James is a teacher
05
Monday is a day
08
1 is a time slot
11
James is busy in time slot 1 on Monday
(a) More facts need to be included.
Fred is a teacher who is busy in time slot 1 on Tuesday.
Write additional clauses for these facts.
15 …
16 …
[2]
(b) Additional clauses are needed to identify whether Jill is busy in time slot 1 on Monday,
Tuesday, or Wednesday.
Write these additional clauses.
17 …
18 …
19 …
[2]
(c) Write a goal, using the variable X, to find all the teachers who are busy in time slot 3 on
Monday.
…
… [1]
(d) Write a rule to find whether a teacher X is free in a specific time slot Y on day Z.
IsTeacherFree(X, Z, Y)
IF
…
…
…
… [4]

2
9608/41/O/N/21 · Question 7Oct/Nov 2021Paper 417 marks
Loading question…
Question text

7
Sonya is writing a computer program that requires a user input. The user should input an integer
between 1 and 100. Sonya wants to use exception handling.
(a) Explain the reasons why Sonya should use exception handling in her program.
…
…
…
… [2]
(b) Write program code to read in the number from the user and raise an exception if the data is
not valid.
Programming language …
Program code
…
…
…
…
…
…
… [3]
(c) Give two other examples of where exception handling can be used in a program.
1 …
2 …
[2]

3
9608/42/O/N/21 · Question 7Oct/Nov 2021Paper 4216 marks
Loading question…
Question text

7
A treasure box is hidden within a computer game.
The box has a code that needs to be entered to allow the user into the box. The box contains up
to 10 objects that are defined as being of the class FieldObject. The definition for the class Box
is:
Box
// small, medium or large
Size : STRING
// the 10 items the box holds
Contents : ARRAY[0 : 9] OF FieldObject
// the code to unlock the box
Lock : STRING
// the strength of the box
Strength : INTEGER
// decreases by 1 each time an
// incorrect code is entered
// instantiates an object of the Box
Constructor()
// class and assigns initial values
// to the attributes
// checks if the code is correct to
Unlock()
// unlock the box
// returns the array
GetContents()
// sets the size of the box
SetSize()
// sets the contents of the box
SetContents()
// sets the lock code
SetLock()
// sets the strength
SetStrength()
(a) The constructor creates a new instance of a box. It takes the size of the box, one item of
content and the lock code as parameters. The strength is initialised to 100.
Write program code to create the class and constructor for Box.
Do not write the code for Unlock() or any of the set or get methods. Use the constructor for
your chosen language.
Programming language …
Program code …
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [5]
(b) The player inputs the code to unlock the box. Each time they enter an incorrect code, the
strength of the box decreases by 1. If the strength of the box becomes 0, the box automatically
unlocks.
The class Box has a method Unlock() that:
•
takes the

Advertisement
4
9608/42/O/N/21 · Question 8Oct/Nov 2021Paper 422 marks
Loading question…
Question text

8
A game stores details about characters.
A declarative programming language is used to represent the following knowledge base:
01 hair(blonde).
02 hair(black).
03 hair(red).
04 face(glasses).
05 face(moustache).
06 face(beard).
07 person(ismail).
08 person(anisha).
09 person(kim).
10 person(kyle).
11 has(kyle, glasses).
12 has(kyle, beard).
13 has(anisha, red).
14 has(kyle, black).
These clauses have the following meaning:
Clause
Explanation
01
Hair can be blonde
04
Glasses can be on the face
08
Anisha is a person
12
Kyle has a beard
13
Anisha has red hair
A person, X, is a selected person if they have black hair and either a moustache or a beard.
Write a rule to represent this condition.
SelectedPerson(X)
IF
…
…
…
… [2]
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

5
9608/41/O/N/20 · Question 3Oct/Nov 2020Paper 4116 marks
Loading question…
Question text

3
A programmer is creating a program for a puzzle competition.
The programmer has designed the PuzzlePlayer class to store details for each player, including
the player’s score.
The following diagram shows the design for the PuzzlePlayer class.
PuzzlePlayer
PlayerID : STRING // initialised in constructor to "PL12a3"
Name : STRING
// initialised in constructor to ""
Score : INTEGER
// initialised in constructor to 0
Constructor()
//
method used to create an instance of the
//
PuzzlePlayer class and initialise its attributes
GetPlayerID()
//
returns PlayerID
GetName()
//
returns Name
GetScore()
//
returns Score
SetPlayerID()
//
validates the parameter value to make sure it
//
is 6 characters in length and starts with
//
"PL", then sets PlayerID to this value
SetName()
//
sets the Name to the parameter value
SetScore()
//
sets the Score to the parameter value
(a) Write program code for the Constructor() method.
Use the appropriate constructor method for your chosen programming language.
Programming language …
Program code
…
…
…
…
…
…
…
…
…
… [2]
(b) Write program code for GetPlayerID() method.
Programming language …
Program code
…
…
…
…
…
… [2]
(c) The method SetPlayerID() validates the parameter value. It checks that it is 6 characters
in length and that the first two characters are "PL". The method sets PlayerID to the
parameter value. It returns TRUE if the parameter value is valid and FALSE if it is not valid.
The function

6
9608/41/O/N/20 · Question 4Oct/Nov 2020Paper 418 marks
Loading question…
Question text

4
A declarative programming language is used to represent the following knowledge base.
01 type(cheddar).
02 type(brie).
03 type(paneer).
04 type(parmesan).
05 country(england).
06 country(france).
07 country(india).
08 country(italy).
09 hard(parmesan).
10 soft(brie).
11 strong_smell(brie).
12 strong_smell(cheddar).
13 origin(brie, france).
These clauses have the following meanings:
Clause
Meaning
02
Brie is a type of cheese
06
France is a country
09
Parmesan is a hard cheese
10
Brie is a soft cheese
12
Cheddar has a strong smell
13
Brie is from France
(a) Camembert is a type of soft cheese from France and has a strong smell.
Write additional clauses to represent this information.
14 …
15 …
16 …
17 …
[4]
(b) Stilton (X) could be from England (Y) and Stilton could be a hard cheese, if Stilton is a type of
cheese, England is a country and Stilton is not a soft cheese.
Write this as a rule.
Cheese_Question(X, Y)
IF …
…
… [4]

7
9608/41/O/N/20 · Question 7Oct/Nov 2020Paper 418 marks
Loading question…
Question text

7
The following table shows part of the instruction set for a processor that has one general purpose
register, the Accumulator (ACC), and an Index Register (IX).
Instruction
Explanation
Op code
Operand
LDM
#n
Immediate addressing. Load the number n to ACC.
Direct addressing. Load the contents of the location at the given
LDD
<address>
address to ACC.
Indirect addressing. The address to be used is at the given address.
LDI
<address>
Load the contents of this second address to ACC.
Indexed addressing. Form the address from <address> + the contents
LDX
<address>
of the Index Register. Copy the contents of this calculated address to
ACC.
LDR
#n
Immediate addressing. Load the number n to IX.
STO
<address>
Store the contents of ACC at the given address.
Indexed addressing. Form the address from <address> + the contents
STX
<address>
of the Index Register. Copy the contents of ACC to this calculated
address.
ADD
<address>
Add the contents of the given address to ACC.
INC
<register>
Add 1 to the contents of the register (ACC or IX).
DEC
<register>
Subtract 1 from the contents of the register (ACC or IX).
JMP
<address>
Jump to the given address.
CMP
<address>
Compare the contents of ACC with the contents of <address>.
CMP
#n
Compare the contents of ACC with number n.
Following a compare instruction, jump to <address> if the compare
JPE
<address>
was True.
Following a compare instruction, jump to <address> if the compare
JPN
<address>
was False.
IN
Key in a character and store its ASCII value in ACC.
OUT
Output to the screen the character whose ASCII value is stored in ACC.
END
Return control to the operating system.
The assembly language program in the table on the opposite page allows a username to be input
as a string of up to 8 characters in length.
For strings of less than 8 characters, the user enters the exclamation mark (!) character to
indicate that no more characters will be entered. The exclamation mark is not saved as part of the
username.
The program then outputs each character of the username in the order input.
The program will use consecutive memory locations, starting at the address labelled USERNAME,
storing one character in each location.
The program in the table is incomplete. The comment column contains descriptions for some
program instructions.
Complete the program using the given instruction set.
Instruction
Label
Comment
Op code
Operand
LDR
#0
LDM
#0
// initialise LENGTH to 0
STO
LENGTH
LOOP:
IN
// is character = EXCLAMATION(!)?
// if TRUE, jump to OUTPUT
// store character in USERNAME +
contents of IX
INC
IX
// increment Index Register
// increment LENGTH
// is LENGTH = MAX ?
// if FALSE, jump to LOOP
OUTPUT:
LDR
#0
// initialise COUNT to 0
LDX
USERNAME
OUT
INC
IX
LDD
COUNT
INC
ACC
// increment COUNT
STO
COUNT
// is COUNT = LENGTH ?
JPN
OUTPUT
END
// end program
LENGTH:
EXCLAMATION:
B0010001
MAX:
8
COUNT:
USERNAME:
[8]

8
9608/42/O/N/20 · Question 3Oct/Nov 2020Paper 4210 marks
Loading question…
Question text

3
A declarative programming language is used to represent the following knowledge base.
01 person(jordan).
02 person(gita).
03 person(paolo).
04 person(cassie).
05 animal(cat).
06 animal(hamster).
07 animal(gecko).
08 animal(fish).
09 has_pet(cassie, gecko).
10 has_pet(paolo, fish).
11 has_pet(cassie, cat).
12 has_pet(jordan, cat).
These clauses have the following meanings:
Clause
Meaning
01
Jordan is a person
05
A cat is an animal
09
Cassie has a pet gecko
(a) Clive is a person who has a pet guinea pig and a pet gecko.
Write additional clauses to represent this information.
13 …
14 …
15 …
16 …
[4]
(b) Using the variable PetOwner, the goal:
has_pet(PetOwner, cat)
returns:
PetOwner = cassie, jordan
Write the result that is returned by the goal:
has_pet(cassie, PetAnimals)
PetAnimals = …
… [1]
(c) Z wants a pet Y, if Z is a person and Y is an animal and Z does not have a pet Y.
Write this as a rule.
wants_pet( … , … )
IF …
…
… [5]

Advertisement
9
9608/42/O/N/20 · Question 4Oct/Nov 2020Paper 4221 marks
Loading question…
Question text

4
A programmer wants to create a mobile application to record the number of calories a person eats
in a day.
The programmer has designed the class, FoodItem, to store details for each item of food.
The following diagram shows the design for the FoodItem class.
FoodItem
FoodID
: STRING // initialised in constructor to parameter value
Name
: STRING // initialised in constructor to an empty string
Calories : INTEGER // initialised in constructor to 0
Constructor()
//
method used to create an instance of the
//
FoodItem class and initialise its attributes
GetFoodID()
//
returns FoodID
GetName()
//
returns Name
GetCalories()
//
returns Calories
SetFoodID()
//
sets the FoodID to the parameter value
SetName()
//
sets the Name to the parameter value
SetCalories()
//
validates the parameter value to make sure
//
it is a positive integer less than 2000, and
//
then sets Calories to this value
(a) Write program code for the Constructor() method.
Use the appropriate constructor method for your chosen programming language.
Programming language …
Program code
…
…
…
…
…
…
…
…
…
… [3]
(b) Write program code for the GetCalories() method.
Programming language …
Program code
…
…
…
…
…
… [2]
(c) The method SetCalories() validates the integer parameter value that is passed to it. It
checks that the value is positive and is less than 2000.
The method sets Calories to the parameter value and returns TRUE if the parameter value
is valid. It return

10
9608/42/O/N/20 · Question 5Oct/Nov 2020Paper 428 marks
Loading question…
Question text

5
The following table shows part of the instruction set for a processor that has one general purpose
register, the Accumulator (ACC), and an Index Register (IX).
Instruction
Explanation
Op code
Operand
LDM
#n
Immediate addressing. Load the number n to ACC.
Direct addressing. Load the contents of the location at the given
LDD
<address>
address to ACC.
Indirect addressing. The address to be used is at the given address.
LDI
<address>
Load the contents of this second address to ACC.
Indexed addressing. Form the address from <address> + the contents
LDX
<address>
of the Index Register. Copy the contents of this calculated address to
ACC.
LDR
#n
Immediate addressing. Load the number n to IX.
STO
<address>
Store the contents of ACC at the given address.
Indexed addressing. Form the address from <address> + the contents
STX
<address>
of the Index Register. Copy the contents of ACC to this calculated
address.
ADD
<address>
Add the contents of the given address to ACC.
INC
<register>
Add 1 to the contents of the register (ACC or IX).
DEC
<register>
Subtract 1 from the contents of the register (ACC or IX).
JMP
<address>
Jump to the given address.
CMP
<address>
Compare the contents of ACC with the contents of <address>.
CMP
#n
Compare the contents of ACC with number n.
Following a compare instruction, jump to <address> if the compare
JPE
<address>
was True.
Following a compare instruction, jump to <address> if the compare
JPN
<address>
was False.
IN
Key in a character and store its ASCII value in ACC.
OUT
Output to the screen the character whose ASCII value is stored in ACC.
END
Return control to the operating system.
Consider the following pseudocode algorithm:
0
Length
INPUT Character
WHILE Character <> "."
Message
Message & Character
Length
Length + 1
INPUT Character
ENDWHILE
Complete the table by writing assembly language code for the algorithm, using the given instruction
set.
Instruction
Label
Comment
Op code
Operand
// initialise IX to zero
// initialise LENGTH
LOOP:
// input character
// is character a FULLSTOP (.) ?
// jump to ENDP if TRUE
// store character in MESSAGE +
contents of IX
// increment IX
// increment LENGTH
// jump to LOOP
ENDP:
END
// end program
LENGTH:
FULLSTOP:
B01100000
// ASCII code for a full stop (.)
MESSAGE:
[8]

11
9608/41/O/N/19 · Question 2Oct/Nov 2019Paper 419 marks
Loading question…
Question text

2
The following table shows part of the instruction set for a processor, which has one general
purpose register, the Accumulator (ACC), and an Index Register (IX).
Instruction
Explanation
Op code
Operand
Immediate addressing. Load the number n to ACC.
LDM
#n
Direct addressing. Load the contents of the location at the given address to
LDD
<address>
ACC.
Indirect addressing. The address to be used is at the given address. Load the
LDI
<address>
contents of this second address to ACC.
Indexed addressing. Form the address from <address> + the contents of the
LDX
<address>
Index Register. Copy the contents of this calculated address to ACC.
Immediate addressing. Load the number n to IX.
LDR
#n
Store the contents of ACC at the given address.
STO
<address>
Indexed addressing. Form the address from <address> + the contents of the
STX
<address>
Index Register. Copy the contents from ACC to this calculated address.
Add the contents of the given address to the ACC.
ADD
<address>
Add 1 to the contents of the register (ACC or IX).
INC
<register>
Subtract 1 from the contents of the register (ACC or IX).
DEC
<register>
Jump to the given address.
JMP
<address>
Compare the contents of ACC with the contents of <address>.
CMP
<address>
Compare the contents of ACC with number n.
CMP
#n
Following a compare instruction, jump to <address> if the compare was True.
JPE
<address>
Following a compare instruction, jump to <address> if the compare was False.
JPN
<address>
Bitwise AND operation of the contents of ACC with the operand.
AND
#n
Bitwise AND operation of the contents of ACC with the contents of <address>.
AND
<address>
Bitwise XOR operation of the contents of ACC with the operand.
XOR
#n
Bitwise XOR operation of the contents of ACC with the contents of <address>.
XOR
<address>
Bitwise OR operation of the contents of ACC with the operand.
OR
#n
Bitwise OR operation of the contents of ACC with the contents of <address>.
OR
<address>
<address> can be an absolute address or a symbolic address.
Bits in ACC are shifted n places to the left. Zeros are introduced on the right
LSL
#n
hand end.
Bits in ACC are shifted n places to the right. Zeros are introduced on the left
LSR
#n
hand end.
Key in a character and store its ASCII value in ACC.
IN
Output to the screen the character whose ASCII value is stored in ACC.
OUT
Return control to the operating system.
END
A programmer writes a program that multiplies two numbers together and outputs the result. The
numbers are stored as NUMONE and NUMTWO.
The programmer has started to write the program in the following table. The comment column
contains explanations for some of the missing program instructions and data.
Complete the program using the given instruction set.
Label
Op code
Operand
Comment
LOOP:
// load the value from ANSWER
// add the value from NUMONE
// load the value from COUNT
// increment the Accumulator
// is NUMTWO = COUNT ?
// if false, jump to LOOP
// load the value from ANSWER
// output ANSWER to the screen
// end of program
NUMONE:
2
NUMTWO:
4
COUNT:
0
ANSWER:
0
[9]

12
9608/42/O/N/19 · Question 1Oct/Nov 2019Paper 4235 marks
Loading question…
Question text

1
A technology company needs software to calculate how much each employee should be paid.
(a) Developing the software will involve the following activities:
Time to
Activity
Description
complete
Predecessor
(weeks)
A
Identify requirements
1
–
B
Observe current system
1
A
C
Create algorithm design
3
B
D
Write code
10
C
E
Test modules
7
C
F
White box testing
2
D
G
Black box testing
3
D
H
Install software
1
E, F, G
I
Acceptance testing
2
H
J
Create user documentation
2
H
(i)
Add the correct activities and times to the following Program Evaluation Review
Technique (PERT) chart for the software development.
Three of the activities and times have been done for you.
5
A
4
8
1
2
3
2 F
1
6
7
9
I
2
11
10
[7]
(ii)
The dashed line connecting nodes 10 and 11 indicates a dummy activity.
State the purpose of a dummy activity.
…
… [1]
(b) A bonus payment may be added to an employee’s salary. A pension payment may also be
subtracted from an employee’s salary.
The company needs to assess what additions and subtractions should be made to the salary
of each employee. There are three conditions to check:
•
If the employee has worked a public holiday, they receive a 3% bonus payment.
•
If the employee has worked 160 or more hours in a month, they receive an additional 5%
bonus payment.
•
If the employee pays into a pension, the company subtracts 4% for the pension payment.
Complete the decision table to show the additions and subtractions.
Rules
Public holiday
Y
Y
Y
Y
N
N
N
N
Conditions
Hours >= 160
Y
Y
N
N
Y
Y
N
N
Pension
Y
N
Y
N
Y
N
Y
N
3% bonus payment
Actions
5% bonus payment
4% pension payment
[3]
(c) The company decides to implement a program for the software using object-oriented
programming (OOP).
Each employee has a unique employee ID, name, address and date of birth. There are two
types of employee: salary and apprenticeship.
Salaried employees are paid a fixed monthly payment. The hours a salary employee works in
a month are recorded to calculate bonus payments. They may receive bonus payments and
make pension payments (given in part(b)).
Apprenticeship employees are paid weekly. They receive an hourly rate of pay. Apprenticeship
employees do not receive bonus payments or make pension payments.
(i)
Complete the following class diagram for the program.
Employee
EmployeeID : STRING
Name : STRING
Address : STRING
DateOfBirth : Date
Constructor()
GetEmployeeID()
GetName()
GetAddress()
GetDateOfBirth()
SetEmployeeID()
SetName()
SetAddress()
SetDateOfBirth()
SalaryEmployee
ApprenticeshipEmployee
MonthlyPayment : CURRENCY
…
HoursThisMonth: REAL
PublicHoliday : BOOLEAN
…
Pension : BOOLEAN
Constructor()
…
GetMonthlyPayment()
GetHoursThisMonth()
…
GetPublicHoliday()
GetHourlyRate()
GetPension()
GetHoursThisWeek()
SetMonthlyPayment()
SetHourlyRate()
SetHoursThisMonth()
SetPublicHoliday()
SetPension()
[3]
(ii)
Write program code for the Constructor() in the Employee class.
All properties are sent as parameters.
Programming language …
Program code
…
…
…

13
9608/42/O/N/19 · Question 5Oct/Nov 2019Paper 4213 marks
Loading question…
Question text

5
The following table shows part of the instruction set for a processor which has one general purpose
register, the Accumulator (ACC) and an Index Register (IX).
Instruction
Explanation
Op code
Operand
Immediate addressing. Load the number n to ACC.
LDM #n
Direct addressing. Load the contents of the location at the given address to
LDD <address>
ACC.
Indirect addressing. The address to be used is at the given address. Load
LDI <address>
the contents of this second address to ACC.
Indexed addressing. Form the address from <address> + the contents of
LDX <address>
the Index Register. Copy the contents of this calculated address to ACC.
Immediate addressing. Load the number n to IX.
LDR #n
Store the contents of ACC at the given address.
STO <address>
Indexed addressing. Form the address from <address> + the contents of
STX <address>
the Index Register. Copy the contents from ACC to this calculated address.
Add the contents of the given address to the ACC.
ADD <address>
Add 1 to the contents of the register (ACC or IX).
INC <register>
Subtract 1 from the contents of the register (ACC or IX).
DEC <register>
Jump to the given address.
JMP <address>
Compare the contents of ACC with the contents of <address>.
CMP <address>
Compare the contents of ACC with number n.
CMP #n
Following a compare instruction, jump to <address> if the compare was
JPE <address>
True.
Following a compare instruction, jump to <address> if the compare was
JPN <address>
False.
Bitwise AND operation of the contents of ACC with the operand.
AND #n
Bitwise AND operation of the contents of ACC with the contents of
AND <address>
<address>.
Bitwise XOR operation of the contents of ACC with the operand.
XOR #n
Bitwise XOR operation of the contents of ACC with the contents of
XOR <address>
<address>.
Bitwise OR operation of the contents of ACC with the operand.
OR #n
Bitwise OR operation of the contents of ACC with the contents of
<address>.
OR <address>
<address> can be an absolute address or a symbolic address.
Bits in ACC are shifted n places to the left. Zeros are introduced on the
LSL #n
right hand end.
Bits in ACC are shifted n places to the right. Zeros are introduced on the
LSR #n
left hand end.
Key in a character and store its ASCII value in ACC.
IN
Output to the screen the character whose ASCII value is stored in ACC.
OUT
Return control to the operating system.
END
(a) A programmer needs a program that multiplies a binary number by 4.
The programmer has started to write the program in the following table. The comment column
contains explanations for the missing program instructions.
Write the program using the given instruction set.
Instruction
Label
Comment
Op code
Operand
// load contents of NUMBER
// perform shift to multiply by 4
// store contents of ACC in NUMBER
// end program
NUMBER:
B00110110
[5]
Note:
denotes immediate addressing
#
denotes a binary number, e.g. B01001010
B
denotes a hexadecimal number, e.g. &4A
&
(b) A programmer needs a program that counts the number of lower case letters in a string.
The programmer has started to write the program in the following table. The comment column
contains explanations for the missing program instructions.
Complete the program using the given instruction set. A copy of the instruction set is provided
on the opposite page.
Instruction
Label
Comment
Op code
Operand
LDR
#0
// initialise Index Register to 0
START:
// load the next value from the STRING
// perform bitwise AND operation with MASK
// check if result is equal to MASK
// if FALSE, jump to UPPER
// increment COUNT
UPPER:
INC
IX
// increment the Index Register
// decrement LENGTH
// is LENGTH = 0 ?
// if FALSE, jump to START
END
// end program
MASK:
B00100000
// if bit 5 is 1, letter is lower case
COUNT:
0
LENGTH:
5
STRING:
B01001000
// ASCII code for 'H'
B01100001
// ASCII code for 'a'
B01110000
// ASCII code for 'p'
B01110000
// ASCII code for 'p'
B01011001
// ASCII code for 'Y'
[8]
Instruction

Advertisement
14
9608/41/O/N/18 · Question 1Oct/Nov 2018Paper 4114 marks
Loading question…
Question text

1
A declarative language is used to represent the following facts and rules about animals.
01 feature(dog, drinks_milk).
02 feature(dog, has_lungs).
03 feature(horse, has_lungs).
04 feature(tuna, lives_in_water).
05 feature(tuna, has_gills).
06 feature(crab, lives_in_water).
07 mammal(drinks_milk).
08 mammal(has_lungs).
09 fish(lives_in_water).
10 fish(has_gills).
11 is_a_mammal(X) IF (feature(X, Y) AND mammal(Y)) AND (feature(X, Z)
AND mammal(Z)).
These clauses are explained in the following table.
Clause
Explanation
01
A dog has the feature, drinks milk
07
A mammal drinks milk
11
X is a mammal, if:
X has the feature Y and a mammal has a feature Y, and
•
X has the feature Z and a mammal has the feature Z
•
(a) More facts are to be included.
(i)
A bird has wings, and a bird lays eggs.
Write the additional clauses to record these facts.
12 …
13 …
[2]
(ii)
An eagle has all the features of a bird.
Write the additional clauses to record this fact.
14 …
15 …
[2]
(b) (i)
Using the variable B, the goal
feature(B, drinks_milk)
returns
B = dog
Write the result returned by the goal
feature(B, lives_in_water)
B = … [2]
(ii)
Write a goal, using the variable C, to find the feature(s) of tuna.
… [2]
(c) An animal is a bird if it lays eggs and it has wings.
Complete the following rule.
is_a_bird(X) IF …
… [3]
(d) Declarative programming and object-oriented programming are two examples of programming
paradigms.
(i)
Define the term programming paradigm.
…
… [1]
(ii)
Give two examples of programming paradigms, other than declarative and object-oriented
programming.
1 …
2 …
[2]

15
9608/41/O/N/18 · Question 5Oct/Nov 2018Paper 4117 marks
Loading question…
Question text

5
A game uses a set of cards. Each card has a number (between 0 and 9 inclusive) and a shape
("square", "triangle" or "circle").
The game is written using object-oriented programming.
The class, Cards, has the private properties:
Number
•
Shape
•
and the methods:
Constructor()
•
GetNumber()
•
GetShape()
•
The purpose of each method in the class Cards is given in the following table.
Method
Purpose
Constructor()
Takes a number and a shape as parameters
Checks that the number and the shape are valid and:
either assigns the parameters to Number and Shape
•
or reports an error.
•
GetNumber()
A public method that returns the number for that card.
GetShape()
A public method that returns the shape for that card.
(a) Explain why the properties are private.
…
…
…
…
… [2]
(b) Write program code for the Constructor() method.
Programming language …
Program code
…
…
…
…
…
…
…
…
…
…
… [5]
(c) Write program code for the GetNumber() method.
Programming language …
Program code
…
…
…
…

Advertisement