6 exam-style questions with full mark schemes and model answers. Write your own answer and the AI examiner marks it against the mark scheme.
Learn this properly: Variables, Constants, and Data TypesThe following program was written for this exercise. A program asks the user how many items they are buying and the price of one item, then prints the total cost. If the customer buys 10 or more items they get free delivery; otherwise a fixed £3.50 delivery charge is added.
A student must write this program. They may answer in OCR Exam Reference Language or any high-level language.
Discuss how the program should be structured, and write a complete program that uses input, a calculation, a selection statement, and output. Explain how each programming construct you use contributes to solving the problem. (6 marks)
The following algorithm was written for this exercise. It is written in OCR Exam Reference Language. Note that MOD gives the remainder after division.
total = 0
for i = 1 to 5
if i MOD 2 == 0 then
total = total + i
endif
next i
print(total)
(a) Complete a trace table showing the value of i, the result of i MOD 2 == 0 (True/False), and the value of total after each iteration of the loop. (3 marks)
(b) State the value that is printed by the print(total) line. (1 mark)
A program needs to check whether a password entered by the user is at least 8 characters long. If it is, the program prints "Valid"; if it is too short, it prints "Too short".
In OCR Exam Reference Language, the number of characters in a string variable password is given by password.length.
Write an algorithm to carry out this check. You should use input, the .length property, a selection statement, and output. (3 marks)
A program stores six daily temperatures in a 1-D array called temps, using indices 0 to 5.
temps = [14, 17, 12, 19, 16, 15]
(a) State the value returned by temps[3]. (1 mark)
(b) Write a few lines in OCR Exam Reference Language (or any high-level language) that use a loop to add up all six values in temps and store the result in a variable called total. (2 marks)
In programming, a variable and a constant are both named stores for data.
Describe the difference between a variable and a constant, and give one example of when a constant would be the better choice. (2 marks)
A program contains the following line written in OCR Exam Reference Language:
result = 17 MOD 5
State the value that is stored in result. (1 mark)