4.1 Fundamentals of Programming Flashcards

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

What is an array

A

an ​ordered, finite set of elements​ of a ​single type​.

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

What is selection

A

Where the program executes different actions depending on the result of the comparison.

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

Difference between definite and indefinite iteration

A

Definite iteration - The number of iterations is known before execution

Indefinite iteration - Number of iterations depends on a logical condition

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

What is nested selection

A

Nested selection is when there is more than one expression to be tested

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

What is nested iteration

A

iterating over elements of one or more iterable objects within another iteration loop.

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

What is the symbol for integer division and for real divison

A

real division - /

integer division - //

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

What is modulus and what is the symbol for it?

A

Modulus calculates the remainder from an integer division

Symbol for modulus is %

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

What is truncation and how is it achieved in python

A

Truncation is the process of limiting the number of digits after the decimal point.

In order to perform it in python you need to import math library and use the math.trunc(number) function

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

What is rounding and how is it achieved in python

A

Rounding replaces a number with an approximate value using fewer digits.

python has an inbuilt round() function

round(number, nr of dp)

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

How do we get a substring of a larger string

A

Characters and phrases can be extracted from a string based on their position using [] in Python

[:3] Extracts the 0th ,1st and 2nd character from the string.

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

What is concatenation and how is it achieved

A

Concatenation is the joining together of strings.

string_3 = string_1 + string_2

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

How do we go from:

character → character code
* character code → character

A

chr() converts ASCII code to character
ord() does the opposite

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

How do we generate a random number in python

A

import random

number =
random.randint(range excluded)

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

What is exception handling

A

Techniques used by the programmer to deal with error conditions.

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

What is subroutine and what are its uses

A

a set of instructions designed to perform a frequently used operation within a program.

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

What are the advantages of using subroutines in programs (2)

A

The same code only has to be written once to be re-used. making it more efficient.

Its also easier to maintain and fix the code

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

What is an interface

A

An interface defines a contract for classes that implement it. It specifies a set of methods (functions) that the implementing classes must provide.

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

What are local variables

A

Variables that are declared and used in a subroutine, only in existence while the subroutine is being executed.

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

How is a stack frame used in the context of subroutines

A

An area of the stack is allocated data to store during a subroutine call, ( return addresses, parameters, local variables)

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

What is a function

A

A subroutine consisting of a series of instructions to perform a task

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

What is recursion

A

Where a suboroutine is defined in terms of itself.

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

What are attributes and what are methods

A

Attributes - Characteristics of an object

Methods - Functions that belong to an object

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

What is a class

A

Template used to create objects

Describes the shared attributes and methods of the objects to be created.

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

what is a object

A

Once instance of a class, representative of a real world object

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

What is instantiation

A

Creating an instance of a class

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

What is encapsulation

A

Protection of attributes and methods of an object so they can’t be accessed or altered by other objects

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

What is inheritance and what is the class diagram symbol for it

A

A new class is created that retains the attributes and methods from the parent class.

Symbol is a arrow with a clear tip

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

What is aggregation and what is the class diagram symbol for it

A

Is where an object is created that can contain other objects.

If original object is deleted composed objects continue to exist

Class diagram symbol - empty diamond arrow

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

What is composition and the class diagram symbol for it

A

is where an object that is created can be composed of other objects.

If the original objects is deleted so are the composed objects.

Class diagram symbol - Filled in diamond arrow

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

What is polymorphism

A

Where different objects in a class can be processed differently

while making use of the same method.

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

What is overriding

A

way of achieving polymorphism:

A subclass can have a different execution for a method compared with the same method of the base class.

32
Q

What are the three oop design principles

A

encapsulate what varies
* favour composition over inheritance
* program to interfaces, not implementation.

33
Q

Elaborate on the phrase “encapsulate what varies”

A

when designing classes and objects, we should encapsulate the parts of the code that are likely to change.

By doing so, we can localize the effects of change, making the code easier to maintain, modify, and extend.

34
Q

What are the different types of association in OOP?

A

Inheritance
Aggregation
Composition
Association

35
Q

Elaborate on the point “favor composition over inheritance”

A

Favoring composition mitigates the risks of the fragile base class problem,

leading to more modular, maintainable, and adaptable object-oriented designs.

36
Q

Explain the point “ Program to interfaces not implementation

A

Instead of relying on specific implementations of objects,

focus on defining interfaces that describe the behaviour or capabilities that objects should have.

37
Q

What are abstract methods

A

A method that doesn’t have any implementation

38
Q

What are static methods

A

Static methods in Python are methods that are bound to the class rather than to an instance of the class.

39
Q

What are virtual methods

A

Methods that can be overridden ina subclass

40
Q

What is meant by public specifier

A

Public members are accessible from any part of the program

41
Q

What is meant by protected specifiers

A

Protected members are accessible within the class itself and by its subclasses

42
Q

