The Five Program Steps
The Five Program Steps
Steps
1. Initialization Step
The purpose of the Initialization Step is to establish the environment in
which the program will run.
The Initialization Step does whatever background preparation must be
done before the program can begin execution to solve its primary task.
2. Input Step
Almost every computer program has a task that is designed to take
some existing state of information, process it in some way, and show the new
state of that information.
The Input Step is the sequence of program statements that are
necessary to acquire the information needed to solve the task at hand.
Example:
If you are writing a fire alarm system, then you take the
information provided by the fire sensors, interpret their current state and, if
there is a fire, do something about it. If the sensor shows no fire, then
perhaps a second set of sensors is read and the process is repeated.
Indeed, your program may do nothing for decades but take new readings
every few seconds and determine whether some remedial action is
necessary.
3. Process Step
Process Step is responsible for taking a set of inputs and processing it to
get a new set of data.
Note that a program may have multiple Process Steps.
Example:
Continuing with our fire alarm program, once
the input from the sensors is received, some body of
code must be responsible for determining whether the
sensors are detecting a fire. In other words, the voltage
(i.e., temperature) must be read (input) and then
interpreted (i.e., the data processed) to determine the
current state of the sensors.
4. Output Step
After the Process Step has finished its work, the new value is typically output on some
display device.
The Output Step is responsible for using the results of the Process Step. This utilization
could be as simple as displaying the new data on a display device or passing that new value on
to some other program.
Example:
In our fire alarm example, the Output Step
may cause an LED for a particular sensor to continue to
display a green color under normal conditions. If a fire is
sensed, perhaps the LED displays red or display some
text like " "Flame detected...! Take action immediately.",
so whomever is in charge can see what area of the
building is on fire.
5. Termination Step
The Termination Step has the responsibility of “cleaning up” after the program is
finished performing its task.
Termination Process should allow for a graceful termination of the currently running
program. However, many automated program are not designed to terminate.
Example:
A fire alarm system is likely designed to
continue running forever, as long as things are “normal.”
No
Even then, however, there may still be a Termination
Process that is followed. For example, if the fire alarm termination
system has a component failure, then the Termination some code.
Process may try to identify the failed component before
the system shuts down for repairs. Perhaps the
Termination Process deactivates the alarm system before
a maintenance shutdown.
Revisit to the Blink Program
If you look closely at the two lines
immediately above, you will see that none of
the lines ends with a semicolon. That is,
none of the lines forms a C program
statement because all program C
statements must end with a semicolon. If
that is the case, what are they and why are
they part of the source code?
Multiline Comments
Multiline comments begin with a slash-
asterisk pair (/*) and end with an asterisk-
slash pair (*/). There are no spaces between
the two characters pairs. Everything in
between these two-character pairs is treated
as a comment and is ignored by the
compiler. Unlike single line comments,
multiline comments can span multiple lines.
Revisit to the Blink Program
Data Definition
The next line in the program is:
int led = 13;