Skip to the worksheet
Revision Library
Choose a subject

Programming Fundamentals - Worksheets, Questions and Revision

17 original exam-style questions - 8 pages of questions with a full mark scheme - free printable PDF.

Grades 1-9

This topic is chapter 10 of GCSE Computer Science Topic Workbook 1 and chapter 10 of GCSE Computer Science 10-Minute Tests.

Revision Library
revisionlibrary.co.uk
GCSE · Computational thinking, algorithms and programming

2.2 Programming Fundamentals

OCR J277 · Calculators not allowed · about 95 minutes
Total Marks
Name: _______________________________    Date: ____ / ____ / ______
Answer ALL questions. Show all your working.
1
This question is about variables and constants.
(a)A program calculates the area of a circle using the formula area = π * radius2. Define the term 'variable' and the term 'constant', giving one example of each from this program.(2)
(b)State two benefits to a programmer of using a named constant, such as PI, instead of writing the literal value 3.14159 directly wherever it is needed in the code.(2)
(Total for Question 1 is 4 marks)
2
Complete the table by evaluating each expression.
17 DIV 5 = ?
17 MOD 5 = ?
2 ^ 3 = ?
(10 - 3) * 2 = ?
(Total for Question 2 is 4 marks)
3
Given the variables x = 7, y = 3 and z = 10, state whether each expression evaluates to True or False.
(i) x > y AND z < y
(ii) NOT (x == y)
(iii) (x + y) ≥ z
(iv) x < y OR z > y
(Total for Question 3 is 4 marks)
4
A program reads a user's age from the keyboard using INPUT, which always stores the value as a String.
(a)Write one line of pseudocode that converts the String stored in ageInput into an integer and stores the result in a variable called age.(1)
(b)Explain why this conversion is necessary before the program can use age in a calculation such as age + 1.(2)
(Total for Question 4 is 3 marks)
5
Write pseudocode that opens a text file called 'players.txt' for reading, reads every line in the file one at a time until the end of the file is reached, outputs each line, then closes the file.
(Total for Question 5 is 5 marks)
6
A sports club keeps a database table Members(MemberID, FirstName, Surname, Town, JoinYear).

Write an SQL query that selects the FirstName and Surname of every member from the town 'Leeds', ordered alphabetically by Surname.
(Total for Question 6 is 4 marks)
7
A program classifies a percentage exam score using the following pseudocode.
INPUT score
IF score >= 90 THEN
  OUTPUT "Distinction"
ELSE IF score >= 70 THEN
  OUTPUT "Merit"
ELSE IF score >= 40 THEN
  OUTPUT "Pass"
ELSE
  OUTPUT "Fail"
ENDIF
(a)Complete the trace table below by stating the output produced for each input score: 95, 68, 40, 39.(4)
(b)State the term used for test data that lies exactly on one of the boundaries in this algorithm, and give one example value from the algorithm that is boundary data.(2)
(Total for Question 7 is 6 marks)
8
A program uses the following pseudocode.
total = 0
FOR i = 1 TO 5
  total = total + i * 2
NEXT i
OUTPUT total
(a)Complete a trace table for this algorithm, showing the value of i and the value of total after each pass through the loop.(5)
(b)State the value output by this algorithm.(1)
(Total for Question 8 is 6 marks)
9
A variable name stores the string "Amelia Khan".
(a)State the value returned by each of the following: (i) LENGTH(name) (ii) SUBSTRING(0, 6, name) (iii) UCASE(name)(3)
(b)Write one line of pseudocode that outputs just the first character of name.(1)
(c)Write a line of pseudocode that joins the title "Ms " to the front of name and stores the result in a new variable called fullName.(2)
(Total for Question 9 is 6 marks)
10
Write an algorithm, using pseudocode, that repeatedly asks the user to input an integer age. The algorithm must use a WHILE loop to reject any value that is not between 0 and 120 inclusive, printing an error message and asking again, and must only continue once a valid age has been entered.
(Total for Question 10 is 5 marks)
11
An array temps stores 6 daily temperatures, in degrees Celsius, recorded in Cambridge: [14, 9, 17, 20, 11, 8].

