2.2 Problem solving and programming Flashcards
Why are programming constructs used?
to represent the programs control flow
Give three constructs of structured programming.
Sequence, branching and iteration
What is the programming construct of sequence?
the code is executed line-by line, from top to bottom
What is the programming construct of Branching/selection ?
the block of code is run if a specific condition is met.
What is the programming construct of iteration?
the block of code is executed a certain number of times or while a condition is met.
What are the two types of iteration?
Count- controlled and condition controlled
What is Count-controlled iteration?
the iteration is repeated a give number of times
What is Condition-controlled
the iteration continues until a specific condition is met
What is Recursion?
a programming construct in which a subroutine calls itself during its execution until a stopping condition is met.
What are the advantages of Recursion?
reduces lines of code and is less prone to errors
What are the disadvantages of Recursion?
its an inefficient use of memory (can cause a stack over) and is difficult to trace
What are the two types of error?
Logic and syntax errors
What is a Logic error?
when the program works, but not in the intended way, produce an unexpected output
What is a Syntax error?
when the rules of the programming language have been broken
What is a Scope?
it refers to the section of code in which the variable is available.
What are Local variables?
variables that can only be accessed within the block of code in which they were defined.
Why are local variables used?
to ensure subroutines are self-contained
What are Global variables?
Variables that can be accessed across the whole program
What are the drawbacks to using global variables?
they can be unintentionally over written and require more memory as they aren’t deleted.
What happens if a local variable has the same name as a global variable?
the local variable will take precedence
What is Modular programming?
a programming technique used to split large, complex programs into smaller, self-contained modules.
What is a benefit of a modular design?
it makes it easier to divide tasks between a team as each component can be dealt with individually. the components are also more reusable.
What is the top-down approach (stepwise refinement)?
the problem is continually broken down into sub-problems, each can be represented as an individual, self- contained blackbox which performs a certain task
What are functions and procedures?
named blocks of code that perform a specific task
Whats the difference between functions and procedures?
procedures do not have to return a value; functions always return a value
What is a parameter?
a value that is passed into a subroutine
What two ways can a parameter be passed into a subroutine?
by value or by reference