STRUCTURE OF A PASCAL PROGRAM / PDF


STRUCTURE OF A PASCAL PROGRAM / PDF




STRUCTURE OF A PASCAL PROGRAM / PDF




Sample of the PDF document







Program Heading

This is the opening statement of all Pascal programs. In this section the program is given a name which should not contain any space or special character.  Standard I/O devices are referred to as (Input, Output).

Format
Program program-name (Input, Output);


            Example
            Program SUM (Input, Output);


Constant Declaration

Any constant value to be used in the program may be declared (assigned) here, and the name of the constant used in the program instead of the actual value.  This allows for easy modification of the program in case we need to change the value of the constant.  This concept is similar to the use of Absolute Addressing in spreadsheets.


Format
const   constant-name            = value-of-constant;


            Example
            const   int-rate = 0.15;


Variable Declaration

Each variable that is used in the program must be declared in this section, along with its data type.  The most common data types we will encounter at this level are Integer, Real and String.


Format
var      variable-name :           data-type;
            variable-name :           data-type;


            Example
            var      A, B    :           Integer;
                        C         :           Real;
                        Name  :           String[20];



Body of Program

This section contains all the executable statements of the program, and is generated from the pseudocode algorithm we would have written prior to attempting to write the program.


Structure
1.                  This section must start with the reserved word begin and terminate with the reserved word end, followed by a full-stop.

2.                  Each statement is terminated by a semi-colon (;).
3.                  := is used to represent the assignment symbol.

4.                  The format of the input statement is:
                             Read (variable-name);

5.                  The format of the output statement is:
                             Either
                                         Write (variable-name);

                             Or
                                         Write (‘comments’);

6.                  When using a conditional statement, (i.e. IF-THEN, FOR-DO, WHILE-DO, DO-UNTIL), we should note the following:

(a)                     Each conditional statement is considered to be a single statement,             and is terminated with a semi-colon.
     
                 Example
                 If A > B then
                    A:= A – 10
                 else
                    B := B – 10;
                

(b)                    If more than one statement is contained within a statement-block,             then they should be enclosed within a begin-end pair.

                 Example
                 If A > B then
                     begin         
                             A:= A – 10;
                             Write (A);
                     end
                 else
                      begin
                             B := B – 10;
                             Write (B);
                       end;
                




7.                  Comments used to explain the program are enclosed using the following for each comment line.

(*                          comments                               *)
     
                            
                             Example
                             Program        Subtractten (Input, Output);

                             (*         This program was written by Peter Davis of Vere Tech,   *)                                         (*         and was designed to read two values, and to subtract 10  *)                                             (*         from the larger one and add ten to the smaller one.            *)

                             etc........















STRUCTURE OF A PASCAL PROGRAM / PDF





0 commentaires: