The following data items will be recorded each time a student successfully logs on to the school network: Data item Example data Student ID "CJL404" Host ID "Lib01" Time and date "08:30, June 01, 2021" The Student ID is six characters long. The other two data items are of variable length. A single string will be formed by concatenating the three data items. A separator character will need to be inserted between items two and three. For example: "CJL404Lib01<separator>08:30, June 01, 2021" Each string represents one log entry. A programmer decides to store the concatenated strings in a 1D array LogArray that contains 2000 elements. Unused array elements will contain an empty string.
- (a)Suggest a suitable separator character and give a reason for your choice. Character Reason[2]
- (b)The choice of data structure was made during one stage of the program development life cycle. Identify this stage.[1]
- (c)A function LogEvents() will: • take a Student ID as a parameter • for each element in the array that matches the Student ID parameter: o add the value of the array element to the existing text file LogFile o assign an empty string to the array element • count the number of lines added to the file • return this count. Write pseudocode for the function LogEvents().[7]
Mark scheme
Marking points from the official mark scheme (Oct/Nov 2021). The mark or mark type is shown in brackets.
- [2] One mark for the character and one for the corresponding reason.
- • Character: Any except alphabetic, numeric, ',' ':' or space
- • Reason: character doesn't occur in data to be recorded
- [1] Design
- [7] FUNCTION LogEvents(StudentID : STRING) RETURNS INTEGER
- DECLARE FileData : STRING
- DECLARE Index, Count : INTEGER
- CONSTANT LogFile = "LogFile"
- Count ← 0
- OPENFILE LogFile FOR APPEND
- FOR Index ← 1 TO 2000
- FileData ← LogArray[Index]
- IF LEFT(FileData, 6) = StudentID THEN
- WRITEFILE (LogFile, FileData) //brackets optional
- Count ← Count + 1
- LogArray[Index] ← "" // clear the element
- ENDIF
- NEXT Index
- CLOSEFILE LogFile
- RETURN Count
- ENDFUNCTION
- 1 mark for each of the following:
- 1 Function heading and ending including parameter and return type
- 2 OPENFILE LogFile for APPEND and subsequent CLOSE
- 3 Loop for 2000 iterations
- 4 Extract first 6 characters from array element in a loop
- 5 Compare first 6 characters with parameter in a loop
- 6 If equal:
- • write whole array element string to file and
- • increment Count and
- • clear array element in a loop
- 7 Return Count (must have been declared and initialised)
Write your answer and get it marked
On Oracle Prep you can write or photograph your own answer and have it marked by AI against this mark scheme, with feedback on what you missed.
Sign up free →