home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 15 / CDACTUAL15.iso / cdactual / program / pascal / PAS_TUT.ZIP / CHAP01.TXT < prev    next >
Encoding:
Text File  |  1991-02-04  |  5.4 KB  |  118 lines

  1.  
  2.  
  3.  
  4.                                                         Chapter 1
  5.                                       WHAT IS A COMPUTER PROGRAM?
  6.  
  7.  
  8. THIS CHAPTER IS FOR NEW PROGRAMMERS
  9. _________________________________________________________________
  10.  
  11. If you are a complete novice to computers you will find the
  12. information in this chapter useful.  If however, you have had some
  13. experience with programming, you can completely ignore this
  14. chapter.  It will deal with a few fundamentals of computers in
  15. general and will introduce nothing that is specific to Pascal.
  16.  
  17.  
  18. WHAT IS A COMPUTER PROGRAM?
  19. _________________________________________________________________
  20.  
  21. A computer is nothing but a very dumb machine that has the ability
  22. to perform mathematical operations very rapidly and very
  23. accurately, but it can do nothing without the aid of a program
  24. written by a human being.  Moreover, if the human being writes a
  25. program that turns good data into garbage, the computer will very
  26. obediently, and very rapidly, turn the good data into garbage.  It
  27. is possible to write a computer program with one small error in it
  28. that will do that very thing, and in some cases appear to be
  29. generating good data.  It is up to the human programmer to design
  30. a program to achieve the desired results.
  31.  
  32. A computer program is simply a "recipe" which the computer will use
  33. on the input data to derive the desired output data.  It is similar
  34. to the recipe for baking a cake.  The input data is comparable to
  35. the ingredients, including the heat supplied by the oven.  The
  36. program is comparable to the recipe instructions to mix, stir,
  37. wait, heat, cool, and all other possible operations on the
  38. ingredients.  The output of the computer program can be compared
  39. to the final cake sitting on the counter ready to be cut and
  40. served.  A computer program is therefore composed of two parts, the
  41. data upon which the program operates, and the program that operates
  42. on the data.  The data and program are inseparable as implied by
  43. the last sentence.
  44.  
  45.  
  46. WHAT ARE CONSTANTS?
  47. _________________________________________________________________
  48.  
  49. Nearly any computer program requires some numbers that never change
  50. throughout the program.  They can be defined once and used as often
  51. as needed during the operation of the program.  To return to the
  52. recipe analogy, once you have defined how big a tablespoon is, you
  53. can use the same tablespoon without regard to what you are
  54. measuring with it.  When writing a computer program, you can define
  55. the value of PI = 3.141592, and continue to use it wherever it
  56. makes sense knowing that it is available, and correct.
  57.  
  58.                                                          Page 1-1
  59.  
  60.                           Chapter 1 - What is a computer program?
  61.  
  62. WHAT ARE VARIABLES?
  63. _________________________________________________________________
  64.  
  65. In addition to constants, nearly every computer program uses some
  66. numbers that change in value throughout the program.  They can be
  67. defined as variables, then changed to any values that make sense
  68. to the proper operation of the program.  An example would be the
  69. number of eggs in the above recipe.  If a single layer of cake
  70. required 2 eggs, then a triple layer cake would require 6 eggs. 
  71. The number of eggs would therefore be a variable.
  72.  
  73.  
  74. HOW DO WE DEFINE CONSTANTS OR VARIABLES?
  75. _________________________________________________________________
  76.  
  77. All constants and variables have a name and a value.  In the last
  78. example, the name of the variable was "eggs", and the value was
  79. either 2 or 6 depending on when we looked at the stored data.  In
  80. a computer program the constants and variables are given names in
  81. much the same manner, after which they can store any value within
  82. the defined range.  Any computer programming language has a means
  83. by which constants or variables can be first named, then assigned
  84. a value.  The means for doing this in Pascal will be given
  85. throughout the remainder of this tutorial.
  86.  
  87.  
  88. WHAT IS SO GOOD ABOUT PASCAL?
  89. _________________________________________________________________
  90.  
  91. Some computer languages allow the programmer to define constants
  92. and variables in a very haphazard manner and then combine data in
  93. an even more haphazard manner.  For example, if you added the
  94. number of eggs, in the above recipe, to the number of cups of
  95. flour, you would arrive at a valid mathematical addition, but a
  96. totally meaningless number.  Some programming languages would allow
  97. you to do just such an addition and obediently print out the
  98. meaningless answer.  Since Pascal requires you to set up your
  99. constants and variables in a very precise manner, the possibility
  100. of such a meaningless answer is minimized.  A well written Pascal
  101. program has many cross checks to minimize the possibility of a
  102. completely scrambled and meaningless output.
  103.  
  104. Notice however, in the last statement, that a "well written" Pascal
  105. program was under discussion.  It is still up to the programmer to
  106. define the data structure in such a way that the program can help
  107. prevent garbage generation.  In the end, the program will be no
  108. better than the analysis that went into the program design.
  109.  
  110. If you are a novice programmer, do not be intimidated by any of the
  111. above statements.  Pascal is a well designed, useful tool that has
  112. been used successfully by many computer novices and professionals. 
  113. With these few warnings, you are ready to begin.
  114.  
  115.  
  116.  
  117.                                                          Page 1-2
  118.