Past-paper question · 2018 May-June · Paper 23 · Q6(b)

Question 6(b) 2018 · May-June · Paper 23 · 9 marks

Original past-paper question for 6(B)
Original past-paper question for 6(B)
Original past-paper question for 6(B)
Reveal official mark-scheme answer Official mark-scheme answer for 6(B)

Official answer for Question 6

Part (b)

✓
FUNCTION Clip(MaxVal : INTEGER) RETURNS BOOLEAN

Question 9

✓
DECLARE i : INTEGER
✓
DECLARE j : INTEGER
✓
DECLARE ClipFlag : BOOLEAN
✓
ClipFlag ← FALSE
✓
FOR i ← 1 TO 8
✓
FOR j ← 1 TO 8
✓
IF Picture[i, j] > MaxVal
✓
THEN
✓
Picture[i, j] ← MaxVal
✓
ClipFlag ← TRUE
✓
ENDIF
✓
ENDFOR
✓
ENDFOR
✓
RETURN ClipFlag
✓
ENDFUNCTION
✓
1 mark for each of the following:

Question 1

✓
Correct Function heading (must have MaxVal and return a BOOLEAN)
✓
and ending

Question 2

✓
Declare and initialise local variable for return BOOLEAN to FALSE / other
✓
mechanism to record pixel being clipped

Question 3

✓
Declare local variables for loop counters

Question 4

✓
Nested loops with correct number of iterations

Question 5

✓
Accessing correct element from Picture array

Question 6

✓
Comparing element with MaxVal

Question 7

✓
Changing value of element if necessary

Question 8

✓
Setting flag to TRUE / other mechanism if element is changed

Question 9

✓
Returning BOOLEAN after loop (following conversion if other
✓
mechanism used)
✓
9608/23
✓
Cambridge International AS/A Level – Mark Scheme
✓
May/June 2018
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks

Mark scheme 9608_s18_ms_23.pdf →

Show text version of question

Question 6

Part (b)

Part (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

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.

Question 13

Write pseudocode to implement the Clip() function.

Assume that Picture is a global variable.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...............................................................................................................................................[9]

Question 14

Topic relevance

Why this question appears here

82% assigned-topic match · Programming › Structured programming

Topic-match percentages estimate how closely each question fits the selected syllabus topic. They are a guide for choosing stricter or broader practice.

Permanent source page: Educate A Change · From 9608_s18_qp_23.pdf

Keep practising this topic