TopicalComputer Science 9618ProgrammingProgramming BasicsPaper 2

Programming Basics — Paper 2 · A Level Computer Science 9618

11.1· 17 questions · 182 marks · 218 min · 2021–2023· Structured questions

Every Cambridge A Level Computer Science Paper 2 question on programming basics, laid out as 30 A4 pages with the mark scheme below. Nothing is left out. Free to read, no account.

Different topic or paper

Questions30 pages

Question 1: (a) A program is being developed to help manage the membership of a football club. Complete the following identifier table. Example Explana…1 / 30
Question 1 (continued)2 / 30
Question 2: (a) Four program modules form part of a program for a library. A description of the relationship between the modules is summarised as follo…3 / 30
Question 2 (continued)4 / 30
Question 2 (continued)5 / 30
Question 3: (a) A program is being developed to help manage the membership of a football club. Complete the following identifier table. Example Explana…6 / 30
Question 3 (continued)7 / 30
Question 4: (a) Four program modules form part of a program for a library. A description of the relationship between the modules is summarised as follo…8 / 30
Question 4 (continued)9 / 30
Question 4 (continued)10 / 30
Question 5: (a) An algorithm to sort a 1D array into ascending order is described as follows: • move the largest value to the end • keep repeating unti…11 / 30
Question 5 (continued)12 / 30
Question 5 (continued)Question 6: (a) A programmer applies decomposition to a problem that she has been asked to solve. Describe decomposition. .............................…13 / 30
Question 6 (continued)Question 7: (a) An algorithm to sort a 1D array into ascending order is described as follows: • move the largest value to the end • keep repeating unti…14 / 30
Question 7 (continued)15 / 30
Question 7 (continued)16 / 30
Question 7 (continued)17 / 30
Question 8: (a) A programmer draws a program flowchart to show the sequence of steps required to solve a problem. Give the technical term for a sequenc…18 / 30
Question 9: (a) A programmer is testing a program using an Integrated Development Environment (IDE). The programmer wants the program to stop when it r…19 / 30
Question 10: A programming language has string functions equivalent to those given in the insert. The language includes a LEFT() and a RIGHT() function,…Question 11: (a) An algorithm includes a number of complex calculations. A programmer is writing a program to implement the algorithm and decides to use…20 / 30
Question 11 (continued)21 / 30
Question 11 (continued)Question 12: A teacher is designing a program to perform simple syntax checks on programs written by students. Student programs are submitted as text fi…22 / 30
Question 12 (continued)23 / 30
Question 12 (continued)Question 13: (a) A programmer is developing an algorithm to solve a problem. Part of the algorithm would be appropriate to implement as a subroutine (a …24 / 30
Question 13 (continued)Question 14: A programmer has written a program which includes the function Calculate(). When the program is run, the function returns an unexpected val…25 / 30
Question 14 (continued)26 / 30
Question 15: A program stores a user’s date of birth using a variable MyDOB of type DATE. (a) Write a pseudocode statement, using a function from the in…27 / 30
Question 16: A programmer has produced the following pseudocode to output the square root of the numbers from 1 to 10. Line numbers are for reference on…28 / 30
Question 16 (continued)Question 17: The following pseudocode represents part of the algorithm for a program. Line numbers are for reference only. 10 DECLARE Sheet4 : ARRAY[1:2…29 / 30
Question 17 (continued)30 / 30

Mark scheme17 answers

Answers below. Sit the paper first if you are practising.

Pastlit

Computer Science 9618 · Programming Basics — Paper 2

A Level · topical answer key — answer key (teacher use)

Question

Answer

Marks

1Mark scheme for question 112
2Mark scheme for question 213
3Mark scheme for question 312
4Mark scheme for question 413
5Mark scheme for question 512
6Mark scheme for question 611
7Mark scheme for question 712
8Mark scheme for question 811
9Mark scheme for question 911
10Mark scheme for question 106
11Mark scheme for question 1112
12Mark scheme for question 129
13Mark scheme for question 1311
14Mark scheme for question 1410
15Mark scheme for question 159
16Mark scheme for question 168
17Mark scheme for question 1710
QuestionAnswerMarksFrom
1see sheet129618/21 May/June 2021
2see sheet139618/21 May/June 2021
3see sheet129618/23 May/June 2021
4see sheet139618/23 May/June 2021
5see sheet129618/21 Oct/Nov 2021
6see sheet119618/22 Oct/Nov 2021
7see sheet129618/23 Oct/Nov 2021
8see sheet119618/21 May/June 2022
9see sheet119618/22 May/June 2022
10see sheet69618/22 May/June 2022
11see sheet129618/21 Oct/Nov 2022
12see sheet99618/21 Oct/Nov 2022
13see sheet119618/22 Oct/Nov 2022
14see sheet109618/21 May/June 2023
15see sheet99618/22 May/June 2023
16see sheet89618/22 May/June 2023
17see sheet109618/23 May/June 2023

Another paper, or another topic

Paper
Paper 217 questionsPaper 4questions coming

All of Programming

Questions as text

Q1 · A program is being developed to help manage the membership of a football club 9618/21 May/June 2021

1 (a) A program is being developed to help manage the membership of a football club. Complete the following identifier table. Example Explanation Variable name Data type value The preferred name of the member "Wong" joining the football club A value to indicate whether an FALSE existing member of the club lives at the same address When the member joined the football 19/02/1983 club The number of points a member has 1345 earned. Members of the club earn points for different activities. [4] (b) Each pseudocode statement in the following table may contain an error due to the incorrect use of the function or operator. Describe the error in each case, or write ‘NO ERROR’ if the statement contains no error. You can assume that none of the variables referenced are of an incorrect type. Statement Error Result 2 & 4 SubString MID("pseudocode", 4, 1) IF x = 3 OR 4 THEN Result Status AND INT(x/2) Message "Done" + LENGTH(MyString) [5] (c) The following data items need to be stored for each student in a group: • student name (a string) • test score (an integer). State a suitable data structure and justify your answer. Structure … Justification … … … [3]

12 marks

Mark scheme: Question Answer Marks 1(a) 4 Example Explanation Variable name Data type value "Wong" The preferred name of the MemberName STRING member joining the football club FALSE A value to indicate FamilyMember BOOLEAN whether an existing member of the club lives at the same address 19/02/1983 When the member joined StartDate DATE the football club 1345 The number of points a Points INTEGER member has earned. Members of the club earn points for different activities. One mark for each appropriate variable name plus data type 1(b) 5 Statement Error Should be arithmetic Result ← 2 & 4 operator (not &) // 2 and 4 should be CHAR / STRING SubString ← MID("pseudocode", 4, 1) NO ERROR Not Boolean values / IF x = 3 OR 4 THEN incorrect operator // Condition incorrect INT(X/2) doesn't evaluate Result ← Status AND INT(X/2) to a boolean value / incorrect operator Can’t add string to number / Message ← "Done" + LENGTH(MyString) "Done" is not a number One mark for each row 1(c) Structure: 3 • Record Justification: • Allows different data types • to be stored under one identifier Mark as follows: One mark for Structure Two marks for justification. Alternative • Two (1D) arrays • One of string, one of integer • Where same index links the name with the score

This question in 9618/21 May/June 2021

Q2 · Four program modules form part of a program for a library 9618/21 May/June 2021

2 (a) Four program modules form part of a program for a library. A description of the relationship between the modules is summarised as follows: Module name Description UpdateLoan() • Calls either LoanExtend() or LoanReturn() • Called with parameters LoanID and BookID • Calls CheckReserve() to see whether the book has been LoanExtend() reserved for another library user • Returns TRUE if the loan has been extended, otherwise returns FALSE • Called with BookID CheckReserve() • Returns TRUE if the book has been reserved, otherwise returns FALSE • Called with parameters LoanID and BookID LoanReturn() • Returns a REAL (which is the value of the fine to be paid in the case of an overdue loan) Draw a structure chart to show the relationship between the four modules and the parameters passed between them. [5] (b) The definition for module LoanReturn() is amended as follows: Module name Description Called with parameters LoanID, BookID and Fine LoanReturn() The module code checks whether the book has been returned on time and then assigns a new value to Fine • LoanID and BookID are of type STRING • Fine is of type REAL Write the pseudocode header for the amended module LoanReturn(). … … [2] (c) A program will: • input 50 unique integer values • output the largest value • output the average of the values excluding the largest value. Draw a program flowchart to represent the algorithm. Variable declarations are not required. It is not necessary to check that each input value is unique. [6]

13 marks

Mark scheme: 2(a) 5 One mark for: 1 All four boxes correctly labelled and positioned 2 Selection diamond (only on UpdateLoan and no iteration arrows) 3 Parameters to and from LoanExtend() 4 Parameters to and from CheckReserve() 5 Parameters to and from LoanReturn() 2(b) PROCEDURE LoanReturn (LoanID, BookID : STRING, 2 BYREF Fine : REAL) One mark for each underlined part 2(c) Example solution: 6 One mark for each functional group as listed below: 2(c) Explanation of mark points: 1 Initialise MAX to first value input 2 Set Total to zero 3 Input 49 more values (or 50 values in total) 4 Sum all values input 5 Set new MAX when Input value > MAX in a loop 6 Sum all but largest (or subtract MAX from total), calculate and output average

This question in 9618/21 May/June 2021

Q3 · A program is being developed to help manage the membership of a football club 9618/23 May/June 2021

1 (a) A program is being developed to help manage the membership of a football club. Complete the following identifier table. Example Explanation Variable name Data type value The preferred name of the member "Wong" joining the football club A value to indicate whether an FALSE existing member of the club lives at the same address When the member joined the football 19/02/1983 club The number of points a member has 1345 earned. Members of the club earn points for different activities. [4] (b) Each pseudocode statement in the following table may contain an error due to the incorrect use of the function or operator. Describe the error in each case, or write ‘NO ERROR’ if the statement contains no error. You can assume that none of the variables referenced are of an incorrect type. Statement Error Result 2 & 4 SubString MID("pseudocode", 4, 1) IF x = 3 OR 4 THEN Result Status AND INT(x/2) Message "Done" + LENGTH(MyString) [5] (c) The following data items need to be stored for each student in a group: • student name (a string) • test score (an integer). State a suitable data structure and justify your answer. Structure … Justification … … … [3]

12 marks

Mark scheme: Question Answer Marks 1(a) 4 Example Explanation Variable name Data type value "Wong" The preferred name of the MemberName STRING member joining the football club FALSE A value to indicate FamilyMember BOOLEAN whether an existing member of the club lives at the same address 19/02/1983 When the member joined StartDate DATE the football club 1345 The number of points a Points INTEGER member has earned. Members of the club earn points for different activities. One mark for each appropriate variable name plus data type 1(b) 5 Statement Error Should be arithmetic Result ← 2 & 4 operator (not &) // 2 and 4 should be CHAR / STRING SubString ← MID("pseudocode", 4, 1) NO ERROR Not Boolean values / IF x = 3 OR 4 THEN incorrect operator // Condition incorrect INT(X/2) doesn't evaluate Result ← Status AND INT(X/2) to a boolean value / incorrect operator Can’t add string to number / Message ← "Done" + LENGTH(MyString) "Done" is not a number One mark for each row 1(c) Structure: 3 • Record Justification: • Allows different data types • to be stored under one identifier Mark as follows: One mark for Structure Two marks for justification. Alternative • Two (1D) arrays • One of string, one of integer • Where same index links the name with the score

This question in 9618/23 May/June 2021

Q4 · Four program modules form part of a program for a library 9618/23 May/June 2021

2 (a) Four program modules form part of a program for a library. A description of the relationship between the modules is summarised as follows: Module name Description UpdateLoan() • Calls either LoanExtend() or LoanReturn() • Called with parameters LoanID and BookID • Calls CheckReserve() to see whether the book has been LoanExtend() reserved for another library user • Returns TRUE if the loan has been extended, otherwise returns FALSE • Called with BookID CheckReserve() • Returns TRUE if the book has been reserved, otherwise returns FALSE • Called with parameters LoanID and BookID LoanReturn() • Returns a REAL (which is the value of the fine to be paid in the case of an overdue loan) Draw a structure chart to show the relationship between the four modules and the parameters passed between them. [5] (b) The definition for module LoanReturn() is amended as follows: Module name Description Called with parameters LoanID, BookID and Fine LoanReturn() The module code checks whether the book has been returned on time and then assigns a new value to Fine • LoanID and BookID are of type STRING • Fine is of type REAL Write the pseudocode header for the amended module LoanReturn(). … … [2] (c) A program will: • input 50 unique integer values • output the largest value • output the average of the values excluding the largest value. Draw a program flowchart to represent the algorithm. Variable declarations are not required. It is not necessary to check that each input value is unique. [6]

13 marks

Mark scheme: 2(a) 5 One mark for: 1 All four boxes correctly labelled and positioned 2 Selection diamond (only on UpdateLoan and no iteration arrows) 3 Parameters to and from LoanExtend() 4 Parameters to and from CheckReserve() 5 Parameters to and from LoanReturn() 2(b) PROCEDURE LoanReturn (LoanID, BookID : STRING, 2 BYREF Fine : REAL) One mark for each underlined part 2(c) Example solution: 6 One mark for each functional group as listed below: 2(c) Explanation of mark points: 1 Initialise MAX to first value input 2 Set Total to zero 3 Input 49 more values (or 50 values in total) 4 Sum all values input 5 Set new MAX when Input value > MAX in a loop 6 Sum all but largest (or subtract MAX from total), calculate and output average

This question in 9618/23 May/June 2021

Q5 · An algorithm to sort a 1D array into ascending order is described as follows: • move the… 9618/21 Oct/Nov 2021

2 (a) An algorithm to sort a 1D array into ascending order is described as follows: • move the largest value to the end • keep repeating until the array is sorted. Apply the process of stepwise refinement to this algorithm in order to produce a more detailed description. Write the more detailed description using structured English. Your explanation of the algorithm should not include pseudocode statements. … … … … … … … … … … … … … … … … … … [6] (b) The program flowchart shown describes a simple algorithm. START Set Count to 1 Set Flag to FALSE Is Flag = YES FALSE AND Count <= 5 ? NO ReBoot() Set Count to Count + 1 Set Flag to Check() YES Is Flag = FALSE ? NO Alert(27) END Write pseudocode for the simple algorithm shown on page 6. … … … … … … … … … … … … … … … … [6]

12 marks

Mark scheme: 2(a) One mark for reference to: 6 1 The use a variable as an index to the array 2 A loop to iterate through the array 3 An Inner loop (with a reducing range) 4 Test if current element is greater than next element 5 if so then swap elements 6 Description of swap 7 Attempt at efficient algorithm Max 6 marks 2(b) Count ← 1 6 Flag ← FALSE WHILE Flag = FALSE AND Count <= 5 CALL ReBoot() Count ← Count + 1 Flag ← Check() ENDWHILE IF Flag = FALSE THEN CALL Alert(27) ENDIF One mark per point: 1 Initialisation of Count AND Flag 2 WHILE ... ENDWHILE // REPEAT ... UNTIL loop 3 ... including both conditions 4 Call ReBoot() AND increment Count inside the loop 5 Assign return value from Check() to Flag inside the loop 6 Final test of Flag AND call to Alert(27) not in a loop

This question in 9618/21 Oct/Nov 2021

Q6 · A programmer applies decomposition to a problem that she has been asked to solve 9618/22 Oct/Nov 2021

1 (a) A programmer applies decomposition to a problem that she has been asked to solve. Describe decomposition. … … … … … … [2] (b) The following pseudocode assigns a value to an element of an array: ThisArray[n] 42 ← Complete the following table by writing the answer for each row. Answer The number of dimensions of ThisArray The technical terms for minimum and maximum values that the variable n may take The technical term for the variable n in the pseudocode statement [3] (c) Complete the pseudocode expressions so that they evaluate to the values shown. Any functions and operators used must be defined in the insert. Expression Evaluates to … 67 ('C') … 54 2 * ("27") … 13 (27 / … ) "Sub" & … ("Abstraction" , … , … ) "Subtract" [4] (d) Evaluate the expressions given in the following table. The variables have been assigned values as follows: PumpOn TRUE ← PressureOK TRUE ← HiFlow FALSE ← Expression Evaluates to PressureOK AND HiFlow PumpOn OR PressureOK NOT PumpOn OR (PressureOK AND NOT HiFlow) NOT (PumpOn OR PressureOK) AND NOT HiFlow [2]

11 marks

Mark scheme: Question Answer Marks 1(a) The process involves: 2 1 Breaking down a problem / task into sub problems / steps / smaller parts 2 In order to explain / understand // easier to solve the problem 3 Leading to the concept of program modules // assigning problem parts to teams Max 2 1(b) 3 Answer The number of dimensions of ThisArray 1 The technical terms for minimum and Lower bound, upper bound maximum values that variable n may take The technical term for the variable n in the Index / Subscript pseudocode expression. One mark per row 1(c) 4 Expression Evaluates to ASC('C') 67 2 * STR_TO_NUM ("27") 54 INT(27 / 2) 13 "Sub" & MID("Abstraction" , 4 , 5) "Subtract" One mark per row Function names must be exactly as shown 1(d) 2 Expression Evaluates to PressureOK AND HiFlow FALSE PumpOn OR PressureOK TRUE NOT PumpOn OR (PressureOK AND NOT HiFlow) TRUE NOT (PumpOn OR PressureOK) AND NOT HiFlow FALSE 1 mark for any two rows correct 2 marks for all rows correct.

This question in 9618/22 Oct/Nov 2021

Q7 · An algorithm to sort a 1D array into ascending order is described as follows: • move the… 9618/23 Oct/Nov 2021

2 (a) An algorithm to sort a 1D array into ascending order is described as follows: • move the largest value to the end • keep repeating until the array is sorted. Apply the process of stepwise refinement to this algorithm in order to produce a more detailed description. Write the more detailed description using structured English. Your explanation of the algorithm should not include pseudocode statements. … … … … … … … … … … … … … … … … … … [6] (b) The program flowchart shown describes a simple algorithm. START Set Count to 1 Set Flag to FALSE Is Flag = YES FALSE AND Count <= 5 ? NO ReBoot() Set Count to Count + 1 Set Flag to Check() YES Is Flag = FALSE ? NO Alert(27) END Write pseudocode for the simple algorithm shown on page 6. … … … … … … … … … … … … … … … … [6]

12 marks

Mark scheme: 2(a) One mark for reference to: 6 1 The use a variable as an index to the array 2 A loop to iterate through the array 3 An Inner loop (with a reducing range) 4 Test if current element is greater than next element 5 if so then swap elements 6 Description of swap 7 Attempt at efficient algorithm Max 6 marks 2(b) Count ← 1 6 Flag ← FALSE WHILE Flag = FALSE AND Count <= 5 CALL ReBoot() Count ← Count + 1 Flag ← Check() ENDWHILE IF Flag = FALSE THEN CALL Alert(27) ENDIF One mark per point: 1 Initialisation of Count AND Flag 2 WHILE ... ENDWHILE // REPEAT ... UNTIL loop 3 ... including both conditions 4 Call ReBoot() AND increment Count inside the loop 5 Assign return value from Check() to Flag inside the loop 6 Final test of Flag AND call to Alert(27) not in a loop

This question in 9618/23 Oct/Nov 2021

Q8 · A programmer draws a program flowchart to show the sequence of steps required to solve a… 9618/21 May/June 2022

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 To calculate the number of days until my next MyDOB 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]

11 marks

Mark scheme: Question Answer Marks 1(a) An algorithm 1 1(b)(i) 4 Variable Use of variable Data type Temp Stores the average temperature REAL PetName Stores the name of my pet STRING MyDOB To calculate how many days until my DATE next birthday LightOn Stores state of light; light is only on or off BOOLEAN One mark for each data type 1(b)(ii) One mark for variable name, and one for reason 2 Variable: Temp Reason: Name does not indicate what the variable is used for 1(c) 4 Expression Evaluation INT((31 / 3) + 1) 11 MID(TO_UPPER("Version"), 4, 2) "SI" TRUE AND (NOT FALSE) TRUE NUM_TO_STR(27 MOD 3) "0" One mark per row

This question in 9618/21 May/June 2022

Q9 · A programmer is testing a program using an Integrated Development Environment (IDE) 9618/22 May/June 2022

1 (a) A programmer is testing a program using an Integrated Development Environment (IDE). The programmer wants the program to stop when it reaches a specific instruction or program statement in order to check the value assigned to a variable. Give the technical term for the position at which the program stops. … [1] (b) The following table lists some activities from the program development life cycle. Complete the table by writing the life cycle stage for each activity. Activity Life cycle stage An identifier table is produced. Syntax errors can occur. The developer discusses the program requirements with the customer. A trace table is produced. [4] (c) An identifier table includes the names of identifiers used. State two other pieces of information that the identifier table should contain. 1 … 2 … [2] (d) 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. You can assume that none of the variables referenced are of an incorrect type. Statement Error Status TRUE AND FALSE IF LENGTH("Password") < "10" THEN Code LCASE("Electrical") Result IS_NUM(-27.3) [4]

11 marks

Mark scheme: Question Answer Marks 1(a) Correct answer only: 1 Breakpoint 1(b) One mark per row 4 Activity Life cycle stage An identifier table is produced. Design Syntax errors can occur. Coding The developer discusses the program requirements with the Analysis customer. A trace table is produced. Testing 1(c) One mark per bullet point to Max 2 2  A description of what the identifier is used for / the purpose of the identifier  The data type of the identifier  The number of elements of an array // the length of a string  An example data value  Value of any constants used  The scope of the variable (local or global) 1(d) One mark per row 4 Statement Error Status  TRUE AND FALSE NO ERROR IF LENGTH("Password") < "10" shouldn’t be a string // must be an "10" THEN integer Code  Parameter must be a char // cannot be a LCASE("Electrical") string Alternative: LCASE should be TO_LOWER Result  IS_NUM(-27.3) Parameter must be a string / char // cannot be a number

This question in 9618/22 May/June 2022

Q10 · A programming language has string functions equivalent to those given in the insert 9618/22 May/June 2022

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]

