2.1 Flashcards
(11 cards)
2.1.1 - OOP
1. What is a class?
2. What is instantiation?
class Person
- The class starts with the keyword ‘class’ followed by the class name.
private name
private age
- The attributes are listed next with the private keyword.
public procedure new(givenName, givenAge)
name = givenName
age = givenAge
end procedure
- Then there is the constructor method, which runs every time an object of that class type is created, taking the values of the parameters passed in and setting its local attributes to their initial values.
public procedure getName()
return name
end procedure
public procedure setName(newName)
name = newName
end procedure
- The methods are then listed for the class, which can set new values for attributes or return existing values for attributes.
endclass
- To end the class definition, we use the keyword endclass.
2.1.1 - OOP
What is the structure of a class in pseudocode?
class Child inherits Person
- The class starts with the keyword ‘class’ followed by the class name (and the class name of the inherited class)
private age
- The attributes are listed next with the private keyword (but not the inherited ones).
public procedure new(givenName, givenAge)
super.new(givenName)
age = givenAge
end procedure
- Then there is the constructor method, which runs every time an object of that class type is created, taking the values of the parameters passed in and setting its local attributes to their initial values.
public procedure getAge()
return age
end procedure
public procedure setAge(newAge)
age = newAge
end procedure
- The methods are then listed for the class, which can set new values for attributes or return existing values for attributes.
endclass
- To end the class definition, we use the keyword endclass.
2.1.1 - OOP
1. How do you create a new object?
2. How do you reference methods in the class?
- To create a new object, you use this format: objectName = new ClassName(parameters).
- You use dot notation; for example personOne.getName, personTwo.setName(“Dan”).
2.1.1
1. How do you write a getter method for a class?
2. How do you write a setter method for a class?
- public function getVariableName():
return variableName
end function - public function setVariableName(newVariableName):
variableName = newVariableName
end function
- What are the different elements of a flowchart?
- What are the general rules of flowcharts?
- The start and stop are in rectangles with curved sides.
- A process is in a rectangle.
- An input or output is in a parallelogram.
- A decision is in a diamond.
- Arrows show the flow of data.
- The start and stop are in rectangles with curved sides.
- All boxes of the flowchart are connected with arrows.
- Flowcharts have one entry point at the top, and one exit.
- The decision symbol has only two exit points, which can be on the sides or the bottom.
- There is one action per process.
- All boxes of the flowchart are connected with arrows.
2.1.1
1. What is computational thinking?
2. What is abstraction?
3. Why is abstraction used (state 5 reasons)?
4. Describe the difference between a virtual version of a place with abstraction applied, compared to the real version
- Computational thinking is an approach to problem solving combining critical thinking and computer processes.
- Abstraction means the process of taking away or removing characteristics from something in order to reduce it to a set of essential characteristics.
- It reduces the complexity of a program, therefore reduces computational resources and can run on lower spec computers. Reduces the programming time, as factors that are not part of the main purpose of the program can be ignored. It reduces the cost of designing and building the program.
- Features are removed, for example there may be no trees or footpaths.
- Symbols or keys are used to represent elements, such as a train.
- It may not be to scale, as relative distances may not be true.n
- Features are removed, for example there may be no trees or footpaths.
2.1.1
What are the different types of abstraction?
Data abstraction: variables, objects, and data structures.
Variables: represents real world values.
Objects: in OOP a class is an abstract representation of something with certain properties (attributes) and operations (methods).
Data structures: arrays, linked-lists, stacks and queues.
Problem abstraction: when faced with a problem deciding which factors are relevant to the problem and the solution.
- What is caching?
- What is a disadvantage of caching?
- Caching is when data that has been used is stored in the cache in case it is needed again, (1) and allows faster access for future use. (1) (If the question is asking what is meant by caching, it is asking about cache generally, not specific to the CPU, so unless it specifies, do not refer to the memory locations in the CPU specifically).
- A drawback is that the nature of predictive logic means that caching algorithms can be very complicated to implement. The wrong data is often fetched and cached.
What is a module or library?
A software module or library is code that has been tested by other developers that can be reused. Using libraries saves work for developers, shortens overall development time and reduces cost. Reusable components can be used by third parties to access data from other software, such as logging into a third party software with your social media account.
2.1.1
How do you write a class function using inheritance?
In the constructor method parameters, you must include all the parameters, including the ones that are inherited from the parent class. However, for the imported variables, you use super.new(parameters). This is a separate line with the function, with the new parameters listed normally underneath.
- Define decomposition
- How does a structure diagram work?
- Decomposition: splitting a problem down into its component parts.
- A structure diagram decomposes a problem and displays how the sub problems relate to each other. Each module is represented by a box, and the structure reflects the problem hierarchy, with the top level containing the least broken-down modules and lower levels containing increasingly specific subtasks. Arrows or lines are used to show the relationships between modules, indicating how data or control flow between them. Imagine you’re designing a program to calculate the area of different geometric shapes. A structure diagram might look like this:
Top level: Calculate Area
Next level:
Calculate Square Area
Calculate Circle Area
Calculate Triangle Area
Sub-levels within each: Get Sides, Get Radius, Get Base and Height (depending on the shape).