home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Education Master 1994 (4th Edition)
/
EDUCATIONS_MASTER_4TH_EDITION.bin
/
files
/
progscal
/
ptutor2a
/
chap1.txt
next >
Wrap
Text File
|
1988-01-15
|
6KB
|
125 lines
CHAPTER 1 - What is a computer program?
If you are a complete novice to computers you will find
the information in this chapter useful. If however, you
have had some experience with programming, you can
completely ignore this chapter. It will deal with a few
fundamentals of computers in general and will introduce
nothing that is specific to Pascal.
WHAT IS A COMPUTER PROGRAM?
A computer is nothing but a very dumb machine that has
the ability to perform mathematical operations very rapidly
and very accurately, but it can do nothing without the aid
of a program written by a human being. Moreover, if the
human being writes a program that turns good data into
garbage, the computer will very obediently, and very
rapidly, turn the good data into garbage. It is possible to
write a computer program with one small error in it that
will do that very thing, and in some cases appearing to be
generating good data. It is up to the human programmer to
design a program to achieve the desired results.
A computer program is simply a "recipe" which the
computer will use on the input data to derive the desired
output data. It is similar to the recipe for baking a cake.
The input data is comparable to the ingredients, including
the heat supplied by the oven. The program is comparable to
the recipe instructions to mix, stir, wait, heat, cool, and
all other possible operations on the ingredients. The
output of the computer program can be compared to the final
cake sitting on the counter ready to be cut and served. A
computer program then is composed of two parts, the data
upon which the program operates, and the program that
operates on the data. The data and program are inseparable
as implied by the last sentence.
WHAT ARE CONSTANTS?
Nearly any computer program requires some numbers that
never change throughout the program. They can be defined
once and used as often as needed during the operation of the
program. To return to the recipe analogy, once you have
defined how big a tablespoon is, you can use the same
tablespoon without regard to what you are measuring with it.
When writing a computer program, you can define the value of
PI = 3.141592, and continue to use it wherever it makes
sense knowing that it is available, and correct.
WHAT ARE VARIABLES?
In addition to constants, nearly every computer program
uses some numbers that change in value throughout the
Page 5
CHAPTER 1 - What is a computer program?
program. They can be defined as variables, then changed to
any values that make sense to the proper operation of the
program. An example would be the number of eggs in the
above recipe. If a single layer of cake required 2 eggs,
then a triple layer cake would require 6 eggs. The number
of eggs would therefore be a variable.
HOW DO WE DEFINE CONSTANTS OR VARIABLES?
All constants and variables have a name and a value.
In the last example, the name of the variable was "eggs",
and the value was either 2 or 6 depending on when we looked
at the stored data. In a computer program the constants and
variables are given names in much the same manner, after
which they can store any value within the defined range.
Any computer programming language has a means by which
constants or variables can be first named, then assigned a
value. The means for doing this in Pascal will be given
throughout the remainder of this tutorial.
WHAT IS SO GOOD ABOUT PASCAL?
Some computer languages allow the programmer to define
constants and variables in a very haphazard manner and then
combine data in an even more haphazard manner. For example,
if you added the number of eggs, in the above recipe, to the
number of cups of flour, you would arrive a a valid
mathematical addition, but a totally meaningless number.
Some programming languages would allow you to do just such
an addition and obediently print out the meaningless answer.
Since Pascal requires you to set up your constants and
variables in a very precise manner, the possibility of such
a meaningless answer is minimized. A well written Pascal
program has many cross checks to minimize the possibility of
a completely scrambled and meaningless output.
Notice however, in the last statement, that a "well
written" Pascal program was under discussion. It is still
up to the programmer to define the data structure in such a
way that the program can prevent garbage generation. In the
end, the program will be no better than the analysis that
went into the program design.
If you are a novice programmer, do not be intimidated
by any of the above statements. Pascal is a well designed,
useful tool that has been used successfully by many computer
novices and professionals. With these few warnings, you are
ready to begin.
Page 6