6 marks

Mark scheme: 7(a) FUNCTION MID(InString : STRING, Start, Num : INTEGER) 4 RETURNS STRING DECLARE MidString : STRING DECLARE InStringLen : INTEGER InStringLen  LENGTH(InString) // solution for RIGHT() then LEFT() MidString  RIGHT(InString, InStringLen – Start + 1) MidString  LEFT(MidString, Num) // alternative solution for LEFT() then RIGHT() MidString  LEFT(InString, Start + Num - 1) MidString  RIGHT(MidString, Num) RETURN MidString ENDFUNCTION Marks as follows: 1 Function heading and ending including parameters and return type 2 Correct use of one substring functions 3 Correct use of both substring functions (in correct sequence) 4 Return substring after a reasonable attempt 7(b) One mark per point 2 Check that:  Start and/or Num are >= 1 // positive  Length of InString is "sufficient" for required operation

This question in 9618/22 May/June 2022

Q11 · An algorithm includes a number of complex calculations 9618/21 Oct/Nov 2022

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]

12 marks

Mark scheme: Question Answer Marks 1(a) One mark per point: 3 1 They are tried and tested so free from errors 2 They perform a function that you may not be able to program yourself (for example encryption) 3 They are readily available / speed up development time 1(b)(i) One mark per point: 3 1 Algorithm to process / search / organise the data is easier to implement // Values may be accessed via a loop-controlled variable / iterated through using index 2 Makes the program easier to design / code / test / understand 3 Multiple instances referenced via a single identifier / so fewer identifiers needed // Easier to amend the program when the number of students increases 1(b)(ii) One mark per point: 2 Purpose: It identifies / references an individual array element // provides the index to the array Data type: Integer 1(c) One mark per row: 4 Statement Error IF EMPTY  "" THEN Should be "=" not  Status  IS_NUM(-23.4) Parameter should be a string (or char) // should not be a real X  STR_TO_NUM("37") + 5 NO ERROR Y  STR_TO_NUM("37" + "5") Wrong operator – should be & or Parameter is not a string

