Subprograms - Subprograms Procedures...

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

View Full Document Right Arrow Icon
Subprograms  Procedures   A procedure is a subprogram.  Subprograms help reduce the amount  of redundancy in a program. Statements  that are executed over and over again  but not contained in a loop are often put  into subprograms. 
Background image of page 1

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

View Full DocumentRight Arrow Icon
Subprograms  Procedures   Subprograms also facilitate top-down design. Top- down design is the tackling of a program from the  most general to the most specific. For example, top  down design for going from one room to another  starts out as:  Get out of first room  Go to second room  Go into second room  Then it is refined to  Get out of first room  Go to door  Open the door  Get out of door  Close door  ... 
Background image of page 2
Subprograms  Procedures   Just going to the door can be  refined further:  Get out of first room  Go to door  Get out of seat  Turn towards door  Walk until you almost bump into it 
Background image of page 3

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

View Full DocumentRight Arrow Icon
Subprograms  Procedures   This, of course, can be further refined to say  how much exercise should be given to your  cardiac myofibrils, and how much adenosine  diphosphate should be converted to  adenosine triphosphate by fermentation or  aerobic respiration. This may seem to be too  detailed, but for computer programming, this  is, in effect what you have to do. The  computer can't understand general  statements -- you must be specific. 
Background image of page 4
Subprograms  Procedures   Main tasks should be contained in  procedures, so in the main program,  you don't have to worry about the  details. This also makes for reusable  code. You can just keep your  procedures in one file and link that into  your program. 
Background image of page 5

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

View Full DocumentRight Arrow Icon
Subprograms  Procedures   A procedure has the same basic format as a  program:  procedure   Name ; const    (* Constants *) var    (* Variables *) begin    (* Statements *) end;  
Background image of page 6
Subprograms  Procedures   There is a semicolon (not a period) at  the end.  To call the procedure from the main  program, just use the name, like you  would writeln. Name ;   Procedures are very often used to  output data. 
Background image of page 7

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

View Full DocumentRight Arrow Icon
Subprograms  Parameters   A parameter list can be included as part  of the procedure heading. The  parameter list allows variable values to  be transferred from the main program to  the procedure. The new procedure  heading is:  procedure   Name   ( formal_parameter_list );  
Background image of page 8
Subprograms  Parameters   The parameter list consists of several  parameter groups, separated by  semicolons:  param_group_1 ;   param_group2 ;   ...   ;   param_groupn   Each parameter group has the form:  identifier_1 ,   identifier_2 ,   ...   ,   identifier_n   :   data_type  
Background image of page 9

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

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

This note was uploaded on 01/02/2012 for the course CHEM E 101 taught by Professor Mr.yuswan during the Spring '11 term at Universitas Indonesia.

Page1 / 34

Subprograms - Subprograms Procedures...

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

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