2.2.1 Programming Techniques Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

Name 3 programming constructs.

A

Sequence
Selection
Iteration

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

What is meant by sequence?

A

Code is executed line-by line from top to bottom

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

What is meant by selection?

A

Particular block of code is run if a specific condition is met

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

Which statements are examples of selection?

A

If
Else

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

Name the 2 types of iteration.

A

Count-controlled
Condition-controlled

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

What is meant by count-controlled iteration?

A

Block of code executed a certain number of times

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

What is meant by condition-controlled iteration?

A

Block of code executed while a condition is met

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

Which loops are examples of iteration?

A

For
While

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

What is recursion?

A

A programming construct in which a subroutine calls itself during its execution

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

How long does recursion continue?

A

Until a stopping condition is met

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

Give 2 advantages of recursion.

A

Can be represented in fewer lines of code
Easier to express some functions recursively

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

Give 2 disadvantages of recursion.

A

Risk of stack overflow if memory runs out
Difficult to trace

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

Which two ways can variables be defined?

A

Within a global scope
Within a local scope

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

What is meant by scope?

A

The section of code in which a variable can be accessed

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

Where can local variables be accessed?

A

Only within the subroutine in which they are defined

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

Where can global variables be accessed?

A

Across the whole program

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

What are 2 benefits of local variables?

A

Ensures subroutines are self-contained
Multiple local variables with the same name can exist in different subroutines

18
Q

What are 2 disadvantages of global variables?

A

Requires more memory as not deleted until program terminates, local variables are deleted once the subroutine ends
Danger of being unintentionally edited

19
Q

What is modular programming?

A

A technique used to split large, complex programs into smaller, self-contained modules

20
Q

Give 3 benefits of using modular programming.

A

Improves reusability of components
Simplifies testing & maintenance
Easier project management

21
Q

What is stepwise refinement / top-down design?

A

Technique used to modularise programs by breaking down problem into sub-problems until each is an individual, self-contained module performing a certain task

22
Q

What is a function?

A

Named block of code that performs a specific task
Always returns a single value

23
Q

What is a procedure?

A

Named block of code that performs a specific task
Do not have to return value

24
Q

State the two methods by which parameters can be passed.

A

By reference
By value

25
Q

What is meant by passing by value?

A

A copy of the value is passed to the subroutine and discarded at the end
Value external to subroutine remains the same

26
Q

What is meant by passing by reference?

A

Address of parameter is given to subroutine
Value will be updated at given address

27
Q

What does IDE stand for?

A

Integrated Development Environment

28
Q

What is an IDE?

A

Program providing a set of tools that allow programmers to write, develop & debug code easily

29
Q

State the 5 common features of IDEs.

A

Stepping
Variable watch
Breakpoint
Source code editor
Debugging tools

30
Q

What is meant by stepping?

A

Executes a single line at a time
Allows programmer to monitor the effect of each individual line of code

31
Q

What is meant by variable watch?

A

Used to observe how the contents of a variable change in real-time through the execution of a program

32
Q

What is meant by breakpoint?

A

Allows programmer to set a point in the program for it to stop
Either based on a condition or at specific line
Helps pinpoint errors

33
Q

What is meant by source code editor?

A

Aims to make coding process easier
Includes autocompletion of words, indentation, syntax highlighting & automatic bracket completion

34
Q

What is meant by debugging tools?

A

Run-time detection of errors with a guide to where in the code they are likely to have occured through line numbers and highlighting

35
Q

What is a class?

A

A template for an object
Defines the state & behaviour

36
Q

How is the state of an object defined?

A

Attributes
Give an object’s properties

37
Q

How is the behaviour of an object defined?

A

Methods
Describe actions an object can perform

38
Q

What is instantiation?

A

An object is an instance of a class
A class can be used to create multiple objects with the same set of attributes & methods

39
Q

What is encapsulation?

A

Attributes are declared as private so can only be altered by public methods

40
Q

Why is encapsulation used?

A

Makes programs less complex by protecting data from being accidentally edited