Aqa Pseudo-code syntax Flashcards

1
Q

IntExp, RealExp, BoolExp, CharExp and StringExp mean

A

IntExp, RealExp, BoolExp, CharExp and StringExp mean any expression which can be evaluated to an integer, real, Boolean (False or True), character or string respectively.

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

Exp means

A

Any expression

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

Emboldened pseudo-code is used

A

Used to indicate the keywords/operators

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

Exam paper questions will assume that indexing for arrays and strings start at __

A

0 unless specifically stated otherwise.

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

Single line comments

A

comment

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

Multi-line comments

A
# comment
# comment and so on
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Variable assignment

A

Identifier ← Exp

a← 3
b ← a + 1
c ← ‘Hello’

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

Constant assignment

A

CONSTANT IDENTIFIER ← Exp

CONSTANT PI ← 3.141 CONSTANT CLASS_SIZE ← 23
# Names of constants will always be
# written in capitals
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Standard arithmetic operations (4)

A

*
/

Used in the normal way with brackets to indicate precedence where needed. For example, a + b * c would multiply b and c together and then add the result to a, whereas (a + b) * c would add a and b together and then multiply the result by c.

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

Integer division

A

IntExp DIV IntExp

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

9 DIV 5
5 DIV 2
8 DIV 4

A

evaluates to 1
evaluates to 2
evaluates to 2

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

Modulus operator

A

IntExp MOD IntExp

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

9 MOD 5
5 MOD 2
8 MOD 4

A

evaluates to 4
evaluates to 1
evaluates to 0

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

Relational operators for types that can be clearly ordered:

Less than - 
Greater than - 
Equal to - 
Not equal to - 
Less than or equal to -  Greater than or equal to -
A
Exp < Exp
   Exp > Exp
   Exp = Exp
   Exp ≠ Exp
   Exp ≤ Exp
   Exp ≥ Exp
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Examples of:

Less than - 
Greater than - 
Equal to - 
Not equal to - 
Less than or equal to -  Greater than or equal to -
A
4 <6
'A' < 'B' 
'adam' < 'adele'
4.1 > 4.0 
3= 3
qty ≠ 7
3 ≤4 
4 ≤4
4≥ 3 
4.5 ≥ 4.5
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is greater, and why?

‘adam’ ‘adele’

A

‘adam’ < ‘adele’

Alphabetically, ‘a’ comes before ‘d’, whichever first letter is different

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

Boolean operations

Logical AND
Logical OR
Logical NOT

A

BoolExp AND BoolExp
BoolExp OR BoolExp
NOT BoolExp

(3 = 3) AND (3 ≤ 4)
(x < 1) OR (x > 9)
NOT (a < b)

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

Indefinite (condition controlled) iteration

REPEAT-UNTIL (repeat the statements until the Boolean expression is True)

A
REPEAT
# statements here UNTIL BoolExp
a←1
REPEAT 
   OUTPUT a
    a←a+1 
UNTIL a = 4

will output 1, 2, 3

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

Indefinite (condition controlled) iteration

WHILE

A

WHILE BoolExp
# statements here
ENDWHILE

a←1
WHILE a < 4
  OUTPUT a
   a←a+1 
ENDWHILE
# will output 1, 2, 3
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Definite (count controlled) iteration

FOR-TO-[STEP]- ENDFOR
If STEP IntExp is missing it is considered to be 1.

A

FOR Identifier ← IntExp TO IntExp [STEP IntExp]
# statements here
ENDFOR
# If STEP IntExp is omitted the step value is 1.

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

FOR a ← 1 TO 3
OUTPUT a
ENDFOR

What will this output?

A

will output 1, 2, 3

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

FOR a ← 1 TO 5 STEP 2
OUTPUT a
ENDFOR

What will this output?

A

will output 1, 3, 5

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

FOR-IN-ENDFOR (repeat the statements the number of times that there are characters
in a string)

A

FOR Identifier IN StringExp
# statements here
ENDFOR

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

Pseudocde to calculate the numbers of characters in message

A

length ← 0
FOR char IN message
length ←length +1
ENDFOR

