paper 2 - OCR reference language Flashcards

1
Q

how do you declare a constant in the OCR reference language?

A

using the keyword const (e.g. const pi = 3.14

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

how can variables in the main program can be made global in OCR reference language?

A

with the keyword global (e.g. global userID = 123)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what would 13MOD5 give?

A

3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

what would 17DIV5 give?

A

3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

give a statement in OCR reference language that will print “Hello” 8 times.

A

for i=0 to 7
print (“Hello”)
next i

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

what does the ‘step 2’ command do in for loops in OCR reference language? Explain an example of it being used

A

it increases the counter (i) by 2 each time. E.g., the program:
for i=0 to 7 step 2
print (“Hello”)
next i
Will print “Hello” 4 times, because the step 2 command increases the counter (i) by 2 each time.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

give an example of a DO…UNTIL loop in OCR reference language

A

do
answer = input(“New answer”)
until answer != “Correct”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

which command will return the length of the string in OCR reference language?

A

stringname.length (e.g. the program
subject = “Computer Science”
print (subject.length)
would return 15)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

how would you print a substring in OCR reference language?

A

stringname. subString (startingPosition, numberOfCharacters)
e. g. when subject = “Computer Science”, subject.substring(3,5) will return “puter” (remember it starts at the 0th character)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

when subject = “Computer Science”, what would subject.left(4) return?

A

“Comp”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

when subject = “Computer Science”, what would subject.right(3) return?

A

“nce”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

how would you convert the variable Subject into upper case letters?

A

Subject.upper

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

how would you convert the variable Subject into lower case letters?

A

Subject.lower

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

in OCR reference language, what command is used to open a file to read from?

A

open(“filename.txt”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

In OCR reference language, which command would be used to return a line of text from the file myFile?

A

x = myFile.readLine()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

what is the command endOfFile used for in OCR reference language?

A

it is used to determine the end of the file, for example, myFile.endOfFile will return true if the program has reached the end of the file

17
Q

write a program to print out the contents of a file called sample.txt

A
myFile = open("sample.txt")
while NOT myFile.endOfFile()
	print(myFile.readLine())
endwhile
myFile.close()
18
Q

what command is used to write to a file in OCR reference language?

A
writeLine
e.g. myFile = open("sample.txt")
myFile.writeLine("Hello World")
myFile.close()
would make "Hello World" the contents of sample.txt (any previous contents are overwritten)
19
Q

how are arrays declared in OCR reference language?

A

with the keyword ‘array’. e.g. array people[5] would create an array called ‘people’ with 6 spaces (it is 0 based)

20
Q

how do you declare a 2D array in OCR reference language?

A

array arrayName[no. of records, no. of fields]
e.g. array board [8,8]
board [0,0] = “rook”

21
Q

how do you define a function in OCR reference language?

A
function functionName(parameter)
e.g. function triple(number) creates a function called 'triple' that takes 'number' as an argument
22
Q

how do you call a procedure in OCR reference language?

A
procedure procedureName(parameter)
e.g. procedure greeting(name) would create a procedure called 'greeting' that takes the parameter 'name'
23
Q

how would you cast the string “3” as an integer in OCR reference language?

A

int(“3”)

24
Q

how would you cast the string “3.14” into a float in OCR reference language?

A

float(“3.14”)

25
Q

how would you cast the integer 3 into a string in OCR reference language?

A

str(3)

26
Q

using the OCR reference language, how would you create a random number between 1 and 6 inclusive?

A

number = random(1,6)