Unit 2.2.1 - Programming Techniques Flashcards

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

What are 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

What is sequence?

A

Instructions in a program are executed in the order they have been written.

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

What is iteration?

A

It allows sections of code to be repeated.

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

What is selection?

A

A program that changes direction depending on the outcome of a condition. They are usually shown using Boolean expressions (IF statement).It allows sections of code to be repeated.

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

What are the two types of loops?

A
  • Count - controlled loop (FOR)
  • Condition - controlled (DO UNTIL/WHILE)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a count-controlled loop?

A

A loop which is used when the required number of iterations is known ahead of execution.

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

What is a condition-controlled loop?

A

A loop with a condition at the start to determine if the iteration should occur or not. As long as the condition is met the iteration continues.

It is used when the number of required iterations are not known.

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

What is a nested construct?

A
  • A programming construct that is included within another programming construct.
  • It enables powerful yet simple programming.
  • It reduces the amount of code needed, while making it simple for a programmer to debug and edit
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is recursion?

A

When a subroutine (often a function) calls itself from within its own subroutine.

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

What characteristics should a recursive subroutine exhibit?

A
  • It contains a terminating condition (base case).
  • For any input value other than the terminating condition, the subroutine should call itself.
  • The base case should be reached within a finite number of times.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What would happen if there wasn’t a base case, or the base case cannot be achieved in a finite number of times?

A

The subroutine would call itself indefinitely, taking up memory and resulting in a stack overflow. This could cause the program to crash.

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

Why is recursion not very efficient?

A

Every time a recursive function calls itself, the processor must remember the address it must jump back to later and the previous variables by using stacks, which takes up space in memory.

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

When is recursion needed rather than iteration?

A
  • Tree traversal algorithms
  • Performing a flood fill in a graphics application
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the scope?

A

The scope of a variable refers to where it is accessible in the code. The scope is global or local.​

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

What is a local variable?

A
  • Declared inside a subroutine.​
  • Only accessible by that subroutine.​
  • Created when the subroutine is called.​
  • Destroyed when the subroutine ends.​
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is a global variable?

A
  • Declared at the top of a program, outside of any subroutine.​
  • Accessible throughout the program.​
  • Created when the program starts.​
  • Destroyed when the program ends.​
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What are the advantages of local variables?

A
  • Memory efficient
  • Avoiding naming conflicts and errors
  • Easier to debug
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What are the disadvantages of local variables?

A
  • Limited scope
  • Difficult to reuse/share data between different parts of a program
  • More difficult to debug (difficult to identify and fix errors)
  • May slow execution
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What are the advantages of global variables?

A
  • Can be accessed from anywhere in a program
  • Can share data between functions
  • Stores persistent data
  • Accessed from any function
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What are the disadvantages of global variables?

A
  • Any change in a global variable is propagated throughout the program
  • Make the code less modular, flexible and scalable
  • Name collisions
  • Logic errors by modifying global variable in one function
  • Takes up memory space
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is a procedure?

A

A block of code that takes in zero, 1 or more parameters and performs a set task.

22
Q

What is a function?

A

A block of code that takes in zero, 1 or more parameters; performs a set task and returns a value.

23
Q

What is modularity?

A

The concept of breaking down a large problem/program into smaller parts.

The goal is to design the program in such a way that each module carries out a single specific task.

24
Q

Why are functions used in modular programming?

A
  • Performs data on input data (parameters) and return a result.
  • Can be called numerous times, reducing duplicated code
  • Enable larger programs to e written using reusable code
  • Stores in libraries for other programmers to use in their programs
25
Q

Why are procedures used in modular programming?

A
  • Used to break a program into manageable sections
  • Easier to read and debug
  • Uses local variables
  • Enables different programmers to work out different parts of the code
  • Allows routines to be reused in other programs
26
Q

What are the three types of sub routines?

A
  • Methods
  • Functions
  • Procedures
27
Q

Why are library functions used in modular programming?

