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

Question 6(b)(i) 2016 · May-June · Paper 23 · 50 marks

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

Official answer for Question 6

Part (b)

(i)

✓
(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)

(i)

Question 6

UNTIL x = 5

[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

"Corrective Maintenance":

Expression Evaluates to

'P' & MID(MyString, 13, 4)

RIGHT(MID(MyString, 6, 10) ,4)

[2]

Question 4

2 The engine management system of a car includes an energy-saving facility. When certain conditions are met, this facility will automatically stop the engine.

The system is to be software-based. It will include a subroutine, EnergySaver, which repeatedly takes data from sensors in the car. The subroutine decides whether or not to set the EngineStop value.

The table of identifiers used by this subroutine is shown below. 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

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

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 the last page.

FUNCTION Decrypt(....................................... , .......................................) RETURNS CHAR

DECLARE Found : ......................................................................................................

DECLARE ........................................................................................................... : INTEGER

DECLARE OriginalChar : CHAR

Index 1 // ........................................................................................................

Found FALSE //search for CipherChar in Lookup:

WHILE ..................................................................................................................................... //compare CipherChar with this array element:

IF ..................................................................................................................................... THEN ..........................................................................//Set the flag ELSE Index .....................................................//Move to next array element ENDIF ENDWHILE //dropped out of loop so must have found CipherChar:

..................................................................//convert Index to original character

RETURN ...................................................................................................................................

ENDFUNCTION

[11]

Question 7

Question 3 continues on page 8.

Question 8

Part (b)

A program is to be written to output part of the Lookup array.

The design of the algorithm is shown below. It may be assumed that the characters output from Lookup are all printable.

START

Input StartIndex and NumberToOutput

Index StartIndex

Loop

Produce OriginalChar from Index (using built-in function)

Assign current array element to Increment Index CipherChar

Output message line (see examples on the next page)

End of NO loop?

YES

STOP

Question 9

For example, for the input of 65 and 3, the output will be:

Index 65: Character A has substitute character Y Index 66: Character B has substitute character Q Index 67: Character C has substitute character F

Write program code to implement the flowchart design.

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

StartIndex, NumberToOutput, Index

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

[6]

Question 10

Question 4

Part (a)

Name two features of your chosen high-level programming language that support the

implementation of a modular design.

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

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

[2]

Part (b)

(i)

The structure chart shows part of the design of a program for an online shopping system.

The user has already added a number of products to their virtual basket.

Draw on the chart, the symbol to show that the process of modifying the basket contents may be iterated (repeated).

Modify Basket Contents

D

B

E

A
F

C

Input product Remove Change product data product quantity

[1]

(ii)

Each arrow in the structure chart above represents a parameter.

The table below shows the three data items that the six parameters pass between modules.

Tick (✓) to match each parameter to the correct data item.

Parameter Data item

A
B C D E F

Product ID

Quantity Flag Value – indicating operation success or fail

[4]

Question 11

5 Claudia stores her large collection of music CDs in different places. Claudia wants to record where she stores each CD. She decides to write a program to do this.

Data items for a typical CD are:

Title: Kind of Green Artist: Miles Coltrane Location: Rack3-23

The data is to be stored in a text file, MyMusic. Each line of the text file will be a string, formed by concatenating the three data items.

Before concatenation, the title and artist will each be made into a fixed-length string of 40 characters. Space characters may need to be added to each data item.

The location is always 8 characters long.

Part (a)

(i)

Explain the benefit of making the stored data into fixed-length strings.

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

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

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

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

State a drawback of this file design.

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

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

[3]

Question 12

(ii)

When Claudia buys a new CD, the CD data must be added to the existing file, MyMusic.

She has written a procedure in pseudocode. This has the following file-handling statements:

OPENFILE "MyMusic" FOR WRITE WRITEFILE "MyMusic", OutputString CLOSEFILE "MyMusic"

There is a problem with the logic of this pseudocode.

State the problem.

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

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

Identify the effect it will have if the final code is implemented in this way.

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

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

Give a possible solution.

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

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

[3]

Part (b)

Claudia needs to output a list of all the CDs in a particular location.

She designs a procedure, OutputLocationList, to do this. She also chooses the following identifiers:

Identifier Data type CDTitle STRING CDArtist STRING CDLocation STRING

The procedure will:

  • prompt for the name of the location
  • input the location (such as “Rack3-23”)
  • search the file for all CDs at this location
  • output the title and artist of each CD found
  • output the total number of CDs found at that location (such as “17 CDs found”)

Question 13

Write program code for the procedure OutputLocationList.

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

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

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

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

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

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

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

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

Keep practising this topic