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)
What are the advantages of using subroutines?
- – Makes problem easier to solve.
- – Can be used several times within a program.
- – Can be stored in a subroutine library and used in other programs.
- – Several programmers can work on a program together.
- – Program maintenance is easier as its easier to change a problem in a subroutine.
What is the difference between procedures and functions?
They are both self-contained sections of code that carry out a specific task however a function returns a value using a RETURN statement.
Explain local variables and give advantages of them.
Local variables are variables found within a subroutine.
Local variables:
— only exist while the subroutine is executing
— are only accessible within the subroutine.
Advantages:
- – Keeps subroutine self-contained which limits confusion between global variables
- – Keeps program easier to debug and maintain
- – Saves memory as space is freed up when subroutine completes.
What is meant by testing in the context of algorithms and programs?
Tesiting is the act of checking if a program runs the way it was intended to run and produces the output expected.
Compare the three types of errors when programming.
Syntax error:
— Spelling or grammar mistakes so when there are mistakes in the actual typing up of the code
Logic error:
— Problems with the actual execution of the code in the sense that although the program may run, it does not produce the expected outcome.
Runtime error:
— When the program crashes while the program is being executed. Possibly caused by an incorrect input midway through the program
What is test data and describe the three types of test data?
Test data:
— Data that is entered to check if a program works effectively.
Normal (typical):
— Data within the allowed range so data that is valid
Boundary:
— Data which includes both ends of the allowed range as well as data just either side of the allowed range.
Erroneous:
— Any data that falls outside the allowed values and should be rejected by the system.
What are the four columns needed in a test plan table?
- – What is being tested
- – Test data
- – Expected outcome
- – Actual outcome