Programming Flashcards

1
Q

What is a does a class consist of?

A
  • Class name
  • Attributes
  • Methods
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the advatnages of OOP?

A
  • Written in modules meaning easy debugging
  • Easy to add new fuctionality with additional modules
  • Programmers can work in thier own self contained modules
  • Objects can inherit attributes and behaviours meaning reusable code
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a class?

A
  • A blueprint defines a realted group of things
  • Properties and methods
  • Doesnt store data
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are objects?

A
  • Created from a class
  • Defined in an istance of a class
  • Same properties and methods from the origin class
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is inheritence?

A
  • Where a class can inherit another class
  • Sharing the properties and methods of another class
  • ‘Is a ‘ relationship (Animal is a cat)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is polymorphism?

A
  • Where objects are processed differently depending on their class
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is overriding?

A
  • Overridden method has the same method in the inherited class but a different implementation
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is association?

A
  • Where objects can have a ‘has a’ relationship
  • ‘Teacher has a student’
  • Can be aggression or composition association
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is aggregation?

A
  • The weaker type of association
  • When an object is associated with another aggression, it will still exist if its containing object is destroyed
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is compostion?

A
  • Stronger relationship between classes
  • Where if the containing object is destroyed so is the associated object
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are the needs for data types?

A
  • Allows for delcleration of data type
  • Which allows for the appropriate amount of data to be set aside
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the diferent data types you need to know?

A
  • Integer
  • Real float
  • String
  • Character
  • Date/Time
  • Boolean
  • Records
  • Arrays / Lists
  • Pointer / Reference
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the integer used for and give an example?

A
  • Stores positive and negative whole numbers
  • 10, -19
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is real / float used for?

A
  • Extension of integer
  • Stores fractions and decimals
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are records?

A

A collection of related different data types

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

What are arrays used for?

A
  • Fixed size
  • Sequential set of elements of the same data type
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What are pointers and what are they used for?

A

Declare a variable that will allow you to point to a physcial address in memory

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

What are user defined data types?

A
  • Complex data types
  • Based on in-built data types provided by the langague
  • As built in data types can be limiting
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What are the programming constructs?

A
  • Sequence
  • Selection
  • Iteration
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is the sequence construct?

A
  • One statment after the other in order
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is the selection construct?

A

Do a set of statment based on a condition to allow your code (if statments)

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

What is the iteration construct?

A

Do a set of statments again and again a known fixed number of times

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

What is a subroutine?

A
  • Self contained set of commands which can be called from different parts of a program
  • Reduces repetition
  • Either procedures or functions (functions return values)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What is an identifier?

A
  • Name an entity within the language
  • Used to name constants, types, classes, etc
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

What are constants?

A
  • NAme used to refer to a fixed value
  • Value set when the code is written
  • Cannot be changed while the program is running
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

What is a variable?

A
  • Name that refers to a particular memory location
  • That stores data
  • Value of data is not known when program is written
  • Can only change when program is running
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

What are the advantages of constants?

A
  • Cannot be accidently changed
  • Program runs faster because constants are replased with memory adresses at compile time
28
Q

What is the addition operator in python?

A
    • symbol
  • Adds to numbers together
29
Q

What is the subtraction operator in python?

A
  • Uses the - symbol
  • Subtracts two numbers together?
30
Q

What is the multiplication operator in python?

A
  • Uses the * symbol
  • Multiplys numbers together
31
Q

What is the DIV operator in python?

A
  • Uses the // operator
  • Divides a number wihout the remainder
32
Q

What is the MOD operator in python?

A
  • Uses the % symbol
  • Returns the remainder of two numbers being devided
33
Q

What is the division operator in python?

A
  • Uses the / symbol
  • Divides two numbers together
34
Q

What is the exponentation operator in python?

A
  • Uses the ** symbol
  • Returns the first number to the power of the second
35
Q

What is the rounding operator in python?

A
  • Uses round() in math libary
  • Takes in a number and rounds it
36
Q

What is the trunciation operator in python?

A
  • Uses the trunc() in math libary
  • Removes the any numbers past a decimal point leaving only the integer
37
Q

How do you turn a string into upper case in python?

A

x = y.upper()

38
Q

How do you turn a tring into lowercase uring python

A

x= y.lower()