This question in 9618/21 Oct/Nov 2022

Q12 · A teacher is designing a program to perform simple syntax checks on programs written by… 9618/21 Oct/Nov 2022

8 A teacher is designing a program to perform simple syntax checks on programs written by students. Student programs are submitted as text files, which are known as project files. A project file may contain blank lines. The teacher has defined the first program module as follows: Module Description • takes the name of an existing project file as a parameter of type string CheckFile() • returns TRUE if the file is valid (it contains at least 10 non-blank lines), otherwise returns FALSE (a) Write pseudocode for module CheckFile(). … … … … … … … … … … … … … … … … … … … … … … … … [7] Further modules are defined as follows: Module Description • takes a line from a project file as a parameter of type string CheckLine() • returns zero if the line is blank or contains no syntax error, otherwise returns an error number as an integer • takes two parameters: ○ the name of a project file as a string ○ the maximum number of errors as an integer • uses CheckFile() to test the project file. Outputs an error CountErrors() message and ends if the project file is not valid • calls CheckLine() for each line in the project file • counts the number of errors • outputs the number of errors or a warning message if the maximum number of errors is exceeded (b) CountErrors() is called to check the project file Jim01Prog.txt and to stop if more than 20 errors are found. Write the pseudocode statement for this call. … … [2] (c) Write pseudocode for module CountErrors(). Assume CheckFile() and CheckLine() have been written and can be used in your solution. … … … … … … … … … … … … …

