comp 2 Flashcards
What is abstraction?
The process of removing unnecessary detail from a problem leaving only the relevant features.
Why is abstraction important?
saves time
saves storage space
makes the problem simpler for programmers to solve
What shape is used for start/end in flowcharts?
ellipse (horizontal oval)
What shape is used for conditions?
diamond
What shape is used for general processing?
rectangle
What shape is used for I/O?
parallelogram
What shape is used for subprograms?
rectangle with bars on sides
What are the 3 programming constructs?
sequence - line by line
selection - conditions
iteration - loops
What is a recursive function?
A function that calls itself until a stopping condition has been met.
What are the benefits and drawbacks of recursion?
provides an elegant solution that takes less lines of code
uses more memory space as variable values have to be transferred into a stack every time the function is called again
What are the benefits and drawbacks of iteration?
less memory space needed as variables are only defined once
can be harder to understand the program and it takes up more lines of code
What is a variable?
An identifier that is used to reference an address in memory. Its value can be changed during program execution.
What is the difference between local and global variables?
Local variables can only be accessed within the scope of the function in which they’re declared whereas global variables can be directly accessed from anywhere in the program.
What are the advantages of global variables?
simple to implement
can be used for config/user info
uses pass by ref so saves memory
What is the disadvantage of global variables?
can cause bugs and problems implementing modules if names are reused
maintainability reduced as purpose of different glob variables may be unclear
What is modular code?
Code that can be separated into small, independent, reusable modules that each perform specific tasks.
What are the advantages of modular code?
organisation
reliability
maintainability
diff people can work on diff modules at same time
What is a subprogram?
A named section of code that performs a clearly defined task.
What are 2 types of subprogram and what is the difference?
function - returns a value
procedure - doesn’t return a value
What are 2 ways of passing variables to subprograms?
passing by value
passing by reference