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

45 questions · page 2 of 3 · Clear filters

0 / 0Answer a question to start your score.
Quick quiz (10)Saved 0
Advertisement
16
9608/42/M/J/20 · Question 5May/June 2020Paper 429 marks
Loading question…
Question text

5
A declarative programming language is used to represent the following knowledge base.
01
person(william).
02
person(deeraj).
03
person(ingrid).
04
person(meghan).
05
country(england).
06
country(spain).
07
country(bangladesh).
08
country(new_zealand).
09
country(malaysia).
10
country(mauritius).
11
visited(william, spain).
12
visited(ingrid, new_zealand).
13
visited(deeraj, spain).
14
visited(meghan, spain).
These clauses have the following meanings:
Clause
Meaning
02
Deeraj is a person
05
England is a country
11
William has visited Spain
(a) Gina is a person who has visited Cyprus.
Write additional clauses to represent this information.
15 …
16 …
17 …
[3]
(b) Write the result returned by the goal:
visited(X, spain).
X = … [2]
(c) P might visit C, if P is a person, C is a country and P has not visited C.
Write this as a rule.
mightvisit(P , C)
IF …
…
… [4]

17
9608/42/M/J/20 · Question 6May/June 2020Paper 425 marks
Loading question…
Question text

6
Object-oriented programming has several features. These include containment, classes, methods
and properties.
(a) Describe what is meant by containment.
…
…
…
…
…
… [3]
(b) Identify two other features of object-oriented programming.
1 …
2 …
[2]

18
9608/42/M/J/20 · Question 7May/June 2020Paper 4218 marks
Loading question…
Question text

7
A programmer is creating a computer game. The programmer has designed the class, Character,
for the characters in the game.
The following class diagram shows the design for the Character class.
Character
Name : STRING
//
initialised in constructor to the parameter
value passed to the constructor
Skill : INTEGER
//
initialised in constructor to 0
Health : INTEGER
//
initialised in constructor to 50
Shield : INTEGER
//
initialised in constructor to a random value
between 1 and 25 (inclusive)
Constructor()
//
method used to create and initialise an object
GetName()
//
returns Name value
GetSkill()
//
returns Skill value
GetHealth()
//
returns Health value
GetShield()
//
returns Shield value
SetSkill()
//
increases Skill by the parameter value
SetHealth()
//
increases or decreases Health by the parameter
value
SetShield()
//
increases or decreases Shield value by 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
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [5]
(b) Write program code for the GetSkill() method.
Programming language …
Program code
…

Advertisement
19
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]

20
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
…
…
…

21
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

22
9608/41/M/J/19 · Question 2May/June 2019Paper 4165 marks
Loading question…
Question text

2
A computer games club wants to run a competition. The club needs a system to store the scores
achieved in the competition.
A selection of score data is as follows:
99, 125, 121, 97, 109, 95, 135, 149
(a) A linked list of nodes will be used to store the data. Each node consists of the data, a left
pointer and a right pointer. The linked list will be organised as a binary tree.
(i)
Complete the binary tree to show how the score data above will be organised.
RootPointer
The symbol ∅ represents a null pointer.
LeftPointer
RightPointer
99
97
125
∅
121
[5]
(ii)
The following diagram shows a 2D array that stores the nodes of the binary tree’s linked
list.
Add the correct pointer values to complete the diagram, using your answer from
part (a)(i).
RootPointer
Index LeftPointer
Data
RightPointer
0
99
0
1
125
2
121
3
97
FreePointer
4
109
5
95
6
135
7
149
8
[6]
(b) The club also considers storing the data in the order in which it receives the scores as a
linked list in a 1D array of records.
The following pseudocode algorithm searches for an element in the linked list.
Complete the six missing sections in the algorithm.
FUNCTION FindElement(Item : INTEGER) RETURNS …
… ← RootPointer
WHILE CurrentPointer … NullPointer
IF List[CurrentPointer].Data <> …
THEN
CurrentPointer ← List[ … ].Pointer
ELSE
RETURN CurrentPointer
ENDIF
ENDWHILE
CurrentPointer ← NullPointer
… CurrentPointer
ENDFUNCTION
[6]
(c) The games club is looking at two programming paradigms: imperative and object-oriented
programming paradigms.
Describe what is meant by the imperative programming paradigm and the object-oriented
programming paradigm.
(i)
Imperative …
…
…
…
…
… [3]
(ii)
Object-oriented …
…
…
…
…
… [3]
(d) Players complete one game to place them into a category for the competition. The games club
wants to implement a program to place players into the correct category. The programmer
has decided to use object-oriented programming (OOP).
The highest score that can be achieved in the game is 150. Any score less than 50 will not
qualify for the competition. Players will be placed in a category based on their score.
The following diagram shows the design for the class Player. This includes the properties
and methods.
Player
Sco

23
9608/42/M/J/19 · Question 1May/June 2019Paper 4244 marks
Loading question…
Question text

