Additional Programming Techniques (OCR GCSE Computer Science)

Exam Questions

1 hour21 questions
11 mark

The function checkblock() checks whether a square on a board has been filled. When checkblock(4,2) is called, the value "A" is returned.

 function checkblock(r,c)

     if gamegrid[r,c] == "A" or gamegrid[r,c] == "B" then

         outcome = gamegrid[r,c]

     else

         outcome = "FREE"

     endif

     return outcome

 endfunction

State one feature of checkblock() that shows that it is a function and not a procedure.

Did this page help you?

21 mark

The algorithm for one section of a vending machine program is shown in pseudocode.

if money >= price then 

   venditem() 

   giveChange(money – price) 

else 

   print("Error – not enough money inserted") 

endif

Give the identifier of one variable used in the algorithm.

Did this page help you?

31 mark

What is the purpose of upper() in string manipulation?

Did this page help you?

41 mark

01 message = "I LOVE COMPUTER SCIENCE"
02

Complete line 02 to output the message in all lowercase.

Did this page help you?

51 mark

State the primary function of the open() method in file handling?

Did this page help you?

6a1 mark

Write a line of code to create a 1D array containing 10 elements.

The array should be named scores

6b1 mark

Write a line of code to add the value 99 as the third element in scores 1D array

Did this page help you?

14 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

Booking records are stored in a database table called TblBookings

The following SQL statement is written to display all customer bookings that stay more than one night.

SELECT ALL

FROM TblBookings

IF Nights < 1

The SQL statement is incorrect.

Rewrite the SQL statement so that it is correct.

Did this page help you?

23 marks

The database table Results stores the results for each student in each of their chosen subjects.

StudentName

Subject

Grade

Alistair

English

3

Jaxon

Art

5

Alex

Art

4

Anna

French

7

Ismaael

Art

9

Complete the SQL query to return all of the fields for the students who take Art.

SELECT

FROM

WHERE

Did this page help you?

31 mark

Data for one week (Monday to Friday) is stored in a 2D array with the identifier minsPlayed.

The following table shows part of this array, containing 4 students.

2D Array

The teacher wants to output the number of minutes Dan (column index 3) played computer games on Wednesday (row index 2). The following code is written:

print(minsPlayed[3,2])

Write a line of code to output the number of minutes that Stuart played computer games on Friday.

You must use either:

  • OCR Exam Reference Language, or

  • a high-level programming language that you have studied.

Did this page help you?

46 marks

A program is being created to convert the data capacity of a storage device into a different measure.

The function, calculate(), takes the measurement (e.g. gigabytes) and the number (e.g. 2) as two parameters.

It then returns the value in bits.

The function returns –1 if an invalid measurement was entered.

Complete the function calculate

function calculate(.......................,number) 

if measurement == "gigabytes" then 

    value = number * 1024 * 1024 * 1024 * 8 

elseif measurement == "....................." then 

    value = number * 1024 * 1024 * 8 

elseif measurement = = "....................." then 

    value = number * 1024 * 8 

elseif measure = = "bytes" then 

    value = number.................. 

else

    .................................................. 

endif 

return ........................... 

endfunction

Did this page help you?

53 marks

OCRBlocks is a game played on a 5 × 5 grid. Players take it in turns to place blocks on the board. The board is stored as a two-dimensional (2D) array with the identifier gamegrid

Fig. 6.1 shows that players A and B have placed three blocks each so far.

June 202_ J276-02_Q6a

The function checkblock() checks whether a square on the board has been filled. When checkblock(4,2) is called, the value "A" is returned.

function checkblock(r,c) 

    if gamegrid[r,c] == "A" or gamegrid[r,c] == "B" then 

       outcome = gamegrid[r,c] 

     else 

       outcome = "FREE" 

     endif 

     return outcome 

endfunction

Give the returned value when the following statements are called

Function call

Returned value

checkblock(2,1)

checkblock(3,0)

checkblock(2,3)

Did this page help you?

64 marks

A vending machine stores the quantity of items available in a database table called ITEMS. The current contents of ITEMS is shown:

ItemCode

ItemName

Stock

A1

Crisps, bacon flavour

6

A2

Crisps, salted

2

B1

Chocolate bar

12

C1

Apple pieces

18

C2

Raisins

7

Complete the following SQL statement to display the item code for all items that have fewer than 10 in stock.

SELECT

FROM

