2.2.1 Programming Techniques Flashcards

1
Q

What are the three main programing constructs?

A
  1. Sequence
  2. Selection / Branching
  3. Iteration
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is sequence?

Programing construct

A

Instructions that are executed one after the other, in order.

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

What is selection / branching?

Programming construct

A

When the computer may execute different instructions based on a condition.

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

What is iteration?

Programming construct

A

When an instruction or group of instructions is run multiple times.

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

What is recursion?

A

A function defined in terms of itself, with a base case that terminates the recursion.

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

What are the advantages of recursion over iteration?

A
  1. More natural for some problems
  2. Uses less lines of code
  3. Divide and conquer recursive algorithms are often faster
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the advantages of iteration over recursion?

A
  1. Requires less memory
  2. Won’t cause stack overflow errors
  3. Iteration is normally faster than recursion
  4. Easier to trace
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the similarities between recursion and iteration?

A

They can both be used to solve the same problems.
They can both involve running the same section of code multiple times.

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

What are the differences between recursion and iteration?

A

A recursive solution creates new local variables each time it is called.
An iterative solution uses the same local variables each time the loop runs.

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

What is modular program design?

A

When a program is divided into seperate self contained subroutines/modules which can be written and tested individually.
Subroutines/modules may be divided further into smaller subroutines/modules.

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

What is a subroutine/module?

A

A named section of a program that performs a specific task.

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

What is a function?

A

A named section of a program that performs a specific task and returns a value.

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

What is a procedure?

A

A named section of a program that performs a specific task but does not return a value.

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

What are the types of subroutine/module?

A

Functions and procedures.

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

What is a parameter?

A

An item of data that is passed into a subroutine/module when it is called, and used as a variable within the subroutine/module when it is used.

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

What are the advantages of designing a program modularly?

A
  1. Code can be reused in the same and other programs, which saves time
  2. Each module can be tested independently, which makes finding bugs easier
  3. Different modules can be worked on by different programers, which saves time and allows people to work on problems they are specialised for
  4. Programmers only have to know the inputs and outputs of the module they are working on, and don’t have to understand the whole problem
  5. It can make the solution more memory efficient (because of local variables)
  6. It can make the code less difficult to write (because it is split into chunks)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is a variable?

A

A named memory location used to store data that can change while the program is running.

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

What is a constant?

A

A named memory location used to store data that cannot change while the program is running.

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

What is scope?

For variables

A

The range of statements/subroutines that a variable can be used in.

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

What is a global variable?

A

A variable that is accessible throughout the whole program

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

What is a local variable?

A

A variable that is accessible only in the module/construct where it was created.

22
Q

What are the differences between global and local variables?

A
  1. Global variables are accessible everwhere and local variables are only accessible in the module/structure where they are defined.
  2. Global variables are normally defined at the start of a program and local variables are normally defined at the start of a subroutine.
  3. If a global and local variable have the same name the local variable will take priority.
23
Q

What are the advantages of using global variables over local variables?

A
  1. Easier to program, because no need for parameters
  2. Easier to use when a value is the same everywhere in the program (e.g. today’s date)
24
Q

What are the disadvantages of using global variables over local variables?

A
  1. They can make it difficult to intergrate modules together.
  2. They can cause unintended changes in other parts of the program.
  3. The can increase the amount of memory used by the program
25
Q

What is passing by value?

Parameter passing

A

A local copy of the variable passed in is made so that the original variable is left unchanged.

26
Q

What is passing by reference?

Parameter passing

A

The location of the original variable is passed in and used so that changes made in the subroutine also effect the original variable.

27
Q

Give one example of programming in sequence.

A

E.g.
Input, output, casting, concatenation, variable assignment/decleration.

28
Q

Give one example of programing with branching/selection.

A

E.g.
If/else if/else statements. Switch/case statements.

29
Q

Give one example of programming iteratively.

A

E.g.
For loop, while loop, repeat loop. do-until loop, BRZ, BRP.

30
Q

What is casting?

A

Changing the data type of a variable

31
Q

What is concatenation

A

Joining two strings into one string

32
Q

What does a comparison operator do?

A

Check if two items are the same

33
Q

What does an assignment operator do?

A

Changes the value of a variable

34
Q

What is an IDE?

A

Intergrated Development Environment. A single program used for developing programs made from a number of components.

35
Q

What are the main features of an IDE?

A
  1. Text editor (for writing code)
  2. Debugging tools
  3. Translator and run time environment
36
Q

What three common debugging features for an IDE?

A

Any from:
1. Pretty printing - highlights key words, unlerlines syntax mistakes
2. Watch window - see how variables change during the run time of the program
3. Break points - stop the program at set points to check the values of variables
4. Error message list - tells you the line number of errors and suggestions for fixing them
5. Step mode - executes programs one statement at a time to watch the variable values and program paths
6. Crash dump/post mortem - shows the state of the program and variables when an error occurs
7. Cross referencers - shows every time a name is used
8. Auto complete/indent - automatically finishes or indents statements

37
Q

What is an imperative procedural language?

A

A high level language that works by giving a series of instuctions in a logical order that explain what the computer should do and how to do it.

38
Q

What is OOP?

A

Object Oriented Programming. Programming using classess and objects.

39
Q

What is an Object Oriented Language?

A

A programming language based around classes, objects, and the interactions between them.

40
Q

What is a class?

A

A template for an object, stating the methods and attributes it should have.

41
Q

What is an object?

A

An instance of a class.

42
Q

What is an attribute?

A

Data an object holds

43
Q

What is a method?

A

A subroutine that can be performed by a class

44
Q

What is instantiation?

A

Setting the original value of something

45
Q

What is inheritence?

A

When a child/subclass takes on the attributes and methods of a parent/superclass. It may also have its own methods and attributes.

46
Q

What is encapsulation?

A

Making attributes private so that they can’t be accessed or altered accidently by other objects

47
Q

What is overriding/polymorphism?

A

When a method name is the same in a parent and child class, but does different things in both.

48
Q

What is a constructor?

A

A method that creates an object

49
Q

What is a getter?

A

A public method/function that returns the value of a private attribute

50
Q

What is a setter?

A

A public method that changes that value of a private attribute