Programming Fundamentals & Data Types (OCR GCSE Computer Science): Exam Questions

Exam code: J277

2 hours32 questions
1
4 marks

Tick (✓) one box in each row to identify whether the OCR Reference Language code given is an example of selection or iteration.

OCR Reference Language code

Selection

Iteration

for i = 1 to 10 print(i) next i

while score != 0 playgame() endwhile

if playerHit() then score = 0 endif

switch bonus: case 0: score = 9 case 1: score = 7 case 2: score = 5 endswitch

2
2 marks

Jack’s program uses the addition (+) arithmetic operator.

This adds together two numbers.

State the purpose of each of the following arithmetic operators

  • *

  • /

3a
2 marks

Customers at a hotel can stay between 1 and 5 (inclusive) nights and can choose between a basic room or a premium room.

A typical booking record is shown in the table:

firstName

Amaya

surname

Taylor-Ling

nights

3

room

Premium

stayComplete

False

State the most appropriate data type for the following fields:

Nights

Room

3b
1 mark

Give the name of one field that could be stored as a Boolean data type.

4a
2 marks

A program is written to allow a user to enter the radius of a circle as a whole number between 1 and 30, then calculate and output the area of the circle.

Identify two variables used in the program

01 radius = 0

02 area = 0.0

03 radius = input("Enter radius")

04 if radius < 1 OR radius > 30 then

05 print("Sorry, that radius is invalid")

06 else

07 area = 3.142 * (radius ^ 2)

08 print (area)

09 endif

4b
1 mark

Identify one item in the program that could have been written as a constant.

4c
1 mark

Give one reason why you have identified this item as a constant.

4d
3 marks

Tick (✓) one box in each row to identify whether each programming construct has or has not been used in the program in part (a).

Has been used

Has not been used

Sequence

Selection

Iteration

5
2 marks

A teacher asks students how long they spend completing homework. Students answer in minutes and hours (for example 2 hours 15 minutes).

The teacher would like to create an algorithm that will display students’ inputs in minutes only.

Identify the input and output required from this algorithm.

6a
2 marks

State what is meant by a real data type and give an example of this data type.

6b
2 marks

State what is meant by an integer data type and give an example of this data type.

7
1 mark

A programmer declares the following variables.

first = "Computer Science"

second = "is great"

State one difference between a variable and a constant.

8a
1 mark

Write a pseudocode statement to assign the value 7.3 to a variable with the identifier timer

8b
1 mark

State the most appropriate data type for the variable timer.

9
3 marks

OCR High School uses a computer system to store data about students’ conduct.

The system records good conduct as a positive number and poor conduct as a negative number.

A TRUE or FALSE value is also used to record whether or not a letter has been sent home about each incident.

An example of the data held in this system is shown below in Fig. 1:

StudentName

Detail

Points

LetterSent

Kirstie

Homework forgotten

−2

FALSE

Byron

Good effort in class

1

TRUE

Grahame

100% in a test

2

FALSE

Marian

Bullying

-3

TRUE

State the most appropriate data type used to store each of the following items of data.

StudentName

Points

LetterSent

10
2 marks

Identify two basic programming constructs that have been used in this algorithm.

01 for k = 1 to 3

02 for p = 1 to 5

03 print (k + p)

04 next p

05 next k

06 m = 7

07 print m * m

1

2

11
4 marks

An infinite loop is where a section of a program repeats indefinitely.

For each of the pseudocode algorithms shown below, tick the appropriate box to show whether they will loop infinitely or not.

Pseudocode

Will loop infinitely

Will not loop infinitely

01 x = 0

02 while True

03 print x

04 endwhile

01 x = 0

02 while x < 10

03 print x

04 endwhile

01 x = 0

02 while x < 10

03 print x

04 x = x + 1

05 endwhile

01 y = 5

02 for x = 1 to y

03 print x

04 next

1
2 marks

A teacher researches the length of time students spend playing computer games each day.

Tick (✓) one box to identify the data type you would choose to store the data and explain why this is a suitable data type.

Data Type

