2.2.1 Programming Techniques Flashcards

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

Sequence

A

Execution of statements or functions one after another

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

Iteration

A

Where a section of code is repeated, controlled by a Boolean expression
Can be count-controlled (for) or condition-controlled (while)

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

Branching/selection

A

Where a section of code is executed based on a condition, controlled by a Boolean expression

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

Local Variables

A

They are declared inside a subprogram and are only visible from that subprogram. The data is lost at the end of the subprogram and they can overwrite global variables
They are stored in RAM in the stack or the heap

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

Local Variables Advantages

A

+ Less likely to be altered by other modules

+ Allows code to be reused as libraries

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

Global Variables

A

Declared outside any subprograms, can be accessed from anywhere in the program.
Stored in RAM in a section called Data

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

Global Variables Advantages

A

+ Can be called anywhere in the program

+ Useful if various subprograms read/write

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

Subroutine

A

A section of code that performs a specific task

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

Functions vs procedures

A

Functions return a value, procedures do not

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

Parameter passing

A

Arguments in brackets are used to pass data to a subroutine e.g. multiply(x,y)
Can be by value or by reference

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

Passing by value

A

A local copy of the value of the data is passed so the value of the original data is unchanged

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

Object

A

A thing that has data (attributes) with operations that can be called on that data (methods)

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

Attributes

A

A property of the object

Shape could be one, round could not

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

Class

A

A blueprint for an object

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

Constructor

A

A method that is used to create objects based on the class

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

Encapsulation

A
Wraps the attributes and methods in the class definition, hiding details of the implementation from the user
Attributes are made private and can only be accessed through public methods
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Pseudocode to define a class

A

class Classname
private attributes

end class

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

Pseudocode constructor method

A

public procedure new (_Name)
name = _Name
end procedure

19
Q

Pseudocode get()

A

public function getName()
return name
end function

20
Q

Instantiating an object in pseudocode

A

variable = new Classname(parameters)

21
Q

Inheritance

A

When a child inherits the properties of a parent class

22
Q

Inheritance pseudocode

A
class Child inherits Parent
inherit attributes/methods with super.
23
Q

Polymorphism

A

The ability of a programming language to process objects differently based on their class.

24
Q

Object Oriented Programming Advantages

A

Code can be reused easily via libraries
Code complexity is reduced as it is not necessary to know how methods are implemented
OOPs are easier to modify and maintain

25
Q

Parameter

A

An item of data that is inputted to a subroutine and is used as a variable within the subroutine

26
Q

Passing by reference

A

The location of data is passed into a subroutine so changes may be made to the value of the data

27
Q

Variable

A

An identifier of a memory location used to store data

28
Q

Scope

A

An area of a program for which a variable is valid

29
Q

Recursion

A

A subroutine where a section of code calls itself. There must be a base case that can be met to stop an infinite loop.

30
Q

Returning values in recursion

A

The returned value is used in the previous running of the function until they have all been completed, inputs are stored in a stack frame

31
Q

IDE

A

A software that allows you to program, debug and run code

32
Q

do until loop

A

do
….
until condition

It will run the code first and then check the condition, which is different to a while

33
Q

Argument vs parameter

A

Parameters are defined in the subroutine definition, arguments are what you pass in

34
Q

Stack overflow

A

Where the call stack in a recursive function runs out of memory

35
Q

Top-down approach

A

The problem is continually broken down into subprograms until each can be represented as an individual, self-contained blackbox which performs a certain task

36
Q

Features of IDEs

A

Stepping: run a line at a time and monitor the effect
Breakpoints: set the program to terminate at a certain line so you can observe the state
Source code editor: autocompletion, indentation, syntax highlighting etc

37
Q

Recursion advantages

A
  • More natural to read
  • Quicker to write/ less lines of code
  • The size of the problem can be continually reduced
38
Q

Recursion disadvantages

A
  • Can run out of stack space due to too many calls causing it to crash
  • More difficult to trace
  • Requires more memory than iterative
  • Usually slower than iterative due to stack maintenance
39
Q

Substring pseudocode

A

StringName.substring(start,length)

Also use for one character of a string

40
Q

Pseudocode for the character in a string at location index

A

StringName.substring(index,1)

41
Q

Pseudocode read from file

A

myFile = openRead(“filename.txt”)
line = myFile.readLine()
myFile.close()

42
Q

Pseudocode determining the end of a file

A

myFile.endOfFile()

43
Q

Pseudocode write to file

A

myFile = openWrite(“filename.txt”)
myFile.writeLine(“text to write”)
myFile.close()