Question 1
Tick (✓) one box in each row to identify the programming construct where each keyword is used.
[3]
Computer Science · OCR J277 · Computational thinking, algorithms and programming · June 2024
Tick (✓) one box in each row to identify the programming construct where each keyword is used.
[3]
State what is meant by the term syntax error. Give one example of a syntax error in a program.
[2]
A student writes an algorithm to input two numbers and add them together to create a total.
If the total is between 10 and 20 inclusive, "success" is output.
If the total is not between 10 and 20 inclusive, "warning" is output.
01 num1 = input("Enter a number") 02 num2 = input("Enter a number") 03 total = num1 + num1 04 if total >= 10 then 05 print("success") 06 else 07 print("warning") 08 endif
The algorithm does not work correctly.
Identify the line number of the two logic errors in the algorithm and refine the code to correct each logic error.
[4]
Show how a binary search will be used to find the number 10 in the following data set:
1 2 5 6 7 10 20
[3]
State one pre-requisite for a binary search algorithm.
[1]
Tick (✓) one box to identify the name of the sorting algorithm that splits data into individual items before recombining in order.
[1]
A program allows users to search for and watch videos. Users give a rating to the videos they watch.
Identify one input and one output for the program.
[2]
Describe one method of defensive design that can be used when creating the program.
[2]
Complete the truth table for P = (A AND B) OR C
| A | B | C | P |
| 0 | 0 | 0 | |
| 0 | 0 | 1 | |
| 0 | 1 | 0 | |
| 0 | 1 | 1 | |
| 1 | 0 | 0 | |
| 1 | 0 | 1 | |
| 1 | 1 | 0 | |
| 1 | 1 | 1 |
[4]
[3]
The variable message is assigned a value.
message = "abcd1234"
Complete the table to show the output when each statement executes.
The first output has been completed for you.
| Statement | Output |
| print(message.length) | 8 |
| print(message.upper) | |
| print(message.left(4)) | |
| print(int(message.right(4))*2) |
[3]
Write an algorithm in pseudocode to:
• store "Hello" in the variable word1
• store "Everyone" in the variable word2
• concatenate word1 and word2 to store "HelloEveryone" in the variable message
[3]
Programs can be written in high-level languages or low-level languages.
Give two reasons why some programs are written in a low-level language.
[2]
Describe the benefits of using a compiler instead of an interpreter when writing a program.
[3]
An algorithm stores the position of a character on a straight line as an integer. A user can move the character left or right.
The following algorithm:
• generates one random number between 1 and 512 (inclusive) to store as the position
• prompts the user to input a direction to move (left or right)
• takes a direction as input until a valid direction is input.
p = random(1, 512) print("The position is ", p) a = "" while a != "left" and a != "right" a = input("Enter direction, left or right") endwhile
Describe two ways to improve the maintainability of the algorithm.
[4]
If the character moves left, 5 is subtracted from the position. If the character moves right, 5 is added to the position.
The position of the character can only be between 1 and 512 inclusive.
The function moveCharacter():
• takes the direction (left or right) and current position as parameters
• changes position based on direction
• sets position to 1 if the new position is less than 1
• sets position to 512 if the new position is greater than 512
• returns the new position.
Complete the function moveCharacter()
function moveCharacter(direction, position)
endfunction
[6]
Students take part in a sports day. The students are put into teams.
Students gain points depending on their result and the year group they are in. The points are added to the team score.
The team with the most points at the end of the sports day wins.
Data about the teams and students is stored in a sports day program.
Identify the most appropriate data type for each variable used by the program.
Each data type must be different.
| Variable | Example | Data type |
| teamName | "Super-Team" | |
| studentYearGroup | 11 | |
| javelinThrow | 18.2 |
[3]
The student names for a team are stored in an array with the identifier theTeam
An example of the data in this array is shown:
Index 0 1 2 3 4 5
A linear search function is used to find whether a student is in the team. The function:
• takes a student name as a parameter
• returns True if the student name is in the array
• returns False if the student name is not in the array.
Complete the design of an algorithm for the linear search function.
function linearSearch(studentName)
for count = 0 to …………….….....……………
[4]
endif
next count
return False
endfunction
[4]
The height a student jumps in the high jump needs to be input and validated. The height is entered in centimetres (cm) and must be between 40.0 and 180.0 inclusive.
Write an algorithm to:
• take the height jumped as input
• output "VALID" or "NOT VALID" depending on the height input.
You must use either:
• OCR Exam Reference Language, or
• A high-level programming language that you have studied.
[4]
The algorithm is tested using a range of tests.
Complete the table to identify an example of test data for each type of test.
| Test data (height jumped in cm) | Type of test | Expected output |
| Normal | "VALID" | |
| Boundary | "VALID" | |
| Erroneous | "NOT VALID" |
[3]
The individual results for each student in each event are stored in a database.
The database table TblResult stores the times of students in the 100 m race. Some of the data is shown:
| StudentID | YearGroup | TeamName | Time |
| 11GC1 | 11 | Valiants | 20.3 |
| 10VE1 | 10 | Super-Team | 19.7 |
| 10SM1 | 10 | Super-Team | 19.2 |
| 11JP2 | 11 | Champions | 19.65 |
Complete the SQL statement to show the Student ID and team name of all students who are in year group 11
SELECT StudentID,........
[4]
Abstraction and decomposition have been used in the design of the sports day program.
Identify one way that abstraction has been used in the design of this program.
[1]
Identify one way that decomposition has been used in the design of this program.
[1]
An algorithm works out which team has won (has the highest score).
Write an algorithm to:
• prompt the user to enter a team name and score, or to enter "stop" to stop entering new teams
• repeatedly take team names and scores as input until the user enters "stop"
• calculate which team has the highest score
• output the team name and score of the winning team in an appropriate message.
You must use either:
• OCR Exam Reference Language, or
• A high-level programming language that you have studied
[6]
The paper as printed
Spotted a mistake on this page?Report a problem