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

10 questions

0 / 0Answer a question to start your score.
New quizSaved 0

Quick quiz: 10 random questions from this topic. Answer them all, then open the Summary.

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

2
9608/42/O/N/17 · Question 6Oct/Nov 2017Paper 4213 marks
Loading question…
Question text

6
A bank has a range of customer accounts, which includes current accounts and savings accounts.
All accounts have:
•
an account number
•
a balance (amount of money in an account).
A current account has a level (bronze, silver or gold). A monthly fee ($) is taken from each account.
Savings account customers pay a regular amount ($) into their account. The payment interval is a
number of weeks (for example, 4).
An object-oriented program will be written to process data about the accounts.
(a) Complete the class diagram.
Account
AccountNumber : STRING
Balance : CURRENCY
Constructor()
GetAccountNumber()
GetBalance()
SetAccountNumber()
SetBalance()
CurrentAccount
SavingsAccount
…
…
…
…
…
…
…
…
Constructor()
…
…
…
…
…
…
…
…
GetPaymentInterval()
SetPaymentInterval()
[3]
(b) Write program code to declare the Account class.
Programming language …
Program code …
…
…
…
…
…
…
…
…
…
…
…
…
…

3
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]

Advertisement
4
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
…
…
…
…
…
…
…
…
…
…
…

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

6
9608/41/M/J/17 · Question 1May/June 2017Paper 4115 marks
Loading question…
Question text

1
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
Operand
code
Immediate addressing. Load the number n to ACC.
LDM
#n
Direct addressing. Load the contents of the location at the given address
LDD
<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 of
LDX
<address>
the index register. Copy the contents of this calculated address to ACC.
Store the contents of ACC at the given address.
STO
<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>
Compare the contents of ACC with the contents of <address>.
CMP
<address>
Jump to given address.
JMP
<address>
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 contents of
AND
<address>
<address>.
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 contents of
OR
<address>
<address>.
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 writes a program that:
•
reads a character from the keyboard (assume it will be a capital letter)
•
outputs the alphabetical sequence of characters from ‘A’ to the character input. For
example, if the character ‘G’ is input, the output is:
ABCDEFG
The programmer has started to write the program in the table on the following page. The
Comment column contains descriptions for the missing instructions, labels and data.
Complete the following program. Use op codes from the given instruction set.
Label
Op code
Operand
Comment
START:
// INPUT character
// store in CHAR
// Initialise ACC (ASCII value for 'A' is 65)
// OUTPUT ACC
// compare ACC with CHAR
// if equal jump to end of FOR loop
// increment ACC
// jump to LOOP
ENDFOR:
END
CHAR:
[8]
(b) The programmer now starts to write a program that:
•
tests whether an 8-bit two’s complement integer stored at address NUMBER is positive or
negative
•
outputs 'P' for a positive integer and 'N' for a negative integer.
Complete the following program. Use op codes from the given instruction set.
Show the required value of MASK in binary.
Label
Op code
Operand
Comment
START:
MASK
// set to zero all bits except sign bit
// compare with 0
// if not equal jump to ELSE
THEN:
// load ACC with 'P' (ASCII value 80)
JMP
ENDIF
ELSE:
// load ACC with 'N' (ASCII value 78)
ENDIF:
END
NUMBER:
B00000101
// integer to be tested
MASK:
// value of mask in binary
[7]

7
9608/41/M/J/16 · Question 4May/June 2016Paper 4110 marks
Loading question…
Question text

