0 ratings 0% found this document useful (0 votes) 43 views 13 pages Paper 3
The document outlines various programming concepts and tasks related to algorithms, testing, sorting, and security systems. It includes exercises on input validation, flowchart implementation, sorting algorithms, and database queries. Additionally, it discusses ticket sales for a music festival and requires the creation of algorithms for password matching and ticket booking functionality.
AI-enhanced title and description
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here .
Available Formats
Download as PDF or read online on Scribd
Go to previous items Go to next items
Section A
A program asks a user to enter a number. Only integer values between 1 and 100
(inclusive) are accepted. The program is tested.
Tick (V) one or more boxes in each row to identify the type or types of test for each
example of test data.
Example test | Normal test | Boundary test | Invalid/Erroneous
data data data test data
27 Oo oO [ra]
“Hello” Oo = i
105 El (e) oO
100 o oO Oo
An algorithm is written for the program.
( Complete the algorithm for the program
num = input(“Enter a number between 1 and 100”)
if num 1 AND num
print(“accepted”)
100 then
print(“not accepted”)
endif
(i Give the identifier of one variable used in the algorithm in part (bi)
(ii) Give one Boolean operator used in the algorithm in part (b){i).
[4]
1)
io)
(12 This flowchart uses iteration.
OUTPUT “OK”
X=x-2
False
True
END
(2) Complete the table by identifying how many mes "OX" wil be output for when wach
value i input
Input value | Number of times "OK" is ouput
7 =
0 =
a
(©) eration sa programming construct
dently and describe two diferent examples of eration that can be used ina high-evel
language
m(©) Aprogrammer implements the flowchart as a program in a high-level language using an
Integrated Development Environment (IDE).
Identify and describe two tools that the programmer could use in the IDE to create a
program from the flowchart,
(a) Show the steps that a merge sort would take to put the data set into ascending numerical order.
25 Ts, 3s Ay Oh Gti 5 4
(4)(b) Tick (V) one box in each table to complete the descriptions.
An insertion sort...
Tick (¥)
‘one box
uses an array of numbers with a sorted part and unsorted part
picks out the middle value to begin with ee
merges arrays of numbers together
‘A bubble sort compares pairs of values and then:
Tick (V7)
fone box
‘always swaps them
‘swaps them if they are in the correct order
‘swaps them if they are in the incorrect order
A sorting algorithm can sort data in an array. An array:
Tick (V7)
one box
is declared with a fixed length oO
stores multiple values that cannot be changed while the o
program is running
can only be declared with @ maximum of one-dimension (1D) oO
(3)
(©) Analgorithm can be used to search for a value in an array. The algorithm
follows these:
‘© compares the first value in the array to the value being searched for
‘© stops if the comparison is true
'* moves to the next value in the array if the comparison is false
(i) Give the name of the searching algorithm described. i
(i) Identify one other condition that will cause the algorithm to stop. 04 Analgorithm is written to read numbers from the extemal text fledata. txt
Each number is checked when it is read from the external text file. The number is output
to the user ifitis not 0.
(a) Complete the algorithm using the OCR Exam Reference Language statements in the
box.
Not all statements are used.
data for if
[Link]() [Link]() inputC)
[Link]() open print
tenp tet x
myFile [Link]”)
while NOT [Link](
temp =
ifint( ) #0
(temp)
endif
endwhite
[5] [Link])
(b) Identify how casting is used in this algorithm
(b) Identify how casting is used in this algorithm.
a
ru5 —_Asecurily system proteds online credit card payments. The system has three inputs:
Input Description
a ‘True when the user enters their correct password
B True when the user enters their correct PIN
c True when the card is blocked
"The output (P) is True if bath of the following conditions are True:
‘* the user has entered either their correct password or has entered their correct PIN
© the card is not blocked
(@) Draw the logic circuit for the security system
(b) Complete the truth table for P = A AND B
A B
[2](€) Computational thinking techniques were used to design the security system,
Draw one line to match each computational thinking technique to its conect example.
Computational thinking
technique
Example
“Abstraction
The system is broken down
Into modules for security and
payments
Decomposition
‘There is an increase inthe
amount of RAM in the
‘computer running the system,
‘Algorithmic thinking
The users identity PIN and
password are required. Al
‘other datas ignored
“The step-by-step process for
Users to securely py online is
designed.
BI
(d) As part of the security system, the user is asked to choose a 4-digit value for their PIN.
This PIN cannot be 1234 or 4321
Create an algorithm that:
takes the PIN as input as a string
‘checks that the PIN is 4 characters in length
checks that the PIN is not either “1234” or “4321”
outputs “VALID PIN” if the PIN meets all of the criteria
outputs “INVALID PIN” if the PIN does not meet all of the criteria.
You do not need to check that the digits entered are numeric,6 OCR Rockfest isa yearly music festival. Visitors buy tickets to attend! and watch the music acts
‘[Link] system is created to sell tickets and store information about visitors and the
music acts
(2) Visitors are asked to choose a password. The password is entered twice and stored in the
variables passA and pass
(Tick () one box to identify the correct OCR Exam Reference Language statements forthe
design ofthis task
‘OCR Exam Reference Language to enter two passwords Tick
cone box:
ass and passB = input(“enter password twice”)
input(“enter your password”) = passA
input(“enter your password again”) = passB
[passA = input(“enter your password")
assB = input(“enter your password again")
“SpassA” = input(enter your password”)
‘spass8” = input(“enter your password again”) 1"
Design an algorithm that:
‘© checks ifthe passwords stored in passA and passB are the same
‘© outputs “passwords match” ifthey are the same
‘© outputs “passwords do not match they arenot the same.(b) The database table TbLMusic stores data about the music acts.
‘Some of the data in TbLMusic is shown:
Ral Stage Day SetLength
1 Platinum Saturday 5
2 Hilts Saturday Ts
z Triangle Sunday To
a Platinum Sanday oS
‘An SQL statement has been written to show Act ID and Stage forall acts playing on
Saturday.
‘The SL statement is incorrect.
SELECT ActID AND Stage
FROM TblActs
IF Day = Saturday
(Refine the SL staternent to correct the errors.
(li) Identity one example of a record from TbUMusic
m
(iii) Give the most appropriate data type for each field shown.
Field name Data stored Data type
Stage The name ofthe stage
SetLength The length of each setin
hours:
(1(c)
wo
Tickets to the festival are £60 each. Visitors can buy multiple tickets. For example, 2
visitor buying 4 tickets would pay £240.
Write a function, calculatePrice()"’) that:
takes the number of tickets to be purchased as a parameter
calculates and retums the total price to pay.
You must use either: [al
* OCR Exam Reference Language, or
a high-level programming language that you have studied
Write an algorithm that:
© uses the function calculatePrice() to find the price far a visitor buying 3 tickets
‘© stores the result in the variable totalPrice
You must use either:
* OCR Exam Reference Language, or
© a high-level programming language that you have studied
totalPrice = calculatePrice(3) 1)(d)_ The number of different music acts on each of the three stages is stored in the array
actNunbers.
Each index of the array represents one stage.
Index 8 1 2
bata ao Tau Ts |
actNumbers
This algorithm adds up the total number of acts on all three stages.
01 count = 0
02 for x = @ to 2
03 count = count + actNumbers[x]
04 next x
05 print(count)
() Complete the trace table for the algorithm. You may not need to use all rows in the table.
in number(li) The array actNunberss is changed to include data for two more stages. The new array is,
shown:
Index 9 1 2 3 4
Data 0 | a4 | 6 | 9 | a
actNunbers
The algorithm from part (i) needs refining to work for the new array. The algorithm is,
repeated here:
61 count = 6
02 for x = @ to2
93 count = count + actNumbers[x]
04 next x
85 print(count)
Identity the line number that will need to be changed for the new array and write the
updated line of code.
(iil) Refine line 08 in the algorithm to output “The total act count is “and then the
content of the variable count:
For example:
The total act count is 50(e) There are 500 tickets available for the music festival. The number of tickets currently
available is stored in the variable tickets
Complete the algorithm to:
prompt the user to enter how many tickets they would like and take this value as input
output “Tickets booked” and reduce the value stored in tickets if there are
‘enough tickets available
output “Not enough tickets” if there are not enough tickets available
repeat the steps until there are no tickets left
‘You must user either.
OCR Exam Reference Language, or
a high-level programming language that you have studied