Programming Flashcards
What is a does a class consist of?
- Class name
- Attributes
- Methods
What are the advatnages of OOP?
- 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
What is a class?
- A blueprint defines a realted group of things
- Properties and methods
- Doesnt store data
What are objects?
- Created from a class
- Defined in an istance of a class
- Same properties and methods from the origin class
What is inheritence?
- Where a class can inherit another class
- Sharing the properties and methods of another class
- ‘Is a ‘ relationship (Animal is a cat)
What is polymorphism?
- Where objects are processed differently depending on their class
What is overriding?
- Overridden method has the same method in the inherited class but a different implementation
What is association?
- Where objects can have a ‘has a’ relationship
- ‘Teacher has a student’
- Can be aggression or composition association
What is aggregation?
- The weaker type of association
- When an object is associated with another aggression, it will still exist if its containing object is destroyed
What is compostion?
- Stronger relationship between classes
- Where if the containing object is destroyed so is the associated object
What are the needs for data types?
- Allows for delcleration of data type
- Which allows for the appropriate amount of data to be set aside
What are the diferent data types you need to know?
- Integer
- Real float
- String
- Character
- Date/Time
- Boolean
- Records
- Arrays / Lists
- Pointer / Reference
What is the integer used for and give an example?
- Stores positive and negative whole numbers
- 10, -19
What is real / float used for?
- Extension of integer
- Stores fractions and decimals
What are records?
A collection of related different data types
What are arrays used for?
- Fixed size
- Sequential set of elements of the same data type
What are pointers and what are they used for?
Declare a variable that will allow you to point to a physcial address in memory
What are user defined data types?
- Complex data types
- Based on in-built data types provided by the langague
- As built in data types can be limiting
What are the programming constructs?
- Sequence
- Selection
- Iteration
What is the sequence construct?
- One statment after the other in order
What is the selection construct?
Do a set of statment based on a condition to allow your code (if statments)
What is the iteration construct?
Do a set of statments again and again a known fixed number of times
What is a subroutine?
- Self contained set of commands which can be called from different parts of a program
- Reduces repetition
- Either procedures or functions (functions return values)
What is an identifier?
- Name an entity within the language
- Used to name constants, types, classes, etc
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
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
What are the advantages of constants?
- Cannot be accidently changed
- Program runs faster because constants are replased with memory adresses at compile time
What is the addition operator in python?
- symbol
- Adds to numbers together
What is the subtraction operator in python?
- Uses the - symbol
- Subtracts two numbers together?
What is the multiplication operator in python?
- Uses the * symbol
- Multiplys numbers together
What is the DIV operator in python?
- Uses the // operator
- Divides a number wihout the remainder
What is the MOD operator in python?
- Uses the % symbol
- Returns the remainder of two numbers being devided
What is the division operator in python?
- Uses the / symbol
- Divides two numbers together
What is the exponentation operator in python?
- Uses the ** symbol
- Returns the first number to the power of the second
What is the rounding operator in python?
- Uses round() in math libary
- Takes in a number and rounds it
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
How do you turn a string into upper case in python?
x = y.upper()
How do you turn a tring into lowercase uring python
x= y.lower()
How do you return the number of characters in a string?
x = len(y)
How do you return the characters to the left of the string?
x = y[:z]
How do you carry out concatenate seperate strings into a single string?
x = ‘Hello ‘, ‘world’
How do you get the ascii code from a character?
x = chr(y)
How do you get the ascii character code from a single character?
a = ord(b)
How do you return characters to the right of the string?
x = y[-z:]
How to extract charcters from the middle part of the string?
x = y[w:z]
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
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
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
What is a global variable?
- Declared at the top of the program
- Used thorughout whole program
- Created when program starts
- Destroyed when program finishes
What is exception handling?
- Code that anticipates possible errors from bad inputs
- And how to deal with them
How do you handle exception?
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
How would you use recursion to find the facotrial of number n?
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
What does Turing Complete mean?
A computer language is able to solve all the problems a computer is able to solve
What is the need for different programming paradigms?
- Evern though langagues might be turing complete
- Different paradigms can best solve different computational problems
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
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)
What are the feautres of assembly languages?
- Assembly
- Mnemonics
- Specific to processor
What does inheritence do?
- Reuse code in a subclass from a superclass
- Extend Attributes and methods
- Without effecting origonal code
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
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
What does polymorphism do?
- Allows for the correct method to be used
- From superclass or subclass
What are the three Object oriented design principles?
- Favour composition over inheritence
- Enncapsulate what varies
- Program to an interface, not implementation
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
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
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