Past-paper question · 2017 May-June · Paper 23 · Q5

Question 5 2017 · May-June · Paper 23 · 10 marks

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

Official answer for Question 5

✓
Pseudocode solution included here for development and clarification of

Question 10

✓
mark scheme.
✓
Programming language example solutions appear in the Appendix.
✓
PROCEDURE SearchFile()
✓
DECLARE FileData : STRING
✓
DECLARE MyArrayRow : INTEGER
✓
DECLARE SearchID : STRING
✓
MyArrayRow ← 0 / 1
✓
OPEN "Loginfile.txt" FOR READ
✓
INPUT SearchID
✓
WHILE NOT EOF("Loginfile.txt")
✓
READFILE "Loginfile.txt", Filedata
✓
IF SearchID = LEFT(FileData,5)
✓
THEN
✓
LoginEvents[MyArrayRow,1] ← MID(Filedata, 6, 4)
✓
LoginEvents[MyArrayRow,2] ← RIGHT(Filedata, 14)
✓
MyArrayRow ← MyArrayRow + 1
✓
ENDIF
✓
ENDWHILE
✓
CLOSEFILE("LoginFile.txt")
✓
ENDPROCEDURE
✓
1 mark for each of the following:
✓
1.
✓
Procedure heading and ending
✓
2.
✓
Declare MyArrayRow as integer // commented in python
✓
3.
✓
Initialising MyArrayRow
✓
4.
✓
Input SearchID
✓
5.
✓
Open file "LoginFile.txt" for input / read
✓
6.
✓
Correct loop incorporating EOF()
✓
7.
✓
Read a line from the file in a loop
✓
8.
✓
Compare SearchID with correct data from file in a loop
✓
9.
✓
Assign both values to LoginEvents[MyArray] in a loop
✓
10.
✓
Increment MyArrayRow correctly in a loop
✓
11.
✓
Close the file not in a loop
✓
9608/23
✓
Cambridge International AS/A Level – Mark Scheme
✓
May/June 2017
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks

Mark scheme 9608_s17_ms_23.pdf →

Show text version of question

Question 5

A
multi-user computer system records user login information in a text file, LoginFile.txt. Each

time a user successfully logs into the system, the following information is recorded:

Item Information Example data

1 A five character user ID "JimAA"

2 A four character port ID "3456"

3 A fourteen character time and date "08:30Jun012015"

The data items are concatenated to form a single string. Each string is saved as a separate line in the text file.

The example data in the preceding table would result in the following text line in the file:

"JimAA345608:30Jun012015"

The computer system can produce a list of the successful login attempts by a given user.

The file LoginFile.txt is searched for a given user ID and the corresponding data are copied into a 2D array, LoginEvents.

LoginEvents has been declared in pseudocode as:

DECLARE LoginEvents[1 : 1000, 1 : 2] OF STRING

A
procedure, SearchFile, is needed to search the file and copy selected data to the array.

The main steps of the procedure are as follows:

  • Input a user ID.
  • Search LoginFile.txt for entries with matching user ID.
  • For matching entries, copy items 2 and 3 above into the LoginEvents array.

You can assume that:

  • the system initialises all elements of LoginEvents to an empty string " ", before it calls
  • SearchFile

  • there will be no more than 1000 successful logins for a single user.

Question 9

Write program code for the procedure SearchFile.

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 10

Topic relevance

Why this question appears here

71% 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_s17_qp_23.pdf

Keep practising this topic