# will calculate the
# number of characters
# in message
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Pseudocde to output a string in revere
``` reversed ← '' FOR char IN message reversed ← char + reversed ENDFOR OUTPUT reversed ``` will output the string in reverse
26
SELECTION IF-THEN-ELSE-ENDIF (execute the statements following the THEN if the Boolean expression is True, otherwise execute the statements following the ELSE)
IF BoolExp THEN # statements here ENDIF ``` a← 1 IF (a MOD 2) = 0 THEN OUTPUT ‘even’ ELSE OUTPUT ‘odd’ ENDIF ```
27
NESTED IF-THEN-ELSE ENDIF (use nested versions of the above to create more complex conditions) Note that IF statements can be nested inside the THEN part, the ELSE part or both
``` IF BoolExp THEN # statements here ELSE IF BoolExp THEN # statements here ELSE # statements here ENDIF ENDIF ```
28
IF-THEN-ELSE IF ENDIF (removes the need for multiple indentation levels)
``` IF BoolExp THEN # statements here ELSE IF BoolExp THEN # statements here # possibly more ELSE ELSE # statements here ENDIF ```
29
ARRAYS ASSIGNMENT
Identifier ← [Exp, ... ,Exp] | primes ← [2, 3, 5, 7, 11, 13]
30
Arrays | Accessing an elemenT
Identifier[IntExp]
31
primes ← [2, 3, 5, 7, 11, 13] | primes[0]
evaluates to 2 (questions on exam papers will start indexing at 0 unless specifically stated otherwise)
32
Arrays | Updating an element
Identifier[IntExp] ← Exp primes ← [2, 3, 5, 7, 11, 13] ``` primes[5] ← 17 # array is now [2, 3, 5, 7, 11, 17] ```
33
Accessing an element in a two-dimensional array
Identifier[IntExp (row)][IntExp (column)]
34
table ← [[1, 2],[2, 4],[3, 6],[4, 8]] table[3][1]
``` # evaluates to 8 as second element # (with index 1) of fourth array # (with index 3) in table is 8 ```
35
Updating an element in a two- dimensional array
Identifier[IntExp][IntExp] ← Exp
36
table ← [[1, 2],[2, 4],[3, 6],[4, 8]] table[3][1] ← 16
table[3][1] ← 16 ``` # table is now #[ [1, 2], # [2, 4], # [3, 6], # [4, 16] ] ```
37
Array length
LEN(Identifier)
38
table ← [[1, 2],[2, 4],[3, 6],[4, 8]] LEN(table)
evaluates to 4
39
table ← [[1, 2],[2, 4],[3, 6],[4, 8]] LEN(table[0])
Evaluates to 2
40
FOR-IN-ENDFOR (repeat the statements the number of times that there are elements in an array) NOTE: array items cannot be modified using this method
FOR Identifier IN array # statements here ENDFOR ``` primes ← [2, 3, 5, 7, 11, 13] total ← 0 FOR prime IN primes total ← total + prime ENDFOR OUTPUT 'Sum of the values in primes is' OUTPUT total ```
41
Record declaration pseudo-code
RECORD Record_identifier field1 : field2 : ... ENDRECORD
42
Record for a car declaration: make, model, reg, price, noOfDoors
``` RECORD Car make : String model : String reg : String price : Real noOfDoors : Integer ENDRECORD ```
43
Pseudo-code record variable initialisation
varName ← Record_identifier(value1, value2, ...)
44
``` RECORD Car make : String model : String reg : String price : Real noOfDoors : Integer ``` Initialise a ford: pseudo-code
myCar ← Car('Ford', 'Focus', 'DX17 | GYT', 1399.99, 5)
45
Assigning a value to a field in a record - pseudo-code
varName.field ← Exp
46
myCar ← Car('Ford', 'Focus', 'DX17 GYT', 1399.99, 5) Change model to fiesta, pseudo-code
``` myCar.model ←'Fiesta' # The model field of the myCar # record is assigned the value # 'Fiesta'. ```
47
Accessing values of fields within records - pseudocode
varName.field
48
What does this do? (Records topic) OUTPUT myCar.model
OUTPUT myCar.model ``` # Will output the value stored in the # model field of the myCar record ```
49
Difference between subroutines and functions in pseudo-code
for the purposes of this pseudo-code definition subroutines that contain a RETURN keyword are functions. Those that do not contain a RETURN keyword are procedures.
50
Subroutine definition
``` SUBROUTINE Identifier(parameters) # statements here ENDSUBROUTINE ```
51
Subroutine to add two numbers
SUBROUTINE showAdd(a, b) result ← a + b OUTPUT result END SUBROUTINE
52
SUBROUTINE sayHi() OUTPUT ‘Hi’ ENDSUBROUTINE Function or procedure?
Procedure
53
SUBROUTINE add(a, b) result ← a + b RETURN result Function or procedure?
Function
54
Calling subroutines without a return value
Identifier(parameters) | showAdd(2, 3)
55
Calling subroutines with a return value
identifier ← identifier(parameters) answer ← add(2, 3)
56
String length pseudo-code
LEN(StringExp)
57
LEN('computer science')
evaluates to 16(including space)
58
Position of a character
POSITION(StringExp, CharExp)
59
POSITION('computer science', 'm')
``` # evaluates to 2 (as with arrays # exam papers will start # indexing at 0 unless # specifically stated otherwise) ```
60
Substring
Substring (the substring is created by the first parameter indicating the start position within the string, the second parameter indicating the final position within the string and the third parameter being the string itself). SUBSTRING(IntExp, IntExp, StringExp)
61
SUBSTRING(2, 9, 'computer science')
evaluates to 'mputer s'
62
Concatenation
StringExp + StringExp
63
'computer' + 'science'
evaluates to 'computerscience'
64
String and character conversion: ``` Converting string to integer - Converting string to real - Converting integer to string - Converting real to string - Converting character to character code - Converting character code to character - ```
``` STRING_TO_INT(StringExp) STRING_TO_REAL(StringExp) INT_TO_STRING(IntExp) REAL_TO_STRING(RealExp) CHAR_TO_CODE(CharExp) CODE_TO_CHAR(IntExp) ```
65
STRING_TO_INT('16') STRING_TO_REAL('16.3') 16.3 INT_TO_STRING(16) REAL_TO_STRING(16.3) CHAR_TO_CODE('a') CODE_TO_CHAR(97)
``` STRING_TO_INT('16') # evaluates to the integer 16 STRING_TO_REAL('16.3') # evaluates to the real 16.3 INT_TO_STRING(16) # evaluates to the string '16' REAL_TO_STRING(16.3) # evaluates to the string '16.3' CHAR_TO_CODE('a') # evaluates to 97 using ASCII/Unicode CODE_TO_CHAR(97) # evaluates to 'a' using ASCII/Unicode ```
66
User input
USERINPUT a ← USERINPUT
67
Output
OUTPUT a OUTPUT a, g The output statement can be followed by multiple StringExp separated by commas
68
Random integer generation
Random integer generation (between two integers inclusively) Identifier ← RANDOM_INT(IntExp, IntExp)
69
diceRoll ← RANDOM_INT(1, 6)
Will randomly generate an integer between 1 and 6 inclusive