Past-paper question · 2015 May-June · Paper 23 · Q4(c)

Question 4(c) 2015 · May-June · Paper 23 · 10 marks

Original past-paper question for 4(C)
Original past-paper question for 4(C)
Original past-paper question for 4(C)
Original past-paper question for 4(C)
Original past-paper question for 4(C)
Reveal official mark-scheme answer Official mark-scheme answer for 4(C)Official mark-scheme answer for 4(C)Official mark-scheme answer for 4(C)

Official answer for Question 4

Part (c)

Part (c)

Mark as follows:

  • Variables declared/commented (at least X2)
✓
(1 mark)
  • Input of ‘ThisBank’ with prompt
✓
(1 mark)
✓
•
✓
File open statement
✓
(1 mark)
✓
•
✓
File mode is ‘Input’
✓
(1 mark)
✓
•
✓
File close
✓
•
✓
Loop (Not a FOR loop)
✓
(1 mark)
✓
•
✓
Until all records considered
✓
•
✓
Isolate LineBankCode
✓
(1 mark)
✓
•
✓
Isolate LineDispenserCode
✓
•
✓
Count initialised
✓
(1 mark)
✓
•
✓
Count incremented
✓
(1 mark)
✓
•
✓
Output – List of dispenser codes
✓
(1 mark)
✓
•
✓
Output – dispenser count
✓
(1 mark)
✓
[max 10]
✓
Visual Basic …
✓
Dim DispenserRecord As String
✓
Dim DispenserCode As String : Dim Bank As String
✓
Dim DispenserCount As Integer
✓
Dim ThisBank As String
✓
FileOpen(1, "C:\DISPENSERS.txt", OpenMode.Input)
✓
Console.WriteLine()
✓
Console.Write("Which bank ..(Three digit code)? ")
✓
ThisBank = Console.ReadLine
✓
DispenserCount = 0
✓
Do
✓
DispenserRecord = LineInput(1)
✓
DispenserCode = Left(DispenserRecord, 5)
✓
Bank = Mid(DispenserRecord, 7, 3)
✓
If Bank = ThisBank Then
✓
DispenserCount = DispenserCount + 1
✓
Console.WriteLine(DispenserCode)
✓
End If
✓
Loop Until EOF(1)
✓
FileClose(1)
✓
Console.WriteLine()
✓
Console.WriteLine("There are " & DispenserCount & " dispensers
✓
for this bank")
✓
Mark Scheme
✓
Syllabus
✓
Paper
✓
Cambridge International AS/A Level – May/June 2015
✓
9608

Question 23

✓
Python …
✓
#
✓
DispenserLine
✓
–
✓
String
✓
#
✓
DispenserCode
✓
-
✓
String
✓
#
✓
Bank
✓
-
✓
String
✓
#
✓
DispenserCount
✓
-
✓
Integer
✓
#
✓
ThisBank
✓
-
✓
String
✓
MyFile = open("c:\DISPENSERS.txt", "r")
✓
ThisBank = input("Which bank ..(Three digit code)? ")
✓
DispenserCount = 0
✓
while 1:
✓
DispenserLine = MyFile.readline()
✓
if not DispenserLine:
✓
break
✓
DispenserCode = DispenserLine[0:5]
✓
# slices chars 0,1,2,3,4
✓
Bank = DispenserLine[6:9] # slices chars 6,7,8
✓
if Bank == ThisBank:
✓
DispenserCount = DispenserCount + 1
✓
print(DispenserCode)
✓
MyFile.close()
✓
print
✓
print("There are " + str(DispenserCount)
✓
" dispensers for this bank")
✓
Pascal …
✓
var
✓
DispenserRecord
✓
:
✓
String ;
✓
var
✓
DispenserCode
✓
:
✓
String ;
✓
var
✓
Bank
✓
:
✓
String ;
✓
var
✓
DispenserCount
✓
:
✓
Integer ;
✓
var
✓
ThisBank
✓
:
✓
String ;
✓
var
✓
TheFile
✓
:
✓
Text ;
✓
begin
✓
assign(TheFile, 'K:\DISPENSERS.txt') ;
✓
reset(TheFile) ;
✓
WriteLn() ;
✓
Write('Which bank ..(Three digit code)? ') ;
✓
Readln(ThisBank) ;
✓
C
✓
DispenserCount := 0 ;
✓
repeat
✓
readln(TheFile, DispenserRecord) ;
✓
DispenserCode := Copy(DispenserRecord,1, 5) ;
✓
Bank := copy(DispenserRecord, 7, 3) ;
✓
If Bank = ThisBank Then
✓
begin
✓
DispenserCount := DispenserCount + 1 ;
✓
Mark Scheme
✓
Syllabus
✓
Paper
✓
Cambridge International AS/A Level – May/June 2015
✓
9608

Question 23

✓
Writeln(DispenserCode)
✓
end ;
✓
until EOF(TheFile) ;
✓
close(TheFile) ;
✓
writeLn() ;
✓
writeLn('Dispenser count: ', DispenserCount) ;
✓
readln ;
✓
end.

Mark scheme 9608_s15_ms_23.pdf →

Show text version of question

Question 4

Part (c)

Question 4

A programming language has the built-in function CONCAT defined as follows:

CONCAT(String1 : STRING, String2 : STRING [, String3 : STRING] ) RETURNS STRING For example: CONCAT("San", "Francisco") returns "SanFrancisco" CONCAT("New", "York", "City") returns "NewYorkCity"

The use of the square brackets indicates that the parameter is optional.

Part (c)

The complete data file is created with the structure shown.

A
new program is to be written to search the file. 00001▼007

00002▼001 The program will: 00003▼002 00004▼003

  • input a bank code 00005▼101
  • output a list of all the dispensers which belong to this bank 00006▼004
  • 00007▼004

  • output the total number of dispensers for this bank

00024▼002 00025▼003 An example of a run of the program is shown: 00026▼007 00027▼007 00028▼102 Enter bank code 007 00001 00011 00026 00027

There are 5 dispensers for this bank

Question 11

Write the program code. Do not attempt to include any validation checks. 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 ............................................................................................................

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

.............................................................................................................................................[10]

Question 12

Topic relevance

Why this question appears here

82% 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_s15_qp_23.pdf

Keep practising this topic