2.2.1 - Programming techniques Flashcards

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

Name the three programming constructs

A

Sequence, Selection, Iteration

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

Which two categories of loop is
iteration split up into?

A
  • Count-controlled
  • Condition-controlled
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Describe how the branching programming construct works

A

A certain block of code is run if a specific condition is met, using IF statements

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

What is recursion?

A

A programming construct in which a subroutine calls itself during its execution until the stopping condition is met.

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

What is the base case in recursion?

A

A condition that must be met in order for the recursion to end

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

State two advantages of recursion

A

●Can be represented in fewer lines of code
● Easier to express some functions recursively than using iteration

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

State a disadvantage of recursion

A

-Inefficient use of memory
- Danger of stack overflow
- Difficult to trace

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

Give two pieces of information that are stored on the call stack

A
  • Parameters
  • Return addresses
  • Local variables
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Define scope

A

The section of the program in which a variable is accessible.

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

Give two advantages of using local variables over global variables

A
  • Less memory is used
  • Self-contained so unaffected by code outside of the subroutine
  • Take precedence over global variables with the same name
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is top-down design?

A

A technique used to modularise programs in which the problem is continually broken down into sub-problems, until each can be represented as an individual, self-contained module which performs a certain task.

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

State two advantages of a modular design

A
  • Makes a problem easier to understand and approach
  • Simpler to divide tasks between a team
  • Easier to manage project
  • Self-contained modules simplify testing and maintenance
  • Greater reusability
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Give another name for top-down design

A

Stepwise refinement

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

What is the difference between procedures and functions?

A

Functions must always return a single value while a procedure does not always have to return a value.

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

What does it mean to pass a parameter to a subroutine by reference?

A

The address in memory of the parameter is passed to the subroutine so its value outside of the subroutine will be updated.

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

State two features of IDEs

A
  • Stepping
  • Variable watch
  • Breakpoint
  • Source code editor
  • Debugging tools
17
Q

What does IDE stand for?

A

Integrated Development Environment

18
Q

What is encapsulation in object-oriented programming?

A

When attributes are declared as private so can only be accessed and edited by public methods.

19
Q

Describe the purpose of encapsulation in object-oriented programming

A

Program complexity is reduced by protecting data from being accidentally edited by other parts of the program.

20
Q

What are objects?

A

These are program building blocks.

They are self-contained.

They are made from data (attributes) and program code (methods).

Objects are based on classes.

Many objects can based on the same class.

Most programs nowadays are built using object-oriented techniques at least to some extent.

21
Q

What is modularity?

A

Program is divided into separate, self-contained, specific modules or tasks.

Modules can be subdivided further into smaller modules.

Each individual module is a small part of the problem and focuses on a small sub-task so is easy to solve,
understand, test, debug and read before integration e.g. by a third party.

Easy to maintain, update and replace a part of the system as the whole program will be well structured with
clearly defined interfaces without affecting the rest.

Development takes place in parallel and can be shared between a team of programmers so the program is
developed faster and easier to monitor progress.

Modules can be allocated according to programmers’ individual strengths and area of expertise improving the
quality of the final product.

Different modules can be programmed in different languages suitable for the application as appropriate.

Reduces the amount of code that needs to be produced because code from other programs can be reused or
standard library routines can be used reducing time of development.

Modules must be linked and programmers must ensure that cross-referencing is done.

Interfaces between modules must be planned and testing of links must be carried out.

22
Q

What is a local variable?

A

A variable declared and defined within one subroutine and is only accessible and visible within that subsection of the program or construct where it is created.

Help to make each function or procedure reusable.

Can be used as parameters.

Is destroyed or deleted when the subprogram exits so the data contained ceases to exit at end of module once the execution of that part of the program it is in is completed.

The same variable names within two different modules will not interfere with one another to allow the same identifier to be used for different purposes without overwriting values or causing errors e.g. loop counter.

Local variables with the same name as global variables will override and take precedence over the values in the global variable.

23
Q

What is a global variable?

A

A variable that is usually declared and defined at the start of a program outside subprograms.

Is visible and available everywhere throughout the whole program in all modules including functions and
procedures.

Used where a value needs to be accessible from various parts of the program.

Allows data to be shared between modules.

It is the same value irrespective of the place where it is accessed e.g. today’s date, VAT rate, π.

Makes it difficult to integrate modules.

It increases the complexity of a program.

It may cause conflicts with names written by others or in other modules.

It may be changed inadvertently when the program is complex.

Global variables are dangerous. They can easily be accidentally altered.