2.2.1 FINAL Programming techniques Flashcards

(54 cards)

1
Q

What is a data type?

A

A classification of data into groups

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

What is an integer?

A

Used to represent whole numbers, either positive or negative

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

What is a real?

A

Used to represent numbers with a fractional part, either positive or negative

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

What is chr?

A

Used to represent a single character such as a letter, digit or symbol

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

What is a string?

A

Used to represent a sequence of characters

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

What is boolean?

A

Used to represent true or false values

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

What is casting?

A

When you convert one data type to another data type

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

What is a programming construct?

A

Determines the order in which lines of code are executed

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

State the 3 types of programming constructs

A

Sequence, Branching, Iteration

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

What is a sequence?

A
  • Refers to lines of code which are run one line at a time
  • The lines of code are run in the order that they are written from the first line of code to the last line of code
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a selection?

A
  • The flow of the program is interrupted and a condition is tested
  • Outcome of the condition will then determine which lines/block of code is run next. Two ways to write selection statements:
  • IF statement: test conditions sequentially
    SWITCH statement: test an expression against multiple possible constant values
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is an iteration?

A
  • Repeating a line or block of code using a loop. It can be:
  • Count controlled: When the code is repeated a fixed number of times (for loop)
  • Condition controlled: When the code is repeated until a condition is met (while loop)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a SWITCH/CASE statement?

A
  • Type of conditional statement that provides an alternative way to perform multiple comparisons based on the value of an expression
  • Useful when you have a single expression that you want to compare against multiple possible values
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a for loop?

A

Count controlled loop that will repeat a fixed number of times

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

What is a while loop?

A

Condition controlled loop that will repeat until a condition is met
- Provides a flexible way to handle situations where the number of iterations in unknown in advance

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

What is modularity?

A

Where problems are broken down into more manageable pieces
- Each piece of the problem should be carried out by one single subroutine

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

What are subroutines?

A
  • Standalone blocks of code and when called, they will complete a task
  • The promote code reusability, modularity and organisation, enabling a programmer to write efficient and maintainable programs
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is a function?

A

Block of code that takes in 0, 1 or more parameters, performs a set task and return a value

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

What is a procedure?

A

Block of code that takes in 0, 1 or more parameters and performs a set task

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

What is a parameter?

A

Pieces of data which are passed into the function or procedure to allow it to complete a task

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

What are the two ways of passing a parameter?

A
  • Passing by value
  • Passing by reference
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What does it mean by parameter passing by value?

A
  • A copy of the actual value is made and assigned to the function’s parameter
  • Any changes to the parameter within the function’s scope do not affect the original value outside the function
  • Function works w/ and changes its own local copy of the value
  • Suitable when you want original data to be protected from being modified within the function
  • When function ends, copy of the value is destroyed
  • Can lead to performance overhead when working with large data structures since a copy is made
23
Q

What does it mean by parameter passing by reference?

A
  • Function receives the memory address of the value rather than a copy of the value
  • Any changes made to the parameter within the function directly affect the original value outside the function
  • Both the function and the calling code share the same memory location
  • Efficient for working w/ large data structures
  • Can lead to unexpected side effects if not handled carefully, as changes made within the function affect other parts of the program
24
Q

What is recursion?

A

When a function calls itself to solve a problem or execute a task
- Uses idea of self-reference to break down complicated problems into more manageable subproblems

