A Level Computer Science 9618 Paper 21, Oct/Nov 2023

Question paper and mark scheme75 marks8 questions

Solve it on ExamPal

Practise

Untimed. Write on the paper and check as you go.

Start

Exam

Timed, with a clock you set, like sitting the real paper.

Start

Opens full screen.

Papers open in

Opening the question paper

Read as textThe questions and the mark scheme as plain text. Easier to read on a phone.

Question paper

9618/21 · Oct/Nov 2023

Download PDF
1

Refer to the insert for the list of pseudocode functions and operators. The following pseudocode represents part of the algorithm for a program: CASE OF ThisValue < 30 : Level ← "Low" // less than 30 Check ← 1 < 20 : Level ← "Very Low" // less than 20 Check ← ThisValue / 2 30 TO 40 : Level ← "Medium" // between 30 and 40 Check ← ThisValue / 3 Data[ThisValue] ← Data[ThisValue] + 1 > 40 : Level ← "High" ENDCASE

a

Complete the table by writing the answer for each row:

Answer
The value assigned to Level when ThisValue is 40
The value assigned to Check when ThisValue is 36
The value assigned to Level when ThisValue is 18
The number of elements in array Data that may be incremented
[4]
b

The pseudocode contains four assignments to variable Level. One of these assignments will never be performed. Identify this assignment and explain why this is the case.

[3]
c

The following line is added immediately before the ENDCASE statement: OTHERWISE : Level ← "Undefined" State why this assignment is never performed.

[1]
d

Give the appropriate data types for the variables ThisValue, Check and Level. ThisValue .............................................................................................................................. Check ....................................................................................................................................... Level ......................................................................................................................................

[3]
2
a

An algorithm is expressed as follows: • input 100 numbers, one at a time • keep a total of all numbers input that have a value between 30 and 70 inclusive and output this total after the last number has been input. Outline, using stepwise refinement, the five steps for this algorithm which could be used to produce pseudocode. Do not use pseudocode statements in your answer. Step 1 ....................................................................................................................................... ................................................................................................................................................... Step 2 ....................................................................................................................................... ................................................................................................................................................... Step 3 ....................................................................................................................................... ................................................................................................................................................... Step 4 ....................................................................................................................................... ................................................................................................................................................... Step 5 ....................................................................................................................................... ...................................................................................................................................................

[5]
b

Sequence is one programming construct. Identify two other programming constructs that will be required when the algorithm is converted into pseudocode. Construct 1 ............................................................................................................................... ................................................................................................................................................... Construct 2 ............................................................................................................................... ...................................................................................................................................................

[2]
3

The diagram represents an Abstract Data Type (ADT). The operation of this stack may be summarised as follows: • The TopOfStack pointer points to the last item added to the stack. • The BottomOfStack pointer points to the first item on the stack. Stack

D1 ← TopOfStack
D3
D4
D5
D2 ← BottomOfStack
a

The stack is implemented using two variables and a 1D array of 8 elements as shown. The variables are used to reference individual elements of the array, in such a way that: • the array is filled from the lowest indexed element towards the highest • all the elements of the array are available for the stack. Complete the diagram to represent the state of the stack as shown above.

Array elementData
8
7
6
5
4
3
2
1
Variable
TopOfStack
BottomOfStack
[3]
b

A function Push() will add a value onto the stack by manipulating the array and variables in part (a). Before adding a value onto the stack, the algorithm will check that space is available. If the value is added to the stack, the function will return TRUE, otherwise it will return FALSE. The algorithm is expressed in five steps. Complete the steps. 1. If ........................................................ then return FALSE 2. Otherwise .......................................... TopOfStack 3. Use TopOfStack as an ................................... to the array. 4. Set the element at this ...................................... to the .............................. being added. 5. Return .............................. .

[5]
4

A global array is declared in pseudocode as follows: DECLARE Data : ARRAY[1:150] OF STRING A function TooMany() will: 1. take two parameters: • a string (the search string) • an integer (the maximum value) 2. count the number of strings in the array that exactly match the search string 3. return TRUE if the count is greater than the maximum value, otherwise will return FALSE

a

Write pseudocode for the function TooMany().

[6]
b

