0% found this document useful (0 votes)
2 views

Tracing Algorithms Questions 15.11.2024

The document contains a series of programming exercises and questions related to pseudocode algorithms, trace tables, and error definitions. It includes tasks for generating staff IDs, pilot codes, and calculating medicine doses, as well as identifying logic and syntax errors. The exercises require completion of trace tables and writing algorithms based on given scenarios.

Uploaded by

Yasmin
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Tracing Algorithms Questions 15.11.2024

The document contains a series of programming exercises and questions related to pseudocode algorithms, trace tables, and error definitions. It includes tasks for generating staff IDs, pilot codes, and calculating medicine doses, as well as identifying logic and syntax errors. The exercises require completion of trace tables and writing algorithms based on given scenarios.

Uploaded by

Yasmin
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

© OCR 2024. You may photocopy this page.

1 of 12 Created in ExamBuilder
1 Read the following pseudocode algorithm:

01 start = 3

02 do

03 print(start)

04 start = start - 1

05 until start == -1

06 print("Finished")

Complete the following trace table for the given algorithm.

Line number start Output

[3]
2 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)

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

Definition

Line number

[2]
Complete the following trace table for the given algorithm when the surname “Kofi” and the year 2021
are entered.

You may not need to use all rows in the table.


Line number surname year staffID Output
01 Kofi

02 2021

[4]
© OCR 2024. You may photocopy this page. 2 of 9 Created in ExamBuilder
3 OCR Drones flies goods around the country using drones.

A pilot code is automatically generated when a new pilot joins the company.

This algorithm generates a code for each pilot:

01 a = input("Enter first letter of first name")

02 b = input("Enter first letter of second name")


03 c = random(1,100)
04 while c < 100
05 c = c * 10
06 endwhile
07 pilotCode = a + b + str(c) 08 print(pilotCode)

Complete the trace table for the given algorithm.

Lines 01 to 03 have already been completed.

You may not need to use all rows in the trace table.
Line number a b c pilotCode Output
01 H

02 K

03 9

[4]

© OCR 2024. You may photocopy this page. 3 of 9 Created in ExamBuilder


4 The following program uses a condition-controlled loop.

x = 15 y = 0
while x > 0
y = y + 1 x
= x – y
endwhile
print(y)

Complete the trace table to test this program.

x y output

[4]

5(a) A computer program calculates the correct dose in grams of a type of medicine.

© OCR 2024. You may photocopy this page. 4 of 9 Created in ExamBuilder


The algorithm used is shown by the flow diagram below.

Use the flow diagram to calculate the correct dose of medicine for a male aged 30.

You must show your working.

© OCR 2024. You may photocopy this page. 5 of 9 Created in ExamBuilder


[3]
(b) Use the flow diagram to calculate the correct dose of medicine for a pregnant female aged 19.
You must show your working.

[4]
6 Charley is writing a program for music students. To make sure that there are no logic errors in the
program, Charley uses a test plan.

Describe what is meant by a logic error.

[2]

7 Heath is researching how long, to the nearest minute, each student in his class spends playing
computer games in one week (Monday to Friday). He is storing the data in a 2D array.

© OCR 2024. You may photocopy this page. 6 of 9 Created in ExamBuilder


Fig. 2 shows part of the array, with 4 students.

For example, student 1, on Monday (day 0), played 30 minutes of computer games.

He wants to output the number of minutes student 3 played computer games on Wednesday (day 2).
He writes the code:
print (hoursPlayed[3,2])

The output is 20.


Write the code to output the number of minutes student 0 played computer games on Wednesday.

[1]

(i) State the output if Heath runs the code:


print (hoursPlayed[2,1])

[1]

(ii) State the output if Heath runs the code:


print (hoursPlayed[3,1] + hoursPlayed[3,2])

[1]

(iii) Write an algorithm to output the total number of minutes student 0 played computer games from
Monday (day 0) to Friday (day 4).

[3]

8 OCR Tech is an online shop that sells electronics such as TVs and game consoles.

© OCR 2024. You may photocopy this page. 7 of 9 Created in ExamBuilder


An item is classified as "In demand" if OCR Tech have between 5 and 25 inclusive in stock.

A program is written that allows the user to input the current stock level and output whether the item is
in demand or not.

stocklevel = input("Enter stock level")


if stocklevel >= 5 or =< 25 then
print(Not in demand)
else
print(In demand)
endif

The program contains syntax and logic errors.

Refine the program to correct the errors and write the refined version of the program.

You must use either:

• OCR Exam Reference Language, or


• A high-level programming language that you have studied

[5]

9(a) Give the output of the algorithm.

© OCR 2024. You may photocopy this page. 8 of 9 Created in ExamBuilder


value = 3

value = value - 1

print(value * 2)

[1]

(b) scores = [3, 6, 6, 9, 2, 8]

number = scores[2]

print(number)

[1]

(c) day = "Monday"

x = day.length

print(x)

[1]

10 State what is meant by the term syntax error. Give one example of a syntax error in a program.

Definition

Example

[2]

END OF QUESTION PAPER Powered by TCPDF (www.tcpdf.org)

© OCR 2024. You may photocopy this page. 9 of 9 Created in ExamBuilder

You might also like