25
What 3 features does a recursive algorithm have?
- Contains a stopping condition (base case) - For any input value other than the stopping condition, the subroutine should call itself (recursion) - Stopping base: Must be reachable after a finite number of times
26
How does recursion work?
- Function must call itself with a modified input parameter until it reaches a base case - Each recursive call breaks down the problem into more minor instances until it reaches the base case
27
Why is it important to have a proper stopping condition or base case when using recursion?
- To avoid stack overflow errors which result in program crashes - If it doesn't have a stopping condition, it will continue to call itself indefinitely, which can use up excessive memory + cause the program to malfunction
28
What are the benefits of recursion?
- Concise: Can often be expressed in a more concise way, especially for structures e.g. trees or fractals - Simple: Simply stating what needs to be done without having to focus on the how it can make it more readable and maintainable
29
What are the limitations of recursion?
- Inefficient use of memory: if the subroutine calls itself too many times, there's a danger of stack overflow, causing the program to crash - Debugging: recursive code can be more difficult to track the state of the program - Limited application: not all problems are suited to recursive solutions
30
What are the benefits of iteration?
- Performance: more efficient than recursion, less memory usage - Debugging: easier to understand and debug - Wider application: more suitable to a wide range of problems
31
What are the limitations of iteration?
- Complexity: can get very complex and use more lines of code than recursive alternatives - Less concise: compared to recursive alternatives, making them harder to understand
32
What is a local variable?
- Declared inside a subroutine - Only accessible by that subroutine - Created when that subroutine is called - Destroyed when the subroutine ends
33
What is a global variable?
- Declared at the top of a program, outside of any subroutine - Accessible throughout the program - Created when the program starts - Destroyed when the program ends
34
What are the benefits of local variables?
- Encapsulate data within a particular subroutine, providing data hiding + preventing unintended access from other parts of the program - Can use the same in different functions without causing conflicts, as each local variable is confined to its own scope (easier for programmers to work w/ each other) - Have a limited lifetime + their memory is automatically reclaimed when the code block ends, making them memory efficient
35
What are the drawbacks of local variables?
- Repeatedly creating + destroying local variables within a loop/recursive function can incur unnecessary memory overhead - Excessive use of them in deeply nested blocks can lead to code cluster + reduce code readability - Slow execution as memory is allocated dynamically when needed
36
What are the benefits of global variables?
- Only needs to be declared once - Don't need to keep passing parameters between different modules
37
What are the drawbacks of global variables?
- Always stored in memory while the program is running which can use up memory - Makes the program difficult to maintain as it's hard to understand where variables are changed in the program - Makes it difficult to test a single block as the programmer will need to run the entire program to set up the global variables
38
What is an IDE?
- Software tool that provides programmers with a comprehensive + integrated platform to write, edit, compile and debug + manage their code efficiently - Designed to streamline the software development process by offering features/tools that can help programmers
39
Features of IDEs that can be used to write programming code
- Syntax highlighting - Autocompletion (code completion) - Code comments - Auto indent
40
Features of IDEs that can be used to debug programming code
- Variable watch window - Breakpoints - Stepping mode
41
What is a class in OOP?
- A template for creating objects with specific attributes and methods - Way of organising code in a modular way
42
What is an object?
An instance of a class that encapsulates attributes and methods into a single entity
42
What is an attribute?
A data member/variable associated with a class or object, representing the state/characteristics of that class/object
43
What is a method?
A subroutine defined within a class that encapsulates a set of actions/behaviours that can be performed by objects of that class
44
What is instantiation?
Creating an object from a class
45
What is a public method?
- Property of a method which allows it to be accessible from everywhere - Changes to them may impact on other parts of the codebase so should be documented whenever possible - Used when you want to provide access to certain functionalities/behaviours of an object/class to other parts of your program
46
What is a private method?
- Property of a method which allows it to only be accessed within the same class - Changes to it have a localised impact as they can only be used internally within the class, providing more flexibility to modify them without affecting other parts of the program - Used when you have internal implementation details that should not be accessed by external code. Meant to be used only within the class itself for managing the code internally
47
What is inheritance?
Allows a class to inherit the methods and attributes of another class
48
What does inheritance promote?
Code reuse - Allows derived classes to inherit and utilise the existing code from the base class - Promotes better organisation and maintainability
49
What two entities does inheritance involve?
- Base class and the derived class - Derived class inherits the characteristics of the base class, meaning it can access and use the methods/attributes defined in the base class
50
What is encapsulation?
Data held within a class can only be accessed through its methods
51
Benefits of encapsulation?
- Ensures data remains secure and not misused by controlling access to them using access modifiers (e.g. public, private) - Organises code by keeping related data and methods together within an object Promotes code reusability (the same object/class can be used in diff. part of a program without rewriting the code
52
What is polymorphism?
- Allows objects to take on different forms/behaviours - Different objects can share the same name/behaviour but can work in different ways
53
What are the benefits of polymorphism?
- Makes code more flexible, reusable and easier to maintain - Allows flexibility and reusability in programming, making it easier to write and manage code - Objects can be treated as belonging to a common group, even if in different classes, making code more versatile and adaptable to changes