Revision Library

Programming Fundamentals - Worksheets, Questions and Revision

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

Download PDFJump to mark scheme (page 10)Read the revision guide
« Previous: AlgorithmsNext: Producing Robust Programs »
Revision Library
revisionlibrary.co.uk
GCSE · Computational thinking, algorithms and programming

P2.2 Programming Fundamentals

OCR J277 · Calculators not allowed · about 105 minutes
Total Marks
Name: _______________________________    Date: ____ / ____ / ______
Answer ALL questions. Show all your working.
1
This question is about data types used in programming.
(a)Which data type would be most appropriate to store the answer to the question 'Is the number even?'(1)
  • A) Integer
  • B) Boolean
  • C) String
  • D) Real
(b)State the most appropriate data type for each value: (i) the number of pets a person owns (ii) the price of a chocolate bar, 2.35 pounds (iii) a student's exam grade letter, for example 'A' (iv) whether a password entered is correct(4)
(c)A programmer stores a UK postcode, for example 'SW1A 1AA', using a Real data type. Explain why this is not appropriate and state a more suitable data type.(2)
(Total for Question 1 is 7 marks)
2
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 2 is 4 marks)
3
Complete the table by evaluating each expression.
17 DIV 5 = ?
17 MOD 5 = ?
2 ^ 3 = ?
(10 - 3) * 2 = ?
(Total for Question 3 is 4 marks)
4
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 4 is 4 marks)
5
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 5 is 3 marks)
6
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 6 is 6 marks)
7
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 7 is 6 marks)
8
A cafe offers a discount: a student spending more than 15 pounds gets 20% off; a student spending 15 pounds or less gets 10% off; a non-student gets no discount.

Write an algorithm, using nested IF statements in pseudocode, that inputs a Boolean isStudent and a Real spend, then outputs the discount percentage that applies (0, 10 or 20).
(Total for Question 8 is 4 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 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 10 is 5 marks)
11
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 11 is 4 marks)
12
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 12 is 5 marks)
13
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 13 is 6 marks)
14
Using the same Members table from Question 11, write an SQL query that counts how many members joined in the year 2020.
(Total for Question 14 is 3 marks)
15
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 15 is 5 marks)
16
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 16 is 4 marks)
17
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 17 is 5 marks)
18
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 18 is 6 marks)
19
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 19 is 6 marks)
20
A school records the test scores, out of 100, of 8 students in a computer science class.

Write an algorithm, using pseudocode, that:
- uses a loop to input 8 scores, validating each one so it must be between 0 and 100 inclusive before it is accepted
- stores each valid score in an array called scores
- calculates and outputs the average (mean) score
- outputs 'Well done, class!' if the average is 60 or above, otherwise outputs 'More revision needed'

Your algorithm should make use of iteration, selection and an array.
(Total for Question 20 is 10 marks)
Mark scheme · P2.2 Programming Fundamentals

Question 1

Question 2

Question 3

Question 4

Question 5

Question 6

Question 7

Question 8

Question 9

Question 10

Question 11

Question 12

Question 13

Question 14

Question 15

Question 16

Question 17

Question 18

Question 19

Question 20

Mark your answers

This checks your answers in your browser, stores nothing on a server and needs no account.

Question 1

7 marks
Did your answer earn the marks?

Question 2

4 marks
Did your answer earn the marks?

Question 3

4 marks

Question 4

4 marks
Did your answer earn the marks?

Question 5

3 marks
Did your answer earn the marks?

Question 6

6 marks
Did your answer earn the marks?

Question 7

6 marks
Did your answer earn the marks?

Question 8

4 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

4 marks
Did your answer earn the marks?

Question 12

5 marks
Did your answer earn the marks?

Question 13

6 marks
Did your answer earn the marks?

Question 14

3 marks
Did your answer earn the marks?

Question 15

5 marks
Did your answer earn the marks?

Question 16

4 marks
Did your answer earn the marks?

Question 17

5 marks
Did your answer earn the marks?

Question 18

6 marks
Did your answer earn the marks?

Question 19

6 marks
Did your answer earn the marks?

Question 20

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