Did this page help you?

7a3 marks

An example of the data held in a 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

Fig. 1

The data shown above in Fig. 1 is stored in a database table called Conduct.

Write an SQL statement to select the StudentName field for all records that have negative Points.

7b1 mark

State the wildcard that can be used in SQL to show all fields from a table.

Did this page help you?

8a2 marks

Functions and procedures are both examples of sub programs.

Describe one difference between a function and a procedure.

8b4 marks

Describe two benefits to a programmer of using sub programs.

Did this page help you?

1a4 marks

A Basic room costs £60 each night. A Premium room costs £80 each night.

Create a function, newPrice(), that takes the number of nights and the type of room as parameters, calculates and returns the price to pay.

You do not have to validate these parameters.

You must use either:

  • OCR Exam Reference Language, or

  • a high-level programming language that you have studied.

1b3 marks

Write program code, that uses newPrice(), to output the price of staying in a Premium room for 5 nights.

You must use either:

  • OCR Exam Reference Language, or

  • a high-level programming language that you have studied.

Did this page help you?

24 marks

A program is created to convert hours and minutes into a total number of minutes.

The teacher wants to create a sub program to perform the calculation.

The program has been started but is not complete.

Complete the design for the program.

hours = input("Please enter number of hours played") 

minutes = input("Please enter number of minutes played") 

finalTotal = ……………………………………………………………….. 

print(finalTotal) 



function ………………………………………………………………………………………………………………

         ………………………………………………………………………………………………………………

         ………………………………………………………………………………………………………………

         ………………………………………………………………………………………………………………

         ………………………………………………………………………………………………………………

endfunction

Did this page help you?

3a1 mark

A programmer declares the following variables.

first = "Computer Science"

second = "is great"

State the output from the following line of program code.

print(first.length)

3b1 mark

State the output from the following line of program code.

print(second.length DIV 3)

3c1 mark

State the output from the following line of program code.

print(3 ^ 2)

Did this page help you?

4a1 mark

A programmer declares the following variables.

first = "Computer Science"

second = "is great"

Strings can be concatenated (joined together) using the + operator.

For example, print("Maths " + second) will output Maths is great

Use string manipulation with the variables first and/or second to produce the following output.

great

4b1 mark

Use string manipulation with the variables first and/or second to produce the following output.

Computer

4c1 mark

Use string manipulation with the variables first and/or second to produce the following output.

Science is great

Did this page help you?

53 marks

The number of goals scored in each football match is held in an array called goals. An example of this array is shown.

goals = [0, 1, 3, 0, 4, 5, 2, 0, 2, 1]

Elliott wants to count how many matches end with 0 goals.

Complete the following pseudocode for an algorithm to count up how many matches with 0 goals are stored in the array and then print out this value.

01 nogoalscount = 0 

02 for count = 0 to (goals.length-1) 

03     if goals[…………………………] == 0 then 

04         nogoalscount …………………………………………………… 

05     endif 

06 next count 

07 print(……………………………………………)

Did this page help you?

6a6 marks

OCR Land is a theme park aimed at children and adults. Entrance tickets are sold online. An adult ticket to OCR Land costs £19.99, with a child ticket costing £8.99. A booking fee of £2.50 is added to all orders.

A function, ticketprice(), takes the number of adult tickets and the number of child tickets as parameters. It calculates and returns the total price to be paid.

Use pseudocode to create an algorithm for the function ticketprice().

6b2 marks

Tick (✓) one box to identify the data type of the value returned from the function ticketprice(), justifying your choice.

Data type of returned value

Tick (✓) one box

Integer

Real

Boolean

String

Justification

Did this page help you?

7a3 marks

A library gives each book a code made from the first three letters of the book title in upper case, followed by the last two digits of the year the book was published.

For example, “Poetry from the War”, published in 2012 would be given the code POE12.

Complete the following pseudocode for a function definition that will take in the book title and year as parameters and return the book code.

01 function librarycode(title, ………………………………………………)

02     parta = title.subString(0, ………………………………………………)

03     partb = year.subString(2, 2)

04     ……………………………………………… parta.upper + partb

05 endfunction
7b6 marks

Use pseudocode to write an algorithm that does the following :

  • Inputs the title and year of a book from the user.

  • Uses the librarycode function above to work out the book code

  • Permanently stores the new book code to the text file bookcodes.txt

Did this page help you?