home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / m / mod2tutr.zip / CHAP01.TXT next >
Text File  |  1989-01-18  |  6KB  |  176 lines

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