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

Question 6(b) 2016 · May-June · Paper 23 · 6 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)
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)

Part (b)

✓
(
✓
Th
✓
he fun
✓
nct tion
✓
n o pe rat tes
✓
s no
✓
orm
✓
mal lly // retu
✓
r urn
✓
ns an
✓
a ‘em
✓
mp
✓
pty str ring
✓
g’
[1]
✓
(i i) E xa mp
✓
ple s o
✓
of suit
✓
s tab
✓
ble tes st stri
✓
s ing
✓
gs:
✓
[3
✓
3]
✓
•
✓
St trin
✓
ngs s w ith all l ca
✓
api tal s
✓
•
✓
St trin
✓
ngs s w ith all l lo
✓
owe
✓
er cas
✓
c se
✓
•
✓
St trin
✓
ngs s w ith firs
✓
st lett
✓
l ters
✓
s of
✓
o wor
✓
w rds s al lrea
✓
ady
✓
y cap
✓
c pita
✓
alise
✓
ed (i.e
✓
e. in cor
✓
c rre ct for rma
✓
at)
✓
•
✓
St trin
✓
ngs s in “re
✓
eve
✓
ers
✓
se” fo rm at – i .e. fir rst lett ter rs lo
✓
ow
✓
wer ca
✓
ase
✓
e, th
✓
he res
✓
st up
✓
u pe r c ase
✓
e
✓
•
✓
St trin
✓
ng w
✓
wit h only
✓
o y one
✓
o e word
✓
w d
✓
•
✓
St trin
✓
ngs s w ith m ulti iple
✓
e spa
✓
s ace s
✓
•
✓
St trin
✓
ngs s w ith nu
✓
um be rs / sy
✓
ym
✓
mbo
✓
ols
✓
One
✓
O e mar
✓
m rk fo
✓
or ea
✓
ach st rin g exa
✓
e am ple
✓
e p
✓
plus
✓
s sup
✓
s ppo
✓
ortin
✓
ng ex
✓
xpla
✓
ana
✓
atio
✓
on.
✓
© 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 23

✓
Appendix – Program Code Example Solutions
✓
Q3 (b): VB.NET
✓
Console.WriteLine("Enter start position")
✓
StartIndex = Console.ReadLine()
✓
Console.WriteLine("Enter how many")
✓
NumberToOutput = Console.ReadLine()
✓
For Index = StartIndex To StartIndex + NumberToOutput - 1
✓
OriginalChar = Chr(Index)
✓
CipherChar = Lookup(Index)
✓
Console.WriteLine("Index " & Index & ": Character " & OriginalChar &
✓
" has substitute character " & CipherChar)
✓
Next Index
✓
Q3 (b): Pascal
✓
Writeln('Enter start position');
✓
Readln(StartIndex);
✓
Writeln('Enter how many');
✓
Readln(NumberToOutput);
✓
For index := StartIndex To StartIndex + NumberToOutput – 1 Do
✓
Begin
✓
OriginalChar := chr(index);
✓
CipherChar := Lookup[index];
✓
writeln("Index " + index + ": Character " + OriginalChar +
✓
" has substitute character " & CipherChar);
✓
end;
✓
Q3 (b): Python
✓
startIndex = int(input("enter start position"))
✓
numberToOutput = int(input("enter how many"))
✓
for index in range(startIndex, (startIndex + numberToOutput)) :
✓
OriginalChar = chr(index)
✓
CipherChar = Lookup[index]
✓
print("Index " + (index) + ": Character " + OriginalChar +
✓
" has subst char " + CipherChar)
✓
Mark Scheme
✓
Syllabus
✓
Paper
✓
Cambridge International AS/A Level – May/June 2016
✓
9608

Question 23

✓
Q5 (b): VB.NET
✓
A StreamReader() solution:
✓
Sub OutPutLocationList()
✓
Dim Total As Integer
✓
Dim FileData As String
✓
Dim ObjReader As IO.StreamReader
✓
ObjReader = New IO.StreamReader("C:\MyMusic.txt")
✓
Dim CDLocation As String
✓
Dim CDTitle As String
✓
Dim CDArtist As String
✓
Total = 0
✓
Console.WriteLine("Input location to search ")
✓
CDSearch = Console.ReadLine
✓
Do While ObjReader.Peek <> -1
✓
FileData = ObjReader.ReadLine()
✓
If Right(FileData, 8) = CDLocation Then
✓
CDTitle = Left(FileData, 40)
✓
CDArtist = Mid(FileData, 41, 40)
✓
Console.WriteLine(CDTitle & "
✓
" & CDArtist)
✓
Total = Total + 1
✓
End If
✓
Loop
✓
Console.WriteLine(Total & " CDs were found")
✓
ObjReader.Close()
✓
End Sub
✓
A legacy FileOpen() solution:
✓
Sub OutPutLocationList()
✓
Dim Total As Integer
✓
Dim FileData As String
✓
FileOpen (1, "C:\MyMusic.txt", OpenMode.Input)
✓
Dim CDLocation As String
✓
Dim CDTitle As String
✓
Dim CDArtist As String
✓
Total = 0
✓
Console.WriteLine("Input location to search ")
✓
CDSearch = Console.ReadLine
✓
Do While NOT EOF(1)
✓
Input(1, FileData)
✓
If Right(FileData, 8) = CDSearch Then
✓
CDTitle = Left(FileData, 40)
✓
CDArtist = Mid(FileData, 41, 40)
✓
Console.WriteLine(CDTitle & "
✓
" & CDArtist)
✓
Total = Total + 1
✓
End If
✓
Loop
✓
Console.WriteLine(Total & " CDs were found")
✓
FileClose(1)
✓
End Sub
✓
Mark Scheme
✓
Syllabus
✓
Paper
✓
Cambridge International AS/A Level – May/June 2016
✓
9608

Question 23

✓
Q5 (b): Pascal
✓
procedure OutputLocationList;
✓
var
✓
FileData, CDLocation, CDTitle, CDArtist : String;
✓
CDFile : Textfile;
✓
Total : Integer;
✓
Begin
✓
Total := 0;
✓
Writeln('Input location to search ');
✓
Readln(CDSearch);
✓
AssignFile(CDFIle, 'MyMusic.txt');
✓
Reset(CDFile);
✓
While not eof(CDFile) Do
✓
Begin
✓
readln(CDFile, FileData);
✓
If copy(FileData, 80, 8) = CDSearch Then
✓
Begin
✓
CDTitle := copy(FileData, 1, 40);
✓
CDArtist := copy(FileData, 41, 40);
✓
Writeln(CDTitle + ‘ : ‘ + CDArtist);
✓
Total := Total + 1;
✓
End;
✓
End;
✓
Writeln(Total + ‘ CDs were found’)
✓
CloseFile(CDFile);
✓
End
✓
Q5 (b): Python
✓
#total : Integer
✓
#CDSearch, LineOfText, LineString
✓
: String
✓
Def OutPutLocationList():
✓
FileHandle = open("MyMusicPy.TXT", "r")
✓
total = 0
✓
CDSearch = input("Enter location to search")
✓
LineOfText = FileHandle.readline()
✓
while len(LineOfText) > 0:
✓
LineString = LineOfText[80:87]
✓
#extact last 8 characters
✓
(location)
✓
if LineString == CDSearch:
✓
total = total+1
✓
CDTitle = LineOfText[0:39]
✓
#extract CD title
✓
CDArtist = LineOfText[40:79] #extract CD artist
✓
print(CDTitle + ": " + CDArtist)
✓
LineOfText = FileHandle.readline() #read next line
✓
print("There are " + str(total) + " in that location")
✓
FileHandle.close()

Mark scheme 9608_s16_ms_23.pdf →

Show text version of question

Question 6

Part (b)

Part (b)

Write the pseudocode equivalent of the structured English. Use the identifiers from the table

in part (a). For the built-in functions list, refer to the Appendix on the last page. ................................................................................................................................................... ................................................................................................................................................... ................................................................................................................................................... ................................................................................................................................................... ................................................................................................................................................... ................................................................................................................................................... ................................................................................................................................................... ................................................................................................................................................... ................................................................................................................................................... ................................................................................................................................................... ................................................................................................................................................... ................................................................................................................................................... ................................................................................................................................................... ................................................................................................................................................... ...............................................................................................................................................[6]

Question 6

Question 3

String encryption was implemented using a simple character-substitution method. A function, Decrypt, is needed to reverse the encryption process and return the original character. The encryption 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. This function, Decrypt, will accept two parameters, a single character, CipherChar, and the 1D array, Lookup. The steps involved in Decrypt are follows: • Search for the character in the array • Note the index value where the character is found (the index value is the ASCII value of the original character) • Use the index value to obtain the original character

Topic relevance

Why this question appears here

71% assigned-topic match · Data types and structures › Arrays

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

Keep practising this topic