1
A company wants an online marking system for an examination.
(a) The following is a selection of data showing final marks.
36, 45, 21, 65, 66, 13, 54, 53, 34
A linked list of nodes will be used to store the data. Each node consists of the data, a left
pointer and a right pointer. The linked list will be organised as a binary tree.
(i)
Complete the binary tree to show how the data above will be organised.
RootPointer
The symbol Ø represents a
null pointer
LeftPointer
RightPointer
36
45
21
Ø
65
66
Ø
Ø
[5]
(ii)
The following diagram shows a 2D array that stores the nodes of the binary tree’s linked
list.
Add the correct pointer values to complete the diagram, using your answer from
part (a)(i).
RootPointer
Index
LeftPointer
Data
RightPointer
0
0
36
1
45
FreePointer
2
21
3
65
4
66
5
13
6
54
7
53
8
34
9
[6]
(b) The company wants to implement a program for the marking system. It will do this with
object-oriented programming (OOP).
Many candidates take the examination. Each examination paper is given a PaperID that is
made up of the centre (school) number followed by the candidate number.
Each examination paper is awarded a grade.
The following diagram shows the design for the ExaminationPaper class. This includes
the attributes and methods.
ExaminationPaper
FinalMark : INTEGER // maximum 2 digits, initialised to 0
Grade
: STRING // "Pass", "Merit", "Distinction"
// or "Fail", initialised to "Fail"
PaperID
: STRING // centre number followed by the
// candidate number, for example
// "ZZ00991001"
Create()
//
creates and initialises a new instance
//
of the ExaminationPaper class using
//
language-appropriate constructor
SetFinalMark()
//
checks that the mark parameter has a
//
valid value, if so, assigns it to
//
FinalMark
SetGrade()
//
sets Grade based on FinalMark
GetFinalMark()
//
returns FinalMark
GetGrade()
//
returns Grade
GetPaperID()
//
returns PaperID
(i)
The constructor receives the centre number and candidate number as parameter values
to create PaperID. Other properties are initialised as instructed in the class diagram.
Write program code for the Create() constructor method.
Programming language …
Program code
…
…
…
…
…
…
…
…
…
… [5]
(ii)
Get and set methods are used to support the security and integrity of data in
object-oriented programming.
Explain how get and set methods are used to support security and integrity.
…

Advertisement
24
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]

25
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
…
…
…
…

26
9608/42/O/N/18 · Question 2Oct/Nov 2018Paper 4210 marks
Loading question…
Question text

2
A declarative language is used to represent facts and rules about dogs that perform tasks to help
people.
01
type(pointer, gundog).
02
type(flushing, gundog).
03
type(retriever, gundog).
04
05
is_a(labrador, retriever).
06
is_a(newfoundland, retriever).
07
is_a(cocker_spaniel, flushing).
08
is_a(springer_spaniel, flushing).
09
is_a(king_charles, flushing).
10
is_a(english_setter, pointer).
11
is_a(irish_setter, pointer).
12
13
fav_bird(pointer, grouse).
14
fav_bird(flushing, pheasant).
15
fav_bird(retriever, waterfowl).
16
17
type(X, Y) IF is_a(Z, X) AND type(Z, Y).
These clauses have the following meaning:
Clause
Explanation
01
A pointer is a type of gundog.
05
A labrador is an example of a retriever.
13
The favourite bird of a pointer is a grouse.
17
X is a type of Y if Z is an example of X and Z is a type of Y.
(a) More facts are to be included.
A standard poodle is an example of a waterdog. A waterdog is a type of gundog.
Write the additional clauses to record these facts.
18 …
19 …
[2]
(b) Using the variable P, the goal
is_a(P, retriever)
returns
P = labrador, newfoundland
Write the result returned by the goal
is_a(H, pointer)
H = … [2]
(c) Write a query, using the variable W, to find out what an irish setter is an example of.
… [2]
(d) Y is the favourite bird of dog X.
Complete the following rule:
fav_bird(X, Y) IF …
… [3]
(e) State the value returned by the goal
NOT(is_a(labrador, retriever))
… [1]

27
9608/42/O/N/18 · Question 4Oct/Nov 2018Paper 4222 marks
Loading question…
Question text

4
A circus is made up of performers. There are three types of performer: clown, acrobat and aerial.
The following data are stored for each performer.
•
First name
•
Last name
•
Secondary role (that can be edited)
•
Stage name (that can be edited)
•
Type of performer (PerfType)
The following statements apply to performers.
•
An acrobat may or may not use fire in his or her act.
•
An aerial performer can be one of two types: either catcher or flyer.
•
Each clown has an item, such as a water-spraying flower or a unicycle.
•
Each clown also has a musical instrument, such as a guitar or an oboe.
Each of the three types of performer has a method that will display all of the information about that
performer in a specific format. For example:
Sally Superstar (real name Sally Smith) is an acrobat. Fire is part of Sally Superstar’s act.
When not performing, Sally Superstar is a set changer.
(a) Complete the following class diagram to show the attributes, methods and inheritance for
the program.
You do not need to write the get and set methods.
Performer
Acrobat
FirstName : STRING
UseFire : BOOLEAN
LastName : STRING
SecondaryRole : STRING
Constructor()
StageName : STRING
PerformerInfo()
PerfType : STRING
Constructor()
EditSecondaryRole()
EditStageName()
Clown
Aerial
…
…
…
Constructor()
Constructor()
…
…
[4]
(b) Write program code for the Performer class.
Programming language …
Program code
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

