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

Question 6(b) 2018 · May-June · Paper 22 · 8 marks

Original past-paper question for 6(B)
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)

✓
Example using single temp variable:

Question 8

✓
PROCEDURE Flip()
✓
//Use of Single temp value
✓
DECLARE temp : INTEGER
✓
DECLARE i : INTEGER //i is the row
✓
DECLARE j : INTEGER //j is the column
✓
FOR i ← 1 TO 5
✓
FOR j ← 1 to 4 //swap element 1&8, 2&7, 3&6, 4&5
✓
temp ← Picture[i,j]
✓
Picture[i,j] ← Picture[i, 9 - j]
✓
Picture[i, 9 - j] ← temp
✓
ENDFOR
✓
ENDFOR
✓
ENDPROCEDURE
✓
Alternative Solution – Use of temp array row:
✓
PROCEDURE Flip()
✓
//Use of temproary row (8 elements)
✓
DECLARE temp : ARRAY[1:8] OF INTEGER
✓
DECLARE i : INTEGER //i is the row
✓
DECLARE j : INTEGER //j is the column
✓
FOR i ← 1 to 5
✓
FOR j ← 1 to 8
✓
temp[j] ← Picture[i, 9 – j] //temp is row i
✓
reversed
✓
ENDFOR
✓
FOR j ← 1 to 8
✓
Picture[i,j] ← temp[j] //copy temp back to row i
✓
ENDFOR
✓
ENDFOR
✓
ENDPROCEDURE
✓
9608/22
✓
Cambridge International AS/A Level – Mark Scheme
✓
May/June 2018
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks

Mark scheme 9608_s18_ms_22.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.

A
graphics program needs a procedure, Flip(), to flip (reflect) the image. An example of an

image before and after the function is:

Before flip After flip

The values contained in the 2D array before the flip are as follows:

Data values

In pseudocode, the array is declared as follows:

DECLARE Picture : ARRAY[1:5, 1:8] OF INTEGER

Question 15

Write pseudocode to implement the Flip() procedure.

Assume that Picture is a global variable.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

[8]

Question 16

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"

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 Description

Concatenates (joins) two strings & Example: "Summer" & " " & "Pudding" produces "Summer Pudding"

Performs a logical AND on two Boolean values AND Example: TRUE AND FALSE produces FALSE

Performs a logical OR on two Boolean values OR Example: TRUE OR FALSE produces TRUE

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.

Topic relevance

Why this question appears here

91% assigned-topic match · Data types and structures › Data types and records

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_22.pdf

Keep practising this topic