39
Q

How do you return the number of characters in a string?

A

x = len(y)

40
Q

How do you return the characters to the left of the string?

A

x = y[:z]

41
Q

How do you carry out concatenate seperate strings into a single string?

A

x = ‘Hello ‘, ‘world’

42
Q

How do you get the ascii code from a character?

A

x = chr(y)

43
Q

How do you get the ascii character code from a single character?

A

a = ord(b)

44
Q

How do you return characters to the right of the string?

A

x = y[-z:]

45
Q

How to extract charcters from the middle part of the string?

A

x = y[w:z]

46
Q

How do you find the position of a substring in a string?

A

x = y.find(z)

z being what you want to find
x now being the starting position of that character

47
Q

What is a local variable?

A
  • Declared and used inside a sub-routine
  • Only avalible in that subroutine
  • Created when subroutine is called
  • Destroyed when subroutine ends
48
Q

What is a local variable?

A
  • Declared and used inside a sub-routine
  • Only avalible in that subroutine
  • Created when subroutine is called
  • Destroyed when subroutine ends
49
Q

What is a global variable?

A
  • Declared at the top of the program
  • Used thorughout whole program
  • Created when program starts
  • Destroyed when program finishes
50
Q

What is exception handling?

A
  • Code that anticipates possible errors from bad inputs
  • And how to deal with them
51
Q

How do you handle exception?

A
52
Q

What is a recursive subroutine?

A
  • Advanced programming construct
  • Which calls itself from within its own subroutine
  • Must have a stop condition
  • Must keep calling itself if the stop condition is not met
  • Stop condition must be reachable after a fintite number of times
53
Q

How would you use recursion to find the facotrial of number n?

A
54
Q

What are the disadvantages of using reursion over iteration?

A
  • Not very efficient on memory so STACKS are used
  • Resulting in Stack Overflow
  • Processor has to remember where it was in the program before it jumps to a new call
  • So it knows where to return aftwards every time the function is ran
  • Required to remember all values in the variable as they are local to the function
55
Q

What does Turing Complete mean?

A

A computer language is able to solve all the problems a computer is able to solve

56
Q

What is the need for different programming paradigms?

A
  • Evern though langagues might be turing complete
  • Different paradigms can best solve different computational problems
57
Q

What is the features of procedural langagues?

A
  • Python
  • Instructions ran in a sequence
  • With selection and iteration
  • Which can be put in procedures and functions
58
Q

What are the features of object oriented languages?

A
  • Java
  • Objects based on real world modles
  • Where the objects can interact with each other
  • (Inheritence, polymorphism)
59
Q

What are the feautres of assembly languages?

A
  • Assembly
  • Mnemonics
  • Specific to processor
60
Q

What does inheritence do?

A
  • Reuse code in a subclass from a superclass
  • Extend Attributes and methods
  • Without effecting origonal code
61
Q

How does overiding work?

A
  • Use a method in a subclass (like outputting a more sepcific name)
  • To overide that function you use same name in the subclass
  • Overidden method = employeeFour.outputName()
  • Superclass method = employeeFour.super.outputName
62
Q

What is encapsulation?

A
  • Protection of atruibutes and methods of an object
  • Preventing access or changes made by other objects
  • Using private attribbutes that can only be changed through public methods provided by the class holding them
  • Any other attempt results in a error
63
Q

What does polymorphism do?

A
  • Allows for the correct method to be used
  • From superclass or subclass
64
Q

What are the three Object oriented design principles?

A
  1. Favour composition over inheritence
  2. Enncapsulate what varies
  3. Program to an interface, not implementation
65
Q

What does the first object oriented design principle mean?

A
  • Favour composition over inheritence
  • Allows greater flexibility
  • Real world objects can be composed of other objects but they dont inherit characteristics
66
Q

What does the second object oriented design principle mean?

A
  • Encapsulate what varies
  • If something varies it should be put in its own class
  • Reducing testing and aids in maintenance
  • Take properties and methods and subbdivide them into as many classes as needed
  • Ensureing true reflection of real liife scenario
67
Q

What does the third object oriented design principle mean?

A
  • Program to interface not implementation
  • Focus on what the code is doing not how it does it
  • Interface is an abstract class which other classes that are in use can take methods from without creating realtionships