9 marks

Mark scheme: 8(a) One mark for each point (Max 7) as follows: 7 1 Function heading and ending including parameter and return type 2 Declaration and initialisation of local Integer for Count 3 OPEN in READ mode and CLOSE 4 Conditional loop until EOF() 5 Read a line in a loop 6 If non-blank, increment count in a loop 7 Terminate loop when 10 non-blank lines have been read 8 Return Boolean in both cases FUNCTION CheckFile(Thisfile : STRING) RETURNS BOOLEAN DECLARE Valid : BOOLEAN DECLARE ThisLine : STRING DECLARE Count : INTEGER Count  0 Valid  FALSE OPEN ThisFile FOR READ WHILE NOT EOF(ThisFile) AND Valid = FALSE READFILE ThisFile, ThisLine IF ThisLine <> "" THEN Count  Count + 1 IF Count > 9 THEN Valid  TRUE ENDIF ENDIF ENDWHILE CLOSEFILE ThisFile RETURN Valid ENDFUNCTION 8(b) CALL CountErrors("Jim01Prog.txt", 20) 2 One mark for each: 1 Module name, at least one parameter in brackets and one parameter correct 2 Completely correct statement 8(c) Mark as follows: 8 1 Procedure heading and ending including parameters 2 Declaration and initialisation of local Integer value for ErrCount 3 Use of CheckFile(), output message and terminate if it returns FALSE 4 Conditional loop until EOF() 5 ...or ErrCount > MaxErrors 6 Read line and use as parameter to CheckLine()in a loop 7 Test return value and increment ErrCount if non-zero in a loop 8 Output either message once only as appropriate PROCEDURE CountErrors(ThisFile : STRING, MaxErrors : INTEGER) DECLARE ErrCount, ThisError : INTEGER DECLARE ThisLine : STRING ErrCount  0 IF CheckFile(ThisFile) = FALSE THEN OUTPUT "That program file is not valid" ELSE OPEN ThisFile FOR READ REPEAT READFILE, ThisFile, ThisLine ThisError  CheckLine(ThisLine) IF ThisError <> 0 THEN ErrCount  ErrCount + 1 ENDIF UNTIL ErrCount > MaxErrors OR EOF(ThisFile) IF EOF(ThisFile) = FALSE THEN OUTPUT "Check terminated – too many errors" ELSE OUTPUT "There were ", ErrCount, " errors." ENDIF CLOSEFILE ThisFile ENDIF ENDPROCEDURE 8(d) One mark for each (Max 2): 2 Examples: 1 Incorrect block structure. Missing keyword denoting part of block (for example ENDPROCEDURE, ENDFUNCTION, ENDTYPE) 2 Data type errors, for example, assigning an integer value to a string 3 Identifier used before it is declared 4 Incorrect parameter use

