1/66
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
Why is it a good practice to use local variables? 3 Reasons
it makes a subroutine self contained;
memory allocated to local variables can be reused when subroutine not in use;
able to debug subroutine independently
State two differences between local and global variables.
global variables accessible to all parts of the program, local variables are only within the subroutine; global variables exist the entire time the program is running, local variables only exist when the subroutine they are in is executing
Explain the differences between definite and indefinite iteration.
definite iteration: the number of iterations is known at the time of execution;
indefinite iteration: the number of iterations depends on a condition (that is tested before / after each iteration)
Explain what exception handling is used for (2 reasons)
to stop a program from crashing; to deal with a run-time error
Subroutine (procedure/function)
A named ‘out of line’ block of code that may be executed (called) by simply writing its name in a program statement. It can be reused multiple times within a program.
Describe two advantages of re-using subroutines.
Saves time as code can be written once and called in many places; Reduced storage space of source code
Recursion
A recursive subroutine is one that has a call to itself as part of its execution.
Base case
A base case is a value that will not cause a recursive call and therefore allow the recursion to complete (and backtrack).
State four components of a stack frame.
return address; local variables; parameters; register values
Stack frame
A stack frame is a portion of the stack memory used with subroutine calls to store:
• return address
• parameters
• local variables.
A stack frame allows us to move to a subroutine call and then return to where we were called from and carry on.
What is the purpose of a hierarchy chart? (2 reasons)
To represent the structure of the program; To aid decomposition of a problem
Hierarchy chart
A hierarchy chart is a diagram that represents the structure of a program. Each subroutine is shown as a rectangle, and the hierarchy shows how subroutines are called from others.
Programmers are encouraged to adopt a structured approach to writing programs. Explain four reasons for adopting the structured approach.
code is easier to understand;
easier to debug and maintain;
can break problems down into sub-tasks;
can re-use subroutines
Structured approach to program design
The structured approach to program design involves breaking down problems into sub-problems. Code is then organised into subroutines.
Explain the difference between protected and private attributes.
Private attributes can only be accessed by the class they belong to whereas protected attributes can also be accessed by any classes that inherit from the class they belong to
Polymorphism
Polymorphism is the concept that different objects can respond to the same method call in different ways based on their class.
Explain the difference between an attribute that has a public specifier and an attribute that has a protected specifier
public means it can be accessed outside of the class it is in; protected means it can be accessed in the class it is in and any subclasses
Overriding
An overridden method has the same name as a method from an inherited class but a different implementation.
Describe two differences between a virtual method and an abstract method
virtual methods do not have to be overridden whereas abstract methods must be overridden by the derived class;
virtual methods contain code (with functionality) wheras abstract methods contain no code (with functionality)
Explain one difference between a local variable and a private class attribute.
A local variable can only be used in the subroutine in which it is declared whereas a private attribute can be accessed anywhere in the class;
Pointer/Reference
A pointer is an object (variable) that stores a memory address. By following a pointer, we can access the value stored at that location – this is known as dereferencing.
Records
A record is a composite data structure and allows for a collection of fields to be grouped together.
State two reasons why many programmers follow the design principle “favour composition over inheritance”
easier to test each class using unit testing; there can be unintended side effects for derived classes if a method in the base class is altered
Aggregation
A type of association where the aggregated object has a weaker form of association with the objects that it is aggregating than is the case with composition. These objects have an existence independent of the aggregated object and can continue to exist even after the aggregated object is disposed of.
Composition
A type of association where the relationship is stronger. If the containing object is destroyed, the associated object is also destroyed.
Describe the relationships aggregation and composition, making it clear what the difference between the two is
composition and aggregation are both ‘has a’ relationships, when an object contains another object; with composition if the containing object is destroyed so are the objects it contains, this is not the case with aggregation
User-defined data type
A custom data type created by the user combining existing data types.
Name two advantages of using constants over hard-coded values
Constants can be given identifier names, making code easier to understand;
updating a value only needs changing in one place
Constant
An identifier that represents a memory location that can store a value. This value cannot change during execution of a program. Note: Python does not have constants, but convention is that an identifier in capitals should indicate the concept of a constant.
Encapsulation
Combining of properties (data) and methods (procedures/functions) together into a class, where the way in which the data is stored, and the methods are carried out is hidden from other classes.
Inheritance
The relationship between two object types in which one is a kind of the other and shares some of its properties or behaviours.
Name three object-oriented design principles
encapsulate what varies;
favour composition over inheritance;
program to interfaces, not implementation
Encapsulate what varies
The separation of code that might need to be constantly changed. Areas of code that might need to be changed can be encapsulated behind an interface. Then, when any changes are needed, software written to use the interface does not need to be changed.
Favour composition over inheritance
The principle that programmers should look to use composition over inheritance when looking at concepts such as polymorphism.
Program to interfaces, not implementation
The principle that programmers should look to communicate between parts of a program by using an interface rather than the knowledge of an implementation.
What error will occur if a recursive subroutine never meets its base case?
Stack overflow
Parameter (of subroutine)
Parameters define the data to be passed to a subroutine.
Subroutines with interfaces
A subroutine interface is the method of passing data in and out of a subroutine.
Class diagram
A class diagram shows the relationship between classes in a program. Class diagrams involve single inheritance, composition (black diamond line), aggregation (white diamond line), public (+), private (-) and protected (#) specifiers.
Data type
Each variable has a data type. The data type determines what type of value the variable will hold, and the set of operations allowed.
Integer
A whole number.
Real/Float
Numbers that can include fractions/values after the decimal point.
Boolean
A data type that can represent the two values True and False.
Character
Stores a single character in a fixed-length format related to a specific character set (for example ASCII).
String
A string is a sequence of characters.
Date/Time
A date and time data type stores values such as a calendar date and time of day. Typically, a data type that is available in databases.
Arrays (lists)
An array is a collection of elements, each accessed using an index (and all elements must be of the same data type).
(Note: a list is typically dynamic and can have its size changed during runtime but an array is usually static and has a defined size.
Note: in Python, lists may contain elements of multiple data types.)
Variable
An identifier that represents a memory location that can store a value. This value can change during execution of a program.
Constant declaration (examples)
C# const int Months = 12; VB Const Months As Integer = 12 Python MONTHS = 12 Java final int MONTHS = 12;
Assignment
An assignment statement sets the value of a variable/constant.
Iteration
Iteration is the repetition of a block of code.
Selection
A selection statement allows blocks of code to be executed only when a certain condition is satisfied. Examples of selection statements include: IF THEN ELSE SWITCH/CASE/MATCH
Nested (selection/iteration)
When an iteration statement appears inside another iteration statement it is considered nested. When a selection statement appears inside another selection statement it is considered nested.
Meaningful identifier names
Meaningful identifier names make code easier to understand and maintain as the name describes the purpose of the variable or subroutine.
Integer division
The process of dividing two integers and gaining a result which is also an integer. Example: 10 // 3 = 3
Integer remainders
While integer division discards the remainder, this can still be a useful value. The remainder can be obtained by using the modulo operator. Example: 10 % 3 = 1
Exponentiation
Exponentiation refers to the repeated multiplication of a base number by a certain amount of times (the power). Examples: C# Math.Pow(b, n); VB Math.Pow(b, n) Python b ** n Java Math.pow(b, n);
Rounding
Rounding refers to replacing a number with an approximate simpler value. This is often a whole number but could be a number with a fixed number of decimal places.
Example: round(2.5)
Truncation
Truncation refers to shortening something. It usually refers to removing digits from a number. Examples: C# Math.Truncate(2.5); VB Math.Truncate(2.5) Python math.trunc(2.5) Note: there is no specific truncate method in Java, but truncation can be done using a combination of other methods, such as floor() and ceil().
Random number generation
The use of algorithms to produce sequences of numbers that appear unpredictable.
Programming paradigm
A programming paradigm is a particular approach to writing programs.
Procedural
A programming approach that is based on the use of procedures and functions.
Object-oriented
The object-oriented paradigm makes use of objects as containers of both properties (data) and methods.
Class
A class defines methods and attribute fields that capture the common behaviours and characteristics of objects.
Object
Objects based on a class are created using a constructor (implicit or explicit) and a reference to the object assigned to a reference variable of the class type.
Instantiation
Creating an instance of a class (creating an object from a class).
Association
An association is a relationship between two classes. There are different types of association: composition and aggregation.