28
9608/41/M/J/18 · Question 1May/June 2018Paper 4110 marks
Loading question…
Question text

1
A declarative language is used to represent facts and rules about flights.
01
direct(edinburgh, paris).
02
direct(palma, rome).
03
direct(glasgow, palma).
04
direct(glasgow, vienna).
05
direct(glasgow, salzburg).
06
07
flies(paris, fly_jet).
08
flies(mumbai, british_air).
09
flies(palma, ciebe).
10
flies(vienna, fly_jet).
11
flies(salzburg, ciebe).
12
13
can_fly(X, Y) IF direct(X, Z) AND direct(Z, Y).
These clauses have the following meaning:
Clause
Explanation
01
There is a direct route from Edinburgh to Paris.
07
Fly Jet operates flights to Paris.
13
It is possible to fly from X to Y if there is a direct flight from X to Z and a direct
flight from Z to Y.
(a) More facts need to be included.
There is a direct flight from London to Rome and British Air flies to Rome.
14 …
15 …
[2]
(b) Using the variable Q, the goal
flies(Q, fly_jet).
returns
Q = paris, vienna
Write the result returned by the goal
flies(K, ciebe).
K = … [2]
(c) Use the variable M to write the goal to find where you can fly direct from Glasgow.
… [2]
(d) If an airline flies to an airport, that airline also flies every direct route out of that airport.
Write a rule to represent this condition.
flies(Y, X)
IF …
… [3]
(e) State what the following goal returns.
can_fly(glasgow, rome).
… [1]

Advertisement
29
9608/41/M/J/18 · Question 5May/June 2018Paper 4121 marks
Loading question…
Question text

5
A computer game is being developed using object-oriented programming. The following image is
a screenshot from the game.
There are scenery elements and animated elements. The player’s character is one of the animated
elements.
Each game element has the attributes:
Attribute
Description
Example value
The x coordinate of the game
PositionX
92
element.
The y coordinate of the game
PositionY
106
element.
The width of the game element.
Width
150
The height of the game element.
Height
200
The filename of the image file for
ImageFilename
GameElementFrame1.png
the game element.
Each game element has a method, GetDetails() that returns a string containing all the
element’s attributes.
The player’s character is one of a number of animated elements. All animated elements have the
attributes:
Attribute
Description
Example value
AnimationFrames
An array of GameElement
"Left"
A string giving the direction the
Direction
object is travelling in.
2000
A value for the strength that
Strength
indicates the power of the object.
100
A value for the health that
Health
indicates the health of the object.
The player’s character can either move left or right, or jump.
(a) Complete the following class diagram for the game.
You do not need to include any additional get or set methods.
GameElement
AnimatedElement
PositionX: INTEGER
AnimationFrames: ARRAY OF GameElement
PositionY: INTEGER
Width: INTEGER
…
Height: INTEGER
ImageFilename: STRING
…
…
Constructor()
Constructor()
GetDetails()
AdjustHealth()
AdjustStrength()
DisplayAnimation()
Scenery
Player
CauseDamage: BOOLEAN
DamagePoints: INTEGER
Constructor()
GiveDamagePoints()
…
…
…
…
[3]
(b) Write program code to define the GameElement class.
Programming language …
Program code
…
…
…
…
…
…
…
…
…
…
…

30
9608/42/M/J/18 · Question 2May/June 2018Paper 4210 marks
Loading question…
Question text

2
A declarative language is used to represent the following facts and rules about iguanas and
lizards.
01
has(reptile, cold_blood).
02
has(reptile, air_breathing).
03
has(reptile, scales).
04
05
is_a(squamata, reptile).
06
is_a(iguana, squamata).
07
is_a(lizard, squamata).
08
is_a(green_iguana, iguana).
09
is_a(cayman, iguana).
10
is_a(smooth_iguana, iguana).
11
12
maxsize(green_iguana, 152).
13
maxsize(cayman, 90).
14
maxsize(smooth_iguana, 70).
These clauses have the following meaning:
Clause
Explanation
A reptile has cold blood.
01
A cayman is a type of iguana.
09
The maximum size of a green iguana is 152 cm.
12
(a) More facts are to be included.
A gecko is a type of lizard. It has a maximum size of 182 cm.
Write the additional clauses to record these facts.
15 …
16 …
[2]
(b) Using the variable R, the goal
is_a(R, squamata).
returns
R = iguana, lizard
Write the result returned by the goal
is_a(T, iguana).
T = … [2]
(c) Write the goal, using the variable X, to find what a squamata is.
… [2]
(d) All iguanas and lizards are squamata. All squamata are reptiles.
Write a recursive rule to make all lizards and iguanas inherit the properties of reptiles.
has(X, Y)
IF
…
… [3]
(e) State what the following goal returns.
NOT(maxsize(cayman, 70)).
… [1]

Advertisement