Skip to main content
A-LevelComputer ScienceProgramming9618/22 · Oct/Nov 2023 · Q818 Marks

A class of students are developing a program to send data between computers. Many computers are connected together to form a wired network. Serial ports are used to connect one computer to another. Each computer: • is assigned a unique three-digit ID • has three ports, each identified by an integer value • is connected to between one and three other computers. Data is sent as individual message strings. Each string contains the destination ID (the ID of the computer that is to receive the message) followed by the data: <DestinationID><Data> Messages may pass through several computers on the way to their destination. When a message arrives at a computer, that is not the destination, the program needs to forward it on to another computer using one of its serial ports. The port to use is obtained from information that is stored in an array RouteTable. RouteTable is a global 2D array of integers. It is declared in pseudocode as follows: DECLARE RouteTable : ARRAY[1:6,1:3] OF INTEGER The values in the first two columns of RouteTable define a range of ID values. Column 3 gives the corresponding port number to use when forwarding the message to a computer with an ID within this range. For example, the contents of RouteTable could be: Column 1 Column 2 Column 3 Row 1 100 199 1 Row 2 200 259 2 Row 3 -1 <undefined> <undefined> Row 4 260 399 2 Row 5 400 599 3 Row 6 600 999 1 In this example, a message that arrives with a DestinationID of "283" will be forwarded using port 2. Row 3 in the example shows an unused row. These may occur anywhere. Unused rows have the column 1 element set to -1. The value of unused elements in the other two columns is undefined. The programmer has defined the first program module as follows: Module Description GetPort() • takes a DestinationID as a parameter of type string • searches for the range corresponding to the DestinationID in the array • returns the port number, or returns -1 if no corresponding range is found

  1. (a)Write pseudocode for module GetPort(). Assume DestinationID contains a valid three-digit string.[7]
  2. (b)Copies of the same program will run on each computer. The program contains a global variable MyID of type string, which contains the unique ID of the computer in which the program is running. When messages are received, they are placed on one of two stacks. Stack 1 is used for messages that have reached their destination and stack 2 is used for messages that will be forwarded on to another computer. Additional modules are defined: Module Description StackMsg() (already written) • takes two parameters: a string representing a message an integer representing the stack number • adds the message to the required stack • returns TRUE if the message is added to the required stack, otherwise returns FALSE ProcessMsg() • takes a message as a parameter of type string • ignores any message with a zero-length data field • extract the DestinationID from the message • checks whether the DestinationID is this computer or whether the message is to be forwarded • uses StackMsg() to add the message to the appropriate stack • outputs an error if the message could not be added to the stack Write pseudocode for module ProcessMsg(). Module StackMsg() must be used.[7]
  3. (c)(i)The program contains a module GetFile() which receives text files sent from another computer. Lines from the file are sent one at a time. Each message contains one line and ProcessMsg() from part (b) adds each message as it is received onto stack 1. Module GetFile() removes messages from stack 1 and writes the data to a text file. There is a problem. Under certain circumstances, the received file does not appear as expected. Assume that while a file is being received ProcessMsg() receives only messages containing lines from the file. Describe the circumstances and explain the problem. Circumstances Explanation[3]
  4. (c)(ii)Suggest a more appropriate Abstract Data Type that could be used to store the messages that would not have the same problem.[1]

Mark scheme

Marking points from the official mark scheme (Oct/Nov 2023). The mark or mark type is shown in brackets.

  1. [7] Mark as follows Max 7:
  2. 1.Function heading and ending including parameter and return type
  3. 2 Convert parameter to a number
  4. 3 (Conditional) loop through array
  5. 4 Skip unused element in a loop
  6. 5 Attempt to check one range with destination in a loop
  7. 6 Test all ranges correctly with destination in a loop
  8. 7 Store port value if destination matched in a loop (and exit loop)
  9. 8 Return port value including -1 if no match found
  10. [7] Mark as follows:
  11. 1. Ignore message if data field is empty
  12. 2. Extract ThisDest from ThisMsg
  13. 3. Test if destination is this computer
  14. 4. Attempt to use StackMsg()
  15. 5. Fully correct use of StackMsg() for both cases / stacks
  16. 6. Test StackMsg() return value for both cases
  17. 7. Following a reasonable attempt at MP6 output warning if StackMsg() returns FALSE
  18. [3] One mark per point Max 3 marks:
  19. Decide on scenario and mark accordingly.
  20. Scenario one:
  21. If more than one line is / all lines are stored on the stack (before line(s) are removed)
  22. The stack operates as a FILO device // Last item added to stack will be in first item out
  23. So lines in the file appear out of sequence
  24. Scenario two:
  25. Stack is Full
  26. Not all lines can be stored on the stack
  27. so resulting file will not contain all the original lines
  28. Scenario three:
  29. (All) the data in a line read can't be stored on the stack
  30. Stack elements have not been allocated enough memory
  31. so only part of each line is stored in the file
  32. Scenario four:
  33. Stack is empty
  34. The stack is being read faster than it is being written to
  35. so blank lines may be inserted into the file
  36. [1] Queue

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 →

About this question

Topic
Programming, A-Level Computer Science (syllabus 9618). Structured question, 18 marks.
Source
A-Level Computer Science, Oct/Nov 2023 Paper 2 Variant 2, question 8.

Questions and mark schemes are from past examination papers and remain the copyright of the exam board. How Oracle Prep builds its content

Related Computer Science questions

© 2026 Oracle Prep