1 (a) A programmer draws a program flowchart to show the sequence of steps required to solve a problem. Give the technical term for a sequence of steps that describe how to solve a problem. [1] (b) The table lists some of the variables used in a program. (i) Complete the table by writing the most appropriate data type for each variable. Variable | Use of variable | Data type Temp | Stores the average temperature | '' PetName | Stores the name of my pet | '' MyDOB | To calculate the number of days until my next birthday | '' LightOn | Stores state of light; light is only on or off | '' [4] (ii) One of the names used for a variable in the table in part 1(b)(i) is not an example of good practice. Identify the variable and give a reason why it is not good practice to use that name. Variable ... Reason ... [2] (c) Complete the table by evaluating each expression. Expression | Evaluation INT((31 / 3) + 1) | '' MID(TO_UPPER("Version"), 4, 2) | '' TRUE AND (NOT FALSE) | '' NUM_TO_STR(27 MOD 3) | '' [4]
A Level Computer Science 9618 · Topic practice
Programming past paper questions
Use focused Programming questions to practise the ideas in context, then return to a mixed set to check whether you can recognise the relevant approach without a topic prompt.
Appears inPaper 2 146
You’re practising 2021–2022 papers. The 2023–2026 papers, including 2026, need a plan.
Unlock from $6/mo1 (a) The following table contains pseudocode examples. Each example may include all or part of: selection, iteration (repetition), assignment. Complete the table by placing one or more ticks (✓) in each row. [5] Pseudocode example | Selection | Iteration | Assignment FOR Index ← 1 TO 3 / Safe[Index] ← GetResult() / NEXT Index | '' | '' | '' OTHERWISE : OUTPUT "ERROR 1202" | '' | '' | '' REPEAT UNTIL Index = 27 | '' | '' | '' INPUT MyName | '' | '' | '' IF Mark > 74 THEN / Grade ← 'A' / ENDIF | '' | '' | '' (b) (i) Program variables have values as follows: Variable | Value AAA | TRUE BBB | FALSE Count | 99 Complete the table by evaluating each expression. [2] Expression | Evaluation AAA AND (Count > 99) | '' AAA AND (NOT BBB) | '' (Count <= 99) AND (AAA OR BBB) | '' (BBB AND Count > 50) OR NOT AAA | '' (ii) Give an example of when a variable of type Boolean would be used. [1]
1 (a) An algorithm includes a number of complex calculations. A programmer is writing a program to implement the algorithm and decides to use library routines to provide part of the solution. State three possible benefits of using library routines in the development of the program. 1 … 2 … 3 … [3] (b) The following pseudocode is part of a program that stores names and test marks for use in other parts of the program. DECLARE Name1, Name2, Name3 : STRING DECLARE Mark1, Mark2, Mark3 : INTEGER INPUT Name1 INPUT Mark1 INPUT Name2 INPUT Mark2 INPUT Name3 INPUT Mark3 (i) The pseudocode needs to be changed to allow for data to be stored for up to 30 students. Explain why it would be good practice to use arrays to store the data. [3] (ii) The following pseudocode statement includes array references: OUTPUT "Student ", Name[Count], " scored ", Mark[Count] State the purpose of the variable Count and give its data type. Purpose … Data type … [2] (c) The pseudocode statements in the following table may contain errors. State the error in each case or write 'NO ERROR' if the statement contains no error. Assume that any variables used are of the correct type for the given function. Statement | Error IF EMPTY ← "" THEN | '' Status ← IS_NUM(-23.4) | '' X ← STR_TO_NUM("37") + 5 | '' Y ← STR_TO_NUM("37" + "5") | '' [4]
1 (a) A programmer is developing an algorithm to solve a problem. Part of the algorithm would be appropriate to implement as a subroutine (a procedure or a function). (i) State two reasons why the programmer may decide to use a subroutine. 1 … 2 … [2] (ii) A procedure header is shown in pseudocode: PROCEDURE MyProc(Count : INTEGER, Message : STRING) Give the correct term for the identifiers Count and Message and explain their use. Term … Use … [2] (b) The algorithm in part (a) is part of a program that will be sold to the public. All the software errors that were identified during in-house testing have been corrected. Identify and describe the additional test stage that may be carried out before the program is sold to the public. Test stage … Description … [4] (c) Part of an identifier table is shown: Variable | Type | Example value FlagDay | DATE | 23/04/2004 CharList | STRING | "ABCDEF" Count | INTEGER | 29 Complete the table by evaluating each expression using the example values. Expression | Evaluation MID(CharList, MONTH(FlagDay), 1) | '' INT(Count / LENGTH(CharList)) | '' (Count >= 29) AND (DAY(FlagDay) > 23) | '' [3]
4 (a) A procedure LastLines() will: - take the name of a text file as a parameter - output the last three lines from that file, in the same order as they appear in the file. Note: Use local variables LineX, LineY and LineZ to store the three lines from the file. You may assume the file exists and contains at least three lines. Write pseudocode for the procedure LastLines(). [6] (b) The algorithm in part (a) is to be amended. The calling program will pass the number of lines to be output as well as the name of the text file. The number of lines could be any value from 1 to 30. It can be assumed that the file contains at least the number of lines passed. Outline three changes that would be needed. 1 ... 2 ... 3 ... [3]
5 Each line of a text file contains data organised into fixed-length fields as shown: <Field 1><Field 2><Field 3> An algorithm is required to search for the first instance of a given value of Field 2 and, if found, to output the corresponding values for Field 1 and Field 3. Describe the algorithm needed. Do not include pseudocode statements in your answer. [6]
5 Study the following pseudocode. Line numbers are for reference only. 10 PROCEDURE Encode() 11 DECLARE CountA, CountB, ThisNum : INTEGER 12 DECLARE ThisChar : CHAR 13 DECLARE Flag : BOOLEAN 14 CountA <- 0 15 CountB <- 10 16 Flag <- TRUE 17 INPUT ThisNum 18 WHILE ThisNum <> 0 19 ThisChar <- LEFT(NUM_TO_STR(ThisNum), 1) 20 IF Flag = TRUE THEN 21 CASE OF ThisChar 22 '1' : CountA <- CountA + 1 23 '2' : IF CountB < 10 THEN 24 CountA <- CountA + 1 25 ENDIF 26 '3' : CountB <- CountB - 1 27 '4' : CountB <- CountB - 1 28 Flag <- FALSE 29 OTHERWISE : OUTPUT "Ignored" 30 ENDCASE 31 ELSE 32 IF CountA > 2 THEN 33 Flag <- NOT Flag 34 OUTPUT "Flip" 35 ELSE 36 CountA <- 4 37 ENDIF 38 ENDIF 39 INPUT ThisNum 40 ENDWHILE 41 OUTPUT CountA 42 ENDPROCEDURE (a) Procedure Encode() contains a loop structure. Identify the type of loop and state the condition that ends the loop. Do not include pseudocode statements in your answer. Type ... Condition ... [2] (b) Complete the trace table below by dry running the procedure Encode() when the following values are input: 12, 24, 57, 43, 56, 22, 31, 32, 47, 99, 0. The first row is already complete. ThisNum | ThisChar | CountA | CountB | Flag | OUTPUT '' | '' | 0 | 10 | TRUE | '' (followed by 13 further blank rows) [6] (c) Procedure Encode() is part of a modular program. Integration testing is to be carried out on the program. Describe integration testing. [2]
5 A program will store attendance data about each employee of a company. The data will be held in a record structure of type Employee. The fields that will be needed are as shown: Field | Typical value | Comment EmployeeNumber | 123 | A numeric value starting from 1 Name | "Smith,Eric" | Format: <last name>','<first name> Department | "1B" | May contain letters and numbers Born | 13/02/2006 | Must not be before 04/02/1957 Attendance | 97.40 | Represents a percentage (a) (i) Write pseudocode to declare the record structure for type Employee. [4] (ii) A 1D array Staff containing 500 elements will be used to store the employee records. Write pseudocode to declare the Staff array. [2] (b) There may be more records in the array than there are employees in the company. In this case, some records of the array will be unused. (i) State why it is good practice to have a standard way to indicate unused array elements. [1] (ii) Give one way of indicating an unused record in the Staff array. [1] (c) A procedure Absentees() will output the EmployeeNumber and the Name of all employees who have an Attendance value of 90.00 or less. Write pseudocode for the procedure Absentees(). Assume that the Staff array is global. [4]
5 A program uses two 1D arrays of type integer. Array1 contains 600 elements and Array2 contains 200 elements. Array1 contains sample values read from a sensor. The sensor always takes three consecutive samples and all of these values are stored in Array1. A procedure Summarise() will calculate the average of three consecutive values from Array1 and write the result to Array2. This will be repeated for all values in Array1. The diagram below illustrates the process for the first six entries in Array1. Array1 | Array2 | Comment 10 | 15 | average of first three values 20 | 41 | average of next three values 15 | '' | 40 | '' | 41 | '' | 42 | '' | [Diagram: the first three entries of Array1 (10, 20, 15) are grouped by a brace with an arrow to the first entry of Array2 (15); the next three entries (40, 41, 42) are grouped by a brace with an arrow to the second entry of Array2 (41).] Write pseudocode for the procedure Summarise(). [5]
5 Examine the following pseudocode. IF A = TRUE THEN IF B = TRUE THEN IF C = TRUE THEN CALL Sub1() ELSE CALL Sub2() ENDIF ENDIF ELSE IF B = TRUE THEN IF C = TRUE THEN CALL Sub4() ELSE CALL Sub3() ENDIF ELSE IF C = FALSE THEN CALL Sub3() ELSE CALL Sub4() ENDIF ENDIF ENDIF A programmer wants to re-write the pseudocode as four separate IF...THEN...ENDIF statements, each containing a single CALL statement. This involves writing a single, simplified logic expression as the condition in each statement. Write the amended pseudocode. 1 … 2 … 3 … 4 … [4]
5 (a) A text string contains three data items concatenated as shown: <StockID><Description><Cost> Item lengths are: Item | Length. StockID | 5. Description | 32. Cost | the remainder of the string. A procedure Unpack() takes four parameters of type string. One parameter is the original text string. The other three parameters are used to represent the three data items shown in the table and are assigned values within the procedure. These values will be used by the calling program after the procedure ends. (i) Write pseudocode for the procedure Unpack(). [6] (ii) Explain the term procedure interface with reference to procedure Unpack(). [2] (b) The design changes and a record structure is defined to store the three data items. A user-defined data type StockItem is created as shown: TYPE StockItem / DECLARE StockID : STRING / DECLARE Description : STRING / DECLARE Cost : REAL / ENDTYPE (i) A variable LineData of type StockItem is declared. Write the pseudocode statement to assign the value 12.99 to the Cost field of LineData. [1] (ii) Procedure Unpack() is modified and converted to a function which takes the original text string as the only parameter. Explain the other changes that need to be made to convert the procedure into a function. [2] (c) Unpack() is part of a program made up of several modules. During the design stage, it is important to follow good programming practice. One example of good practice is the use of meaningful identifier names. Give the reason why this is good practice. Give two other examples of good practice. Reason Example 1 Example 2 [3] (d) The program that includes Unpack() is tested using the walkthrough method. Describe this method and explain how it can be used to identify an error. [3]
6 (a) An algorithm will: - output each integer value between 100 and 200 that ends with the digit 7, for example, 107 - output a final count of the number of values that are output. Write pseudocode for this algorithm. Any variables used must be declared. [5] (b) Study the following pseudocode. CASE OF MySwitch 1: ThisChar <- 'a' 2: ThisChar <- 'y' 3: ThisChar <- '7' OTHERWISE: ThisChar <- '*' ENDCASE Write pseudocode with the same functionality without using a CASE structure. [4]
6 A string represents a series of whole numbers, separated by commas. For example: "12,13,451,22" Assume that: the comma character ',' is used as a separator; the string contains only the characters '0' to '9' and the comma character ','. A procedure Parse will: take the string as a parameter; extract each number in turn; calculate the total value and average value of all the numbers; output the total and average values with a suitable message. Write pseudocode for the procedure. PROCEDURE Parse(InString : STRING) ... ENDPROCEDURE [7]
6 (a) The factorial of a number is the product of all the integers from 1 to that number. For example: factorial of 5 is given by 1 × 2 × 3 × 4 × 5 = 120; factorial of 7 is given by 1 × 2 × 3 × 4 × 5 × 6 × 7 = 5040; factorial of 1 = 1. Note: factorial of 0 = 1. A function Factorial() will: be called with an integer number as a parameter; calculate and return the factorial of the number; return −1 if the number is negative. Write pseudocode for the function Factorial(). [6] (b) A procedure FirstTen() will output the factorial of the numbers from 0 to 9. The procedure will use the function from part (a). The required output is: Factorial of 0 is 1 Factorial of 1 is 1 Factorial of 2 is 2 ... Factorial of 9 is 362880 The program flowchart represents an algorithm for FirstTen(). [Flowchart: START, then process box 'Set Num to 0', then decision diamond labelled A with exit B going down to END and exit C going right to a predefined-process box D, then an input/output parallelogram E, then a process box F whose arrow returns to the line above the decision A.] Complete the table by writing the text that should replace each label A to F. [4] Label | Text A | '' B | '' C | '' D | '' E | '' F | ''
6 (a) The factorial of an integer number is the product of all the integers from that number down to 1. In general, the factorial of n is n × (n−1) × ... × 2 × 1 For example, the factorial of 5 is 5 × 4 × 3 × 2 × 1 = 120 In this question, n will be referred to as the BaseNumber. A function FindBaseNumber() will: • be called with a positive, non-zero integer value as a parameter • return BaseNumber if the parameter value is the factorial of the BaseNumber • return −1 if the parameter value is not a factorial. For example: Parameter value | Value returned 120 | 5 12 | −1 6 | 3 1 | 1 FindBaseNumber(12) will return −1 because 12 is not a factorial. You may use the rest of this page for rough working. Write pseudocode for the function FindBaseNumber(). [7] (b) A program is written to allow a user to input a sequence of values to be checked using the function FindBaseNumber(). The user will input one value at a time. The variable used to store the user input has to be of type string because the user will input 'End' to end the program. Valid input will be converted to an integer and passed to FindBaseNumber() and the return value will be output. Complete the table by giving four invalid strings that may be used to test distinct aspects of the required validation. Give the reason for your choice in each case. Input | Reason for choice '' | '' '' | '' '' | '' '' | '' [4]
6 Components are weighed during manufacture. Weights are measured to the nearest whole gram. Components that weigh at least 3 grams more than the maximum weight, or at least 3 grams less than the minimum weight, are rejected. A component is rechecked if it weighs within 2 grams of either the maximum or minimum weight. The final outcome of weighing each component is shown below: [diagram: a vertical column of weight boxes beside outcome labels; from the top, Reject above two boxes, then three boxes Max + 2, Max (arrow labelled Maximum weight), Max - 2 labelled Recheck, then a box with Accept below, a wavy break, then three boxes Min + 2, Min (arrow labelled Minimum weight), Min - 2 labelled Recheck, and Reject below with further boxes] A function Status() will be called with three parameters. These are integers representing the weight of an individual component together with the minimum and maximum weights. The value returned from the function will be as follows: Outcome | Return value. Accept | 'A'. Reject | 'R'. Recheck | 'C'. (a) Complete the following test plan for five tests that could be performed on function Status(). The tests should address all possible outcomes. Test number | Component weight | Min | Max | Expected return value. 1 | '' | '' | '' | 'A'. 2 | '' | '' | '' | ''. 3 | '' | '' | '' | ''. 4 | '' | '' | '' | ''. 5 | '' | '' | '' | ''. [5] (b) Write pseudocode for Status(). [6]
7 A string is a palindrome if it reads the same forwards as backwards. The following strings are examples of palindromes: "Racecar" "madam" "12344321" Upper-case and lower-case characters need to be treated the same. For example, 'A' is equivalent to 'a'. (a) A function IsPalindrome() will take a string parameter. The function will return TRUE if the string is a palindrome and will return FALSE if the string is not a palindrome. Write pseudocode for IsPalindrome(). [7] (b) Strings may consist of several words separated by spaces. For example, the string "never odd or even" becomes a palindrome if the spaces are removed. The program flowchart represents an algorithm to produce a string OutString by removing all spaces from a string InString. [Flowchart: START -> box 'Set Index to 1' -> box A -> decision B. B: YES -> END; NO -> decision C. C: branch F -> box E; branch G -> box D -> box E. Box E -> back to the line entering decision B (loop).] Complete the table by writing the text that should replace each of the labels B, C, D, F and G. Label | Text A | Set OutString to "" B | '' C | '' D | '' E | Set Index to Index + 1 F | '' G | '' [4]
7 A programming language has string functions equivalent to those given in the insert. The language includes a LEFT() and a RIGHT() function, but it does not have a MID() function. (a) Write pseudocode for an algorithm to implement your own version of the MID() function which will operate in the same way as that shown in the insert. Do not use the MID() function given in the insert, but you may use any of the other functions. Assume that the values passed to the function will be correct. [4] (b) The values passed to your MID() function in part (a) need to be validated. Assume that the values are of the correct data type. State two checks that could be applied to the values passed to the function. 1 ... 2 ... [2]
7 The following pseudocode represents an algorithm intended to output the last three lines as they appear in a text file. Line numbers are provided for reference only. 10 PROCEDURE LastLines(ThisFile : STRING) 11 DECLARE ThisLine : STRING 12 DECLARE Buffer : ARRAY[1:3] OF STRING 13 DECLARE LineNum : INTEGER 14 LineNum ← 1 15 OPENFILE ThisFile FOR READ 16 17 WHILE NOT EOF(ThisFile) 18 READFILE Thisfile, ThisLine // read a line 19 Buffer[LineNum] ← ThisLine 20 LineNum ← LineNum + 1 21 IF LineNum = 4 THEN 22 LineNum ← 1 23 ENDIF 24 ENDWHILE 25 26 CLOSEFILE ThisFile 27 FOR LineNum ← 1 TO 3 28 OUTPUT Buffer[LineNum] 29 NEXT LineNum 30 ENDPROCEDURE (a) There is an error in the algorithm. In certain cases, a text file will have at least three lines but the output will be incorrect. (i) State how the output may be incorrect. [1] (ii) Describe the error in the algorithm and explain how it may be corrected. Description … Explanation … [4] (b) The original algorithm is implemented and sometimes the last three lines of the text file are output correctly. State the condition that results in the correct output. [1] (c) Lines 20 to 23 inclusive could be replaced with a single pseudocode statement. Write the pseudocode statement. [2]
7 A simple arithmetic expression is stored as a string in the format: <Value1><Operator><Value2> An operator character is one of the following: '+' '-' '*' '/' Example arithmetic expression strings: "803+1904" "34/7" (a) A procedure Calculate() will: • take an arithmetic expression string as a parameter • evaluate the expression • output the result. Assume: • the string contains only numeric digits and a single operator character • Value1 and Value2 represent integer values • Value1 and Value2 are unsigned (they will not be preceded by '+' or '-'). (i) Write pseudocode for the procedure Calculate(). [7] (ii) Calculate() is changed to a function that returns the value of the evaluated expression. Write the header for the function in pseudocode. [1] (b) A string representing an arithmetic expression could be in the correct format but be impossible to evaluate. Give an example of a correctly formatted string and explain why evaluation would be impossible. Example string … Explanation … [2]
Programming: quick facts
How often does Programming come up in A Level Computer Science 9618?
Programming is tagged on 146 of the 750 A Level Computer Science 9618 past-paper questions on PastPaperPrep (19%), from papers sat 2021-2026. Paper 2 has the most Programming questions, with 146. These are archive counts, not a prediction, and a question can carry more than one topic.
Are the A Level Computer Science 9618 Programming questions free?
42 of the 146 A Level Computer Science 9618 Programming questions are free to practise. The other 104 need a plan for A Level Computer Science 9618, from $6 a month.
Do the A Level Computer Science 9618 Programming questions have answers?
Yes. Each A Level Computer Science 9618 Programming question shows the official mark scheme answer.