This question in 9618/21 Oct/Nov 2022

Q13 · A programmer is developing an algorithm to solve a problem 9618/22 Oct/Nov 2022

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]

11 marks

Mark scheme: Question Answer Marks 1(a)(i) One mark for each point (Max 2): 2 • When a task which is repeated / reused / performed in several places • When a part of an algorithm performs a specific task • Reduces complexity of program / program is simplified // subroutine already available • Testing / debugging / maintenance is easier 1(a)(ii) One mark for each part: 2 Term: Parameter(s) Use: to pass values / arguments to the procedure 1(b) One mark for test stage, one mark for each description point 4 (Max 3 for Description) Test stage: Beta testing Description: 1 Testing carried out by a small group of (potential) users 2 Users will check that the software works as required / works in the real world / does not contain errors 3 Users will feedback problems / suggestions for improvement 4 Problems / suggestions identified are addressed (before the program is sold) 1(c) One mark per row: 3 Expression Evaluation MID(CharList, MONTH(FlagDay), 1) 'D' INT(Count / LENGTH(CharList)) 4 (Count >= 99) AND (DAY(FlagDay) > 23) FALSE

This question in 9618/22 Oct/Nov 2022

Q14 · A programmer has written a program which includes the function Calculate() 9618/21 May/June 2023

