Programming Fundamentals - Worksheets, Questions and Revision
17 original exam-style questions - 8 pages of questions with a full mark scheme - free printable PDF.
Programming Fundamentals revision guideMore GCSE Computer Science practiceMock exams
This topic is chapter 10 of GCSE Computer Science Topic Workbook 1 and chapter 10 of GCSE Computer Science 10-Minute Tests.
2.2 Programming Fundamentals
17 DIV 5 = ?
17 MOD 5 = ?
2 ^ 3 = ?
(10 - 3) * 2 = ?
(i) x > y AND z < y
(ii) NOT (x == y)
(iii) (x + y) ≥ z
(iv) x < y OR z > y
Write an SQL query that selects the FirstName and Surname of every member from the town 'Leeds', ordered alphabetically by Surname.
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
total = 0 FOR i = 1 TO 5 total = total + i * 2 NEXT i OUTPUT total
Write an algorithm using a FOR loop that calculates and outputs the mean of the values in temps.
total = 0
FOR num = 1 TO 10
IF num MOD 2 == 1 THEN
total = total + num
ENDIF
NEXT num
OUTPUT totalWrite 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.
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 ENDWHILECLOSEFILE(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.