(P1) Fundamentals of Programming Flashcards

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

What is a data type?

A

Data types are defined by the values it can take or the operations that can be performed on it.

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

What is an integer?

A

A whole number, positive or negative. Including zero.

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

What is a real/float number?

A

A positive or negative number which can have a fractional part.

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

What is a boolean value?

A

Value which is either true or false.

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

What is a character?

A

A single number, letter or symbol.

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

What is a string?

A

A collection of characters.

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

What is the data type ‘data/time’?

A

Way of storing a point in time, many different formats are used.

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

What is a pointer/reference?

A

Way of storing memory addresses.

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

What is a record?

A

Collection of fields, each of which could have a different data type. Rows from a table.

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

What is an array?

A

An indexed set of related elements each of which has the same data type.

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

What is variable declaration?

A

Creating a variable for the first time, giving it a name and sometimes a data type. This allocates a portion of the computer’s memory to the variable.

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

What is constant declaration?

A

Creating a constant for the first time, giving it a name and a data type. The value of the constant does not change while the program is running.

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

What is assignment?

A

Giving a constant or variable a value.

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

What is iteration?

A

Repeating an instruction, this could be definite or indefinite.

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

What is selection?

A

Comparing values and choosing an action based on those values.

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

What is a subroutine?

A

A named block of code containing a set of instructions designed to perform a frequently used operation.

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

Give two examples of iteration.

A

For loop
While loop

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

What is definite iteration?

A

Iteration in which the number of repetitions required is known before the loop starts.

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

What is indefinite iteration?

A

Iteration in which the number of repetitions required is not known before the loops starts.

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

Give an example of definite iteration.

A

For loop.

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

Give an example of indefinite iteration.

A

While loop.

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

What does it mean if code is ‘nested’ and how can you identify it.

A

Nested: One structure is placed within another.
Identified by indentations.

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

How can you make your code easier to understand?

A

Use indentations.
Choose sensible indentifier names.

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

What does the operation real/float division do?

A

When one value is divided by another, both a quotient and the remainder are returned.

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

What does the operation Modulo do?

A

Returns the remainder of an integer division.

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

Why can constants be more useful than variables?

A

When the constant is required multiple times throughout the code. If the constant needs to be changed then it only needs to be updated in one place.

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

What is concatention?

A

Joining two or more strings together to form a new string.

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

Why can a computer never truly generate a random number?

A

Computer generated numbers are pseudo-random, which means they use a mathematical formula.

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

When might an error be ‘thrown’?

A

Using the wrong data type.
Dividing by zero.
Accessing non-existent elements in an array.

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

What does the computer do once an error has been ‘thrown’?

A

Handles the exception to avoid crashing by:
Pausing execution of program.
Saving the current volatile state of the program on the stack system.
Running code called ‘catch block’.

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

What does the computer do once an error has been detected and has prevented the program form crashing?

A

Might inform user that an error has occured.
Program uses system stack to restore its previous state before resuming execution.

32
Q

Why are subroutines used?

A

Reduces repetition of code and hence makes code more compact and easier to read.

33
Q

Give two examples of a subroutine.

A

Function
Procedure

34
Q

What is the difference between a function and a procedure?

A

Functions always return a value.
Procedures don’t have to return a value.

35
Q

What are parameters?

A

Information passed to a subroutine to define the values it is to use.
They hold information that the subroutine needs to run.

36
Q

What is the name of the actual value passed by a parameter?

A

Argument.

37
Q

What is local variable?

A

Variable that can obly be accessed from the subroutine within which it is declared.
They only exist in the computer’s memory when their parent subroutine is executing.
Making local variables more memory efficient.

38
Q

What is a global variable?

A

Variable that can be accessed from any part of a program and exist in memory for the entire duration of the program’s execution.
Defined outside any subroutines.

39
Q

What is the purpose of stacks?

A

Store return addresses, parameters and local variables.

40
Q

Describe a recursive subroutine.

A

Defined in terms of itself.

41
Q

What must all recursive subroutines have?

A

A stopping condition (called a base case), which must be met at some point in the exection of the program.

42
Q

What would happen if a recursive subroutine didn’t have a base case?

A

Algorithm never terminates, causing a stack overflow as more stacks frames are pushed onto the call stack.

43
Q

Compare iterative solutions with recursive solutions.

A

Iterative: easier to program.
Recursive: More compact in code.

44
Q

Write pseudocode for an iterative binary search.

A

SUBROUTINE BinarySearch (Array, ToFind)
Low <- 0
High <- Length(Array)
Middle <- 0
WHILE Low <= High
Middle <- (Low + High) / 2
IF Array(Middle) > ToFind THEN
High <- Middle + 1
ELSEIF Array(Middle) < ToFind THEN
Low <- Middle + 1
ELSE
RETURN Middle
ENDIF
ENDWHILE
ENDSUBROUTINE