The global array is changed to a 2D array, organised as 150 rows by 2 columns. It is declared in pseudocode as follows: DECLARE Data : ARRAY[1:150, 1:2] OF STRING The algorithm for the function in part (a) is changed. Strings will only be counted if both of the following conditions are true: • The current row is an even number. • The search string exactly matches the value in either column. Write pseudocode to check these conditions. Assume that the row index is contained in variable Row and the search string in variable Search.

[3]
5

An algorithm is designed to find the smallest numeric value from an input sequence and count how many numeric values have been input. An example of an input sequence is: 23, AB56, 17, 23ZW, 4, 10, END Numeric input values are all integers and non-numeric input is ignored, except for the string "END" which is used to terminate the sequence. The algorithm is expressed in pseudocode as shown: DECLARE NextInput : STRING DECLARE Min, Count, Num : INTEGER Min ← 999 Count ← 0 REPEAT INPUT NextInput IF IS_NUM(NextInput) = TRUE THEN Num ← STR_TO_NUM(NextInput) IF Num > Min THEN Min ← Num ENDIF Count ← Count & 1 ENDIF UNTIL NextInput ← "END" OUTPUT "The minimum value is ", Min, " and the count was ", Count

a

The pseudocode contains three errors due to the incorrect use of operators. Identify each error and state the correction required. 1 ................................................................................................................................................ ................................................................................................................................................... 2 ................................................................................................................................................ ................................................................................................................................................... 3 ................................................................................................................................................ ...................................................................................................................................................

[3]
b(i)

The operator errors are corrected and the algorithm is tested as follows: The input sequence: 18, 4, ONE, 27, 189, ERIC, 3, 65, END produces the output: The minimum value is 3 and the count was 6 The algorithm is tested with a different test data sequence. The sequence contains a mix of integer and non-numeric values. It is terminated correctly but the algorithm produces unexpected results. Explain the problem with the algorithm.

[2]
b(ii)

Give a sequence of four test data values that could be input to demonstrate the problem. Value 1 .............................................................................................................................. Value 2 .............................................................................................................................. Value 3 .............................................................................................................................. Value 4 ..............................................................................................................................

[2]
6

The pseudocode OUTPUT command starts each output on a new line.

a

A new procedure MyOutput() will take a string and a Boolean parameter. MyOutput() may be called repeatedly and will use concatenation to build a string using a global variable MyString, up to a maximum length of 255 characters. MyString will be output in either of these two cases: 1. The Boolean parameter value is TRUE 2. The resulting string (after concatenation) would be longer than 255 characters. If MyString is not output, the string is concatenated with MyString. For example, the calls to MyOutput() given below would result in the output as shown: MyOutput("Hello ", FALSE) MyOutput("ginger ", FALSE) MyOutput("cat", TRUE) MyOutput("How are you?", TRUE) Resulting output: Hello ginger cat How are you? Notes: • MyString is initialised to an empty string before MyOutput() is called for the first time. • No string passed to MyOutput() will be longer than 255 characters. Write pseudocode for MyOutput().

[7]
b

The design of the procedure given in part (a) is modified and MyString is changed from a global to a local variable declared in MyOutput(). When the modified procedure is converted into program code, it does not work as expected. Explain why it does not work as expected.

[2]
7

An algorithm is represented by a state-transition diagram. The table shows the inputs, outputs and states for the algorithm:

Current stateInputOutputNext state
S1A1X1S2
S2A3noneS1
S2A2X4S5
S5A1X1S5
S5A4X2S2
S5A3noneS3
S1A9X9S3
S3A9X9S4

Complete the state-transition diagram to represent the information given in the table.

[5]
Figure 1 of 1 for question 7
8

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. Messages are sent between computers as a string of characters organised into fields as shown: <STX><DestinationID><SourceID><Data><ETX>

Field numberField nameDescription
n/aSTXa single character marking the start of the message<br>(ASCII value 02)
1DestinationIDthree numeric characters that identify the destination computer
2SourceIDthree numeric characters that identify the source computer
3Dataa variable length string containing the data being sent<br>(Minimum length is 1 character)
n/aETXa single character marking the end of the message<br>(ASCII value 03)