1 A programmer has written a program which includes the function Calculate(). When the program is run, the function returns an unexpected value. (a) Describe how a typical Integrated Development Environment (IDE) could be used to help debug the program to find the errors in the function Calculate(). … … … … … … … … [4] (b) The algorithm for function Calculate() contains the three pseudocode statements shown. Describe the error in each statement or write ‘no error’ if the statement contains no error. Assume any variables used are of the correct type for the given function. Statement 1: Index STR_TO_NUM(("27") + 2) Error … … Statement 2: Index STR_TO_NUM(MID("CPE1704TKS", 4, 2)) Error … … Statement 3: IF MONTH(ThisDate) > '6' THEN Error … … [3] (c) The program contains variables with values as follows: Variable Value Active TRUE Points 75 Exempt FALSE (i) Complete the table by evaluating each expression. Expression Evaluation 1 (Points > 99) OR Active 2 (Points MOD 2 = 0) OR Exempt 3 (Points <= 75) AND (Active OR Exempt) 4 (Active OR NOT Active) AND NOT Exempt [2] (ii) Write expression 4 from the table in part (c)(i) in its simplest form. … [1]

10 marks

Mark scheme: Question Answer Marks 1(a) For example: 4 Could set a breakpoint to stop the program at a particular point / instruction then the value of variables could be checked using a report/watch window while single stepping can be used to execute one statement/line at a time. Marks available as follows:  One mark for each underlined term  One mark for an explanation of each term Note: max 4 marks 1(b) One mark for correct description of: 3 Error 1: Brackets mismatch // 2/value should be added after brackets/function // Addition between a string and a number is not valid // STR_TO_NUM / the function needs to be passed a string / not an integer Error 2: No Error Error 3: MONTH() returns an integer and this is being compared with a character/string // Integer cannot be compared to a string // 6 should not be in quotes 1(c)(i) 2 Expression Evaluation 1 (Points > 99) OR Active TRUE 2 (Points MOD 2 = 0) OR Exempt FALSE 3 (Points <= 75) AND (Active OR Exempt) TRUE 4 (Active OR NOT Active) AND NOT Exempt TRUE One mark for any two rows correct Two marks for all rows correct 1(c)(ii) NOT Exempt 1

