home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / PASCTUT1.ZIP / CHAP1.TXT next >
Encoding:
Text File  |  1986-07-14  |  6.0 KB  |  125 lines

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