2.2.1 - programming techniques Flashcards
11
algorithm
A set of rules or a sequence of steps specifying how to solve a problem.
variables
Identifiers (names} given to memory locations whose contents will change during the course of the program.
2 reasons why variable names should be standardised
- makes the program easy to follow and update when required.
- leaves less room for errors and
inconsistencies in the names in a large program
3 basic programming constructs
- sequence
- selection
- iteration
define sequence
just two or more statements executed one after the other
define selection
used to select which statement will be executed next, depending on some
condition
iteration
involves performing a
loop in the program to repeat a number of statements
3 types of loops
- while…endwhile
- repeat…until
- for…next
integrated development environment (IDE)
A single program used for developing programs made from a number of components.
compiler/ interpretor
Translates high level code into machine code.
3 IDE tools to spot logic errors
- breakpoint
- watch
- step through
subroutine
A named block of code which performs a specific task within a program.
2 types of subroutines
- functions
- procedures
function
A named section of a program that performs a specific task. Returns a value.
procedure
Performs a task but doesn’t return a value.
by value
A copy of the variable is passed to the subroutine. Changing a parameter inside the subroutine will not affect its value outside the subroutine.
by reference
The memory location of the variable is passed to the subroutine. If it is changed in the subroutine, its value in the main program will also change.
global variables
Declared in the main program and can be used anywhere in the program, including subroutines.
local variables
Can be used within the subroutine and exist only during the execution of the subroutine. Cannot be accessed outside the subroutine.
modular programming
The process of subdividing a computer program into separate sub-programs.
advantages of subroutines
- Small so relatively easy to understand, debug and maintain.
- Can be tested independently.
- Can be reused indifferent programs or parts of the same program.
- Programmers can work on different subroutines.
- A large project becomes easier to monitor and control.
2 searching algorithms
- linear search
- binary search
linear search pseudocode
function LinearSearch(alist,itemSought}
index = -1
i = 0
found = False
while i < length(alist) and found = False
if alist[iI = itemSought then
index = i
found = True
endif
i = i + 1
endwhile
return index
endfunction
linear search
If the items are not in any particular sequence, the data items have to be searched one by one until the required one is found or the end of the list is reached.