Computer Science (9608) · Oct/Nov 2015 · Question paper 21

Cambridge Computer Science (9608) question paper for paper 21, Oct/Nov 2015 — 9608/21/O/N/15, file 9608_w15_qp_21.pdf.

Advertisement
Loading the paper…
Text of this paper

www.dynamicpapers.com

Cambridge International Examinations
Cambridge International Advanced Subsidiary and Advanced Level

* 9 7 0 2 7 5 7 8 6 6 *

9608/21

COMPUTER SCIENCE
Paper 2 Fundamental Problem-solving and Programming Skills

October/November 2015
2 hours

Candidates answer on the Question Paper.
No Additional Materials are required.
No calculators allowed.
READ THESE INSTRUCTIONS FIRST
Write your Centre number, candidate number and name in the spaces at the top of this page.
Write in dark blue or black pen.
You may use an HB pencil for any diagrams, graphs or rough working.
Do not use staples, paper clips, glue or correction fluid.
DO NOT WRITE IN ANY BARCODES.
Answer all questions.
No marks will be awarded for using brand names of software packages or hardware.
At the end of the examination, fasten all your work securely together.
The number of marks is given in brackets [ ] at the end of each question or part question.
The maximum number of marks is 75.

This document consists of 19 printed pages and 1 blank page.
DC (NH/CGW) 95372/4
© UCLES 2015