This question in 9618/21 May/June 2023

Q15 · A program stores a user’s date of birth using a variable MyDOB of type DATE 9618/22 May/June 2023

2 A program stores a user’s date of birth using a variable MyDOB of type DATE. (a) Write a pseudocode statement, using a function from the insert, to assign the value corresponding to 17/11/2007 to MyDOB. … [1] (b) MyDOB has been assigned a valid value representing the user’s date of birth. Write a pseudocode statement to calculate the number of months from the month of the user’s birth until the end of the year and to assign this to the variable NumMonths. For example, if MyDOB contains a value representing 02/07/2008, the value 5 would be assigned to NumMonths. … [2] (c) The program will output the day of the week corresponding to MyDOB. For example, given the date 22/06/2023, the program will output "Thursday". An algorithm is required. An array will be used to store the names of the days of the week. Define the array and describe the algorithm in four steps. Do not use pseudocode statements in your answer. Array definition … … Step 1 … … … Step 2 … … … Step 3 … … … Step 4 … … … [6]

9 marks

Mark scheme: 2(a) MyDOB  SETDATE(17, 11, 2007) 1 2(b) NumMonths  12 - MONTH(MyDOB) 2 One mark per underlined part 2(c) 6 One mark per array definition bullet:  A (1D) array containing 7 elements  of type STRING One mark per Step: Step1: Assign value "Sunday" to first element, "Monday" to second element etc. Step2: Use the function DAYINDEX() to return / find the day number from MyDoB Step3: Use the returned value as the array index / to access the element that contains the name / string Step4: Output the element / name / string Note: Max 2 for Array definition, Max 4 for steps

