2.2.1 - Programming Techniques Flashcards

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

Define the programming construct Sequence

A

All instructions are executed once in the order in which they appear.

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

Define the programming construct Iteration

A

A section of code loops or a group of statements/instructions are executed repeatedly for a set number of times or until a condition is met.

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

Define the programming construct Selection

A

A condition is used to determine which of the sections of code (if any) will be executed. As a result some instructions may not be executed.

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

What is Recursion?

A

When a function/procedure calls itself from within the function.

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

What are some features of a recursive function

A
  • Contains a stopping condition called the base case; there may be more than one.
  • Stopping condition should be reachable in a finite number of times
  • For any other input value other than the stopping condition, the function should call itself
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

List some advantages of using recursive function rather than an iterative function

A
  • Quicker to write/generally less lines of code as some functions are naturally recursive.
  • Suited to certain problems for example those using trees.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

List some disadvantages of using recursive function

A
  • Creates new variables for each call therefore is less efficient use of memory.
  • Is more likely to run out of stack space/memory due to too many calls causing it to crash.
  • Requires more memory and resources than the equivalent iterative algorithm.
  • Algorithm may be more difficult to trace/debug as each frame on the stack has its own set of variables.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Define 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.

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

Define 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.
  • Can be used as parameters
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

When is a Local Variable Destroyed?

A

When the subprogram is exited

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

When is a Global Variable Destroyed?

A

When the whole program ends

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

Explain what is meant by ‘Scope’ in relation to Global and Local Variables.

A
  • A range of statements/functions that a variable is valid for
  • A local variable takes precedence over a global variable of the same name/allow the same identifier to be used for different purposes without conflict
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Disadvantages of Global Variables

A
  • It increases the complexity of a program.
  • It may be changed inadvertently when the program is complex.
  • They can easily be accidentally altered because Local variables with the same name as global variables will override and take precedence over the values in the global variable.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is an advantage of a local variable

A

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

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

What is Modularity

A
  • Program is divided into separate, self-contained, specific modules or tasks.
  • Modules can be subdivided further into smaller modules.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Explain the advantages of using a modular approach.

A
  • Work is easier to divide between a team; allowing members to work in their area of expertise
  • Each team member just needs to know what values go into their subroutine and the expected functionality
  • Saves time as work takes place in parallel
  • Breaks problems into smaller areas.
  • Easier to test/debug/read; each subroutine can be tested before integration.
  • Code can be reused in the project/future projects
17
Q

What is a function?

A

A piece of code that uses local variables to perform specific tasks or calculations; returning a single data type value

18
Q

What is a procedure?

A

A piece of code that is given an identifier and performs a task using local variables but it does not necessarily have to return a value by parameter passing

19
Q

Advantages of Subroutines

A
  • Programs easier to write
  • Programs easier to debug
  • Creates reusable components
  • Programs easier to test
20
Q

What is the main difference between a function and a procedure?

A

A procedure does not return a value /
A function has to return a value

21
Q

Define the term Parameter

A

(A description of) an item of data that is passed to a subroutine and used as a variable within the
subroutine

22
Q

What does it mean by passing a parameter by value?

A
  • A local copy of the data is used
  • Data is discarded when the subprogram exits
  • Does not override/change the original data
23
Q

What does it mean by passing a parameter by reference?

A
  • Memory location of data is sent
  • Changes are made to the original data
  • Changes remain after the subprogram exits
24
Q

Explain Parameter Passing

A
  • Parameters passed by value or by reference
  • By value, local copy of data is used then discarded so value of (original) data is unchanged
  • By reference, location of data is used so changes may be made to value of data
25
Q

What is an Integrated Development Environment (IDE) (HINT for Features: ‘PBE, DBT, CVC’)

A
  • A single program used for developing programs made from a number of components
  • IDEs often provide features for: program building, editing, debugging, testing, compilation and version control
26
Q

What are debugging tools?

A

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

27
Q

What is Translator/Error Diagnostics

A
  • Reports and picks up when syntax errors (when code doesn’t follow the rules of the language) are made
  • Suggests solutions and informs the programmer who can then correct the error
  • But sometimes the error messages are incorrect or in the wrong place.
28
Q

What is a Breakpoint

A
  • Used to test the program works up to specific points or at specified lines of code.
  • Allows the programmer to check variable contents at chosen points and set where the program stops running
29
Q

What is a Variable Watch

A

Monitors the status of variables and objects as you pass through code and causes the program to halt in execution if a condition is met such as a variable changing.

30
Q

What is Stepping

A
  • Can set the program to run code line by line; slowing down execution and allowing the programmer to watch the effect of each line of code in turn to find the point where an error occurs
  • Can be used with breakpoints or variable watches.
31
Q

What are other types of features of IDEs

A
  • Syntax highlighting - to identify key words, variables and help identify syntax errors
  • Auto-complete - start typing a command/identifier and it completes it
  • Error diagnostics - to locate and fix errors