What is meant by private specifiers

A

Private members are accessible only within the class in which they are declared.

43
Q

What is a paradigm

A

a fundamental model that guides how we approach and solve problems

44
Q

Why is the OOP paradigm used (4)

A

Programs are written as a series of modules making them easy to modify and maintain should a fault occur.

Data can be hidden within the class that accesses it providing greater system security

Through inheritance code can easily be reused saving memory.

Classes are only concerned with the data defined within it, so it is unlikely to access other data accidentally.

45
Q

What is instantiation

A

Creating an instance of a class

Dog1 = Dog()

46
Q

How do we alter the name of An instance of a class item named “Item 1”

A

Item1.name = “new name”

47
Q

How do we change a string to make it all upper case.

String1 = “aaa”

A

String1 = String1.upper()

48
Q

What is a procedure

A

A procedure is a block of code that performs a specific task and may or may not return a value

49
Q

What are identifiers

A

Symbolic names used for any variable, function or definition in a computer program

50
Q

What does the DIV operator do

A

The div operator performs integer division if both operands are integers.

It gives the result of the calculation and the remainder

5 DIV 2 = 2R1 ( 2 remainder 1)

51
Q

How do we perform exponentiation

A

X**n

X is multiplied repeatedly n times

52
Q

Difference between functions and procedures

A

Function always returns a value

Procedure may not return a value

53
Q

What is a constructor method and how do we define it in python

A

def __init__():

initialize newly created objects of a class.

The __init__ method is called automatically when an object is instantiated

54
Q

What is the role of the self parameter

A

self parameter in Python refers to the instance of the class itself.

55
Q

Define a class for a dog with a bark method

A

class dog:
def bark(self):
print(“bark”)

56
Q

Within the class dog i have a bark function

How do i make use of the bark function for my object

dog1 = dog()

A

dog1.bark

57
Q

class customer:
def__init__(self, name, email)

What is missing from the code and why must it be there

A

self.name = name
self.email = email

Assigns a name and email for each instance of a class, the self represents whichever instance of the class we are dealing with.

58
Q

what function allows us to add a item to the end of a list

A

ListName.append(“item”)

59
Q

If we want the dog class to inherit the methods and attributes of the pet class what words must be added to the code below

class dog():

A

pet must be put as a parameter

class dog(pet):

60
Q

what does super() do in python

A

Reference the super class (class we inherit from)

way of specifically inheriting only certain methods from a parent class

61
Q

how do we convert integer to binary in python

A

using the inbuilt bin() function

for example bin(9) returns:

1001

62
Q

How do we convert a number into hexadecimal string

A

Using the inbuilt hex() function

hex(15)

output f

63
Q

How do we return the absolute value of a number

A

abs()

abs(-19.345)

output 19.345

64
Q

which function can we use to simulate mod division

A

divmod()

Returns:

(quotient, remainder)

divmod(30,4)

(7,2)

65
Q

What function can be used to find the unique identifier of variables

A

id()

66
Q

how do we find the maximum and minimum values of an iterable variable

A

max()
min()

67
Q

How do we print the reverse of a string

named string

A

reverse_string = string[::-1]

a[start:stop

68
Q

round num to 2 dp
num = 9.76515

A

RoundedNumber = round(num,2)

uses inbuilt function round()

69
Q

Advantage of static structure and one advantage of dynamic data structure

A

Static - Memory addresses will be allocated at compile time and are fixed and contiguous allowing faster access,

Dynamic - memory allocation can be varied to meet needs making it efficient

70
Q

Definition of 3 types of queues

A

Linear queue - FIFO data structure organised as a line of data. Has a start and end pointer

Circular queue - FIFO data structure where the first and end pointers wrap around the array.

Priority queue - same as linear except each element in queue has a priority

71
Q

How does a firewall operate

A

A firewall is either software or hardware that controls access to and from a network
Data packets from specific IP addresses can be filtered
Data packets also have ports which can be used to only allow traffic through from certain port numbers.

72
Q

Describe packet filtering

A

Packets of data are inspected by the firewall to check their source IP address and which port they are attempting to access
Different network protocols use different port numbers for example, HTTP traffic, used to transfer web page data, uses port 80 or 8080
If this traffic is to be allowed through, the port must be opened for the duration of the connection, otherwise the firewall will automatically reject it

73
Q

What is a proxy server

A

A proxy server makes a web request on behalf of your own computer, hiding the true request IP addresses from the recipient

74
Q

What are the functions of a proxy server

A

Enables anonymous surfing

Can be used to filter undesirable online content

Logs user data with their requests

Provides a cache of previously visited sites to speed up access

75
Q

four different ways that a firewall can protect computers on a LAN

A

Block/allow traffic on specific ports

Block/allow traffic from specific IP addresses

Block/allow certain types of packet

Firewall maintains information about current connections and only allows packets relevant to these connections through