2.2.1 - Programming Techniques Flashcards

Component 2 (34 cards)

1
Q

What is a variable?

A
  • Identifier of a memory location used to store data
  • Used to store a value which can change during execution
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the global variables?

A
  • The variable can be accessed throughout the scope of the program (visible throughout a program)
  • Using passing by reference is an equivalent of a global variable.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the negatives of global variables?

A
  • Uses more memory - memory is declared when the program starts and remains in use throughout.
  • Testing more difficult - it is difficult to test an individual block of code.
  • Reduces data accuracy - Changing a global variable may have an impact on another module.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the positives of global variables?

A
  • Simpler to program - values do not need to be passed between different subroutines.
  • Do not need to worry about returning values - all parts of the program can access the value.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a local variable?

A
  • Can only be accessed within the scope of the sub-program where it is created
  • A parameter that is passed into a subroutine becomes a local variable in the subroutine e.g. LoadLevel(Difficulty)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is an IDE?

A

Integrated Development Environment (IDE) - A program used for developing programs, made from several components.

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

Describe and explain the tools that are provided by an IDE to develop software

A
  • Auto-complete – Will predict variable and built-in functions and finish off the word. Can avoid spelling mistakes and speed up development
  • Syntax highlighting (colour coding text) - Can distinguish between different features quickly to check code is correct
  • Auto Indent – Indents code automatically within structures to avoid errors
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Describe and explain the tools that are provided by an IDE to debug software?

A
  • Error highlighting - Syntax errors highlight dynamically so they can be corrected before running the program (saving time)
  • Variable Watch window – Display the values of the variables during running of the program
  • Break points- Stop the program at set points to check the values of variables. Developer can add multiple breakpoints.
  • Error message list- Tells you where errors are and suggests corrections
  • Stepping - Executes program one line at a time to watch variable values and program pathways
  • Traces - Printouts of variable values for each statement execution
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the three programming constructs?

A

Sequence

Selection / Branching

Iteration

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

What is an example of a count controlled loop?

A

FOR Loop - Will run for a set number of predetermined times.

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

What is an example of a condition controlled loop?

A

WHILE / DO WHILE - Will run whilst a condition is true or false

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

What is the difference between a WHILE loop and a DO loop?

A
  • While loop will check the condition at the start of the loop - this means the code may never run
  • Do loop will check the condition at the end of the loop - this means the code will always run at least once
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are parameters?

A
  • Parameters are the variables listed between the brackets, after the procedure/function name e.g.
  • They become local variables in the routines that they are passed to.
  • characterMovement(inputKey, characterx, charactery)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What does passing by value mean?

A

By Value (ByVal)
* Does not override the original data
* A local copy of the data is used
* Data is discarded when the subprogram exits

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

What does passing by reference mean?

A

By Reference (ByRef)
* Changes are made to the original data
* Memory location of data is sent
* Changes remain after the subprogram exits
* Uses less memory

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

What is a function?

A
  • A named block of code which always returns a value
  • Uses the keyword return
  • Assigns the returned value to a variable (e.g. y)
17
Q

What is a procedure?

A
  • A named block of code which does not return a value
  • Does not use the keyword return
  • Is called by writing its name but not assigning the result to a variable
18
Q

What is modularity and what are the benefits of using it when writing code?

A

Breaking code down into functions / procedures / scripts

  • Write once and call repeated times - Avoids repeated code.
  • Can be tested individually and then added to the main program.
  • Can be reused in other programs - No need to reprogram so saves time
  • Can give sub-routines to different programmers to build concurrently
  • Breaks problems into smaller areas. Small sub-programs are easier to read / understand / modify
19
Q

What is an OO class?

A

A template for defining methods and attributes, which is used to instantiate objects.

20
Q

What is an OO object?

A

An instance of a class which is created using a constructor (new)

21
Q

What is an OO method?

A

These are the actions that can be performed by an object; for example, get a position on a game board. Can get a value (getter) or set a value (setter)

22
Q

What is an OO attribute?

A
  • Each object will have its own public or private attributes.
  • The attributes of a player in a game of Monopoly might include its PlayerID and money.
23
Q

Define encapsulation and the benefits of using it.

A
  • Attributes are set as private so they can only be accessed and changed via public methods
  • Uses ‘set methods’ to modify the value of a private attribute
  • Uses ‘get methods’ to retrieve the value of a private attribute
  • Prevents unexpected changes to attributes having unforeseen consequences.
24
Q

Define inheritance

A
  • A child class has its own attributes and methods, but it also gets all attributes and methods from the parent class.
  • Uses the key word ‘inherits’ and ‘super’
25
Define **polymorphism** (overriding)
* Code can be written that is able to handle different objects in the same way, this reduces the amount of code. * Using methods with the same name in a subclass as in a parent class is called overriding, which is a type of polymorphism. * Overriding allows a sub-class to use its own method rather than that of the parent.
26
Write the **constructor** for the following class All objects have a **money** value of **2000**.
public procedure new(thePlayerID, thePosition) playerID = thePlayerID boardPosition = thePosition money = 2000 endprocedure
27
Write the line to instantiate an object called "Boot" at position 10 using the Player class with the attributes **PlayerID, boardPosition, money** All objects have an unchangeable money value of 2000.
*ObjectName = new ClassName (attributes required)* Boot = new Player(“Boot”, 10)
28
Write the pseudocode for the '**getter**' getPosition()
public function getPosition() return position end function
29
Write the pseudocode for the '**setter**' setPosition()
public procedure setPosition (Theposition) position = Theposition end procedure
30
How would you write a full **OO class declaration?**
classname **inherits otherClassName** (inheritance optional) private attribute1 ... public function getter() return attribute1 end function public procedure setter(aValue) attribute1 = aValue end procedure endclass
31
What is **recursion**? Why does it need a **stopping condition**?
**Recursion is the process of a subroutine calling itself from within itself** A stopping condition must be included which when met means that the routine will stop calling itself and will start to 'unwind‘ No stopping condition would cause a ‘Stack Overflow’ error by filling the memory uncontrollably.
32
What are the pros and cons of **recursive** algorithms?
(-) Too many calls may cause the program to run out of memory with a "Stack overflow" error (-) Each call produces a new local variable which means more memory spaces needed (+) Uses less lines of code and produces a more elegant solution
33
What is **iteration**? What are the pros and cons of **iterative** algorithms?
Uses a loop to repeat instructions. There is an end condition to the loop which decides when to stop looping: * (+) Has no limit to the number of times it may be called. * (+) Only one copy of the variable is required. This means that less memory will be used * (-) Takes more lines of code and can be harder to understand
34
What would be the output if 10 was passed as a parameter into this function?
(1 + 2 + 3 + 6 + 7 + 10) = **29**