home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / PROG / PASCAL / PASTUT24.ZIP / PTUTRTXT.ZIP / CHAP01.TXT next >
Encoding:
Text File  |  1989-12-01  |  5.6 KB  |  178 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
  13. some experience with programming, you can completely ignore
  14. this chapter.  It will deal with a few fundamentals of
  15. computers in general and will introduce nothing that is
  16. specific to Pascal.
  17.  
  18.  
  19. WHAT IS A COMPUTER PROGRAM?
  20. ____________________________________________________________
  21.  
  22. A computer is nothing but a very dumb machine that has the
  23. ability to perform mathematical operations very rapidly and
  24. very accurately, but it can do nothing without the aid of a
  25. program written by a human being.  Moreover, if the human
  26. being writes a program that turns good data into garbage, the
  27. computer will very obediently, and very rapidly, turn the good
  28. data into garbage.  It is possible to write a computer program
  29. with one small error in it that will do that very thing, and
  30. in some cases appear to be generating good data.  It is up to
  31. the human programmer to design a program to achieve the
  32. desired results.
  33.  
  34. A computer program is simply a "recipe" which the computer
  35. will use on the input data to derive the desired output data. 
  36. It is similar to the recipe for baking a cake.  The input data
  37. is comparable to the ingredients, including the heat supplied
  38. by the oven.  The program is comparable to the recipe
  39. instructions to mix, stir, wait, heat, cool, and all other
  40. possible operations on the ingredients.  The output of the
  41. computer program can be compared to the final cake sitting on
  42. the counter ready to be cut and served.  A computer program
  43. is therefore composed of two parts, the data upon which the
  44. program operates, and the program that operates on the data. 
  45. The data and program are inseparable as implied by the last
  46. sentence.
  47.  
  48.  
  49. WHAT ARE CONSTANTS?
  50. ____________________________________________________________
  51.  
  52. Nearly any computer program requires some numbers that never
  53. change throughout the program.  They can be defined once and
  54. used as often as needed during the operation of the program. 
  55. To return to the recipe analogy, once you have defined how big
  56. a tablespoon is, you can use the same tablespoon without
  57. regard to what you are measuring with it.  When writing a
  58.  
  59.                                                      Page 1-1
  60.  
  61.                                   What is a Computer Program?
  62.  
  63. computer program, you can define the value of PI = 3.141592,
  64. and continue to use it wherever it makes sense knowing that
  65. it is available, and correct.
  66.  
  67.  
  68. WHAT ARE VARIABLES?
  69. ____________________________________________________________
  70.  
  71. In addition to constants, nearly every computer program uses
  72. some numbers that change in value throughout the program. 
  73. They can be defined as variables, then changed to any values
  74. that make sense to the proper operation of the program.  An
  75. example would be the number of eggs in the above recipe.  If
  76. a single layer of cake required 2 eggs, then a triple layer
  77. cake would require 6 eggs.  The number of eggs would therefore
  78. be a variable.
  79.  
  80.  
  81. HOW DO WE DEFINE CONSTANTS OR VARIABLES?
  82. ____________________________________________________________
  83.  
  84. All constants and variables have a name and a value.  In the
  85. last example, the name of the variable was "eggs", and the
  86. value was either 2 or 6 depending on when we looked at the
  87. stored data.  In a computer program the constants and
  88. variables are given names in much the same manner, after which
  89. they can store any value within the defined range.  Any
  90. computer programming language has a means by which constants
  91. or variables can be first named, then assigned a value.  The
  92. means for doing this in Pascal will be given throughout the
  93. remainder of this tutorial.
  94.  
  95.  
  96. WHAT IS SO GOOD ABOUT PASCAL?
  97. ____________________________________________________________
  98.  
  99. Some computer languages allow the programmer to define
  100. constants and variables in a very haphazard manner and then
  101. combine data in an even more haphazard manner.  For example,
  102. if you added the number of eggs, in the above recipe, to the
  103. number of cups of flour, you would arrive at a valid
  104. mathematical addition, but a totally meaningless number.  Some
  105. programming languages would allow you to do just such an
  106. addition and obediently print out the meaningless answer. 
  107. Since Pascal requires you to set up your constants and
  108. variables in a very precise manner, the possibility of such
  109. a meaningless answer is minimized.  A well written Pascal
  110. program has many cross checks to minimize the possibility of
  111. a completely scrambled and meaningless output.
  112.  
  113. Notice however, in the last statement, that a "well written"
  114. Pascal program was under discussion.  It is still up to the
  115. programmer to define the data structure in such a way that the
  116. program can help prevent garbage generation.  In the end, the
  117.  
  118.                                                      Page 1-2
  119.  
  120.                                   What is a Computer Program?
  121.  
  122. program will be no better than the analysis that went into the
  123. program design.
  124.  
  125. If you are a novice programmer, do not be intimidated by any
  126. of the above statements.  Pascal is a well designed, useful
  127. tool that has been used successfully by many computer novices
  128. and professionals.  With these few warnings, you are ready to
  129. begin.
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.                                                      Page 1-3
  178.