Programming Techniques Flashcards
Explain the term procedure.
- A block of code/ set of instructions
- Performs a task
- Receives parameter values
- Uses local variables
- May return values
Explain how parameters are used.
- Supplied to a procedure or function
- They are used to pass values between functions/procedures
- They are passed by reference or by value
- Uses as a local variable
State benefits of using procedures.
- procedures tested separately
- easier to maintain program
- main program is simpler/code is clearly structured
- use of library routines to save time
- code is reusable
- program produced faster/to a higher standard…
- …as procedures may be shared between
programmers
Describe stepwise refinement.
- problem broken into sections…
- which become progressively smaller
- until each section can be written as a single
procedure/represents one step in the algorithm
Explain the term global variable.
- a variable defined at the start of a program
- exists throughout program…
- including functions & procedures
- allows data to be shared by modules
- overridden by local variables with same name
Explain the term local variable.
- a variable defined within one module…
- & only accessible in that module
- data is lost when module is completed
- same variable name may be used in different
modules
Discuss the use of functions in developing programs.
- block of code…
- …which performs a single task/calculation…
- returns a single value
- uses local variables
Discuss the use of procedures in developing programs.
- block of code…
- …which performs a task
- …which may or may not produce a single value
- uses local variables
Discuss the use of stepwise refinement in developing programs.
- breaks a problem into sections…
- …which become progressively smaller…
- …until each module can be written as a single procedure/function
- each module can be tested separately
- library routines can be used
What data structure is used to handle procedure calling and parameter passing?
Stack
Explain the term parameter.
- (information about) an item of data…
- …supplied to a procedure or function
- may be passed by reference or by value
- used as a local variable
State the purpose of of syntax diagrams.
to unambiguously define terms for a computer language
What other notation can be used other than syntax diagrams?
Backus-Naur Form
State advantages of using reverse polish notation compared with infix algebraic notation.
-any expression can be processed in order (left to right)
- no rules of precedence are needed/no brackets are
needed/unambiguous
What tree traversal should be used for reverse polish notation?
post order