Write an algorithm using a FOR loop that calculates and outputs the mean of the values in temps.
(Total for Question 11 is 6 marks)
12
Using the same Members table from Question 6, write an SQL query that counts how many members joined in the year 2020.
(Total for Question 12 is 3 marks)
13
Write a function called findLargest that takes two integer parameters, num1 and num2, and returns whichever value is the larger of the two.
(Total for Question 13 is 5 marks)
14
A procedure declares a variable called total that is used only inside that procedure.
(a)State what is meant by the term 'local variable'.(1)
(b)Identify whether total is a local or global variable, and explain the problem this could cause if another part of the program needs to use the value stored in total after the procedure has finished running.(3)
(Total for Question 14 is 4 marks)
15
A programmer intended the following algorithm to sum only the even numbers from 1 to 10, but it contains a logic error.
total = 0
FOR num = 1 TO 10
  IF num MOD 2 == 1 THEN
    total = total + num
  ENDIF
NEXT num
OUTPUT total
(a)State what this algorithm actually calculates as it is currently written.(1)
(b)Identify the line of pseudocode that contains the logic error.(1)
(c)State the corrected line of pseudocode needed so the algorithm sums only the even numbers.(1)
(d)Using the corrected algorithm, state the value that would be output.(2)
(Total for Question 15 is 5 marks)
16
A game of noughts and crosses stores its board as a 2D array board[0:2, 0:2], where each cell contains "X", "O" or "-" for an empty cell.

Write pseudocode, using nested FOR loops, that searches every cell of board and counts how many cells contain "X", storing the result in a variable called count.
(Total for Question 16 is 6 marks)
17
A large program is currently written as one long sequence of instructions. Discuss the benefits to the programmer of breaking the program down into functions and procedures (subprograms) instead. Refer to code reuse, testing, readability and maintenance in your answer.
(Total for Question 17 is 6 marks)
Mark scheme · 2.2 Programming Fundamentals

Question 1

  • (a) variable: a named storage location whose value can change while the program runs, e.g. radiusB1
  • (a) constant: a named storage location whose value stays fixed throughout the program, e.g. π (3.14159)B1
  • (a) Answer: Variable: radius (its value changes each time the program runs). Constant: π = 3.14159 (its value never changes).
  • (b) if the value needs updating it only has to be changed in one place, reducing errors oeB1
  • (b) a meaningful name makes the code easier to read and understand oeB1
  • (b) Answer: 1. Only one place needs updating if the value changes. 2. A named constant makes the code's purpose clearer to read.

Question 2

  • 17 DIV 5 = 3 caoB1
  • 17 MOD 5 = 2 caoB1
  • 2 ^ 3 = 8 caoB1
  • (10 - 3) * 2 = 14 caoB1
  • Answer: 3, 2, 8, 14

Question 3

  • (i) False caoB1
  • (ii) True caoB1
  • (iii) True caoB1
  • (iv) True caoB1
  • Answer: (i) False (ii) True (iii) True (iv) True

Question 4

  • (a) age = STRING_TOINT(ageInput) or equivalent cast, any correct syntaxM1
  • (a) Answer: age = STRING_TOINT(ageInput)
  • (b) INPUT stores the value as a String / text data typeB1
  • (b) arithmetic operators only work on numeric data types, so the String must be cast to an integer first oeB1
  • (b) Answer: Because INPUT always produces a String, and a String cannot be used with + in arithmetic; it must first be cast to an Integer.

Question 5

  • file opened for reading, e.g. file = OPENFILE("players.txt", READ)M1
  • loop condition correctly tests for end of file using EOF(file)M1
  • a line is read from the file inside the loop using READFILEM1
  • each line read is output inside the loopM1
  • file closed after the loop using CLOSEFILE(file); any correct logic, ignore minor syntaxM1
  • Answer:
    file = OPENFILE("players.txt", READ)
    WHILE NOT EOF(file)
      line = READFILE(file)
      OUTPUT line
    ENDWHILE
    CLOSEFILE(file)

