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
What are constants?
- NAme used to refer to a fixed value - Value set when the code is written - Cannot be changed while the program is running
26
What is a variable?
- 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
27
What are the advantages of constants?
- Cannot be accidently changed - Program runs faster because constants are replased with memory adresses at compile time
28
What is the addition operator in python?
- + symbol - Adds to numbers together
29
What is the subtraction operator in python?
- Uses the - symbol - Subtracts two numbers together?
30
What is the multiplication operator in python?
- Uses the * symbol - Multiplys numbers together
31
What is the DIV operator in python?
- Uses the // operator - Divides a number wihout the remainder
32
What is the MOD operator in python?
- Uses the % symbol - Returns the remainder of two numbers being devided
33
What is the division operator in python?
- Uses the / symbol - Divides two numbers together
34
What is the exponentation operator in python?
- Uses the ** symbol - Returns the first number to the power of the second
35
What is the rounding operator in python?
- Uses round() in math libary - Takes in a number and rounds it
36
What is the trunciation operator in python?
- Uses the trunc() in math libary - Removes the any numbers past a decimal point leaving only the integer
37
How do you turn a string into upper case in python?
x = y.upper()
38
How do you turn a tring into lowercase uring python
x= y.lower()
39
How do you return the number of characters in a string?
x = len(y)
40
How do you return the characters to the left of the string?
x = y[:z]
41
How do you carry out concatenate seperate strings into a single string?
x = 'Hello ', 'world'
42
How do you get the ascii code from a character?
x = chr(y)
43
How do you get the ascii character code from a single character?
a = ord(b)
44
How do you return characters to the right of the string?
x = y[-z:]
45
How to extract charcters from the middle part of the string?
x = y[w:z]
46
How do you find the position of a substring in a string?
x = y.find(z) z being what you want to find x now being the starting position of that character
47
What is a local variable?
- Declared and used inside a sub-routine - Only avalible in that subroutine - Created when subroutine is called - Destroyed when subroutine ends
48
What is a local variable?
- Declared and used inside a sub-routine - Only avalible in that subroutine - Created when subroutine is called - Destroyed when subroutine ends
49
What is a global variable?
- Declared at the top of the program - Used thorughout whole program - Created when program starts - Destroyed when program finishes
50
What is exception handling?
- Code that anticipates possible errors from bad inputs - And how to deal with them
51
How do you handle exception?
52
What is a recursive subroutine?
- 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
How would you use recursion to find the facotrial of number n?
54
What are the disadvantages of using reursion over iteration?
- 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
What does Turing Complete mean?
A computer language is able to solve all the problems a computer is able to solve
56
What is the need for different programming paradigms?
- Evern though langagues might be turing complete - Different paradigms can best solve different computational problems
57
What is the features of procedural langagues?
- Python - Instructions ran in a sequence - With selection and iteration - Which can be put in procedures and functions
58
What are the features of object oriented languages?
- Java - Objects based on real world modles - Where the objects can interact with each other - (Inheritence, polymorphism)
59
What are the feautres of assembly languages?
- Assembly - Mnemonics - Specific to processor
60
What does inheritence do?
- Reuse code in a subclass from a superclass - Extend Attributes and methods - Without effecting origonal code
61
How does overiding work?
- 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
What is encapsulation?
- 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
What does polymorphism do?
- Allows for the correct method to be used - From superclass or subclass
64
What are the three Object oriented design principles?
1. Favour composition over inheritence 2. Enncapsulate what varies 3. Program to an interface, not implementation
65
What does the first object oriented design principle mean?
- Favour composition over inheritence - Allows greater flexibility - Real world objects can be composed of other objects but they dont inherit characteristics
66
What does the second object oriented design principle mean?
- 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
What does the third object oriented design principle mean?
- 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