Past-paper question · 2018 May-June · Paper 23 · Q5(c)

Question 5(c) 2018 · May-June · Paper 23 · 10 marks

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

Official answer for Question 5

Part (c)

✓
‘Pseudocode’ solution included here for development and clarification of
✓
mark scheme.
✓
Programming language solutions appear in the Appendix.
✓
FUNCTION GetAverageScore(MembershipNumber : STRING)
✓
RETURNS INTEGER
✓
DECLARE FileData, FileMembershipNumber : STRING
✓
DECLARE NumberOfScores, TotalScore, AverageScore :
✓
INTEGER
✓
OPENFILE "ScoreDetails.txt" FOR READ
✓
NumberOfScores ← 0
✓
TotalScore ← 0
✓
WHILE NOT EOF("ScoreDetails.txt")
✓
READFILE("ScoreDetails.txt", FileData)
✓
FileMembershipNumber ← LEFT(FileData, 4)
✓
IF FileMembershipNumber = MembershipNumber
✓
THEN
✓
NumberOfScores ← NumberOfScores + 1
✓
TotalScore ← TotalScore +
✓
INT(RIGHT(FileData, 2))
✓
ENDIF
✓
ENDWHILE
✓
AverageScore ← INT(TotalScore / NumberOfScores)
✓
CLOSEFILE("ScoreDetails.txt")
✓
RETURN(AverageScore)
✓
ENDFUNCTION
✓
1 mark for each of the following:

Question 1

✓
Function heading and ending including Input and return parameter

Question 2

✓
Declare variables to store NumberOfScores and TotalScore as
✓
INTEGERs (commented in Python) (variable names may be different)

Question 3

✓
Initialisation of NumberOfScores and TotalScore to 0

Question 4

✓
Open file in READ mode

Question 5

✓
Loop until EOF()

Question 6

✓
Read a line from the file in a loop

Question 7

✓
Use of substring function to extract at least one data item

Question 8

✓
Compare the membership number

Question 9

✓
Convert score to an integer

Question 10

✓
Increment NumberOfScores and sum TotalScore

Question 11

✓
Calculate the average outside the loop

Question 12

✓
Close the file

Question 13

✓
Return the parameter
✓
9608/23
✓
Cambridge International AS/A Level – Mark Scheme
✓
May/June 2018
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks

Mark scheme 9608_s18_ms_23.pdf →

Show text version of question

Question 5

Part (c)

Question 5

A golf club holds information about its members. When a member completes a round of golf, their

score is stored along with their membership number and the date of the round.

A
program is to be written to store and process the score information.

The information to be stored is as follows:

  • MembershipNumber is a four-digit numeric string.
  • Date is a six-digit numeric string in the format DDMMYY
  • Score is a two-digit numeric string in the range “50” to “99”.

This information is stored in a single string in the format:

<MembershipNumber><Date><Score>

Part (c)

The strings are stored in a text file, ScoreDetails.txt.

The program needs a function, GetAverageScore().

The structured English representing the algorithm for this function is as follows:

1 Receive a membership number as its argument. 2 Search the ScoreDetails.txt file for all scores for that member. 3 Calculate the average score. 4 Return the average score.

You can assume that there will be at least one score relating to each member.

Question 11

Write program code for the GetAverageScore() 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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Question 12

Topic relevance

Why this question appears here

82% assigned-topic match · Programming › Constructs

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