Past-paper question · 2016 May-June · Paper 21 · Q6(b)(ii)

Question 6(b)(ii) 2016 · May-June · Paper 21 · 49 marks

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

Official answer for Question 6

Part (b)

(ii)

✓
( ii)
✓
Va
✓
alu
✓
ue: 0 / ze
✓
ero
✓
o

Question 2

✓
tr in g2 no
✓
ng1
✓
M ea nin
✓
ng: St
✓
ot fou
✓
f und
✓
d in
✓
n S tr in

Question 1

✓
(i ii)
✓
O pti ion
✓
n 1

Question 2

✓
•
✓
o St ri
✓
It i s pos
✓
p ssib
✓
ble
✓
e to
✓
o “fa
✓
all off f” th
✓
he en
✓
nd of
✓
ing
✓
g1 (or r by
✓
y exa
✓
e amp
✓
ple
✓
e) whi
✓
w le str ring
✓
g
✓
ma
✓
atch
✓
h (f for ex
✓
xam
✓
mpl le, St trin g1 = "R
✓
Retr rac
✓
ce" , S trin
✓
ng2
✓
2 = "R
✓
Rac
✓
ced
✓
d")
✓
•
✓
ri ng
✓
x 1 )// de
✓
MI
✓
ID (S
✓
Str
✓
g1, x,
✓
esc
✓
crip
✓
ptio
✓
on of
✓
o 'su
✓
' bs cri pt ou t o f ra
✓
ang
✓
ge' '
✓
O pti ion
✓
n 2
✓
•
✓
If eith
✓
e her r st trin g i s em
✓
e pty y th
✓
hen
✓
n
✓
•
✓
su bsc
✓
crip
✓
pt o
✓
out t of f ra
✓
ang
✓
ge err ror r // de
✓
esc ript tion
✓
n
✓
O pti ion
✓
n 3
✓
•
✓
If Str
✓
S ing
✓
g1 f fou
✓
und
✓
d with
✓
w hin St ring
✓
g 2
✓
•
✓
An
✓
n en
✓
ndl les ss l oo p will
✓
w oc ccu
✓
ur
✓
© Ca
✓
amb
✓
brid
✓
dge
✓
e In
✓
nter rnat tion
✓
nal Ex
✓
xam
✓
mina
✓
atio
✓
ons
✓
s 20
✓
016

Question 6

✓
Mark Scheme
✓
Syllabus
✓
Paper
✓
Cambridge International AS/A Level – May/June 2016
✓
9608

Question 21

✓
Appendix - Program Code Solutions

Mark scheme 9608_s16_ms_21.pdf →

Show text version of question

Question 6

Part (b)

(ii)

Question 6

ELSE Message = "Error"

[6]

Question 3

(ii)

State the purpose of each statement in the table in part (a)(i).

Do not use mathematical symbols in your descriptions.

Item Purpose of statement

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

Question 1

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

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

Question 2

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

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

Question 3

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

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

Question 4

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

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

Question 5

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

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

Question 6

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

[6]

(iii)

Evaluate the following expressions when MyString has the value "Adaptive

Maintenance".

Expression Result

'D' & RIGHT(MyString, 4)

LEFT(RIGHT(MyString, 7), 3)

[2]

Question 4

2 A team is designing a software system to monitor temperature in a process. To do this, the system needs to sample the temperature repeatedly. If the temperature exceeds a given threshold value, an alarm will sound.

The system is to be software-based. It will include a subroutine, SampleTemp, which samples the temperature and sets the alarm state to either ON or OFF.

The initial design stage will produce a prototype of SampleTemp with a user interface. The structured English for this is:

1. IF the temperature does not exceed threshold value, SET alarm state to OFF 2. INPUT threshold value (to two decimal places) 3. INPUT sensor value (a whole number in the range 0 to 100) 4. MULTIPLY sensor value by conversion factor 1.135 to give temperature 5. IF temperature exceeds threshold value SET alarm state to ON 6. IF temperature exceeds threshold value OUTPUT message “Temperature Alarm” 7. IF temperature does not exceed threshold value OUTPUT message “Temperature OK” Write the pseudocode equivalent of the structured English. Use the identifiers from the table in part (a).

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

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

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

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

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

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

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

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

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

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

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

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

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

...............................................................................................................................................[6]

Question 6

Question 3 begins on page 7.

Question 7

3 A string encryption function is needed. The encryption uses a simple character-substitution method.

In this method, a new character substitutes for each character in the original string. This will create the encrypted string.

The substitution uses the 7-bit ASCII value for each character. This value is used as an index for a 1D array, Lookup, which contains the substitute characters. Lookup contains an entry for each of the ASCII characters. It may be assumed that the original string and the substitute characters are all printable.

For example:

  • ‘A’ has ASCII value 65
  • Array element with index 65 contains the character ‘Y’ (the substitute character)
  • Therefore, ‘Y’ substitutes for ‘A’
  • There is a different substitute character for every ASCII value

The programmer writes a function, EncryptString, to return the encrypted string. This function will receive two parameters, the original, PlainText string and the 1D array.

Part (a)

The first attempt at writing the pseudocode for this function is shown below.

Complete the pseudocode.

For the built-in functions list, refer to the Appendix on page 18.

FUNCTION EncryptString(.............................) RETURNS STRING

DECLARE .................... , ...................... : CHAR

DECLARE OldCharValue : ......................................

DECLARE n : INTEGER

DECLARE OutString : STRING

.............................. //initialise the return string

//loop through PlainText to produce OutString

FOR n 1 TO ................. //from first to last character

OldChar ...................//get next character

OldCharValue ..............//find the ASCII value

NewChar ...................//look up substitute character

.............................//concatenate to OutString

ENDFOR

............................................................. ENDFUNCTION

[10]

Question 8

Part (b)

Additional code needs to be written to allow the user to change some of the characters in the

array Lookup.

The user will input:

  • the array start position
  • the number of elements to change
  • each new substitute character

At the end, the program will finally output a confirmation message.

The first version of the algorithm is represented by the flowchart on the following page.

(ii)

Write program code to implement the flowchart design.

In addition to the Lookup array, assume that the following variables have been declared:

StartPos, NumToChange, n, NewChar

Programming language .....................................................................................................

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

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

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

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

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

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

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

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

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

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

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

.......................................................................................................................................[6]

Question 9

START

Input StartPos

Input NumToChange

n 0

Loop

Output prompt for new substitute character

Input NewChar

Increment n

Assign NewChar to current array element

No n = NumToChange – 1?

Yes

Output message stating number of elements changed

STOP

Question 10

Question 4

Part (a)

Structured programming involves the breaking down of a problem into modules.

Give two reasons why this is done.

1 ................................................................................................................................................

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

2 ................................................................................................................................................

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

[2]

Part (b)

A team needs to write a program to implement an online shopping system. Customers will

access the program via a website.

Customers can search for items before adding them to a virtual shopping basket. When they have finished shopping, they pay for the items. The program provides output for the dispatch of the items.

Some of the key features of the system are as follows:

  • a customer can add many items to the shopping basket
  • payment may be either by credit or debit card, or by adding to a customer account
  • the shop may dispatch the items in one or more packages

The structure chart below shows the program modules only.

(i)

Draw on the chart, the symbols that represent the key features listed in part

Part (b)

above.

Online shopping

Select Item Checkout Dispatch

Card Account Print Print Search Add to dispatch address basket payment payment list label

[3]

Question 11

(ii)

A section of the chart in part (b)(i) is shown below. It is to show the parameters passed

between the Checkout and Card payment modules.

Checkout

B
A

C

Card Account payment payment

Name the three data items corresponding to the arrows.

Arrow Data item

A

B

C

[3]

Question 12

Question 5 begins on page 13.

Question 13

5 Toni has a large collection of jazz CDs that are stored in different places. She wants to record where the CDs are stored. She decides to write a program to do this.

The program must store the data in a file, MyMusic.

Part (a)

(i)

Why is a file needed?

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

.......................................................................................................................................[1]

(ii)

MyMusic is a text file with the data for each CD as one line of text.

Data for a typical CD are:

Title: Kind of Green Artist: Miles Coltrane Location: Rack1-5

The line will be formed by concatenating the three data items.

For the example above, the line stored will be:

Kind of GreenMiles ColtraneRack1-5

Describe a problem that might occur when organising the data in this way.

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

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

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

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

Describe a possible solution.

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

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

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

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

[4]

Question 14

Part (b)

Toni must input the data into the file for all of her CDs.

A
procedure, InputData, is needed to do this.

Toni designs the procedure and chooses the following identifiers:

Identifier Data type CDTitle STRING CDArtist STRING CDLocation STRING

The procedure repeatedly performs the following steps:

  • input a CD title (A rogue value of “##” is to be used to end the input)
  • input the artist
  • input the location
  • create the text line
  • write the text line to the file

When the rogue value is encountered the file is closed.

Question 15

Write program code for the procedure InputData.

Visual Basic and Pascal: You should include declaration statements for variables. Python: You should show a comment statement for each variable used with its data type.

Programming language ............................................................................................................

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

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

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

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

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

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

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

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

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

Topic relevance

Why this question appears here

75% assigned-topic match · Programming › Programming basics

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

Keep practising this topic