45
Q

Write pseudocode for a recursive binary search.

A

SUBROUTINE BinarySearch(Low, High, Array, ToFind)
Middle <- (Low + High) / 2
IF ToFind < Array(Middle) THEN
RETURN BinarySearch(Low, Middle Array, ToFind)
ELSEIF ToFind > Array(Middle) THEN
RETURN BinarySearch(Middle, High, Array, ToFind)
ELSEIF ToFind = Array(Middle) THEN
Return Middle
ENDIF
ENDSUBROUTINE

46
Q

What are programs written in procedural programming paradigms formed from?

A

Sequences of instructions that are executed in the order that they appear.

47
Q

What is recursion?

A

The process in which a block of code that is defined in terms of itself makes a call to itself.

48
Q

Define the term ‘global scope’

A

A data structure that can be accessed from all parts of the program.

49
Q

Define the term ‘local scope’

A

A local variable can only be accessed from the structure within which it is declared.

50
Q

What are the four basic structures?

A

Assignment, sequence, selection and iteration.

51
Q

What is the advantage of designing programs from top down?

A

Maintenence of the program is easier as navigation of different elements of the overall solution is improved.
If all code is contained within the same module, then finding specific lines of code that need fixing is difficult.

52
Q

What is a hierarchy chart?

A

Graphically represents the structure of a structured program.
Each procedure is displayed as a rectangle which is connected to any other procedures that are used within it.

53
Q

What are new objects created from?

A

Classes.

54
Q

What is instantiation?

A

Process of creating a new object.

55
Q

What is a class?

A

A blueprint for objects, they specify what properties and methods objects of their type will have.
A set of objects which share common structures and a common behaviour.

56
Q

What is meant when a method or property is listed as private?

A

Can only be accessed from within an object.

57
Q

What is encapsulation?

A

Process of combining methods and procedures to form an object.
An object is said to encapsulate its contents, forming a single entity which encompasses all of the object’s properties and methods.

58
Q

What is an advantage of using encapsulation?

A

Allows the development of large programs to be split across a team of developers, each of whom can be allocated a class to develop. As long as the developers knkw the methods which belong to other classes, they can develop their own class without knowing specific implementation of methods in other classes.

59
Q

What is inheritance?

A

Inheritance allows one class to share the properties and methods of another class, while having its own properties and methods too.

60
Q

What is overriding?

A

An overridden method has the same name as a emthod in an inherited class but different implementation.

61
Q

What is association?

A

A relationship between two classes. Two types of association: aggression and composition.

62
Q

What is aggregation?

A

Weaker kind of association. When an object is associated to another by aggregation, it will still exist if its containing object is destoryed.

63
Q

What is composition?

A

Stronger relationship between classrs. If two objects are associated by composition and the containing object is destoyed, the associated object is also destroyed.

64
Q

Why is object orientated programming used?

A

Has a clear structure that makes developing and testing programs eadier for developers.
Using the paradigm also allows for large projects to be divided among a team of a developers.
Use of classes allows code to be reused throughout the program.
This improves the space efficency of the code.

65
Q

When coding why should you encapsulate anything that varies?

A

Any requirements that are likely to change in the future shiuod be encapsulated in a class so that any changes can be easily made when required.

66
Q

When coding why should you favour composition over inheritance?

A

Composition is seen as a more flexible relationship between objects.

67
Q

When coding why should you program to interfaces not implementions?

A

This design principle allows unrelated classes to make use of similar methods.
When a new object is created, it can implement an interface which provides it with the correct properties and methods.

68
Q

What is an interface?

A

An interface is defined as a collection of abstract procedures that can be implemented by unrelated classes.

69
Q

What is a class diagram?

A

Visually representation of the relationships that exist between classes.

70
Q

What is an inheritance diagram?

A

A type of class diagram that shows the different inheritance relationships that exist between classes.

71
Q

Describe the layout of inheritance diagrams.

A

Unfilled arrows which point from an inherited class towards the class which inherits it. Arrows always point upwards.

72
Q

Describe the layout of association diagrams.

A

Aggregation: Unfilled diamond headed arrows.
Composition: Filled diamond headed arrow.

73
Q

Describe the representation of a class.

A

Three boxes: top box contains the class name, middle box contains the class properties and the bottom class contains the class method.

74
Q

What does the plus sign in a class represent?

A

Public property or method

75
Q

What does the minus sign in a class represent?

A

Private property or method.

76
Q

What does the hashtag sign in a class represent?

A

Protected property or method.

77
Q

What are protected properties or methods?

A

Accessible from within the object that declares them and also from any inherited objects.