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

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

✓
'Pseudocode' solution included here for development and clarification of

Question 8

✓
mark scheme.
✓
Programming language example solutions appear in the Appendix.
✓
FUNCTION FindCD(SearchCDArtist : STRING,
✓
SearchCDTitle : STRING) RETURNS STRING
✓
DECLARE
✓
CDTitle : STRING
✓
DECLARE
✓
CDArtist : STRING
✓
DECLARE
✓
CDLocation : STRING
✓
DECLARE
✓
Location : STRING
✓
Location ← ""
✓
OPENFILE "MyCDs.txt" FOR READ
✓
WHILE NOT EOF ("MyCDs.txt") AND Location = ""
✓
READFILE "MyCDs.txt", CDArtist
✓
READFILE "MyCDs.txt", CDTitle
✓
READFILE "MyCDs.txt", CDLocation
✓
IF SearchCDArtist = CDArtist AND
✓
SearchCDTitle = CDTitle
✓
THEN
✓
Location ← CDLocation
✓
ENDIF
✓
ENDWHILE
✓
CLOSEFILE("MyCDs.txt")
✓
RETURN Location
✓
ENDFUNCTION
✓
One mark for each of the following:

Question 1

✓
Function header and close (where appropriate), including parameters

Question 2

✓
Declaration of local STRING variables for CDArtist and CDTitle

Question 3

✓
OPEN and CLOSE file for reading (Allow MyCDs or MyCDs.txt)

Question 4

✓
(WHILE) loop checking for EOF

Question 5

✓
read three lines from file in a loop

Question 6

✓
compare search values with file values in a loop«

Question 7

✓
«If true, set Location and exit loop in a loop

Question 8

✓
Return Location
✓
9608/21
✓
Cambridge International AS/A Level – Mark Scheme
✓
May/June 2019
✓
PUBLISHED
✓
Program Code Example Solutions
✓
Q6 (b) (i): Visual Basic
✓
Function FindCD(SearchCDArtist As String, SearchCDTitle As String) As
✓
String
✓
Dim
✓
CDTitle As String
✓
Dim
✓
CDArtist As String
✓
Dim
✓
CDLocation As String
✓
Dim
✓
Location As String
✓
Location = ""
✓
FileOpen(1,"MyCDs.txt", OpenMode.Input)
✓
Do While Not EOF(1) And Location = ""
✓
CDArtist = LineInput(1)
✓
CDTitle = LineInput(1)
✓
CDLocation = LineInput(1)
✓
If SearchCDArtist = CDArtist And SearchCDTitle = CDTitle Then
✓
Location = CDLocation
✓
End If
✓
Loop
✓
FileClose(1)
✓
EndFunction
✓
Q6 (b) (i): Python
✓
def FindCD(SearchCDArtist, SearchCDTitle):
✓
# CDTitle, CDArtist, CDLocation, Location : string
✓
Location = ""
✓
myFile = open("MyCDs.txt", 'r')
✓
while True:
✓
# or Location == "":
✓
CDArtist = myFile.readline()
✓
if CDArtist == "":
✓
break
✓
else:
✓
CDTitle = myFile.readline()
✓
CDLocation = myFile.readline()
✓
if SearchCDArtist == CDArtist.strip()and SearchCDTitle ==
✓
CDTitle.strip():
✓
Location = CDLocation
✓
myFile.close
✓
return (Location)
✓
9608/21
✓
Cambridge International AS/A Level – Mark Scheme
✓
May/June 2019
✓
PUBLISHED
✓
Q6 (b) (i): Pascal
✓
function FindCD(SearchCDArtist, SearchCDTitle:string): string;
✓
var
✓
CDTitle, CDArtist, CDLocation, Location : string;
✓
FileHandle : TextFile;
✓
begin
✓
Location := '';
✓
AssignFile(FileHandle,'MyCDs.txt');
✓
Reset (FileHandle);
✓
while not eof(FileHandle) and (Location = '') do
✓
begin
✓
readln(FileHandle, CDArtist);
✓
readln(FileHandle, CDTitle);
✓
readln(FileHandle, CDLocation);
✓
if (SearchCDArtist = CDArtist) and (SearchCDTitle = CDTitle)
✓
then
✓
Location := CDLocation;
✓
end;
✓
Close (FileHandle);
✓
FindCD := Location;
✓
end;

Mark scheme 9608_s19_ms_21.pdf →

Show text version of question

Question 6

Part (b)

Question 6

A text file, MyCDs.txt, stores information relating to a Compact Disc (CD) collection. Information

about each CD is stored on three separate lines in the file as follows:

Line 1: <Artist Name> Line 2: <CD Title> Line 3: <Storage Location>

Information is stored as data strings.

A
section of the file is shown:

File line Data 100 "Green Floyd" 101 "Bowlful of Cereal" 102 "Shelf 4" 103 "Strolling Bones" 104 "Exile on Station Road" 105 "Box 12"

Part (b)

The module, FindCD(), will check whether a given CD exists in the collection. The module

will be implemented as a function.

The function will:

  • be called with two strings as parameters, representing the artist name and CD title
  • return a string that gives the storage location, or an empty string if the given CD has not

been found.

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 Assessment International Education Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download at www.cambridgeinternational.org after the live examination series.

Cambridge Assessment International Education is part of the Cambridge Assessment Group. Cambridge Assessment is the brand name of the University of Cambridge Local Examinations Syndicate (UCLES), which itself is a department of the University of Cambridge.

Question 15

Write program code for the function FindCD().

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

Program code

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

[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 "BCD"

LENGTH(ThisString : STRING) RETURNS INTEGER returns the integer value representing the length of 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 "ABC"

RIGHT(ThisString : STRING, x : INTEGER) RETURNS STRING returns rightmost x characters from ThisString

Example: RIGHT("ABCDEFGH", 3) returns "FGH"

INT(x : REAL) RETURNS INTEGER returns the integer part of x

Example: INT(27.5415) returns 27

ASC(ThisChar : CHAR) RETURNS INTEGER returns the ASCII value of character ThisChar

Example: ASC('A') returns 65

RAND(x : INTEGER) RETURNS REAL returns a real number in the range 0 to x (x not inclusive).

Example: RAND(87) could return 35.43

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

Topic relevance

Why this question appears here

99% 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_s19_qp_21.pdf

Keep practising this topic