Programming Techniques End of Unit Quiz Lesson Element
Programming Techniques End of Unit Quiz Lesson Element
2 Programming
Techniques
1.
a. Compare the use of variables and constants in a computer program, giving one
similarity and one difference.
01 input y
02 x = y MOD 5
03 if x == 0 then
04 print “True”
05 end if
bii. What is one input that would case the program to output True and explain why this
is the case?
biii. What are two basic programming constructs that have been used in the code
above?
2. Create an algorithm that will allow the user to enter a word and then count how many times
the letter A appears in that word. Both upper case (“A”) and lower case (“a”) letters must be
counted. The algorithm should repeat until a word is entered that has 3 or more letter As.
3.
a. The following algorithm prints out the times table of the number entered using a
count controlled loop.
01 input b
02 for x = 1 to 100
03 print b * x
04 next
Rewrite the algorithm to produce the same result using a condition controlled
loop.
4.
a. Complete the data type column on the below table to show the most appropriate
data type for each:
Number of goals 2
scored
Complete the algorithm below to add the new trainingdata to the text file.
d. Using the trainingdata array from the previous question, give the pseudocode
that a programmer would use to output just the training venue details(“Bycars
Park”) from this array. You may assume that the array is zero-indexed.
b. Write SQL statements to display the following data from the songs table:
(i) Show the SongTitle and Length for all songs by the band Penguin Steak
(ii) Show the SongTitle for all songs that are over 3 minutes in length.
a. Procedures and functions are both examples of subroutines. What are two
advantages of producing modular code using subroutines?
cii. Use the function defined in part (i) above to check whether “HELLO123” is a valid
password, printing out True or False as appropriate. You must use the function
defined in part (i).
Similarity:
Both refer to a memory location
Both are given an identifier
Both are used to store data whilst the program is running
Difference:
Variable’s value can be changed / Constant’s value cannot be changed whilst the
program is running
01 input y
02 x = y MOD 5
03 if x == 0 then
04 print “True”
05 end if
Do not award for simply rewording the line (eg “on line 03, if x is equal to zero then
it…”
bii. What is one input that would case the program to output True and explain why this
is the case?
Any integer value that is divisible by 5 (so ends in 5 or 0). Eg 35, 90, 5. MOD
produces the remainder when y is divided by 5……this has to be zero to allow the
output to be True.
biii. What are two basic programming constructs that have been used in the code
above?
Sequence, Selection.
biv. What is the name of one programming construct that has not been used in the code
above and give an example of how this construct could be used?
2. Create an algorithm that will allow the user to enter a word and then count how many times
the letter A appears in that word. Both upper case (“A”) and lower case (“a”) letters must be
counted. The algorithm should repeat until a word is entered that has 3 or more letter As.
Example:
3.
a. The following algorithm prints out the times table of the number entered using a
count controlled loop.
01 input b
02 for x = 1 to 100
03 print b * x
04 next
Rewrite the algorithm to produce the same result using a condition controlled
loop.
input b
x = 1
while x <=10
print b * x
x = x + 1
endwhile
b. Write an algorithm that will ask the user for their age (in years) and then print the
message “happy birthday” that many times.
Example:
input age
for x = 1 to age
print “happy birthday”
next x
4.
a. Complete the data type column on the below table to show the most appropriate
data type for each:
c. The data from part (a) is stored in an array called trainingdata. The training
sessions are stored in a text file called allsessions.txt
Complete the algorithm below to add the new trainingdata to the text file.
Example:
open allsessions.txt…
…for append
write trainingdata
close file
d. Using the trainingdata array from the previous question, give the pseudocode
that a programmer would use to output just the training venue details(“Bycars
Park”) from this array. You may assume that the array is zero-indexed.
print trainingdata[1]
2D array has rows and columns / treated like a table / accessed via two indexes.
First index / rows / columns can hold data for one training session.
Second index / subsequent rows / columns can hold other training sessions.
Suitable example.
5.
a. A database table called songs is used to store details of music that is played on an
Internet radio station.
b. Write SQL statements to display the following data from the songs table:
(iii) Show the SongTitle and Length for all songs by the band Penguin Steak
(iv) Show the SongTitle for all songs that are over 3 minutes in length.
SELECT SongTitle
FROM songs
WHERE Length > 3
6.
a. Procedures and functions are both examples of subroutines. What are two
advantages of producing modular code using subroutines?
Can reuse code / can use pre-built or external subroutines. Easier to debug /
maintain. Work can be split between programmers / programmers can concentrate
on their areas of expertise.
Procedures are called by their name / functions are called by assign their return
value to something. Procedures do not return values / Functions always return a
Example:
function checkpassword(password)
if password.length >= 8 then
return True
else
return False
endfunction
Does not matter what the function is called or the parameter is called, but this must
logically work.
cii. Use the function defined in part (i) above to check whether “HELLO123” is a valid
password, printing out True or False as appropriate. You must use the function
defined in part (i).
print checkpassword(“HELLO123”)
This formative assessment resource has been produced as part of our free GCSE teaching and learning support package. All the
GCSE teaching and learning resources, including delivery guides, topic exploration packs, lesson elements and more are available on
the qualification webpages.
If you are looking for examination practice materials, you can find Sample Assessment Materials (SAMs) on the qualification webpage:
Computer Science (9-1)
We’d like to know your view on the resources we produce. By clicking on ‘Like’ or ‘Dislike’ you can help us to ensure that our resources
work for you. When the email template pops up please add additional comments if you wish and then just click ‘Send’. Thank you.
Whether you already offer OCR qualifications, are new to OCR, or are considering switching from your current provider/awarding
organisation, you can request more information by completing the Expression of Interest form which can be found here:
www.ocr.org.uk/expression-of-interest
Looking for a resource? There is now a quick and easy search tool to help find free resources for your qualification:
www.ocr.org.uk/i-want-to/find-resources/