4.1 Fundamentals Of Programming Flashcards
What are pointers
Variables that are used as stores for memory addresses if objects created at runtime
What is a procedure and what are the advantages
A procedure is a section of a computer program that can be used when required at several different points in the program
It can help save time, keep code easy to maintain and to ensure bugs can be found easily
Difference between local and global variables
The main difference between a local and global variable is that a local variable is declared inside a function or other
enclosed code block. In contrast, the global variable is declared outside the functions in the program.
A global variable can be used throughout the computer program, where a local variable can only be used within the
enclosed code block where it is declared. As soon as the enclosed code block finishes executing, the variable falls out
of scope and the memory is freed up for other uses (it will no longer exist).
Role of stack frames
Every time a subroutine calls another subroutine or function, the state of the stack for the calling sub routine needs
to be remembered. This is achieved by using a stack frame.
As the computer encounters a function or subroutine call, it
stores the local variables, parameters and current address in
memory and adds it to the stack. Once it is done with the call,
it removes that frame from the stack and looks at the return
address of the next frame (which would belong to the
function that called it) and resumes executing at that point.
This goes on until the stack is empty (i.e., it returns to the first
subroutine in the program) and the program finishes.
What is recursion/ a recursive algorithm
Recursion is to define a problem (or function/subroutine) in terms of itself.
The term re-entrant is used to describe a recursive call. The base case is the condition in which the recursive calls
will begin to unwind. The general case is the condition in which a recursive call will be made.
Advantages of structured programming
- Easier to read and understand
- User Friendly
- Easier to Maintain
- Mainly problem based instead of being machine based
- Easier to Debug
Define Class
A class defines methods and property/attribute fields that capture the common behaviours
and characteristics of objects. A class is a template that can be used to create objects.
Define Object
An instance of a class.
Define Behaviours/Methods
The procedures of an object – what the object does
Define Attributes/Properties
A characteristic of an object
Define Instantiation
The definition (creation) of an object based on a class.
Define Encapsulation
A technique used to hide data (data hiding) allowing only certain data to be protected (or not)
from modification outside of the class. This is done using the private, public, protected
modifiers.
Public (+) Encapsulation - Can be accessed by any other code outside of the class it was declared within.
Private (-) Encapsulation – Can only be accessed within the same class.
Protected (#) Encapsulation – Can only be accessed within the same class and inherited classes.
Define Inheritance
The relationship between two objects in which one is a kind of the other and shares some of its properties and methods.
Define Aggregation
Aggregation means using instances of classes in other classes. These instances should not be
destroyed when the class using them is destroyed.
In the Unified Modelling Language (UML) aggregation is represented by a white diamond line.
Define Composition
Composition means using instances of classes in other classes. These instances should be
destroyed when the class instantiating them is destroyed.
In the Unified Modelling Language (UML) composition is represented by a black diamond line.