review for exam 2

review for exam 2 - Computer Science Notes Chapter 4 Simple...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Computer Science Notes Chapter 4 Simple Pascal Procedures Procedure declaration- name given to a sequence of statements. Procedure compliment; {heading} Begin { body} Writeln(‘a lovely letter’); Writeln (‘one of my favorites’); End; {end of body} In the program, the identifier ‘compliment’ can be used anyplace a statement can be used. Procedure call/ invocation- statement used when a procedure is called inside of a program. Variable Parameters Formal variable parameter is a blank in a procedure that must be filled with a variable when the procedure is called. Getnumber (var number : integer); Actual variable parameter- variable in the procedure call. Getnumber( halfdollars ) A procedure may be called more than once using different actual parameters each time. Parameter Lists
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
A procedure can have any number of formal variable parameters. They are all listed in parentheses after the procedure name in the heading. Separated by semicolons. Ex: procedure Total (var p1 : integer; var p2, p3 : real ); When the procedure is called, all actual variable parameters are substituted for all occurrences of formal variable parameters inside procedure body. Actual parameter and formal parameter must be in same order and same type. Actual parameters are separated only by commas; formal parameters are separated by both commas and semicolons. Parameter list- list of both formal parameters [in the heading] and actual parameters [in procedure call] Procedure call process- 1) Actual parameters are substituted for the formal parameters. 2) Body of the procedure declaration is substituted for the procedure call. 3) Actions are executed by code. Substitution follows the ordering of the formal parameters in the formal parameter list and does not depend on their order in the procedure body. Value Parameters An actual variable parameter is a variable that the procedure can access or change. Variable parameters can be used to bring information into the procedure and/or pass information out of the procedure to the rest of the program. Value parameter- ‘one way’ parameters; they can be used to supply information to a procedure, but they cannot be used to get information out of a procedure. Formal value parameters are listed in the procedure heading just like formal variable parameters are, except that formal value
Background image of page 2
parameters are not preceded by the word var. procedure output( length, width : integer ); What Kind of Parameter to Use If the procedure is suppose to provide information to some other part of the program, then use a variable parameter and have the procedure set to values of the variable parameters. If the parameter is being used only to give information to the
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 12

review for exam 2 - Computer Science Notes Chapter 4 Simple...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online