For example, the following message contains the data "Hello Kevin" being sent from computer "101" to computer "232": <STX>"232101Hello Kevin"<ETX> Each computer will run a copy of the same program. Each program will contain a global variable, MyID of type string, that contains the unique ID of the computer in which the program is running. The programmer has defined the first two program modules as follows:

ModuleDescription
Transmit()<br>(already written)• takes two parameters:<br>o a string containing a message<br>o an integer containing a port number<br>• transmits the message using the given port
SendFile()• takes three parameters:<br>o a string containing a text file name<br>o a string containing a Destination ID<br>o an integer containing a Port number<br>• transmits the file one line at a time<br>• transmits a final message with data string "****"
a

Write pseudocode for module SendFile(). Assume: • module Transmit() has already been written and is used to transmit a message • the value of MyID may be used as SourceID • the file specified contains no blank lines • the file specified does not contain the line "****"

[7]
b

Module SendFile() is used to copy a file from one computer to another. A module within the program running on the destination computer will receive the data and write it to a new file. Explain why module SendFile() transmits the message with data string "****" after the last line of the file.

[2]
c(i)

One of the text files to be sent contains several blank lines (lines that do not contain any text). Explain why this is a problem.

[2]
c(ii)

Explain how the message format could be changed to allow a blank line to be sent.

[2]
d

A new module has been defined:

ModuleDescription
GetField()• takes two parameters:<br>o a string containing a message<br>o an integer containing a field number<br>• If the field number is valid (in the range 1 to 3, inclusive), it returns a string containing the required field, otherwise it returns an empty string.

As a reminder, a message is defined as follows: <STX><DestinationID><SourceID><Data><ETX>

Field numberField nameDescription
Not applicableSTXa single character marking the start of the message<br>(ASCII value 02)
1DestinationIDthree numeric characters that identify the destination computer
2SourceIDthree numeric characters that identify the source computer
3Dataa variable length string containing the data being sent<br>(Minimum length is 1 character)
Not applicableETXa single character marking the end of the message<br>(ASCII value 03)

Write pseudocode for module GetField().

[6]

Mark scheme

9618/21 · Oct/Nov 2023

Download PDF

1a · 4 marks

  • 1 mark

    The value assigned to Level when ThisValue is 40 : "Medium"

  • 1 mark

    The value assigned to Check when ThisValue is 36 : 12

  • 1 mark

    The value assigned to Level when ThisValue is 18 : "Low"

  • 1 mark

    The number of elements in array Data that may be incremented : 11

1b · 3 marks

  • 1 mark

    Level  "Very Low" // the level is assigned value “very low”

  • 1 mark

    because CASE clauses are checked in sequence // because of the order of the clauses

  • 1 mark

    a value < 30 satisfies the first clause // Clause '< 20' will never be tested

1c · 1 mark

  • 1 mark

    all of the possible values are addressed via all / four / three / the other clauses // there are no other possible values to map to OTHERWISE

1d · 3 marks

  • 1 mark

    ThisValue: INTEGER

  • 1 mark

    Check: REAL

  • 1 mark

    Level: STRING

2a · 5 marks

  • 1 mark

    Set total to zero

  • 1 mark

    Input a number

  • 1 mark

    Check if number greater than 29 and less than 71

  • 1 mark

    … if check is true - add number to total

  • 1 mark

    Repeat from step 2 99 times // for a total of 100 iterations

2b · 2 marks

  • 1 mark

    An iterative construct // a (count-controlled) loop

  • 1 mark

    A selection construct // an IF statement

3a · 3 marks

  • 1 mark

    all values in the order and location shown

  • 1 mark

    TopOfStack value is index of element containing D1

  • 1 mark

    BottomOfStack value is index of element containing D2

3b · 5 marks

  • 1 mark

    If TopOfStack = 8 // (stack) full then return FALSE

  • 1 mark

    Otherwise, increment TopOfStack

  • 1 mark

    Use TopOfStack as an index to the Array

  • 1 mark

    Set the element at this index / location / position to the value / data / item being added

  • 1 mark

    Return TRUE

4a · 6 marks

  • 1 mark

    Function heading, ending and return type

  • 1 mark

    Declare Count and Index as integers

  • 1 mark

    Initialise Count

  • 1 mark

    Loop (any type) for 150 iterations

  • 1 mark

    Compare Data element with parameter - if equal, increment Count in a loop

  • 1 mark

    Compare Count with Max and return Boolean in both cases outside the loop

4b · 3 marks

  • 1 mark

    Test for row being even number

  • 1 mark

    Test for either column value equal to Search

  • 1 mark

    Selection structure is either: Single IF statement using AND, or Two nested IFs using AND, or Single IF and the use of a two-iteration loop. Either of these structures correctly formed scores the mark

5a · 3 marks

  • 1 mark

    Num > Min should be Num < Min

  • 1 mark

    Count & 1 should be Count + 1

  • 1 mark

    NextInput  "END" should be NextInput = "END"

5b(i) · 2 marks

  • 1 mark

    If all the numeric input values are greater than 999 // If there are no numeric values in the sequence

  • 1 mark

    then the minimum will be given as 999 (and not one of the input values)

5b(ii) · 2 marks

  • 1 mark

    Mixture non-numeric and numeric with 3 or 4 values - with all numerics greater than 999 Examples: 1325, DOG, 7868, 7615 // SNAKE, 3478, SPIDER

  • 1 mark

    Final value: END

6a · 7 marks

  • 1 mark

    Procedure heading, including parameters, and ending

  • 1 mark

    Produce concatenated string

  • 1 mark

    … Check whether resulting string would be too long

  • 1 mark

    If so, then output old MyString

  • 1 mark

    … and assign NewString to MyString

  • 1 mark

    Else concatenate NewString to MyString

  • 1 mark

    (test for length < 255) Test EOL – If TRUE then Output

6b · 2 marks

  • 1 mark

    A new (instance of) variable MyString is created each time the procedure is called / executed

  • 1 mark

    So the previous contents are lost

7 · 5 marks

  • 1 mark

    S2 labelled

  • 1 mark

    S3, S4 and S5 added

  • 1 mark

    Line from S1 to S3

  • 1 mark

    All three lines between S2 and S5 (including S5 to S5)

  • 1 mark

    Line from S5 to S3 AND from S3 to S4

8a · 7 marks

  • 1 mark

    OPEN file in READ mode – using parameter - and subsequently CLOSE

  • 1 mark

    Conditional loop to EOF()

  • 1 mark

    Use of READFILE to get a line from the file

  • 1 mark

    ‘Attempt’ to form a message (minimum is DestID, MyID, FileData)

  • 1 mark

    Message formed is completely correct

  • 1 mark

    Call Transmit() with correct MP4 string in a loop

  • 1 mark

    Transmit the "****" message (all parts present) after the loop

8b · 2 marks

  • 1 mark

    Indicates that all the lines of the file have been sent // it is the end of the transmission / file transfer

  • 1 mark

    So that the receiving program can stop waiting for further data

8c(i) · 2 marks

  • 1 mark

    A message cannot contain a zero-length data field

  • 1 mark

    … so a blank line cannot be sent // there is no way to send a blank line

8c(ii) · 2 marks

  • 1 mark

    Append a (special) character to the start of the message text // Change the message protocol and use an additional field to act as an indicator

  • 1 mark

    interpret the new field data as a blank line // Interpret the new field data

8d · 6 marks

  • 1 mark

    Use of CASE ... ENDCASE or IF ... THEN ... ENDIF

  • 1 mark

    Field 1 and Field 2 extracted correctly

  • 1 mark

    Calculate a length of field 3

  • 1 mark

    Field 3 extracted correctly

  • 1 mark

    Return empty string in case of invalid parameter (via OTHERWISE or initialisation)

  • 1 mark

    Final RETURN, after a reasonable attempt

Questions

  1. 1
    Question 111 marks
    Mark scheme ›
  2. 2
    Question 27 marks
    Mark scheme ›
  3. 3
    Question 38 marks
    Mark scheme ›
  4. 4
    Question 49 marks
    Mark scheme ›
  5. 5
    Question 57 marks
    Mark scheme ›
  6. 6
    Question 69 marks
    Mark scheme ›
  7. 7
    Question 75 marks
    Mark scheme ›
  8. 8
    Question 819 marks
    Mark scheme ›

More 9618 papers

Other papers from Oct/Nov 2023

Solve it on ExamPalStart