2.2.1 Programming Techniques 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
What is meant by passing by value?
A copy of the value is passed to the subroutine and discarded at the end Value external to subroutine remains the same
26
What is meant by passing by reference?
Address of parameter is given to subroutine Value will be updated at given address
27
What does IDE stand for?
Integrated Development Environment
28
What is an IDE?
Program providing a set of tools that allow programmers to write, develop & debug code easily
29
State the 5 common features of IDEs.
Stepping Variable watch Breakpoint Source code editor Debugging tools
30
What is meant by stepping?
Executes a single line at a time Allows programmer to monitor the effect of each individual line of code
31
What is meant by variable watch?
Used to observe how the contents of a variable change in real-time through the execution of a program
32
What is meant by breakpoint?
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
What is meant by source code editor?
Aims to make coding process easier Includes autocompletion of words, indentation, syntax highlighting & automatic bracket completion
34
What is meant by debugging tools?
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
What is a class?
A template for an object Defines the state & behaviour
36
How is the state of an object defined?
Attributes Give an object's properties
37
How is the behaviour of an object defined?
Methods Describe actions an object can perform
38
What is instantiation?
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
What is encapsulation?
Attributes are declared as private so can only be altered by public methods
40
Why is encapsulation used?
Makes programs less complex by protecting data from being accidentally edited