[Turn over

www.dynamicpapers.com
2
Throughout the paper you will be asked to write either pseudocode or program code.
Complete the statement to indicate which high-level programming language you will use.
Programming language

© UCLES 2015

9608/21/O/N/15

www.dynamicpapers.com
3
1

Computer programs have to evaluate expressions.
Study the sequence of pseudocode statements.
Write down the value assigned to each variable.

DECLARE h, w, r, Perimeter, Area : REAL
DECLARE A, B, C, D, E
h
w

←
←

13.6
6.4

Perimeter
r

←

: BOOLEAN

←

(h + w) * 2

(i) Perimeter [1]

10

Area 3.142 * r^2

(ii) Area [1]

Z

←

11 + r / 5 + 3

(iii) Z [1]

A

←

NOT(r > 10)

(iv) A [1]

2

A programmer uses an Integrated Development Environment (IDE) for all program development.
(i)

Describe what is meant by an IDE.

[2]

(ii)

Name three features you would expect to be available in an IDE to help initial error detection
or debugging.
1

2

3
[3]

© UCLES 2015

9608/21/O/N/15

[Turn over

www.dynamicpapers.com
4
3

A program is to simulate the operation of a particular type of logic gate.
•
•

The gate has two inputs (TRUE or FALSE) which are entered by the user.
The program will display the output (TRUE or FALSE) from the gate.

The program uses the following identifiers in the pseudocode below:
Identifier

Data type

Description

InA

BOOLEAN

Input signal

InB

BOOLEAN

Input signal

OutZ

BOOLEAN

Output signal

01

INPUT InA

02

INPUT InB

03

IF (InA = FALSE AND InB = FALSE) OR (InA = FALSE AND InB = TRUE)
OR (InA = TRUE AND InB = FALSE)

04

THEN

05
06

OutZ
ELSE

07
08
09

OutZ

←

TRUE

←

FALSE

ENDIF
OUTPUT OutZ

(a) The programmer chooses the following four test cases.
Show the output (OutZ) expected for each test case.
Input
Test case

InA

InB

1

TRUE

TRUE

2

TRUE

FALSE

3

FALSE

TRUE

4

FALSE

FALSE

Output
OutZ

[4]

© UCLES 2015

9608/21/O/N/15

www.dynamicpapers.com
5
(b) The selection statement (lines 03 – 08) could have been written with more simplified logic.
Rewrite this section of the algorithm in pseudocode.

[3]

© UCLES 2015

9608/21/O/N/15

[Turn over

www.dynamicpapers.com
6
4

A program is to be written to calculate the discount given on purchases.
A purchase may qualify for a discount depending on the amount spent. The purchase price
(Purchase), the discount rate (DiscountRate) and amount paid (Paid) is calculated as shown
in the following pseudocode algorithm.
INPUT Purchase
IF Purchase > 1000
THEN
0.10
DiscountRate
ELSE
IF Purchase > 500
THEN
0.05
DiscountRate
ELSE
0
DiscountRate
ENDIF
ENDIF

←

←
←

←

Purchase * (1 - DiscountRate)
Paid
OUTPUT Paid

The algorithm is also to be documented with a program flowchart.
Complete the flowchart by:
•

filling in the flowchart boxes

•

labelling, where appropriate, lines of the flowchart

© UCLES 2015

9608/21/O/N/15

www.dynamicpapers.com
7

[6]

© UCLES 2015

9608/21/O/N/15

[Turn over

www.dynamicpapers.com
8
5

A driver buys a new car.
The value of the car reduces each year by a percentage of its current value.
The percentage reduction is:
•
•

in the first year, 40%
in each following year, 20%

The driver writes a program to predict the value of the car in future years.
The program requirements are:
•
•
•

enter the cost of the new car (to nearest $)
calculate and output the value of the car at the end of each year
the program will end when either the car is nine years old, or when the value is less than
$1000

(a) Study the incomplete pseudocode which follows in part (b) and fill in the identifier table.
Identifier

Data type

Description

[3]
(b) Complete the pseudocode for this design.
OUTPUT "Enter purchase price"
INPUT PurchasePrice

←

CurrentValue
1
YearCount

←

WHILE AND
IF
THEN
CurrentValue * (1 – 40 / 100)
CurrentValue
ELSE

CurrentValue
ENDIF

←
←

OUTPUT YearCount, CurrentValue

ENDWHILE
[6]

© UCLES 2015

9608/21/O/N/15

www.dynamicpapers.com
9
6

A firm employs five staff who take part in a training programme. Each member of staff must
complete a set of twelve tasks which can be taken in any order. When a member of staff
successfully completes a task, this is recorded.
A program is to be produced to record the completion of tasks for the five members of staff.
To test the code, the programmer makes the program generate test data.
The program generates pairs of random numbers:
•

the first, in the range, 1 to 5 to represent the member of staff

•

the second, in the range, 1 to 12 to represent the task

Each pair of numbers simulates the completion of one task by one member of staff.
(a) Explain why the generation of 60 (5 staff x 12 tasks) pairs of random numbers will not simulate
all tasks completed by all staff.

[2]
(b) Data is currently recorded manually as shown.
Staff
number

1

2

3

4

Task number
5
6
7
8

9

10

11

12

1
2
3

4

5

The table shows that two members of staff have each successfully completed one task.
The program must use a suitable data structure to store, for all staff:
•

tasks successfully completed

•

tasks not yet successfully completed

The program will output the staff number and task number in the order in which tasks are
completed.

© UCLES 2015

9608/21/O/N/15

[Turn over

www.dynamicpapers.com
10
The program design in pseudocode is produced as follows:
01

DECLARE StaffNum

: INTEGER

02

DECLARE TaskNum

: INTEGER

03

DECLARE
DECLARE NewStaffTask
: BOOLEAN

04
05
06

CALL InitialiseTaskGrid

07

Completed

08

WHILE Completed <> 60

←

0

←

09

NewStaffTask

10

WHILE NewStaffTask = FALSE

FALSE

← RANDOM(1,5)
← RANDOM(1,12)

11

StaffNum

12

TaskNum

13

IF TaskGrid[StaffNum, TaskNum] = FALSE

14

//generates a random number
//in the given range

THEN

15

TaskGrid[StaffNum, TaskNum]

16

NewStaffTask

17

OUTPUT StaffNum, TaskNum

18

←

TRUE

ENDIF

19

ENDWHILE

20

Completed

←

Completed + 1

21

ENDWHILE

22

OUTPUT "Staff Task Count", Completed

23
24

// end of main program

25
26

PROCEDURE InitialiseTaskGrid()

27

DECLARE i : INTEGER

28

DECLARE j : INTEGER

29

FOR i

30

←

FOR j

31

1 TO 5

←

1 TO 12

TaskGrid[i, j]

32

←

FALSE

ENDFOR

33

ENDFOR

34

ENDPROCEDURE

© UCLES 2015

9608/21/O/N/15

←

TRUE

www.dynamicpapers.com
11
Study the pseudocode and answer the questions below.
Give the line number for:
(i)

The declaration of a BOOLEAN global variable.

[1]

(ii)

The declaration of a local variable.

[1]

(iii)

The incrementing of a variable used as a counter, but not to control a ‘count controlled’
loop.
[1]

(iv)

A statement which uses a built-in function of the programming language.
[1]

(c) (i)

State the number of parameters of the InitialiseTaskGrid procedure.
[1]

(ii)

Copy the condition which is used to control a ‘pre-condition’ loop.
[1]

(iii)

Explain the purpose of lines 13 – 18.

[3]

(iv)

Give the global variable that needs to be declared at line 03.
[2]

© UCLES 2015

9608/21/O/N/15

[Turn over

www.dynamicpapers.com
12
(d) Line 17 in the pseudocode outputs the staff number and the task number.
A new requirement is to display the name of the
member of staff given in the table.
Write a CASE structure using variable StaffNum.
Assign to a new variable StaffName the appropriate
staff name.

Staff number

Staff name

1

Sadiq

2

Smith

3

Ho

4

Azmah

5

Papadopoulos

[4]

© UCLES 2015

9608/21/O/N/15

www.dynamicpapers.com
13

Question 7 begins on page 14.

© UCLES 2015

9608/21/O/N/15

[Turn over

www.dynamicpapers.com
14
7

ASCII character codes are used to represent a single character.
Part of the code table is shown below.
ASCII code table (part)
Character

Decimal

Character

Decimal

Character

Decimal

<Space>

32

I

73

R

82

A

65

J

74

S

83

B

66

K

75

T

84

C

67

L

76

U

85

D

68

M

77

V

86

E

69

N

78

W

87

F

70

O

79

X

88

G

71

P

80

Y

89

H

72

Q

81

Z

90

Some pseudocode statements follow which use the built-in functions below:
ONECHAR(ThisString : STRING, Position : INTEGER) RETURNS CHAR
returns the single character at position Position (counting from the start of the string with value 1)
from the string ThisString.
For example: ONECHAR("Barcelona", 3) returns 'r'.
CHARACTERCOUNT(ThisString : STRING) RETURNS INTEGER
returns the number of characters in the string ThisString.
For example: CHARACTERCOUNT("BRAZIL") returns 6.
CHR(ThisInteger : INTEGER) RETURNS CHAR
returns the character with ASCII code ThisInteger.
For example: CHR(65) returns character 'A'.
ASC(ThisCharacter : CHAR) RETURNS INTEGER
returns the ASCII value for character ThisCharacter.
For example: ASC('A') returns 65.
(a) Show the values stored by variables A, B, C and D.
The & operator is used to concatenate two strings.
Num1
A
B
C
D

←
←
←
←

←

15

CHR(67) & CHR(65) & CHR(84)

(i) A [1]

ASC('P') - ASC('F') + 3

(ii) B [1]

ASC(ONECHAR("BISCUITS", 3))

(iii) C [1]

CHARACTERCOUNT("New York City") + 2 (iv) D [1]

© UCLES 2015

9608/21/O/N/15

www.dynamicpapers.com
15
(b) A program is to be written which accepts a string and then calculates a numeric value from
this string. The input string and the calculated value are then to be sent to a remote computer
over a communications link.
Study the following pseudocode:
OUTPUT "Enter string"
INPUT MyString
0
StringTotal

←

←

1 TO CHARACTERCOUNT(MyString)
FOR i
ASC(ONECHAR(MyString, i))
NextNum
StringTotal + NextNum
StringTotal
ENDFOR

←

←

OUTPUT MyString, StringTotal
Write the above pseudocode algorithm as program code.
There is no need to show the declaration of variables or comment statements.

[6]
(c) Explain the purpose of sending the value of StringTotal to the remote computer, in
addition to MyString.

[2]

© UCLES 2015

9608/21/O/N/15

[Turn over

www.dynamicpapers.com
16
8

In this question you will need to use the given pseudocode built-in function:

ONECHAR(ThisString : STRING, Position : INTEGER) RETURNS CHAR
returns the single character at position Position (counting from the start of the string with value 1)
from the string ThisString.
For example: ONECHAR("Barcelona", 3) returns 'r'.
(a) Give the value assigned to variable y by the following statement:
y

← ONECHAR("San Francisco", 6)

y

[1]

A program reads a string entered by the user. The string represents the addition or subtraction
of two fractions. Each part of the fraction within the string is always a single digit only and the
top digit is always less than the bottom digit.
Example strings are: "3/8+3/5" and "5/8-1/4"
The program steps are:
•
the user enters the string
•
the program isolates each digit and the operator
•
the program computes the answer as either:
a fraction
a whole number followed by a fraction
a whole number
•
the program displays the answer to the user
Op

é
N4Char
N3Char
N2Char
N1Char
The identifier table shows the variables to be used to store the characters in the string as
shown in the diagram.

© UCLES 2015

Identifier

Data type

FractionString

STRING

N1Char

CHAR

See diagram

N2Char

CHAR

See diagram

N3Char

CHAR

See diagram

N4Char

CHAR

See diagram

Op

CHAR

See diagram

9608/21/O/N/15

Description
String input by user.
For example: "5/8-1/4"

www.dynamicpapers.com
17
(b) Study the sequence of pseudocode statements.
Show the values assigned to each variable.
FractionString
N3Char
Op
(iii)

←

←

←

"3/7+2/9"

ONECHAR(FractionString, 5)

ONECHAR(FractionString, 4)

(i) N3Char [1]
(ii) Op [1]

Complete the function call to isolate the character '9' from FractionString.
FractionString

←

"3/7+2/9"

ONECHAR(FractionString, )

[1]

The following additional variables are to be used by the program:
Identifier

Data type

Description

N1

INTEGER

The number value of N1Char

N2

INTEGER

The number value of N2Char

N3

INTEGER

The number value of N3Char

N4

INTEGER

The number value of N4Char

TopAnswer

INTEGER

The numerator of the fraction answer

BottomAnswer

INTEGER

The denominator of the fraction answer

© UCLES 2015

9608/21/O/N/15

[Turn over

www.dynamicpapers.com
18
(c) The following pseudocode uses these additional built-in functions:
TONUM(ThisDigit : CHAR) RETURNS INTEGER
returns the integer value of character ThisDigit
For example: TONUM('8') returns digit 8.

TOSTR(ThisNumber : INTEGER) RETURNS STRING
returns the string value of integer ThisNumber
For example: TOSTR(27) returns "27".
Study the pseudocode.
Complete the three dry runs for the three given values of FractionString.
OUTPUT "Enter the expression"
INPUT FractionString
// isolate each number digit and assign its number value
ONECHAR(FractionString, 1)
N1Char
TONUM(N1Char)
N1
ONECHAR(FractionString, 3)
N2Char
TONUM(N2Char)
N2
ONECHAR(FractionString, 5)
N3Char
TONUM(N3Char)
N3
ONECHAR(FractionString, 7)
N4Char
TONUM(N4Char)
N4

←
←
←
←
←
←
←
←

BottomAnswer

←

N2 * N4

←

ONECHAR(FractionString, 4)
Op
IF Op = '+'
THEN
// add fractions
(BottomAnswer / N2) * N1 + (BottomAnswer / N4) * N3
TopAnswer
ELSE
// subtract fractions
(BottomAnswer / N2) * N1 - (BottomAnswer / N4) * N3
TopAnswer
ENDIF

←
←

IF TopAnswer = BottomAnswer
THEN
OUTPUT '1'
ELSE
IF TopAnswer > BottomAnswer
THEN
TopAnswer MOD BottomAnswer
TopAnswer
// the & operator joins strings or character values
OUTPUT "1 " & TOSTR(TopAnswer) & "/" & TOSTR(BottomAnswer)
ELSE
OUTPUT TOSTR(TopAnswer) & "/" & TOSTR(BottomAnswer)
ENDIF
ENDIF

←

© UCLES 2015

9608/21/O/N/15

www.dynamicpapers.com
19
(i)
N1

N2

FractionString
N3

N4

←

"2/5-3/8"

BottomAnswer

Op

TopAnswer

OUTPUT

[2]
(ii)
N1

N2

FractionString
N3

N4

←

"3/4+1/4"

BottomAnswer

Op

TopAnswer

OUTPUT

[2]
(iii)
N1

N2

FractionString
N3

N4

←

"7/9+2/3"

BottomAnswer

Op

TopAnswer

OUTPUT

[3]
(d) The programmer writes code from the given pseudocode design. The program works, but the
design is limited.
The programmer is to make amendments to the design following suggested specification
changes.
(i)

State the name for this type of maintenance.
[1]

(ii)

Describe three specification changes which will make the program more useful.
1

2

3
[3]

© UCLES 2015

9608/21/O/N/15

www.dynamicpapers.com
20
BLANK PAGE

Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every reasonable
effort has been made by the publisher (UCLES) to trace copyright holders, but if any items requiring clearance have unwittingly been included, the 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 International
Examinations Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download at www.cie.org.uk after
the live examination series.
Cambridge International Examinations is part of the Cambridge Assessment Group. Cambridge Assessment is the brand name of University of Cambridge Local
Examinations Syndicate (UCLES), which is itself a department of the University of Cambridge.

© UCLES 2015

9608/21/O/N/15

Advertisement