Question 6

  • SELECT FirstName, SurnameM1
  • FROM MembersM1
  • WHERE Town = 'Leeds'M1
  • ORDER BY Surname; any correct logic, ignore case/semicolonM1
  • Answer: SELECT FirstName, Surname FROM Members WHERE Town = 'Leeds' ORDER BY Surname;

Question 7

  • (a) score 95 -> Distinction caoB1
  • (a) score 68 -> Pass caoB1
  • (a) score 40 -> Pass caoB1
  • (a) score 39 -> Fail caoB1
  • (a) Answer: 95 -> Distinction, 68 -> Pass, 40 -> Pass, 39 -> Fail
  • (b) boundary data (accept borderline data)B1
  • (b) any one of 90, 70 or 40 given as an exampleB1
  • (b) Answer: Boundary data, for example 40.

Question 8

  • (a) i = 1, total = 2 caoB1
  • (a) i = 2, total = 6 caoB1
  • (a) i = 3, total = 12 caoB1
  • (a) i = 4, total = 20 caoB1
  • (a) i = 5, total = 30 caoB1
  • (a) Answer: i: 1,2,3,4,5 -> total: 2,6,12,20,30
  • (b) 30, follow through from part (a)B1
  • (b) Answer: 30

Question 9

  • (a) (i) 11 caoB1
  • (a) (ii) Amelia caoB1
  • (a) (iii) AMELIA KHAN caoB1
  • (a) Answer: (i) 11 (ii) Amelia (iii) AMELIA KHAN
  • (b) OUTPUT SUBSTRING(0, 1, name) or equivalent, any correct syntaxM1
  • (b) Answer: OUTPUT SUBSTRING(0, 1, name)
  • (c) correct use of concatenation (+) between "Ms " and nameM1
  • (c) correct assignment to fullName in the correct orderA1
  • (c) Answer: fullName = "Ms " + name

Question 10

  • an initial INPUT of age before the loop condition is testedM1
  • WHILE condition correctly tests both bounds, e.g. age < 0 OR age > 120M1
  • an error message is output inside the loopM1
  • age is re-input inside the loopM1
  • overall structure correctly repeats until a valid value is entered; any correct logic, ignore minor syntaxM1
  • Answer:
    INPUT age
    WHILE age < 0 OR age > 120
      OUTPUT "Invalid age, try again"
      INPUT age
    ENDWHILE
    OUTPUT "Age accepted"

Question 11

  • a total variable is declared and initialised to 0 before the loopM1
  • a FOR loop correctly iterates across all 6 indices of the arrayM1
  • each element temps[i] is added to total inside the loopM1
  • mean is correctly calculated as total divided by 6 after the loopM1
  • the mean is outputM1
  • final value correct: 13.2 (1 dp), cao ft from the algorithmA1
  • Answer:
    total = 0
    FOR i = 0 TO 5
      total = total + temps[i]
    NEXT i
    mean = total / 6
    OUTPUT mean

Question 12

  • COUNT function used, e.g. COUNT(*) or COUNT(MemberID)M1
  • FROM MembersM1
  • WHERE JoinYear = 2020; any correct logic, ignore semicolonM1
  • Answer: SELECT COUNT(*) FROM Members WHERE JoinYear = 2020;

Question 13

  • correct FUNCTION header with two parameters, e.g. FUNCTION findLargest(num1, num2)M1
  • an IF statement correctly compares num1 and num2M1
  • correct RETURN of num1 when num1 is largerM1
  • correct RETURN of num2 in the ELSE branchM1
  • function correctly closed with ENDFUNCTION; any correct logic, ignore minor syntaxM1
  • Answer:
    FUNCTION findLargest(num1, num2)
      IF num1 > num2 THEN
        RETURN num1
      ELSE
        RETURN num2
      ENDIF
    ENDFUNCTION

Question 14

  • (a) a variable that can only be accessed / used within the subprogram (procedure or function) in which it is declaredB1
  • (a) Answer: A local variable is one that only exists and can be used inside the subprogram in which it was declared.
  • (b) identifies total as a local variableB1
  • (b) explains that total goes out of scope / is deleted once the procedure ends, so its value is lostB1
  • (b) states a valid fix, e.g. return the value from a function, pass it as a parameter, or make it global oeB1
  • (b) Answer: total is local. Once the procedure ends, total no longer exists, so its value cannot be read elsewhere. This could be fixed by using a function to RETURN the value, or by passing it out via a parameter.