A
  • They are already tested
  • Make use of other programmers’ expertise
  • Can be written in other languages as they’re already compiled
28
Q

What does the interface (first line) of a subroutine specify?

A
  • Name of subroutine
  • List of parameters required when it’s called
  • Order of parameters
  • Data type for these parameters
29
Q

What is Object Oriented Programming (OOP)?

A

A paradigm, involving the attempt to capture or group information, data and related functionality into structure items known as objects.​

30
Q

What is an IDE (Integrated Development Environment)?

A

A software application that provides a set of tools and related functionality to maximise the programmer’s productivity.

It is designed to allow the programmer to modify, compile and debug their program.

31
Q

What are the common features of an IDE?

A
  • Code editors​
  • Error diagnostics​
  • Runtime environments​
  • Translators​
  • Auto-documentation​
  • Syntax highlighting​
  • Autocompletion​
32
Q

What is a class?

A

A template for creating objects. It defines the attributes and behaviours that the instantiated objects will have.

Classes act as user-defined data types in OOP.

33
Q

What is an object?

A

An instance of a class which represents a real-world entity, combining data (attributes) and the actions (methods) that can be performed on that data.

34
Q

What is an attribute?

A

A specific item of data for a class/object.

35
Q

What is a method?

A

A subroutine defined within a class.

36
Q

What is a Private method?

A

An access modifier which can only be accessed within the class.

36
Q

What is encapsulation?

A

Data held within a class (attributes) that can only be accessed via its methods.

They cannot be accessed directly, thus promoting data hiding and the principle of information hiding.

37
Q

What is a Public method?

A

An access modifier which can be accessed anywhere from the scope of the class.

38
Q

What is Instantiation?

A

The process of creating an instance (object) of a class.

It involves allocating memory and initializing the object based on the structure and behaviour defined by the class.

39
Q

What is Inheritance?

A

A mechanism that allows a new class (subclass or derived class) to inherit attributes and behaviours from an existing class (base class) and add further functionality to it.

It promotes code reuse and the creation of a hierarchy of classes.

40
Q

What is a Base (Super) Class?

A

The class from which a subclass inherits its attributes and behaviours.

It is higher in the class hierarchy and provides a common set of features that multiple subclasses can share.

41
Q

What is abstraction (in OOP)?

A

The ability to represent a real-world object as a simplified representation in code.

42
Q

What is a constructor?

A

A special method which creates an object from a class.

43
Q

What is Overloading?

A

The ability for different methods to have the same names but different number of parameters which therefore exhibit different behaviours.

44
Q

What is Polymorphism?

A

The ability for methods of the same name to be used in inherited classes with different behaviours exhibited.

45
Q

What is the purpose of a code editor in an IDE?

A
  • A text area for programmers to enter code directly into the IDE
  • Often supports additional features like syntax highlighting, autocomplete and automatic indentation
46
Q

What is the purpose of error diagnostics in an IDE?

A
  • Reports errors (mainly syntax) in the code and where they can be found
  • Often suggests possible fixes
47
Q

What is the purpose of a run-time environments in an IDE?

A
  • Software that supports the execution and running of programs
  • Allows programmers to easily run code during development
48
Q

What is the purpose of translators in an IDE?

A

A program that converts high-level code into executable machine code.​

49
Q

What is the purpose of auto-documentation in an IDE?

A

Tracks variables declared by the programmer, modules and other special programmer comments with a view to producing documentation that aids in program maintenance, debugging and support.​

50
Q

What does it mean to ‘Pass by value’?

A
  • When a function is called, a copy of the actual parameter’s value is passed to the function
  • The original parameter remains unchanged outside the function
  • Suitable when you only need to use the parameter for computation within the function without altering it for the client program
51
Q

What does it mean to ‘Pass by reference (address)’?

A
  • A copy of the address (reference) of the actual parameter is stored
  • Any changes made to the parameter within the function directly affect the original parameter outside the function
  • Used when you intend to modify the parameter passed in by the client program