4
When a car reaches a certain age, a safety assessment has to be carried out. A car’s brakes and
tyres must be tested. The tyre test result and the brakes test result for each car are recorded. If the
car passes the assessment, a safety certificate is issued.
Cars have a unique three-character registration.
The following knowledge base is used:
01
car(a05).
02
car(h04).
03
car(a03).
04
car(h07).
05
car(a23).
06
car(p05).
07
car(b04).
08
carRegYear(a05, 2015).
09
carRegYear(h04, 2013).
10
carRegYear(a03, 2008).
11
carRegYear(h07, 2011).
12
carRegYear(a23, 2008).
13
carRegYear(p05, 2014).
14
carRegYear(b04, 2014).
15
testBrakes(h07, pass).
16
testTyres(h07, fail).
17
testBrakes(a03, fail).
18
testTyres(a03, fail).
19
testBrakes(a23, pass).
20
testTyres(a23, pass).
21
carAssessmentDue if carRegYear(Car, RegYear)
and RegYear <= DeadlineYear.
22 issueCertificate(Car) if testTyres(Car, Result) and
testBrakes(Car, Result) and Result = pass.
DeadlineYear is assigned value 2011.
(a) (i)
Identify the car registrations for cars which are due to be tested.
… [1]
State how clause 22 determines whether or not a safety certificate will be issued.
(ii)
…
… [1]
(b) If a car fails one of the two tests, a retest is allowed.
Write a new rule for this.
retestAllowed( … ) if …
…
… [3]
(c) Logic programming uses a data structure called a list.
A new fact is added to the knowledge base.
23 carList = [a03,p05,b04,h04,h07,a23].
The following notation and operators are to be used with a list:
[X|Y] denotes a list with:
X the first list element
•
Y the list consisting of the remaining list elements
•
[] denotes an empty list
The list [a07,p03] is denoted by [A|B]
(i)
State the value of A and B.
A = …
B = …
[2]
The lists [c03,d02,n05|C] and [c03,d02,n05,p05,m04] are identical.
(ii)
State the value of C.
C = …
[1]
The list [a06,a02] is denoted by [D,E|F]
(iii)
State the value of F.
F = …
[1]
(d) The predicate conCatCompare is defined as a rule and returns TRUE or FALSE as follows:
conCatCompare(X, Y, Z)
Concatenates the lists X and Y and compares the new list with
list Z .
If equal, the clause evaluates to TRUE , otherwise FALSE .
Consider the clause:
conCatCompare(X, Y, [a7,b6,c4])
If:
the clause evaluates to TRUE
•
and Y represents the list [a7, b6, c4]
•
State the value of X.
X = … [1]

8
9608/41/M/J/20 · Question 1May/June 2020Paper 416 marks
Loading question…
Question text

1
Carlos is writing exception handling code for his program.
(a) State what is meant by an exception.
…
… [1]
(b) Give three situations where an exception handling routine would be required.
1 …
…
2 …
…
3 …
…
[3]
(c) Describe the benefits of using exception handling in a program.
…
…
…
… [2]

Advertisement
9
9608/42/M/J/18 · Question 4May/June 2018Paper 4216 marks
Loading question…
Question text

4
X-Games is an international extreme sports competition.
A program will store and process data about the teams in the competition.
•
Each team is made up of members.
•
Members can be added and removed from each team.
•
Each member has a first name, last name, date of birth and gender.
•
Each member can be an official or a competitor.
•
Each official has a job title and may be first-aid trained.
•
Each competitor takes part in one sport.
The program is written using object-oriented programming.
The program can output the full name and date of birth of any member. For example, “Nadia Abad
16/05/1995”
An introduction about a team member can be output using their name. For example, “Hello, I’m
Nadia Abad”.
The program outputs a different version of the introduction for a competitor. This version includes
the competitor’s sport. For example, “Hello, I’m Sally Jones and my sport is Skateboard Park.”
(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.
Member
Team
FirstName : STRING
TeamName : STRING
LastName : STRING
TeamList : ARRAY OF Member
DateOfBirth : DATE
Gender : STRING
Constructor()
Constructor()
…
Introduction()
…
DisplayFullnameAndDateOfBirth()
Competitor
Official
Sport : STRING
…
…
Constructor()
Constructor()
Introduction()
DisplayJobTitle()
[3]
(b) Write program code for the Member class.
Programming language …
Program code
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…

10
9608/41/M/J/17 · Question 4May/June 2017Paper 4130 marks
Loading question…
Question text

4
An ordered linked list Abstract Data Type (ADT) has these associated operations:
•
create list
•
add item to list
•
output list to console
The ADT is to be implemented using object-oriented programming as a linked list of nodes.
Each node consists of data and a pointer.
(a) There are two classes, LinkedList and Node.
(i)
State the term used to describe the relationship between these classes.
… [1]
(ii)
Draw the appropriate diagram to represent this relationship. Do not list the attributes and
methods of the classes.
[2]
(b) The design for the Node class consists of:
•
attributes
Data : STRING
Pointer : INTEGER
•
methods
CreateNode(Data, Pointer)
SetData(Data)
SetPointer(Pointer)
GetData() RETURNS STRING
GetPointer() RETURNS INTEGER
The constructor method sets the attributes to the initial values that are passed as parameters.
Write program code for:
•
the Node class declaration
•
the constructor.
Programming language used …
Program code
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [5]
(c) The identifier table for the LinkedList class is:
Identifier
Data type
Description
HeadPointer
INTEGER
Pointer to the first node in the ordered list.
FreeListPointer
INTEGER
Pointer to the first node in the free list.
NodeArray
ARRAY[0 : 7] OF Node
1D array stores the nodes that make the
ordered linked list. The unused nodes are
linked together into a free list.
Constructor()
Constructor instantiates

Advertisement