Unit 11 - Programming Techniques Flashcards

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

What are the main programming constructs? (4)

A

Sequence: code is executed line by line

Selection: code is executed if a condition is true

Iteration: code is repeatedly executed until a condition is met (condition-controlled) or a count has been reached (count-controlled)

Recursion: a subroutine calls itself within its own code until a stopping condition is met

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

What are the advantages and disadvantages of recursion? (2 each)

A

Adv.
- Can be represented in fewer lines of code
- Easier to express some functions recursively (eg. factorial)

Disadv.
- high memory usage (can cause overflow error)
- difficult to trace

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

What is the difference between global and local variables? (3)

A
  • Local variables can only be accessed within the subroutine they are created in; global variables can be accessed anywhere in the program
  • Local variables can have the same name if they are created in different subroutines; global variables must have unique names
  • Local variables are deleted after their subroutine ends; global variables are deleted when the program ends (requiring more memory)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the features of an IDE? (know at least 4/5)

A
  • Line numbers
  • Automatic code indentation
  • Auto-complete code
  • Syntax highlighting
  • Debugger
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the difference between a variable and constant?

A
  • Variables are able to change their value while the program is being executed, constants cannot
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the difference between parameters and arguments?

A
  • Parameters are the variables which hold the value passed into a subroutine when it is being called.
  • Arguments are the values passed into the subroutine which are stored in the corresponding parameter.

EXAMPLE:

1 procedure dap_up(name)
2 print(“yooo”, name)
3
4 dap_up(“eggmo”)

‘name’ is the parameter, ‘eggmo’ is the argument

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

What are the two ways arguments can be passed into a subroutine?

A

Passing by value:
- a copy of the argument’s value is passed into the subroutine and discarded when the subroutine ends
- the argument’s value remains unaffected after the subroutine ends

Passing by reference:
- the address of the argument is passed into the subroutine
- the argument’s value will change after the subroutine ends

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

What is modular programming?

A
  • Tasks are broken down in to smaller subtasks which are further broken down into modules
  • Each module performs a single function
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the main characteristics of OOP? (3)

A

Encapsulation: attributes (class variables) and methods (class subroutines) are wrapped in the class definition to stop data from being directly accessible. Methods are made public and attributes are made private and change be read/altered using getter/setter methods.

Inheritance: classes can be declared as a ‘child’ of other classes to inherit the parent class’ attributes and methods while having their own individual attributes and methods.

Polymorphism: the ability to process objects differently depending on their class. If a child class inherits its parent’s methods, it can override them so that they share the same subroutine name but execute different code.

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

What is the difference between method overloading and method overriding?

A

Method overloading allows multiple methods in the same class to have the same name but different parameters.

Method overriding allows child classes to redefine existing methods in their parent class so that each use of the method is specific to the object calling it.

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

What are the advantages of OOP? (4)

A
  • Modular nature makes it easier to manage and deal tasks to developers
  • Code is reusable
  • Code is easier to maintain
  • Data hiding (like encapsulation) increases code security
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is meant by a heuristic approach?

A

Solving a problem using a ‘good enough’ solution because traditional methods would take too long to implement or execute

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

What is performance modelling?

A

When the behaviour of an object is tested or simulated before it is used in the real world

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