Tick (✓) one box

String

Integer

Real

Boolean

Explanation:

2a
1 mark

DIV and MOD are both operators used in computing-related mathematics.

State the value of 13 DIV 4

2b
1 mark

State the value of 13 MOD 4

3
1 mark

The symbol ^ is used for exponentiation.

Give the result of a^b when a = 3 and b = 2.

4
2 marks

Each member of staff that works in a restaurant is given a Staff ID. This is calculated using the following algorithm.

01     surname = input("Enter surname") 

02     year = input("Enter starting year") 

03     staffID = surname + str(year) 

04     while staffID.length < 10 

05         staffID = staffID + "x" 

06     endwhile 

07     print("ID " + staffID)

Define the term casting and give the line number where casting has been used in the algorithm.

5
3 marks

Tick (✓) one box in each row to identify the programming construct where each keyword is used.

Keyword

Programming construct

Selection

Iteration

if

for

while

6
3 marks

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

7
2 marks

A library system assigns unique Member IDs to new users. The following algorithm is used to generate these IDs.

01     firstname = input("Enter first name")
02     month = input("Enter birth month as number")
03     memberID = firstname + str(month)
04     while memberID.length < 12
05         memberID = memberID + "z"
06     endwhile
07     print("Member ID: " + memberID)

Define the term casting and give the line number where casting has been used in the algorithm.

8
5 marks

A library management system assigns unique Member IDs to new library users. The following algorithm is used to generate these IDs:

01     firstName = input("Enter first name")
02     lastName = input("Enter last name")
03     membershipYear = input("Enter membership year")
04     tempID = firstName[0] + lastName + str(membershipYear)
05     memberID = tempID.upper()
06     counter = 1
07     while len(memberID) < 12
08         memberID = memberID + str(counter)
09         counter = counter + 1
10     endwhile
11     finalID = memberID[:12]
12     print("Member ID: " + finalID)

Define the term casting and identify all line numbers where casting has been used in this algorithm. Explain why casting is necessary in each instance you have identified.

9
2 marks

Describe one reason why a programmer would use a constant instead of a variable for the value of pi (π)

10
2 marks

Explain the importance of using a string prompt inside an input() statement

11
2 marks
print(total)
total = total + price

Describe how the order of these lines affects the logic of the algorithm

12
2 marks
if mark ≥ 70 then
    grade = "A"
elseif mark ≥ 60 then
    grade = "B"
endif

Describe the role of the elseif statement in this code

13
2 marks

Consider the two loops below:

for i = 1 TO 3
    password = input("Enter password")
next i

while password != "secure"
    password ← input("Enter password")
endwhile

Explain why a while loop is more suitable than a for loop in this situation

14
2 marks

Identify the result of the Boolean expression

(X > 5) AND (Y < 10)

if X = 7 and Y = 12

1
4 marks

Identify and correct the errors in the Python program below.

Explain why each correction is necessary.

NAME = "Alice"

PI = 3.14159

name = "Bob"

NAME = "Charlie"

radius = 10

area = PI * radius ^ 2

print("The area of the circle is", area)

2
2 marks

Modify the Python code to include a selection construct that only adds even numbers to the total.

total = 0

for i in range(5):

num = int(input("Enter a number: "))

total = total + num

print("Total is:", total)

3a
3 marks

Identify the output of each print statement in the following Python program:

a = True

b = False

print(a and b)

print(a or b)

print(not a)

Statement

Output

print(a and b)

print(a or b)

print(not a)

3b
4 marks

Modify the code in part(a) to include a conditional that prints:

"Both are True" if both a and b are true

AND

"One is True" if either a or b is true but not both

4
6 marks

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.

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

5
3 marks
balance = balance − amount
if balance ≥ 0 then
    print("Withdrawal approved")
endif

Explain the possible impact of this sequence error

6
3 marks
do
    password = input("Enter password")
until password == "secure"

Evaluate why a do until loop may be more suitable than a while loop for this system

7
3 marks

Justify why the Real (Float) data type should be used instead of Integer to store the result of a division