Notes For Structured Programming, Procedure and Function: Components
Notes For Structured Programming, Procedure and Function: Components
Notes For Structured Programming, Procedure and Function: Components
If you own a stereo system, you are probably familiar with the concept of
components. A typical stereo system, for instance, includes a receiver, a tape deck,
a CD changer, and speakers. Manufacturers know that if they provide each
component separately, then consumers can mix and match the components as
necessary. Component stereo systems are also a more attractive alternative than
integrated systems (one-piece systems) because they can upgrade by simply
purchasing a new component. For example, you can easily replace a 3 CD-changer in
a component system with a 10-CD changer. Additionally, as technology improves and
new components become available, they can add to the system.
B) Subprograms
Procedures and functions represent the two types of subprograms (or routines).
Let's review one of these routines, the division of two numbers in our calculator
problem :-
Let look at an user-defined procedures below. This time, the procedure Adder sum
two numbers.
In this code, num1, num2, and sum are the parameters of the Adder procedure.
The variable FirstNum, SecondNum, and Result are the arguments of the Adder
procedures; these variables contains the values that are passed to the procedure. An
argument can consists of any expression that is of the same type as its corresponding
parameter.
value.
Pass by value is a type of parameter passing in which the value of the argument
is passed to the subprogram, allowing the subprogram to access a copy of the variable.
Pass by value preserves the contents of the original variable. It is the default method
of parameter passing in Object Pascal.
Pass by
Procedures and function that are not built into Object Pascal are called user-defined
subprograms. The general form to defining a procedures is
To invoke a procedure, you state the procedure name along with any required
arguments. The general syntax of a procedure call follows :
The general form of a function invocation with the returned value assigned to a
variable follows :