2.2.1 - Programming techniques Flashcards

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

What is a sub routine?

A

A named Block of code that performs a specific task within a program

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

What is a function?

A

A subroutine that returns a value and produces information from a given task.

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

What is a procedure?

A

A subroutine that performs a task that does not return a value.

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

Define passing by value

A

The value of the variable is passed into the subroutine and treated as a local variable within. If the parameter value is changed it will not affect the original variable.
This is often the default in programming languages.

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

Define passing by reference.

A

Passing by reference passes the actual memory address of the variable into the subroutine - therefore the actual/original value of the variable can be changed within the subroutine.

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

Explain global variables

A

Variables that are declared in the main section of the program.
Can be used anywhere they have “Global scope”

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

Explain local variables

A

LOCAL SCOPE.
Only local to the subroutine that they are declared within.
They have no effect whatsoever on variables outside of that subroutine.

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

How is encapsulation useful in sub routine programming

A

If all needed variables are encapsulated within the subroutine then it becomes modular and can be used elsewhere independently.

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

Define modular programming

A

A long complex program can be broken down into smaller subroutines/subtasks and this can help design an algorithm that is easier to manage anymore efficient.

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

Advantages of modular programming with subroutines

A

Relatively easy to understand, debug and maintain - especially if its purpose is clearly defined and well documented.
Subroutines can be tested independently, thereby shortening the time taken to get to a large program working
Once a subroutine has been thoroughly tested, it can be reused with confidence.

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

Define a recursive subroutine

A

The process of a subroutine calling itself.

A subroutine written in terms of itself.

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

Recursion has three main characteristics:

A

For input values, the routine must call itself
A stopping condition - when the condition is met the subroutine will stop calling itself and unwind.
The stopping condition must be reached after a finite amount of calls.

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

Difference between an iterative approach and recursive approach

A

Recursive algorithms are often shorter; but more difficult to trace.
If a recursive routine is called a very large number of times before the stopping condition is reached, the program may crash due to a stack overflow.

An iterative routine has no limits to the number of times it repeats or how many times it can be called - to some extent

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

what is stack memory?

A

Memory where the return addresses, parameters and local variables of a subroutine are temporarily stored when called.
This follows the Stack data structure framework.
The data held in the stack frame is then popped once the subroutine is finished executing.

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

What is an IDE?

A

Integrated development environment
A software package that helps write code easily.
Provides tools that may help edit, enter, compile, test and debug your program.

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

What specific tools can an IDE give you to help solve a logical error within your program?

A

Breakpoint - Run the program until the breakpoint line is reached, and then the program is stopped.
Watch a variable - A variable is watched and the IDE displays its current value each time it’s changed.
Step through - Step through the program line by line to assess what is happening.

17
Q

What types of data should be used when testing a program?

A

normal data - Normal expected data - if the range was 0-100, 1-99 should be tested
Boundary data - if the range of data is 0-100, 0 and 100 must be tested
Erroneous data - Different data types or data that is just outside the normal range.

18
Q

What is dry-running a program?

A

Trace tables

19
Q

What is object-oriented programming? and explain attributes and methods.

A

Everything is viewed as a collection of objects, which are created based on a blueprint model called a class. Each object is responsible for its own data attributes and methods.
Attributes are information/data assigned to variables within the object.
Methods/behaviours are operations/procedures that can be performed by the object.

20
Q

Explain classes, and give an example.

A
Class is a blueprint for an object. An object is an instance of a class blueprint, there can be many objects to one class. 
A class defines the attributes and methods of the objects. 
The constructor method is always present within a class - it maps inputs to attributes.
21
Q

What is instantiation?

A
Creating an instance of a class. 
Multiple instances can be created from one class, however, each instance can have different values to the attributes of the class. 
Book = new StockItem(Data)
22
Q

Explain getter and setter messages in OOP

A

Get is a function that returns a value from within the object class.
Set is a procedure that sets an attribute to a given input value.

23
Q

What is encapsulation?

A

In a large project, programmers can work on different classes and not have to worry about how other parts of different classes affect their class. They can also use other methods from different classes without having to worry about how they work - this is called information hiding.
Information hiding is whereby details of an object’s instance variables are hidden so that other objects must use messages to interact with that object’s state.
For E.G radio1.setvolume(5) sets the volume without us interacting with the actual state of the variables within the object. It uses public methods for this.

24
Q

What is inheritance?

A
A class can inherit attributes and methods from a parent class. 
A parent class is referred to as a superclass and a child as a subclass.
25
Q

When to use inheritance?

A

If two classes share somewhat a direct relationship.
“Is a” rule.
Is a cat a mouse etc.

26
Q

What is polymorphism?

A
Refers to the ability to process objects differently depending on their class. 
For example, a cat may inherit moveLeft from the animal superclass. 
However, the program may want the cat to be able to move left 3 spaces, but the moveLeft method is set to two spaces for the animal inheritance. 
The Cat class can override that method and treat it differently, allowing the cat to still have the moveLeft method, but act differently from the original method.