home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / PASCAL / PASTUT34 / STRUCT.PAS < prev    next >
Pascal/Delphi Source File  |  1993-06-03  |  4KB  |  82 lines

  1.   PROGRAM DataCreation;              { Choose any suitable name. }
  2.  
  3.   {~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
  4.   { Appropriate comment and explanation, contained within braces. }
  5.   { At any point in the program comments can be inserted to help  }
  6.   { the user understand the program, provided they are in braces. }
  7.   {                                                               }
  8.   { Words fully in capitals are Reserved words in Turbo Pascal.   }
  9.   {                                                               }
  10.   { STRUCT.PAS  ->  .EXE   R Shaw     7.5.93                      }
  11.   {_______________________________________________________________}
  12.  
  13.   USES Crt;                  { A list of all units employed by the        }
  14.                              { program, in this case just the Crt unit.   }
  15.  
  16.   LABEL Continue, Finish;    { Only used occasionally, as GOTO statements }
  17.                              { are not needed in a structured language.   }
  18.                              { Not used in this demonstration program.    }
  19.  
  20.   CONST                                             { Global constants.   }
  21.      Max = 10;                                      { A numeric constant. }
  22.      Str = 'Press any key to continue: ';           { A string constant.  }
  23.  
  24.   TYPE                                              { Global types.       }
  25.      LinePointer   = ^LineOfNumbers;                { A pointer type, not }
  26.                                                     { used in this program}
  27.      LineOfNumbers = String[79];               { A string of fixed length.}
  28.  
  29.   VAR                                              { Global variables.    }
  30.      Line : LineOfNumbers;                         { Specific instances of}
  31.      Ptr  : Array[1..Max] of LinePointer;          { user-defined types,  }
  32.                                                    { but Ptr not actually }
  33.                                                    { used in this program.}
  34.      j    : Integer;                               { Instance of Integer  }
  35.                                                    { type.                }
  36.  
  37.   PROCEDURE CreateData;                        { Choose a meaningful name. }
  38.  
  39.        { Local Labels, Constants and Types may be declared here. }
  40.  
  41.   VAR                                     { Local variables, as necessary. }
  42.      i  : Integer;                        { Used as counter in a FOR loop. }
  43.      n  : Array[0..79] of char;           { An array of 80 character types.}
  44.  
  45.   BEGIN
  46.      Line := '';                          { Initialise Line to be empty.   }
  47.      FOR i := 0 TO 79 DO                  { A FOR loop repeated 80 times.  }
  48.         BEGIN
  49.            n[i] := Chr(Random(9) + 48);   { Use of Chr & Random functions, }
  50.                                           { to generate ASCII characters   }
  51.                                           { from 48 (=0) to 57 (=9).       }
  52.            Line := Line + n[i];           { Add all the characters to form }
  53.                                           { line of 80 characters.         }
  54.         END;
  55.   END;
  56.  
  57.   FUNCTION ReturnZero : Integer;        { A trivial example of a function.} 
  58.   BEGIN 
  59.      ReturnZero := 0; 
  60.   END; 
  61.  
  62.  
  63.   { Main part of program. } 
  64.  
  65.   BEGIN 
  66.      ClrScr;              { Procedure from Crt unit to clear the screen.  } 
  67.      FOR j := 0 TO Max DO   
  68.        BEGIN 
  69.          CreateData;                   { Call to procedure declared above.} 
  70.          Writeln(Line);                { Call to system procedure Writeln.} 
  71.        END;
  72.     Writeln;
  73.     Writeln('Function return value = ',ReturnZero);
  74.     Writeln;
  75.     Write(Str);               { Call to procedure Write for constant Str  }
  76.     REPEAT UNTIL KeyPressed;  { Function KeyPressed returns True if a key }
  77.                               { has been pressed, ensuring that nothing   }
  78.                               { happens until a key is pressed.           }
  79.   END.
  80.  
  81.  
  82.