Question 15

  • (a) the sum of the odd numbers from 1 to 10 (or equivalent description)B1
  • (a) Answer: It sums the odd numbers between 1 and 10.
  • (b) IF num MOD 2 == 1 THENB1
  • (b) Answer: IF num MOD 2 == 1 THEN
  • (c) IF num MOD 2 == 0 THENB1
  • (c) Answer: IF num MOD 2 == 0 THEN
  • (d) even numbers 2, 4, 6, 8, 10 identified / addedM1
  • (d) 30 cao, ft from part (c)A1
  • (d) Answer: 30

Question 16

  • count initialised to 0 before the loopsM1
  • outer FOR loop correctly iterates rows 0 to 2M1
  • inner FOR loop correctly nested, iterating columns 0 to 2M1
  • IF statement correctly compares board[row, col] to "X"M1
  • count incremented by 1 inside the IFM1
  • count correctly output after both loops complete; any correct logic, ignore minor syntaxM1
  • Answer:
    count = 0
    FOR row = 0 TO 2
      FOR col = 0 TO 2
        IF board[row, col] == "X" THEN
          count = count + 1
        ENDIF
      NEXT col
    NEXT row
    OUTPUT count

Question 17

  • Level 1 Basic, isolated points about subprograms with little or no reference to the given themes (reuse, testing, readability, maintenance). Little linking of ideas.1-2
  • Level 2 Sound discussion covering two or three relevant benefits, with some explanation of why each matters, but underdeveloped or only loosely linked to programming practice.3-4
  • Level 3 Thorough, well-linked discussion covering multiple benefits (for example reuse, testing, readability, maintenance, division of work) with clear explanation of why each improves the development process, using appropriate technical vocabulary throughout.5-6
  • Indicative content:
    • Code reuse: a subprogram can be called multiple times from different parts of the program (or in other programs), avoiding rewriting the same logic repeatedly.
    • Reduces duplication, so there is less code to maintain and less chance of the same bug existing in several places.
    • Testing: each subprogram can be tested in isolation before being integrated, making faults easier to locate.
    • Readability: splitting a program into clearly named subprograms makes the overall structure easier to follow than one long block of code.
    • Maintenance: if a fault is found or a rule changes, it only needs to be corrected once, inside the relevant subprogram, rather than in every place the logic is used.
    • Parameters allow subprograms to be flexible and reused with different data.
    • Larger projects can be divided between different programmers, who can each work on separate subprograms.
    • Abstraction: subprograms hide the detail of how a task is done, so other parts of the program only need to know what the subprogram does, reducing complexity.

Mark your answers

Check answers without an account. Some answers can be checked automatically; use the mark scheme to mark the rest.

Question 1

4 marks
Did your answer earn the marks?

Question 2

4 marks

Question 3

4 marks
Did your answer earn the marks?

Question 4

3 marks
Did your answer earn the marks?

Question 5

5 marks
Did your answer earn the marks?

Question 6

4 marks
Did your answer earn the marks?

Question 7

6 marks
Did your answer earn the marks?

Question 8

6 marks
Did your answer earn the marks?

Question 9

6 marks
Did your answer earn the marks?

Question 10

5 marks
Did your answer earn the marks?

Question 11

6 marks
Did your answer earn the marks?

Question 12

3 marks
Did your answer earn the marks?

Question 13

5 marks
Did your answer earn the marks?

Question 14

4 marks
Did your answer earn the marks?

Question 15

5 marks
Did your answer earn the marks?

Question 16

6 marks
Did your answer earn the marks?

Question 17

6 marks
Did your answer earn the marks?
Mark my answers

Keep going

Worksheets are written for Revision Library and come with a full mark scheme; a few English packs quote an out-of-copyright text, and name it on the page. Exam board names and specification codes say which qualification a pack suits: we are not affiliated with, endorsed by or approved by any exam board, and no past-paper question is reproduced here. Rights queries: hello@revisionlibrary.co.uk