1/35
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
sequence
code is executed line-by-line, from top to bottom
branching
a certain block of code is run if a specific condition is met, using IF statements
also known as ‘selection
iteration
a block of code is executed a certain number of times or while a condition is met
Iteration uses FOR or WHILE loops
count-controlled Iteration is repeated a given number of times
for i in range (0,10):
print i
condition-controlled Iteration continues until a given condition is met
while i <= 20:
print “Not true”;
i=i+1
endwhile
recursion
a programming construct in which a subroutine calls itself during its execution
this continues until a certain condition - called the stopping condition / base case - is met, at which point the recursion stops
ADV recursion
represented in fewer lines of code, which makes them less prone to errors
however it is essential that recursive subroutines are clearly defined so as to reach a stopping condition after a finite number of function calls
DIS recursion
inefficient use of memory
if the subroutine calls itself too many times, there is a danger of a stack overflow, which is when the call stack runs out of memory
this would cause the program to crash
recursion is difficult to trace, especially with more and more function calls
local variables
they can only be accessed within the block of code in which they were defined
if a local variable is defined within a subroutine, it can only be accessed within that subroutine
ensures subroutines are self-contained, with no danger of variables being affected by code outside of the subroutine
destroyed when the subroutine exits
global variables
global variables can be accessed across the whole program
all variables used in the main body of a program are automatically declared to be global
useful for values that need to be used by multiple parts of the program
as global variables are not deleted until the program terminates, they require more memory than local variables which are deleted once the subroutine has been completed
modular programming
technique used to split large, complex programs into smaller, self-contained modules
a modular design also makes it easier to divide tasks between a team and manage, whilst simplifying the process of testing and maintenance, as each component can be dealt with individually
improves the reusability of components, as once a module has been tested, it can be reused with confidence
modular programming - top down approach
problem is continually broken down into sub-problems, until each can be represented as an individual, self-contained blackbox which performs a certain task
also known as stepwise refinement
these modules form blocks of code called subroutines, which can be categorised as either functions or procedures
procedures
a self contained block of code that preforms a specific task
doesn’t have to return a value
can return multiple values
typically given data as parameters for manipulation
functions
self contained block of code that preforms a specific task
must always return a value
must return a single value
makes use of local variables
parameter
variable inside the implementation of the subroutine
passing by value
the value created for the subroutine is a copy of the original
once it is passed in, the parameter is held in a separate memory location
therefore is only available to that subroutine
the copy is now a local variable of that subroutine
its value outside the subroutine will not be affected
passing by reference
a pointer that contains the memory address of the original value is created
any changes to that value from within the called subroutine will also affect the value of the original variable
IDE def
Integrated Development Environment
a program which provides a set of tools to make it easier for programmers to write, develop and debug code
features of an IDE
stepping
allows you to monitor the effect of each individual line of code by executing a single line at a time
variable watch
sometimes used to pinpoint errors, this is a useful feature to observe how the contents of a variable change in real-time through the execution of a program
breakpoint
allow users to set a point in the program at which the program will stop.
can either be based on a condition or set to occur at a specific line.
help to pinpoint where an error is occurring
debugging
tools Some IDEs also provide run-time detection of errors with a guide as to where in the code they are likely to have occurred through line numbers and highlighting
auto complete
start typing a command and it fills in the rest
auto indent
indents code automatically within structures to avoid errors
class
a template for objects
defines a data structure by providing initial values for attributes and methods
attribute
characteristics of a class that can be accessed by other objects
method
a function that is defined inside a class and typically operates on objects of that class
used to manipulate the attributes of an object and perform operations on it
object
an instance of a class
encapsulation
bundling of data with the methods that operate on the data
ADV of reusable components
saves time from having to write the same algorithm again
reduced testing requirements
aggregation
relationship between two classes where one class contains or is composed of one or more objects from another class
composition
implements a has-a relationship between classes
one class contains 1 or more objects from another class
polymorphism
allows you to work with objects of different types though a common interface
inheritance
capability to derive a class properties and characteristics from another class
implements an is-a relationship between classers
constructor
creates an instance of an object from a class
operators
=,+=,<,>
use of validation
check to ensure that data entered is sensible and feasible
variable
something that can hold a value
branching
allow the flow of execution to jump to a different part of the program if a specific condition is met
procedural programming
statements are executed in the order they are written
object orientated programming
designed around objects rather than functions
objects represent real-world entities and have attributes (data) and behaviours (methods)
promotes modularity, code reuse, and scalability
variable
Name (Identifier) – A unique name assigned to the variable e.g. user_age
Data Type – Specifies what kind of value the variable can hold e.g. boolean
Value – The actual data stored in the variable, which can change during execution
Memory Location – The address in memory where the variable’s value is stored
Scope – Defines where in the program the variable can be accessed e.g. local, global
instantiation
the process of creating an object (or instance) from a class