In the program in
, after each employee’s pay rate is read into memory, it is increased by $2.00. The
value of the pay rate on the input storage device is not altered. When processing is complete, the input file retains
the original data for each employee, and the output file contains the revised data. Many organizations would keep
the original file as a backup file. A
is a copy that is kept in case values need to be restored to their
original state. The backup copy is called a
and the newly revised copy is a
Logically, the verbs
mean the same thing
all produce output. In conversation, however, programmers
usually reserve the word
for situations in which they mean
produce hard copy output
. Programmers are more likely to
when talking about sending records to a data file and
when sending records to a monitor. In some
programming languages, there is no difference in the verb used for output regardless of the hardware; you simply assign
different output devices (such as printers, monitors, and disk drives) as needed to programmer-named objects that represent
Watch the video
Throughout this book, you have been encouraged to think about input as basically the same process, whether it
comes from a user typing interactively at a keyboard or from a stored file on a disk or other media. The concept
remains valid for this chapter, which discusses applications that commonly use stored file data.
Two Truths & a Lie
Performing File Operations
You give a
file an internal name in a program and then associate it with the operating system’s name for the file.
When you read from a file, you copy values from memory to a storage device.
When you read from a file, you copy values from a storage device into memory. When you write to a file, you copy values
from memory to a storage device.
If you fail to close an input file, usually no serious consequences will occur; the data values still exist in the file.
Understanding Control Break Logic
is a temporary detour in the logic of a program. In particular, programmers use a
to do the following:
Read in records from a sorted sequential file so that all records that belong to specific groups are stored
together in sequence.
Process each record, checking to determine if it still belongs to the same group as the previous record.
Pause for special processing whenever a new group of records is encountered.
For example, a control break program might be used to generate a report that lists all company clients in order by
state of residence, with a count of clients after each state’s client list. See
for an example of a
that breaks after each change in state.