Procedures-Computer Programming For Aeronautical Engineering And Sciences-Lecture Slides, Slides of Aeronautical Engineering

Prof. Balamohan Pawar delivered this lecture at Allahabad University for Aeronautical Engineering and Computer Programming course. Its main points are: Procedure, Declaration, Definition, Constant, Variable, Begin, End, Call, Return, Function, Parameter

Typology: Slides

2011/2012

Uploaded on 07/20/2012

savitha_48
savitha_48 🇮🇳

3

(1)

109 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Procedures
procedure name (arguments) is
constant definitions
variable definitions
procedure definitions
begin --name
statements
end name;
defined for use in
this procedure only
declaration
definition
Example
procedure display is
num : integer;
begin --show_answer
num:= 71;
new_line;
put(“the number of students is :”);
put(num);
new_line;
end display;
-- comment explaining purpose
-- display a number
docsity.com
pf3
pf4
pf5

Partial preview of the text

Download Procedures-Computer Programming For Aeronautical Engineering And Sciences-Lecture Slides and more Slides Aeronautical Engineering in PDF only on Docsity!

Procedures

procedure name (arguments) is

constant definitions variable definitions procedure definitions

begin --name statements end name;

defined for use in

this procedure only

declaration

definition

Example

procedure display is

num : integer;

begin --show_answer

num:= 71;

new_line;

put(“the number of students is :”);

put(num);

new_line;

end display;

-- comment explaining purpose

-- display a number

Procedure Call

begin

get_two_nums;

add_two_nums;

show_answer;

end ;

visible

with

Procedure Call and Return

calling code

called procedure

called procedure

caller

• Write its name

• Include arguments in brackets

• Procedure must be

  • Declared earlier
  • Included via

procedure calls

• Procedure call

  • Remember where we are in
  • Transfer to
    • Set up storage for local variables
    • Associate parameters with values
    • Start execution at first statement of callee

• Procedure finishes executing

  • Wind up
    • Return value through parameter
    • Dispose of storage
  • Pick up where left of in

Procedures with Parameters

declaration shows the

number and type of arguments

call supplies specific

arguments

between calling and called procedure

Formal Parameters

formal

parameters

in , out ,

  • procedure adjust ( exam : in INTEGER; mark : ) is

begin

end adjust;

• Parameters (argument to a procedure)

  • The procedure
    • Formal parameter
  • The procedure
    • Actual parameter

• Parameter modes

  • Indicate how data may be communicated

• Procedure declaration defines

  • general rules for every call to procedure
    • Mode: in out
    • data type: integer, character, ...
    • internal name: (for use inside procedure)
  • In brackets after procedure name

-- exam mark in out INTEGER -- overall subject mark

-- local declarations

-- statements

Actual Parameters

  • call includes actual parameters
    • specific parameter values for this call

get_integer ( exam, 0, 50 ); get_integer ( number, 1, 5 ); get_integer ( number, low, low+4 );

begin get_exam (exam); get_lab (labs); mark := exam + labs; adjust (exam, mark); PUT (mark); print_grade (mark); end ;

Function or Procedure?

procedure abs ( x : in y : out ) is begin if x >= 0 then y := x; else y := -x; ; end abs; (^) abs (x,y);

abs (-4, temp); y := 10 * temp;

procedure

can differ for each call GET ( val );

-- abs: absolute value

INTEGER; -- argument INTEGER -- abs(argument)

-- abs

end if -- y := abs(x);

-- temp:= abs(-4); -- y:= 10*abs(-4)