Computer Science (9608) · May/June 2018 · Question paper 23

Cambridge Computer Science (9608) question paper for paper 23, May/June 2018 — 9608/23/M/J/18, file 9608_s18_qp_23.pdf.

Advertisement
Loading the paper…
Text of this paper

www.dynamicpapers.com

Cambridge International Examinations
Cambridge International Advanced Subsidiary and Advanced Level

* 8 9 5 5 0 1 7 8 4 7 *

COMPUTER SCIENCE
Paper 2 Fundamental Problem-solving and Programming Skills

9608/23
May/June 2018
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 15 printed pages and 1 blank page.
DC (CE/SG) 146142/3
© UCLES 2018

[Turn over

www.dynamicpapers.com

2
1

(a) A program controls the heating system of an energy-efficient house.
Give a suitable identifier name for each of the data items.
Description of data item

Suitable identifier name

The temperature inside the house
The temperature outside the house
The wind speed
Whether it was raining or not
(b) (i)

[4]

Program variables have values as follows:
Variable

Value

Quality

'D'

DayNumber

20

MyName

"Stephen"

QualityConfirmed

TRUE

Factor

6.5

Evaluate each expression in the following table.
If an expression is invalid, write ERROR.
For the built-in functions list, refer to the Appendix on page 15.
Expression

Evaluates to

MID(MyName, 4, 4) & "ol"
QualityConfirmed AND (Factor >= 6.5)
20 + ASC(Quality)
QualityConfirmed + 3
MOD(Factor * 2, 9)

© UCLES 2018

[5]

9608/23/M/J/18

3
(ii)

www.dynamicpapers.com

Programming languages support different data types.
Give an appropriate data type for each of these variables from part (b)(i).
Variable

Data type

QualityConfirmed
DayNumber
Factor
Quality
MyName

© UCLES 2018

[5]

9608/23/M/J/18

[Turn over

4
2

www.dynamicpapers.com

The following is a function design in pseudocode.
Line numbers are given for reference only.
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

FUNCTION GradeCalc(Mark : ARRAY[] OF INTEGER) RETURNS INTEGER
DECLARE
DECLARE
DECLARE
DECLARE

DGradeCount : INTEGER
n : INTEGER
Grade : STRING
ThisMark : INTEGER

DGradeCount
1
n
1
ThisMark
REPEAT
ThisMark

0

// initialise variables

Mark[n]

// get next mark from Mark array

IF ThisMark > 74
THEN
"Distinction"
Grade
DGradeCount + 1 // one more Distinction
DGradeCount
ELSE
IF ThisMark > 59
THEN
"Merit"
Grade
ELSE
IF ThisMark > 39
THEN
"Pass"
Grade
ELSE
"Fail"
Grade
ENDIF
ENDIF
ENDIF
OUTPUT "Grade for Student " & n & " is " & Grade
n + 1
n
UNTIL n = 101 // no more elements in the array
RETURN Grade // return the number of Distinction grades
ENDFUNCTION
DECLARE Mark : ARRAY[1:100] OF INTEGER
DECLARE DistinctionGrades : INTEGER
CALL GetMarks(Mark[]) // fill the array with student marks
GradeCalc(Mark[])
DistinctionGrades

© UCLES 2018

9608/23/M/J/18

5

www.dynamicpapers.com

(a) This pseudocode includes features that are examples of good practice.
Explain why it is useful to include the two following features.
Comments

Indentation

[2]
(b) Study the function GradeCalc(). Identify the features of the function in the following table.
Feature

Answer

A line number containing an example of an integer assignment statement
A line number containing the start of a selection structure
A line number containing the end of a selection structure
The upper bound of the Mark array
The number of dimensions of the Mark array
The name for the type of loop structure used
A line number containing an unnecessary assignment statement
The number of times OUTPUT is called
The number of local variables
[9]
(c) (i)

There is a mistake in the pseudocode that would produce a data type mismatch error if a
programmer were to write similar program code.
Describe this mistake and how it may be corrected.

[2]

© UCLES 2018

9608/23/M/J/18

[Turn over

6
(ii)

www.dynamicpapers.com

Lines 14 to 30 of the pseudocode on page 4 could be written using a CASE structure.
Write the equivalent CASE structure in pseudocode.

[4]

© UCLES 2018

9608/23/M/J/18

7
3

www.dynamicpapers.com

A modular program design consists of four modules:
Module1 has three sub-tasks. Each sub-task is implemented by a single subroutine (either a
function or a procedure).
The subroutine headings are defined as follows:
FUNCTION Module2 (Weight : REAL) RETURNS BOOLEAN
PROCEDURE Module3 (Weight : REAL, Customer : STRING, Purchased : DATE)
FUNCTION Module4 (Purchased : DATE, Account : INTEGER) RETURNS INTEGER
(a) State the term given to values passed between modules.
[1]
(b) Draw a structure chart to represent the program design.
Use the letters in the table to label the values passed between modules.
Value

Structure chart

© UCLES 2018

Label

Boolean return value

A

Integer return value

B

Account

C

Customer

D

Purchased

E

Weight

F

9608/23/M/J/18

[4]
[Turn over

8
4

www.dynamicpapers.com

A program controls a chemical process in a factory.
The temperature is monitored as part of the control process. The temperature is measured at
fixed time intervals and the value is stored in an array, PTemp. The array contains 100 elements,
representing 100 temperature values. The first element is PTemp[1].
The program will check whether the temperature is outside the acceptable range more than 20
times. This task is performed by a function, IsTempOK().
The algorithm for the function IsTempOK() is expressed in structured English as follows:
1
2

Examine each array element and count the number of times that a temperature is less than
MinTemp or more than MaxTemp.
If the count in step 1 exceeds 20, return FALSE, otherwise return TRUE.

Draw a program flowchart, on the next page, to represent the algorithm for the function
IsTempOK().
Assume:

•
•

the array contains 100 valid temperature values
PTemp, MinTemp and MaxTemp are global variables.

Note that variable declarations are not required in program flowcharts.

© UCLES 2018

9608/23/M/J/18

9

© UCLES 2018

9608/23/M/J/18

www.dynamicpapers.com

[9]
[Turn over

10
5

www.dynamicpapers.com

A golf club holds information about its members. When a member completes a round of golf, their
score is stored along with their membership number and the date of the round.
A program is to be written to store and process the score information.
The information to be stored is as follows:

•
•
•

MembershipNumber is a four-digit numeric string.
Date is a six-digit numeric string in the format DDMMYY
Score is a two-digit numeric string in the range “50” to “99”.

This information is stored in a single string in the format:
<MembershipNumber><Date><Score>
(a) (i)

The program designer considers storing the strings in an array.
State how many dimensions the array would require.
[1]

(ii)

The designer has decided to store the strings in a file.
Give a reason for this choice.

[1]

(b) The program will be developed using an Integrated Development Environment (IDE). One
feature provided by an IDE is known as prettyprint.
Name two presentation features provided by prettyprint.
Feature 1

Feature 2

[2]
(c) The strings are stored in a text file, ScoreDetails.txt.
The program needs a function, GetAverageScore().
The structured English representing the algorithm for this function is as follows:
1
2
3
4

Receive a membership number as its argument.
Search the ScoreDetails.txt file for all scores for that member.
Calculate the average score.
Return the average score.

You can assume that there will be at least one score relating to each member.
© UCLES 2018

9608/23/M/J/18

11

www.dynamicpapers.com

Write program code for the GetAverageScore() function.
Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.
Programming language
Program Code

[10]
© UCLES 2018

9608/23/M/J/18

[Turn over

www.dynamicpapers.com

12
6

(a) Individual elements in a 1D array are referenced using an integer variable.
For example, using the variable n, an individual element would be referenced in pseudocode
as:
StudentGrade[n]
Give the correct technical term for the variable n.
[1]
(b) A 2D array, Picture, contains data representing a bitmap image. Each element of the array
represents one pixel of the image. The image is grey-scale encoded where the value of each
pixel ranges from 0 (representing black) to 255 (representing white) with intermediate values
representing different levels of grey.
The following is an example of an image and the corresponding data values for the Picture
array.
Bitmap image

Values
240 10

10

10

10

10

10 240

80

80 240 80

80 240 80

80

80

80 240 80

80 240 80

80

80

80 150 150 150 150 80

80

80

80 240 240 240 240 80

80

80

80 150 150 150 150 80

80

240 240 150 150 150 150 240 240
240 240 150 150 150 150 240 240
In pseudocode, the array is declared as follows:
DECLARE Picture : ARRAY[1:8, 1:8] OF INTEGER
A function, Clip(), is required that will:

•
•
•

take an integer parameter, MaxVal, to represent the maximum allowed value for each
pixel
limit each pixel value to the maximum allowed value
return TRUE if any of the pixel values have been changed, otherwise return FALSE

An example use of the function is:
IsClipped

Clip(234)

This will limit the maximum pixel value within the array to 234. Pixels with a value not greater
than 234 will remain unchanged.
© UCLES 2018

9608/23/M/J/18

13

www.dynamicpapers.com

Write pseudocode to implement the Clip() function.
Assume that Picture is a global variable.

[9]

© UCLES 2018

9608/23/M/J/18

[Turn over

14
7

www.dynamicpapers.com

A function, IsFactor() takes two integer parameters and checks whether the second parameter
is a factor of the first parameter.
For example IsFactor(6,3) would return TRUE as six divided by three has a remainder of zero.
This function returns FALSE if there is a non-zero remainder, or if the value of the second
parameter is zero.
Write program code to implement the IsFactor() function.
Visual Basic and Pascal: You should include the declaration statements for variables.
Python: You should show a comment statement for each variable used with its data type.
Programming language
Program code

[6]

© UCLES 2018

9608/23/M/J/18

15

www.dynamicpapers.com

Appendix
Built-in functions (pseudocode)
Each function returns an error if the function call is not properly formed.
MID(ThisString : STRING, x : INTEGER, y : INTEGER) RETURNS STRING
returns a string of length y starting at position x from ThisString
Example: MID("ABCDEFGH", 2, 3) returns string "BCD"
LENGTH(ThisString : STRING) RETURNS INTEGER
returns the integer value representing the length of string ThisString
Example: LENGTH("Happy Days") returns 10
LEFT(ThisString : STRING, x : INTEGER) RETURNS STRING
returns leftmost x characters from ThisString
Example: LEFT("ABCDEFGH", 3) returns string "ABC"
RIGHT(ThisString : STRING, x : INTEGER) RETURNS STRING
returns rightmost x characters from ThisString
Example: RIGHT("ABCDEFGH", 3) returns string "FGH"
INT(x : REAL) RETURNS INTEGER
returns the integer part of x
Example: INT(27.5415) returns 27
ASC(ThisChar : CHAR) RETURNS INTEGER
returns the ASCII value of character ThisChar
Example: ASC(′A') returns 65
MOD(ThisNum : INTEGER, ThisDiv : INTEGER) RETURNS INTEGER
returns the integer value representing the remainder when ThisNum is divided by ThisDiv
Example: MOD(10,3) returns 1

Operators (pseudocode)
Operator
&
AND
OR

© UCLES 2018

Description
Concatenates (joins) two strings.
Example: "Summer" & " " & "Pudding" produces "Summer Pudding"
Performs a logical AND of two Boolean values.
Example: TRUE AND FALSE produces FALSE
Performs a logical OR of two Boolean values.
Example: TRUE OR FALSE produces TRUE

9608/23/M/J/18

16

www.dynamicpapers.com

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 2018

9608/23/M/J/18

Advertisement