Section 2 - Programming Flashcards
What are the five data types and what type of data are they used for?
- – Integer: a whole number
- – Float: a decimal number
- – Boolean: true or false
- – Character: a single character like a letter, number etc.
- – String: zero or more characters
What is an example of definite iteration?
FOR i
What is an example of indefinite iteration with the condition at the start?
WHILE Notsolved
Instructions here…
ENDWHILE
What is an example of indefinite iteration with the condition at the end?
REPEAT
Instructions here…
UNTIL Solved
What is nested selection and nested iteration?
This is when you have a selection or iteration programme within another selection or iteration programme.
What are the seven arithmetic operations?
Arithmetic operations: \+ (addition) - (subtraction) * (multiplication) / (division) ^ (exponential) // (DIV): outputs whole number of division % (MOD): outputs reminder of division
What are the six comparison operators?
Comparison operations: < (less than) > (greater than) <= (less than or equal to) >= (greater than or equal to) != or <> (not equal to) = or == (equal to
What are the three logical operations for boolean expressions and when are they used?
- – AND: when both expressions are true
- – OR: when only one expression needs to be true
- – NOT: inverses true to false and false to true
What are two advantages of using arrays?
- – Codes are easier to follow and easier to debug and maintain
- – Can easily be processed by a FOR loop
How do you get the length, substring and position of a string?
Length:
— LEN (stringExp) e.g. LEN (“Hello World”) would evaluate to 11
Substring:
— SUBSTRING (startPos, endPos, stringExp) e.g. SUBSTRING (3, 8, “Hello World”) evaluates to “lo Wor”
POSITION:
— POSITION (stringExp, char) e.g. POSITION (“Hello World”, d) evaluates to 10
What is concatenation?
Concatenation:
— Joining two or more strings together
How do you convert characters to and from ASCII?
CHAR_TO_CODE (“A”) evaluates to 65
CODE_TO_CHAR (66) evaluates to “B”
What are the functions you would use for these string handing operations:
- – String to integer
- – String to real
- – Integer to string
- – Real to string
- – STRING_TO_INT (StringExp) e.g. STRING_TO_INT (“45”) evaluates to 45
- – STRING_TO_REAL (StringExp) e.g. STRING_TO_REAL (“72.5”) evaluates to 72.5
- – INT_TO_STRING (StringExp) e.g. INT_TO_STRING (21) evaluates to “21”
- – REAL_TO_STRING (StringExp) e.g. REAL_TO_STRING (3.142) evaluates to “3.142”
What is a subroutine?
Subroutine:
— A named “out of line” block of code that is executed (called) by simply writing its name in a program statement.
What is the function used for random number generation in python and pseudocode?
Python:
import random
x = random.randint(1,10)
print(x)
Pseudocode:
x = RANDOM_INT (1,10)