unit 2b - programing techniques Flashcards

1
Q

what is a scope?

A

the area of a program where an item (variable, constant, subroutine etc.) is recognised by the program

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

what is a subroutine?

A

a selection of code that you can group together under a name and then call later in the program

example:
SUBROUTINE showKeys()
OUTPUT “keyboard controls”
OUTPUT “=============”
ENDSUBROUTINE

showKeys()

note that the subroutine above has no parameters hence the empty brackets

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

what is data validation?

A

it ensures that the data entered is the right type

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

what can validation not ensure?

A

it cannot ensure that the user has not typed in the wrong value or if there is a spelling mistake but rather if the data is reasonable and conforms to a set of rules

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

what are the 5 types of validation checks?

A

range check, type check, length check, presence check, format check

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

what does a range check do?

A

checks whether a number or date is within a sensible/allowed range

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

what does a type check do?

A

checks if the data is the right type eg. string or integer

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

what does a length check do?

A

checks if the data entered is of the right lengtheg. between a certain number of characters

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

what does a presence check do?

A

checks if data has been entered into a field or not ie. in case the field has been left blank

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

what does a format do?

A

checks if the data is the correct format eg. if was a postcode or email address

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

what is verification?

A

it is used to double check that the data has been typed in correctly

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

what is double-entry verification?

A

example: if a user is making a new password, they may be asked to enter it twice and if the two passwords don’t match, they’ll be asked to enter it again

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

what is authentication used for?

A

used to make sure a person is who they claim to be - checks this by identifying a valid username and password

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

how can programs be made easier to understand and maintain?

A
  • comments to show who wrote the program and when
  • comments to explain what the harder parts of code do
  • comments to explain the functionality of each subroutine (function or procedure)
  • meaningful variable names
  • a modular structure
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

what are trace tables used for?

A

used to determine the outputs from a program as it runs. enables a programmer to find errors in their programs

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

how do your create a trace table?

A
  • make a column of each variable used in the order in which they appear
  • record the value of each variable as it changes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

why is a trace table useful?

A
  • determining the purpose of an algorithm
  • finding the output of an algorithm
  • finding errors in an algorithm
18
Q

what are logical errors?

A

any error that isn’t a syntax error so the program will run/compile but not as intended by the programmer

19
Q

what are syntax errors?

A

where the code written doesn’t conform to the rules of the language - the program can’t be run (and will return an error) if there are syntax errors

20
Q

what is testing and why is it important?

A

it is important that the programs are fully to find logical errors
a test plan tests for normal data, boundary data and erroneous data

21
Q

what is normal data?
program: number between 1 and 100

A

normal data would be 5 (checks a single-digit) and 14 (checks two digits)

22
Q

what is boundary data?
program: number between 1 and 100

A

so boundary data would be the values either side of the boundary.
- 1 (checks the lowest valid data)
- 100 (checks highest valid data)
- 0 (checks invalid data at the boundary)
- 101 (checks invalid data at the boundary)

23
Q

what is erroneous data?
program: number between 1 and 100

A

erroneous data would something completely out of the range like -5 (checks a negative number) or 1012 (checks a large number) or “#$%” (checks that the data is of the wrong type) is rejected

24
Q

what are two techniques to finding logic errors?

A
  • trace table - traces through a program to scan for errors
  • inserting output statements at various points in the program to find the values of variables
25
Q

what are two types of subroutines?

A

functions and procedures

26
Q

what can be passed to both procedures and functions and which of the two return a value?

A

values can be passed to both procedures and functions and functions will return a value after processing has taken place

27
Q

what are built in subroutines and what are some examples in python?

A

they are built in procedures and functions to perform common tasks

examples:
- print(“hello”) - procedure
- input (“type in your name:”) - function
- random(1,6) - function

28
Q

what is one difference between procedures and functions?

A
  • procedures execute code in a subroutine - but they don’t return anything
  • functions will return something, so input returns what the user typed, random returns a number
29
Q

what is a function?

A
  • basically a procedure that returns a value at the end

example:
SUBROUTINE sum (a,b)
total <- a + b
return total
ENDSUBROUTINE

answer <- sum(5,3)
OUTPUT answer

30
Q

what are parameters?

A

a variable names in a subroutine heading that will receive and whatever value you pass through it

in sum(a,b), a and b are parameters

31
Q

how do you call a subroutine?

A

write the subroutine name and add parameters

example:
SUBROUTINE averageScore (totalScore, numScores)
avg <- totalScore / numScores
return avg
ENDSUBROUTINE

to call the function
OUTPUT “entire the total:”
total <- USERINPUT
OUTPUT “enter the number of scores:”
n <- USERINPUT
OUTPUT averageScore(total,n) «< calling
the function

32
Q

why are subroutines useful?

A
  • useful to break up a large program into self contained units
  • each subroutine can be tested separately to make sure it works correctly
  • many programmers can work on a lrage program at the same time, cutting down development time
  • subroutines can be re-used in other programs because they can be stored in a subroutine library
  • program maintenance is much easier because subroutines can be easily modified
33
Q

what are local variables?

A

they only exist while the subroutine is executing and are only accessible within the subroutine

34
Q

what are global variables?

A

they are accessible anywhere in the program

35
Q

how are global variables written in pseudocode?

A

using the keyword global score

36
Q

what are global and local constants?

A

they follow the same rules as global and local variables except a constant cannot be changed once declared

37
Q

what is an advantage of using local variables?

A

local variables keep a subroutine self-contained so it can be used in any program without variable names conflicting with those used in the main program

38
Q

how should subroutines be written?

A
  • they should be able to take any inputs (through parameters) and if necessary return values
  • they should be written in a modular way so that they can be reused multiple times in the program or in other programs
39
Q

what is the structured approach?

A

subroutines should be well-documented to show:
- the parameters that the subroutine takes, what they are used for and what data types are needed
- the purpose of the subroutine
- the return value and its data type

40
Q

what are advantages to using the structured programming technique?

A
  • the modularised approach of using subroutines helps to decompose large problems
  • programmers only need to use the interfaces of subroutines - the parameters and return values so they don’t need to worry about the workings of each subroutines
  • programs will have fewer bugs and be easier to maintain