Please enable JavaScript.
Coggle requires JavaScript to display documents.
programming features (procedures and functions (benefits (procedure code…
programming features
procedures and functions
benefits
procedure code can be saved and re-used in future projects
the repetition of lines of code is avoided
Testing of the procedure code can take place in isolation from the main program.
Debugging of the main program is simplified as each procedure can be individually tested.
a procedure consists of:
a heading
a declaration part
an action part
per-defined functions
round
length
random
a function consists of:
a heading
a declaration part
an action part
parameter passing and data flow
here are two types of variable that can be used in a program:
Local variables
A local variable exists within one subroutine, function, or procedure.
Local variables are created when the subroutine is called and are then destroyed when the subroutine terminates.
They cannot be accessed or assigned a value except within that subroutine.
Global variables
A global variable can be accessed and altered from any part of the program, even from another script/event so long as it is declared at the very start
Global variables should be used with care as their values may accidentally change if the programmer forgets that they have already used them in another subroutine
the type of variable determines where it can be used in a program
A parameter can be either a variable or an array. It can be passed into a sub-routine in one of two ways
Passed by value
Passing a parameter by value is used when a parameter is needed in a subroutine but its value is not going to change in the subroutine.
The subroutine will be passed a copy of the original parameter, so that the original parameter remains unchanged.
Passed by reference
Passing a parameter by reference is used when a parameter is needed in a subroutine and its value is going to change in the subroutine when it is passed in.
The subroutine will be passed the original parameter and any changes made in the subroutine will result in a change to the original value(s) held within the parameter.
program design
Program design is very important. It allows programmers to think about the structure of the program before they begin to create it
program design
In our program design at this level, we now need to show:
Top level design (the main steps of the design)
The data flow (the information that must flow in or out from the subprograms)
Refinements (a break down of the top level design when required)
scope of variables
The scope means where the variable is visible in the program.
For a local variable the scope is limited to a single procedure or function.
For a global variable the variable is visible throughout the whole program. This means the scope is the whole program.
formal and actual parameters
formal parameter
A formal parameter is used as a placeholder within a subprogram for the values received or sent to the main program’s actual parameters.
actual parameters
An actual parameter is the actual value that is passed into the procedure.