Past-paper question · 2018 May-June · Paper 23 · Q7

Question 7 2018 · May-June · Paper 23 · 6 marks

Original past-paper question for 7
Original past-paper question for 7
Original past-paper question for 7
Reveal official mark-scheme answer Official mark-scheme answer for 7

Official answer for Question 7

✓
‘Pseudocode’ solution included here for development and clarification of

Question 6

✓
mark scheme.
✓
Programming language solutions appear in the Appendix.
✓
FUNCTION IsFactor(Num1: INTEGER, Num2: INTEGER)
✓
RETURNS BOOLEAN
✓
IF Num2 <> 0
✓
THEN
✓
IF MOD(Num1, Num2) = 0
✓
THEN
✓
RETURN TRUE
✓
ENDIF
✓
ENDIF
✓
RETURN FALSE
✓
ENDFUNCTION
✓
1 mark for each of the following:

Question 1

✓
Correct Function heading (including parameters) and ending

Question 2

✓
Check that Num2 is not zero

Question 3

✓
Mechanism to ensure no call to MOD (or equivalent) if Num2 is zero

Question 4

✓
Use of MOD function or alternative

Question 5

✓
Check value of remainder

Question 6

✓
Return Boolean value
✓
*** End of Mark Scheme – program code example solutions follow ***
✓
9608/23
✓
Cambridge International AS/A Level – Mark Scheme
✓
May/June 2018
✓
PUBLISHED
✓
Appendix
✓
Program Code Example Solutions
✓
Q5(c): Visual Basic
✓
Function GetAverageScore(ByVal MembershipNumber As String) As Integer
✓
Dim
✓
FileData As String
✓
Dim
✓
FileMembershipNumber As String
✓
Dim
✓
NumberOfScores As Integer
✓
Dim
✓
TotalScore As Integer
✓
Dim
✓
AverageScore As Integer
✓
Dim
✓
ObjReader As IO.StreamReader
✓
ObjReader = New IO.StreamReader("ScoreDetails.txt")
✓
NumberOfScores = 0
✓
TotalScore = 0
✓
Do While ObjReader.Peek <> -1
✓
FileData = ObjReader.ReadLine()
✓
FileMembershipNumber = LEFT(FileData, 4)
✓
If FileMembershipNumber = MembershipNumber Then
✓
NumberOfScores = NumberOfScores + 1
✓
TotalScore = TotalScore + INT(RIGHT(FileData, 2))
✓
End If
✓
Loop
✓
AverageScore = INT(TotalScore / NumberOfScores)
✓
ObjReader.Close()
✓
Return (AverageScore)
✓
End Function
✓
Q5(c): Pascal
✓
function GetAverageScore(MembershipNumber : string):integer;
✓
var
✓
FileData, FileMembershipNumber: string;
✓
NumberOfScores, TotalScore, AverageScore : integer;
✓
ScoreFile : textFile;
✓
begin
✓
NumberOfScores := 0;
✓
TotalScore := 0;
✓
assignFile(ScoreFile, ‘ScoreDetails.txt’);
✓
reset(ScoreFile);
✓
while not eof(ScoreFile) do
✓
begin
✓
readln(ScoreFile, FileData);
✓
FileMembershipNumber := copy(FileData, 1, 4);
✓
if FileMembershipNumber = MembershipNumber then
✓
begin
✓
NumberOfScores := NumberOfScores + 1
✓
TotalScore := TotalScore + StrToInt(RightStr(FileData, 2));
✓
end;
✓
end;
✓
9608/23
✓
Cambridge International AS/A Level – Mark Scheme
✓
May/June 2018
✓
PUBLISHED
✓
AverageScore := StrToInt(TotalScore / NumberOfScores);
✓
GetAverageScore := AverageScore;
✓
CloseFile (ScoreFile);
✓
end;
✓
Q5(c): Python
✓
#
✓
FileData AS STRING
✓
#
✓
FileMembershipNumber AS STRING
✓
#
✓
NumberOfScores AS INTEGER
✓
#
✓
TotalScore AS INTEGER
✓
#
✓
AverageScore AS INTEGER
✓
def GetAverageScore(MembershipNumber):
✓
FileHandle = open("ScoreDetails.txt", "r")
✓
NumberOfScores = 0
✓
TotalScore = 0
✓
FileData = FileHandle.readline()
✓
while len(FileData) > 0:
✓
FileMembershipNumber = FileData[0:4]
✓
if FileMembershipNumber == MembershipNumber:
✓
NumberOfScores = NumberOfScores + 1
✓
TotalScore = TotalScore + int(FileData[-2])
✓
FileData = FileHandle.readline()
✓
AverageScore = int(TotalScore / NumberOfScores)
✓
Return (AverageScore)
✓
FileHandle.close()
✓
9608/23
✓
Cambridge International AS/A Level – Mark Scheme
✓
May/June 2018
✓
PUBLISHED
✓
Q7: Visual Basic
✓
Function IsFactor(Num1 As Integer, Num2 As Integer) As Boolean
✓
If Num2 <> 0 Then
✓
If Num1 Mod Num2 = 0 Then
✓
Return True
✓
End If
✓
End if
✓
Return False
✓
End Function
✓
Q7: Pascal
✓
function IsFactor(Num1,Num2 : integer) : boolean;
✓
begin
✓
if Num2 <> 0 then
✓
begin
✓
if Num1 MOD Num2 = 0 then
✓
Return True;
✓
end;
✓
Return False;
✓
end;
✓
Q7: Python
✓
def IsFactor (Num1, Num2):
✓
if Num2 != 0:
✓
if Num1 % Num2 == 0:
✓
Return True
✓
Return False

Mark scheme 9608_s18_ms_23.pdf →

Show text version of question

Question 7

A
function, IsFactor() takes two integer parameters and checks whether the second parameter

is a factor of the first parameter.

For example IsFactor(6,3) would return TRUE as six divided by three has a remainder of zero.

This function returns FALSE if there is a non-zero remainder, or if the value of the second parameter is zero.

Write program code to implement the IsFactor() function.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Question 15

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

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

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

Example: RIGHT("ABCDEFGH", 3) returns string "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

MOD(ThisNum : INTEGER, ThisDiv : INTEGER) RETURNS INTEGER returns the integer value representing the remainder when ThisNum is divided by ThisDiv

Example: MOD(10,3) returns 1

Operators (pseudocode)

Operator Description Concatenates (joins) two strings. & Example: "Summer" & " " & "Pudding" produces "Summer Pudding" Performs a logical AND of two Boolean values. AND Example: TRUE AND FALSE produces FALSE Performs a logical OR of two Boolean values. OR Example: TRUE OR FALSE produces TRUE

Question 16

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

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

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

Keep practising this topic