Programming Flashcards

(29 cards)

1
Q

What is a procedure?

A

A subroutine that does not return a value

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 return a value

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

How can you tell if a variable is a constant?

A

Named with all capital letters e.g. EMPTYSTRING

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

What is a local and global variable?

A
  • A local variable is declared in a subroutine or similar
  • A global variable is declared at the highest possible level in a program so that it can be used in any lower level statements
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are programming paradigms?

A

Approaches to programming

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

What are the two main paradigms in programming?

A

1) Functional programming
2) Imperative programming

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

What are the two main types of imperative programming?

A

1) Procedural programming
2) Object-Oriented programming

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

What is functional programming?

A

Programming that has no variables, and instead uses functions as mappings from one value to another

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

What is imperative programming?

A

Programming that has commands that the computer performs in a specific sequence

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

What is procedural programming?

A
  • Programming made up of imperative commands that are run sequentially
  • Uses sequence, selection and iteration
  • Broken up into smaller parts or modules using subroutines
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are the main parts of the structured approach to programming?

A

1) Organise programs into subroutines and modules by using hierarchy charts to break a program down

2) Store data in variables and constants with meaningful identifiers

3) Program to the interface by using subroutines

4) Use local variables instead of global variables

5) Use indentation, spacing and comments

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

What are the advantages to using the structured approach to programming?

A
  • Can individually test subroutines and modules
  • Modules with related subroutines make it easy to navigate for developers
  • Indented code is easier to read
  • Comments can explain how program works to other developers
  • Meaningful identifiers make it easier to follow
  • Parameters and return values to pass values into and out of subroutines reduces likelihood for errors
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Why is it good practice to use local variables?

A
  • Modularisation of a program
  • Allows re-use of subroutines
  • Less chance of side effects
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the difference between a local and global variable?

A

Local variables have a more limited scope.
Global variables can be accessed from any part of the program.

MS:
Mark is for AO1 (understanding)
Local variables have more limited scope;
Global variables exist throughout the entire program;
Local variables only exist in a part/block/subroutine of the program;
Local variables can only be accessed in a part/block/subroutine of the program;
Global variables can be accessed from any part of the program;
Max 1 mark

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

What is the difference between a protected and a private attribute?

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

Why is it good practice to use local variables?

A

Mark is for AO1 (knowledge)

Modularisation of a program;
Allows reuse of subroutines;
Less chance of side-effects;

Max 1 mark

17
Q

What is meant by the base case of a recursive subroutine?

A

The circumstance(s) when a recursive subroutine does not call itself;

18
Q

What are the components of the stack frame?

A

local variables;
return address;
parameters;
register values;

19
Q

State advantages of using subroutines.

A

Easier to test/debug as each subroutine can be tested separately;
Easier to understand the code if sensible identifiers are used for subroutine names;
Code can be easily reused as each subroutine is independent of rest of program;
Makes it easier to work as a team of programmers as each subroutine can be
worked on independently;
Can be used as often as needed without having to write the code each time;
Makes program easier to maintain/update (in future) as fewer changes will need to
be made to make an update;
Allows the use of recursive techniques because subroutines can call themselves;
Easier to understand the code as each subroutine can be considered in isolation;
Less likely to be errors in the code due to reuse of code;
Reduces/eliminates side effects (eg unexpected change to value in global variable)
through use of local variables;

20
Q

What is string concatenation?

A

Joining (two) strings (to form one string // into one);

21
Q

What is encapsulation?

A

Combining a record with the procedures and functions that manipulate it in order to create a new data type;

22
Q

What is polymorphism?

A

Objects of different classes / types respond differently to the use of a common interface / the same usage

23
Q

What is method overriding?

A

When a derived class / subclass has a different implementation for a method /
function / subroutine to the class it inherits from / from the base class;

24
Q

What are the differences between virtual and abstract methods?

A

Virtual methods can be overridden by the derived class //
virtual methods do not have to be overridden //
abstract methods must be overridden by the derived class;
Virtual methods have an implementation/body //
virtual methods contain code (with functionality) (in the base class) //
abstract methods do not contain an implementation/body //
abstract methods contain no code (with functionality) (in the base class) //
abstract methods only contain a declaration (in the base class);
Abstract methods can only be declared in abstract classes //
virtual methods can be declared in abstract and non-abstract classes;

25
When is it suitable to use a private method?
Because it is only called by methods inside the class // because it is never used/called from outside the class;
26
What is the difference between a local variable and a private attribute?
A local variable can only be used in the method/subroutine/program block in which it is declared whereas a private attribute can be used/accessed anywhere in the class;
27
Why favour composition over inheritance?
There can be unintended side effects for derived class by altering a method in the base class.
28
How to get all ASCII letters?
Ascii code between 65 and 90 and uppercase between 97 and 122
29
Explain why setting attributes and using public getter methods to access them is favoured in object-oriented programming.
The way that the attribute is represented can be modified without having to change any other objects that interact with the attribute;