This question in 9618/22 May/June 2023

Q16 · A programmer has produced the following pseudocode to output the square root of the… 9618/22 May/June 2023

5 A programmer has produced the following pseudocode to output the square root of the numbers from 1 to 10. Line numbers are for reference only. 10 DECLARE Num : REAL 11 Num 1.0 ... 40 REPEAT 41 CALL DisplaySqrt(Num) 42 Num Num + 1.0 43 UNTIL Num > 10 ... 50 PROCEDURE DisplaySqrt(BYREF ThisNum : REAL) 51 OUTPUT ThisNum 52 ThisNum SQRT(ThisNum) // SQRT returns the square root 53 OUTPUT " has a square root of ", ThisNum 54 ENDPROCEDURE The pseudocode is correctly converted into program code. Function SQRT() is a library function and contains no errors. The program code compiles without errors, but the program gives unexpected results. These are caused by a design error. (a) Explain why the program gives unexpected results. … … … … … … [3] (b) Explain why the compiler does not identify this error. … … [1] (c) Describe how a typical Integrated Development Environment (IDE) could be used to identify this error. … … … … … … [3] (d) The pseudocode is converted into program code as part of a larger program. During compilation, a complex statement generates an error. The programmer does not want to delete the complex statement but wants to change the statement so that it is ignored by the compiler. State how this may be achieved. … … [1]

8 marks

Mark scheme: 5(a) One mark per point: 3  parameter / Num has been passed by reference // should have been passed by value  so when the value / ThisNum is modified (in procedure DisplaySqrt())  the new value will be used in the loop (lines 40–43) // Num will be changed to modified value 5(b)  The rules of the language have not been broken // there are no syntax 1 errors 5(c) Could use an IDE to: 3  Set a breakpoint to stop the program at a certain line / statement / point  Step through the program line by line / statement by statement  checking the value of 'num' / a variable using a report / watch window One mark per bullet 5(d) Answers include: 1  Change the statement into a comment  Change the statement to a string representing a literal value and assign it to a variable / output it Note: max 1 mark

This question in 9618/22 May/June 2023

Q17 · The following pseudocode represents part of the algorithm for a program 9618/23 May/June 2023

1 The following pseudocode represents part of the algorithm for a program. Line numbers are for reference only. 10 DECLARE Sheet4 : ARRAY[1:2, 1:50] OF INTEGER … 100 FOR PCount 0 TO 49 101 Sheet4[1, PCount] 0 102 Sheet4[2, PCount] 47 103 NEXT PCount (a) The pseudocode contains references to an array. Complete the table by writing the answer for each row. Answer The dimension of the array The name of the variable used as an array index The number of elements in the array [3] (b) The pseudocode contains two errors. One error is that variable PCount has not been declared. Identify the other error and state the line number where it occurs. Error … … … Line number … [2] (c) The pseudocode does not include a declaration for PCount. State the data type that should be used in the declaration. … [1] (d) The pseudocode statements given in the following table are used in other parts of the algorithm. Complete the table by placing one or more ticks (✓) in each row. The first row has already been completed. Pseudocode statement Input Process Output INPUT MyChoice ✓ OUTPUT FirstName & LastName WRITEFILE YourFile, TextLine READFILE MyFile, TextLine Result SQRT(NextNum) [4]

10 marks

Mark scheme: Question Answer Marks 1(a) 3 Answer The dimension of the array 2 The name of the variable used as an array index PCount The number of elements in the array 100 1(b) One mark per point: 2  The (second dimension/index of the) array is declared from 1 to 50 but the loop runs from 0 to 49  Line number: 10 / 100 / 101 / 102 1(c) Integer 1 1(d) One mark for each of rows 2 - 5 4 Pseudocode statement Input Process Output INPUT MyChoice  OUTPUT FirstName & LastName   WRITEFILE OutputFile, TextLine  READFILE MyFile, TextLine  Result  SQRT(NextNum) 

This question in 9618/23 May/June 2023