4.1 Fundamentals of Programming Flashcards

1
Q

The 3 Programming Concepts

A
  • Sequence (do one statement after the other in order)
  • Selection (do a set of statements based on a condition)
  • Iteration (count or condition controlled)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Nested Statements (definition)

A

You have one set of commands inside another set of statements

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

Identifiers (definition)

A

The unique names given to elements such as variables or routines so that they can be identified

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

The Importance of Identifiers

A

It is important that identifiers are meaningful and relevant to the program
so that the program can be understood

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

Indenting your code (2)

A
  • increases readability
  • allows the human eye to trace code block more efficiently
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

A Pointer (definition)

A

A data type that stores a value of a given type as well as the memory location of the next item in the list

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

DIV =
MOD =

A

DIV = ignore remainder
MOD = remainder

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

Relational Operations are used in
e.g …

A
  • conditional statements
  • =, ==, <, >
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Constants vs Variables (definition)

A
  • Variables can change at run time
  • Constants are fixed value variables and are fixed in the source code (cannot change during run time)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Advantages of Constants Over Variables (2)

A
  • value cannot be accidentally changed during running of program
  • program runs faster as all references to constants are replaced by compiled value at run time, whereas variable’s value has to be retrieved from memory every time
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Advantages of Constants Over the Actual Value (2)

A
  • expression much easier to understand with meaningful identifiers
  • value only needs to be changed once to change all instances
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Strings are

A

Immutable

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

Casting (definition)

A

The process of converting between data types

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

Concatenation (definition)

A

Joining together separate strings into a single string

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

Computers and Random Numbers (3)

A
  • hard for a logical computer to produce something truly random
  • no matter how the random numbers are produced the computer must rely on source code produced by a human
  • it is impossible for humans not to introduce a portion of bias into a system
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Exception Handling (definition) (3)

A
  • The process of anticipating possible errors and writing code to deal with them
  • (robust programming)
  • can be used to help your program recover from run time errors such as invalid user inputs or divisions by zero
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Subroutine (definition) (2)

A
  • A self contained set of commands that can be called from different parts of a program
  • Blocks of code which are independent of anything external to them
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Types of Subroutines

A
  • Procedures: returns any amount of results including none
  • Functions: must return a value/values
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Built In Methods:
- abs()
- chr()
- ord()
- upper()
- lower()
- strip()
- len()
- split(‘:’)

A
  • abs(): absolute value
  • chr(): ascii character
  • ord(): ascii value
  • upper(): turn string to uppercase
  • lower(): turn string to lowercase
  • strip()
  • len()
  • split(‘:’)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Args
- symbol
- meaning
- produces a

A
  • *
  • means an arbitrary number of parameters
  • produces a tuple
20
Q

Local Variables (3)
- access
- exist
- memory

A
  • accessible only within the subroutine
  • only exist while the subroutine is being executed
  • once control is returned to main body of code, all memory is reallocated
21
Q

Advantages of Local Variables (2)

A
  • increases modularity
  • decreases the volume of memory used

(Modularity = the degree to which a problem has been decomposed into individual problems)

22
Q

Global Variables (4)

A
  • variables that can be called and are operable by all blocks of code
  • assigned memory at run time
  • memory only released when program closes
  • try to minimise use of global variables
23
Q

Disadvantages of Global Variables (2)

A
  • program runs more slowly
  • may be called and edited accidentally (especially if names are similar)
24
Q

Stack Frames contain (3)

A
  • parameters
  • return address
  • local variables
25
Q

Stack Frames:
- advantage
- disadvantage

A
  • adv: they maintain the order in which procedures need to be executed in an efficient way
  • dis: a recursive procedure which calls itself indefinitely will run out of stack space
26
Q

Recursion (definition)

A

The ability to call itself to complete its task until a condition is met

27
Q

Two Parts of a Recursive Solution

A
  • the recursive: the code that calls itself for another iteration and passes new variable values
  • the limiter: what stops the code from creating an infinite loop
28
Q

Recursion is – efficient than iteration as …

A
  • less
  • recursion stores all previously existing variables used in the function
29
Q

OOP Design Principals

A
  • encapsulate what varies
  • favour composition over inheritance
  • program to the interface, not the implementation
30
Q

Public Attributes (definition) (symbols)

A
  • can be accessed outside and inside of the class
  • UML: +
  • Python:
31
Q

Private Attributes (definition) (symbols)

A
  • can only be accessed inside of the class (cannot be accessed directly)
  • UML: -
  • Python: __
32
Q

Protected Attributes (definition) (symbols)

A
  • can be accessed within the class and any class that inherits from it i.e. a child
  • UML: #
  • Python: _
33
Q

Object (definition)

A

An instance of a class

34
Q

A Constructor (definition)

A

A method that is automatically called when an instance of a class is created

35
Q

Constructors:
- identifier
- purpose

A
  • identifier: __init__
  • can be called explicitly
  • purpose: to prepare a new object for use by setting initial values of the attributes of an object
36
Q

Encapsulation (definition)

A

The concept that attributes and the methods that manipulate them are bound together

37
Q

Inheritance (definition)

A

An OOP technique that allows once class to inherit (share) the attributes and methods of another class (parent)
- “a kind of” or “a type of” relationship

38
Q

Parent Class =
Child Class =

A
  • superclass
  • subclass
39
Q

Aggregation/Composition is the stronger relationship

A

Composition

40
Q

Class Diagram Structure

A

Class Name, Attributes, Methods

41
Q

UML Diagrams:
- inheritance
- aggregation
- composition

A
  • inheritance: hollow headed arrow pointing upwards from child to parent
  • aggregation: empty diamond
  • composition: filled diamond
42
Q

Overriding

A

When you change the base characteristics of a class without having to change the source code

43
Q

A Virtual Method (definition)

A

An inheritable and overridable method

44
Q

Virtual Methods Allows for

A

Polymorphism

45
Q

An Abstract Method

A

A method that has no implementation

46
Q

An Abstract Class

A

A class that contains at least one abstract method
- doesn’t create objects itself but rather creates child classes

47
Q

An Interface (definition)

A

The collection of abstract methods in an abstract class

48
Q

The base case of a recursive subroutine is

A

The circumstances when a recursive subroutine does not call itself