Overview of Computers and Programming
1.1
Electronic Computers Then and Now
The first electronic computer was built in the
late 1930s by Dr. John Atanasoff and Clifford Berry at Iowa State University.
Atanasoff designed his computer to assist graduate students in nuclear physics
with their mathematical computations. The first large-scale, general-purpose
electronic digital computer, called the ENIAC, was completed in 1946 at the
University of Pennsylvania with funding from the U.S. Army. Weighing 30 tons and
occupying a 30-by-50-foot space, the ENIAC was used to compute ballistics
tables, predict the weather, and make atomic energy calculations. These early
computers used vacuum tubes as their basic electronic component. Technological
advances in the design and manufacture of electronic components led to new
generations of computers that were considerably smaller, faster, and less expensive
than previous ones.
Using today’s technology, the entire circuitry of a computer
processor can be packaged in a single electronic component called a computer or microprocessor chip,
which is less than one-fourth the size of a standard postage stamp. Their affordability
and small size enable computer chips to be installed in watches, cellphones, GPS
systems, cameras, home appliances, automobiles, and, of course, computers. Today,
a common sight in offices and homes is a personal computer, which can cost less
than $1000 and sit on a desk and yet has as much computational power as one
that 40 years ago cost more than $100,000 and filled a 9-by-12-foot room. Even
smaller computers can fit inside a briefcase or purse or your hand. Modern
computers are categorized according to their size and performance. Personal computers are used by a single person at a time. Large real-time
transaction processing systems, such as ATMs and other banking networks, and
corporate reservations systems for motels, airlines, and rental cars use mainframes , very powerful
and reliable computers. The largest capacity and fastest computers are called supercomputers and
are used by research laboratories and in
computationally
intensive applications such as weather forecasting.
The elements of a computer system fall into two major categories:
hardware and software. Hardware is the equipment used to perform the necessary computations and
includes the central processing unit (CPU), monitor, keyboard, mouse, printer, and
speakers. Software consists of the programs
that enable us to solve problems
with a computer by providing it with lists of instructions to perform.
Programming a computer has undergone significant changes over the
years. Initially, the task was very difficult, requiring programmers to write
their program instructions as long binary
numbers (sequences of 0s and 1s).
High-level programming languages such as C make programming much easier.
1.2 Computer Hardware
Despite significant variations in cost, size, and capabilities,
modern computers resemble one another in many basic ways. Essentially, most
consist of the following components:
■ Main
memory
■ Secondary
memory, which includes storage devices such as hard disks, CDs, DVDs, and flash
drives
■ Central
processing unit
■ Input
devices, such as keyboards, mouses, touch pads, scanners, joysticks
■ Output
devices, such as monitors, printers, and speakers
Memory
Memory is an essential component in any computer. Let’s look at
what it consists of and how the computer works with it.
Anatomy of Memory Imagine
the memory of a computer as an ordered sequence of storage locations called memory. To store and access information,
the computer must have some way of identifying the individual memory cells.
Therefore, each memory cell has a unique address
that indicates its relative
position in memory. Figure 1.4 shows a computer memory consisting of 1000
memory cells with addresses 0 through 999. Most computers, however, have millions
of individual memory cells, each with its own address. The data stored in a
memory cell are called the contents of the cell. Every memory cell always has some contents, although
we may have no idea what they are. In a memory cell can also contain a program instruction.
The ability to store programs as well as data is called the stored
program concept : A
program’s instructions must be stored in main memory before they can be
executed. We can change the computer’s operation by storing a different program
in memory.
Bytes and Bits A
memory cell is actually a grouping of smaller units called bytes.
Storage and Retrieval of Information in Memory Each value in memory is represented by a particular pattern of 0s
and 1s. A computer can either store a value or retrieve a value. To store a value, the computer sets each
bit of a selected memory cell to either 0 or 1, destroying the previous
contents of the cell in the
process. To retrieve a value from a memory cell, the computer copies the pattern of 0s
and 1s stored in that cell to another storage area for processing; the copy operation
does not destroy the contents of the cell whose value is retrieved. This process
is the same regardless of the kind of information—character, number, or
program instruction—to be stored or retrieved.
Main Memory Main memory
stores programs, data, and results. Most computers have two types of main
memory: random access memory (RAM) , which offers temporary storage of programs and data, and read-only memory (ROM) , which stores
programs or data permanently. RAM temporarily stores programs while they are
being executed (carried out) by the computer. It also temporarily stores such data
as numbers, names, and even pictures while a program is manipulating them.
RAM is usually volatile memory , which means that everything in
RAM will be lost when the computer is switched off.
ROM, on the other hand, stores information permanently within the
computer.
The computer can retrieve (or read), but cannot store (or write)
information in ROM, hence its name, read-only. Because ROM is not volatile, the
data stored there do not disappear when the computer is switched off. Start-up
instructions and other critical instructions are burned into ROM chips at the
factory. When we refer to
main memory in this text, we mean RAM because that is the part of
main memory that is normally accessible to the programmer.
Secondary Storage Devices Computer
systems provide storage in addition to main memory for two reasons. First,
computers need storage that is permanent or semipermanent so that information
can be retained during a power loss or when the computer is turned off. Second,
systems typically store more information than will
fit in memory.
Secondary storage devices and storage media. Most personal computers use two types
of disk drives as their secondary storage devices—hard drives and optical drives.
Hard disks are attached to their disk drives and are coated with a magnetic
material. Each data bit is a magnetized spot on the disk, and the spots are arranged in
concentric circles called tracks. The disk drive read/write head accesses data by
moving across the spinning disk to the correct track and then sensing the spots as
they move by. The hard disks in personal computers usually hold several hundred
gigabytes (GB) of
data, but clusters of hard drives that store data for an entire
network may provide as much as several terabytes (TB) of storage (see Table 1.1
).
Most of today’s personal computers are equipped with optical drives for
storing and retrieving data on compact disks (CDs) or digital versatile disks
(DVDs) that can be removed from the drive. A CD is a silvery plastic platter on
which a laser records data as a sequence of tiny pits in a spiral track on one
side of the disk. One CD can hold 680 MB of data. A DVD uses smaller pits
packed in a tighter spiral,
allowing storage of 4.7 GB of data on one layer. Some DVDs can
hold four layers of data—two on each side—for a total capacity of 17 GB,
sufficient storage for as much as nine hours of studio-quality video and
multi-channel audio.
Flash drives such as the one
pictured in Fig. 1.6 use flash memory packaged in small plastic cases about
three inches long that can be plugged into any of a computer’s USB (Universal
Serial Bus) ports. Unlike hard drives and optical drives that must spin their
disks for access to data, flash drives have no moving parts and all data
transfer is by electronic signal only. In flash memory, bits are represented as
electrons trapped in microscopic chambers of silicon dioxide. Typical USB flash
drives store 1 to several GB of data, but 64-GB drives are also available.
Information stored on a disk is organized into separate
collections called files.
One file may contain a C program. Another file may contain the
data to be processed by that program (a data file ). A third file
could contain the results generated by a program (an output file ). The names of
all files stored on a disk are listed in the disk’s directory . This directory
may be broken into one or more levels of subdirectories or folders, where each subdirectory stores the names
of files that relate to the same general topic. For example, you might have
separate subdirectories of files that contain homework assignments and programs
for each course you are
taking this semester. The details of how files are named and
grouped in directories vary with each computer system. Follow the naming
conventions that apply to your system.
Central Processing Unit
The central processing unit
(CPU) has two roles: coordinating all
computer operations and performing arithmetic and logical operations on data.
The CPU follows the instructions contained in a computer program to determine
which operations should be carried out and in what order. It then transmits
coordinating control signals to the other computer components. For example, if
the instruction
requires scanning a data item, the CPU sends the necessary control
signals to the input device.
To process a program stored in main memory, the CPU retrieves each
instruction in sequence (called fetching
an instruction ), interprets the instruction to
determine what should be done, and then retrieves any data needed to carry out that
instruction. Next, the CPU performs the actual manipulation, or processing, of the
data it retrieved. The CPU stores the results in main memory.
The CPU can perform such arithmetic operations as addition,
subtraction, multiplication, and division. The CPU can also compare the contents
of two memory cells (for example, Which contains the larger value? Are the
values equal?) and make decisions based on the results of that comparison. The
circuitry of a modern CPU is housed in a single integrated circuit or chip, millions
of miniature circuits manufactured in a sliver of silicon. An integrated
circuit
(IC) that is a full central processing unit is called a
microprocessor. A CPU’s current instruction and data values are stored
temporarily inside the CPU in special high-speed memory locations called registers.
Some computers have multiple CPUs ( multiprocessors ) or
a multi-core CPU. These computers are capable of faster speeds because they can
process different sets of instructions at the same time.
Input/Output Devices
We use input/output (I/O)
devices to communicate with the
computer. Specifically, they allow us to enter data for a computation and to
observe the results of that computation. You will be using a keyboard as an input
device and a monitor (display screen) as an
output device. When you press a letter or digit key on a keyboard,
that character is sent to main memory and is also displayed on the monitor at
the position of the cursor , a moving place marker (often a blinking line or rectangle). A
computer keyboard has keys for letters, numbers, and punctuation marks plus
some extra keys for performing special functions. The twelve function keys along the top
row of the keyboard are labeled F1 through F12. The activity performed when you
press a function key depends on the program
currently being executed; that is, pressing F1 in one program will
usually not produce the same results as pressing F1 in another program. Other
special keys enable you to delete characters, move the cursor, and “enter” a
line of data you typed at the keyboard.
Another common input device is a mouse. A mouse is a handheld device used to
select an operation. Moving the mouse around on your desktop moves the mouse cursor (normally a small rectangle or
an arrow) displayed on the monitor’s screen.
You select an operation by moving the mouse cursor to a word or icon (picture) that represents the
computer operation you wish to perform and then pressing a mouse button to
activate the operation selected.
A monitor provides a temporary display of the information that
appears on its screen. If you want hard
copy (a printed version) of some
information, you must send that information to an output device called a printer .
Computer Networks
The explosion we are experiencing in worldwide information access
is primarily due to the fact that computers are now linked together in networks
so they can communicate with one another. In a local area network (LAN),
computers and other devices in a building are connected by cables or a wireless
network, allowing them to share information and resources such as printers,
scanners, and secondary storage devices ( Fig. 1.7 ). A computer that controls
access to a secondary storage device such as a large hard disk is called a file server .
Local area networks can be connected to other LANs using the same
technology as telephone networks. Communications over intermediate distances
use phone lines, fiber-optics cables or wireless technology, and long-range
communications use either phone lines or microwave signals that may be relayed
by satellite.
A network that links many individual computers and local area
networks over a large geographic area is called a wide area network (WAN).
The most well-known WAN is the Internet, a network of university, corporate,
government, and publicaccess networks. The Internet is a descendant of the
computer network designed
by the U.S. Defense Department’s 1969 ARPAnet project. The goal of
the project was to create a computer network that could continue to operate
even if partially destroyed. The most widely used aspect of the Internet is the
World Wide Web (WWW), the universe of Internet-accessible resources that are navigable
through
the use of a graphical
user interface (GUI) .
If you have a computer with a modem, you can connect to the
information superhighway through a telephone line, television or fiber-optic
cable, or through wireless or satellite communications. A modem ( mo dulator/ dem odulator) converts binary
computer data into audio tones that can be transmitted to another computer
over a normal telephone circuit. At the computer on the receiving
end, another modem converts the audio tones back to binary data.
Early modems for telephone lines transmitted at only 300 baud (300
bits per second). Today’s modems transmit over 50,000 bits per second, or if
you have a digital subscriber line ( DSL
connection ) or fiber-optics telephone
line, the associated modem can transmit 1.5 million bits per second (DSL) or a
few billion bits per second (fiber optics) while allowing you to use the same
line simultaneously for voice calls. Cable
Internet access brings Internet data to your
computer at speeds of several billion bits per second using the same coaxial
cable that carries cable TV.
Wireless and
satellite communications provide data speeds comparable to cable.
1.3
Computer Software
Operating System
The collection of computer programs that control the interaction
of the user and the computer hardware is called the operating system (OS) .
The operating system of a computer is often compared to the conductor of an
orchestra, for it is the software that is responsible for directing all
computer operations and managing all computer resources. Usually part of the
operating system is stored permanently in a read-only memory (ROM) chip so that
it is available as soon as the computer is turned on. A computer can look at
the values in read-only memory, but cannot write new values to the chip. The
ROM-based portion of the OS contains the instructions necessary for loading
into memory the rest of the operating system
code, which typically resides on a disk. Loading the operating
system into memory is called booting
the computer .
Here is a list of some of the operating system’s many responsibilities:
1. Communicating with the computer user: receiving commands and
carrying them out or rejecting them with an error message.
2. Managing allocation of memory, of processor time, and of other
resources for various tasks.
3. Collecting input from the keyboard, mouse, and other input
devices, and providing this data to the currently running program.
4. Conveying program output to the screen, printer, or other
output device.
5. Accessing data from secondary storage.
6. Writing data to secondary storage.
In addition to these responsibilities, the operating system of a
computer with multiple users must verify each individual’s right to use the
computer and must ensure that each user can access only data for which he or
she has proper authorization.
Table 1.2 lists some widely used operating systems. An OS that
uses a command-line interface displays a brief message, called a prompt, that indicates its readiness to
receive input, and the user then types a command at the keyboard.
Application Software
Application programs are
developed to assist a computer user in accomplishing specific tasks. For
example, a word-processing application such as Microsoft Word or OpenOffice.org
Writer helps to create a document, a spreadsheet application such as Microsoft
Office Excel helps to automate tedious numerical calculations and
to generate charts that depict data, and a database management
application such as Microsoft Office Access or dBASE assists in data storage
and quick keyword-based access to large collections of records.
Computer users typically purchase application software on CDs or by
downloading files from the Internet and install
the software by copying the
programs to the hard disk. When buying software, you must always check that the
program you are purchasing is compatible with both the operating system and the
computer
hardware you plan to use. We have already discussed some of the
differences among operating systems; now we will investigate the different
languages understood by different processors.
Computer Languages
Developing new software requires writing lists of instructions for
a computer to execute. However, software developers rarely write in the
language directly understood by a computer, since this machine language is a
collection of binary numbers.
Another drawback of machine language is that it is not standardized:
There is a different machine language for every type of CPU. This same drawback
also applies to the somewhat more readable assembly language , a
language in which computer operations are represented by mnemonic codes rather
than binary numbers and
variables can be given names rather than binary memory addresses.
Table 1.3 shows a tiny machine language program fragment that adds two numbers
and the equivalent fragment in assembly language. Notice that each assembly
language instruction corresponds to exactly one machine instruction: The
assembly language memory cells labeled A and B are space for variables; they
are not instructions.
The symbol indicates that we do not know the contents of the
memory cells with addresses 00000101 and 00000110.
To write programs that are independent of the CPU on which they
will be executed, software designers use high-level
languages that combine algebraic expressions
and symbols taken from English. For example, the machine/assembly language
program fragment shown in Table 1.3 would be a single statement in a high-level
language:
a = a + b;
This statement means “add the values of variables a and b , and store the result in variable
a (replacing
a ’s
previous value).”
There are many high-level languages available. Table 1.4 lists
some of the most widely used ones along with the origin of their names and the
application areas that first popularized them. Although programmers find it far
easier to express problem solutions in high-level languages, there remains the
problem that computers do NOT understand these languages. Thus, before a
high-level language program can be executed, it must first be translated into
the target computer’s machine language. The program that does this translation
is called a compiler.
Figure 1.11 illustrates the role of the compiler in the process of
developing and testing a high-level language program. Both the input to and the
output from the compiler (when it is successful) are programs. The input to the
compiler is a source file containing the text of a high-level language program. The software
developer creates this file by using a word processor or editor. The format of
the source file is text, which means that it is a collection of character
codes. For example, you might type a program into a file called myprog.c. The compiler will scan this
source file, checking the program to see if it follows the high-level
language’s syntax (grammar) rules. If the program is syntactically correct, the
compiler saves in an object file the machine language instructions that carry out the program’s purpose.
For program myprog.c , the object file created might be named myprog. obj . Notice that this file’s format
is binary. This means that you should not send
it to a printer, display it on your monitor, or try to work with
it in a word processor because it will appear to be meaningless garbage to a
word processor, printer, or monitor. If the source program contains syntax
errors, the compiler lists these errors but does not create an object file. The
developer must return to the word processor, correct the errors, and recompile
the program.
Although an object file contains machine instructions, not all of
the instructions are complete. High-level languages provide the software
developer with many named chunks of code for operations that the developer will
likely need. Almost all high-level language programs use at least one of these
chunks of code called functions
that reside in other object files available to the system. The linker program combines these prefabricated
functions with the object file, creating a complete machine language program
that is ready to run. For your sample program, the linker might name the
executable file it creates myprog.exe
.
As long as myprog.exe is just stored on your disk, it does nothing. To run it, the
loader must copy all its instructions into memory and direct the CPU to begin execution
with the first instruction. As the program executes, it takes input data from
one or more sources and sends results to output and/or secondary storage devices.
Some computer systems require the user to ask the OS to carry out
separatelyeach step illustrated in Fig. 1.11 . However, most high-level
language compilers are sold as part of an integrated development environment (IDE) , a package that combines a simple word processor with a compiler,
linker, and loader. Such environments
give the developer menus from which to select the next step, and
if the developer tries a step that is out of sequence, the environment simply
fills in the missing steps automatically.
The user of an integrated development environment should be aware
that the environment may not automatically save to disk the source, object, and
executable files. Rather, it may simply leave these versions of the program in memory.
Such an approach saves the expenditure of time and disk space needed to make
copies and keeps the code readily available in memory for application of the
next step in the translation/execution process. However, the developer
can risk losing the only copy of the source file in the event of a
power outage or serious program error. To prevent such a loss when using an
IDE, be sure to explicitly save the source file to disk after every
modification before attempting to run the program.
Executing a Program
To execute a machine language program, the CPU must examine each
program instruction in memory and send out the command signals required to
carry out the instruction. Although the instructions normally are executed in
sequence, as we will discuss later, it is possible to have the CPU skip over
some instructions or execute
some instructions more than once.
During execution, data can be entered into memory and manipulated
in some specified way. Special program instructions are used for entering or
scanning a program’s data (called input
data ) into memory. After the input
data have been processed, instructions for displaying or printing values in
memory can be executed
to display the program results. The lines displayed by a program
are called the program output .
1.4
The Software Development Method
Software Development Method
1. Specify the problem requirements.
2. Analyze the problem.
3. Design the algorithm to solve the problem.
4. Implement the algorithm.
5. Test and verify the completed program.
6. Maintain and update the program.
PROBLEM
Specifying the problem requirements forces you to state the problem clearly and unambiguously and to
gain a clear understanding of what is required for its solution.
Your objective is to eliminate unimportant aspects and zero in on
the root problem.
This goal may not be as easy to achieve as it sounds. You may find
you need more information from the person who posed the problem.
ANALYSIS
Analyzing the problem involves
identifying the problem (a) inputs, that is, the data you have to work with; (b) outputs , that is, the desired results;
and (c) any additional requirements or constraints on the solution. At this
stage, you should also determine the required format in which the results
should be displayed (for example, as a table with specific column headings) and
develop a list of problem variables and their relationships. These
relationships may be expressed as formulas.
If steps 1 and 2 are not done properly, you will solve the wrong
problem. Read the problem statement carefully, first, to obtain a clear idea of
the problem and second, to determine the inputs and outputs. You may find it
helpful to underline phrases in the problem statement that identify the inputs
and outputs, as in the
problem statement below.
Computer and display the total cost of apples given the number of
pounds of apples purchased and the cost per pound of apples .
Next, summarize
the information contained in the underlined phrases:
Problem Inputs
quantity of apples purchased (in pounds)
cost per pound of apples (in dollars per pound)
Problem Output
total cost of apples (in dollars)
Once you know the problem inputs and outputs, develop a list of
formulas that specify relationships between them. The general formula
Total cost _ Unit cost _ Number of units
computes the total cost of any item purchased. Substituting the
variables for our particular problem yields the formula
Total cost of apples _
Cost per pound _ Pounds of apples
In some situations, you may need to make certain assumptions or
simplifications to derive these relationships. This process of modeling a
problem by extracting the essential variables and their relationships is called
abstraction .
DESIGN
Designing the algorithm to solve the problem requires you to develop a list of steps called an algorithm to solve the
problem and to then verify that the algorithm solves the problem as intended.
Writing the algorithm is often the most difficult part of the problem-solving
process. Don’t attempt to solve every detail of the problem at the beginning; instead,
discipline yourself to use top-down design. In
top-down design (also
called divide and conquer ), you first list the major steps, or subproblems, that need to be
solved. Then you solve the original problem by solving each of its subproblems.
Most computer algorithms consist of at least the following subproblems.
ALGORITHM FOR A PROGRAMMING PROBLEM
1. Get the data.
2. Perform the computations.
3. Display the results.
Once you know the subproblems, you can attack each one
individually. For example, the perform-the-computations step may need to be
broken down into a more detailed list of steps through a process called stepwise refinement .
You may be familiar with top-down design if you use an outline
when writing a term paper. Your first step is to create an outline of the major
topics, which you then refine by filling in subtopics for each major topic.
Once the outline is complete, you begin writing the text for each subtopic. Desk
checking is an important part of algorithm design that is often overlooked.
To desk check an algorithm, you must carefully perform each algorithm step (or its
refinements) just as a computer would and verify that the algorithm works as intended.
You’ll save time and effort if you locate algorithm errors early in the problem-solving
process.
IMPLEMENTATION
Implementing the algorithm (step
4 in the software development method) involves writing it as a program. You
must convert each algorithm step into one or more statements in a programming
language.
TESTING
Testing and verifying the program requires testing the completed program to verify that it works as
desired. Don’t rely on just one test case. Run the program several times using
different sets of data to make sure that it works correctly for every situation
provided for in the algorithm.
MAINTENANCE
Maintaining and updating the program involves modifying a program to remove previously undetected
errors and to keep it up-to-date as government regulations or company policies
change. Many organizations maintain a program for five years or more, often
after the programmers who originally coded it have left or moved on
to other positions.
A disciplined approach is essential if you want to create programs
that are easy to read, understand, and maintain. You must follow accepted
program style guidelines (which will be stressed in this book) and avoid tricks
and programming shortcuts.
1.5
Applying the Software Development Method
We walk you through a sample case study next. This example
includes a running commentary on the process, which you can use as a model in
solving other problems.
CASE STUDY
Converting Miles to Kilometers
PROBLEM
Your summer surveying job requires you to study some maps that
give distances in kilometers and some that use miles. You and your coworkers prefer
to deal in metric measurements. Write a program that performs the necessary
conversion.
ANALYSIS
The first step in solving this problem is to determine what you
are asked to do. You must convert from one system of measurement to another,
but are you supposed to convert from kilometers to miles, or vice versa? The
problem states that you prefer
to deal in metric measurements, so you must convert distance
measurements in miles to kilometers. Therefore, the problem input is distance in miles and
the problem output is distance in kilometers . To write the program, you need to know the relationship
between miles and kilometers. Consulting a metric table shows that
one mile equals 1.609 kilometers.
The data requirements and relevant formulas are listed below. miles identifies the memory cell that
will contain the problem input and kms identifies the memory cell that
will contain the problem input and kms identifies the memory cell that
will contain the program result, or the problem output.
DATA REQUIREMENTS
Problem Input
miles /* the distance in miles*/
Problem Output
kms /* the distance in kilometers */
Relevant Formula
1 mile = 1.609 kilometers
DESIGN
Next, formulate the algorithm that solves the problem. Begin by
listing the three major steps, or subproblems, of the algorithm.
ALGORITHM
1. Get the distance in miles.
2. Convert the distance to kilometers.
3. Display the distance in kilometers.
Now decide whether any steps of the algorithm need further
refinement or whether they are perfectly clear as stated. Step 1 (getting the
data) and step 3 (displaying a value) are basic steps and require no further
refinement. Step 2 is fairly straightforward,
but some detail might help:
Step 2 Refinement
2.1 The distance in kilometers is 1.609 times the distance in
miles.
We list the complete algorithm with refinements below to show you
how it all fits together. The algorithm resembles an outline for a term paper.
The refinement of step 2 is numbered as step 2.1 and is indented under step 2.
ALGORITHM WITH REFINEMENTS
1. Get the distance in miles.
2. Convert the distance to kilometers.
2.1 The distance in kilometers is 1.609 times the distance in
miles.
3. Display the distance in kilometers.
Let’s desk check the algorithm before going further. If step 1
gets a distance of 10.0 miles, step 2.1 would convert it to 1.609 _ 10.00 or 16.09 kilometers. This correct
result would be displayed by step 3.
IMPLEMENTATION
To implement the solution, you must write the algorithm as a C
program. To do this, you must first tell the C compiler about the problem data
requirements—that is, what memory cell names you are using and what kind of
data will be stored in each memory cell. Next, convert each algorithm step into
one or more C statements.
If an algorithm step has been refined, you must convert the
refinements, not the original step, into C statements.
Figure 1.13 shows the C program along with a sample execution or
run. For easy identification, the program statements corresponding to algorithm
steps are in color as is the input data typed in by the program user. Don’t
worry about understanding the details of this program yet. We explain the
program in the next chapter.
TESTING
How do you know the sample run is correct? You should always
examine program results carefully to make sure that they make sense. In this
run, a distance of 10.0 miles is converted to 16.09 kilometers, as it should
be. To verify that the program
works properly, enter a few more test values of miles. You don’t
need to try more than a few test cases to verify that a simple program like
this is correct.
1.6
Professional Ethics for Computer Programmers
Privacy and Misuse of Data
As part of their jobs, programmers may have access to large data
banks or databases containing sensitive information on financial transactions
or personnel, or information that is classified as “secret” or “top secret.”
Programmers should always behave
in a socially responsible manner and not retrieve information that
they are not entitled to see. They should not use information to which they are
given access for their own personal gain, or do anything that would be
considered illegal, unethical, or harmful to others. Just as doctors and
lawyers must keep patient information confidential, programmers must respect an
individual’s rights to privacy.
A programmer who changes information in a database containing
financial records for his or her own personal gain—for example, changes the
amount of money in a bank account—is guilty of computer theft or computer fraud .
This is a felony that can lead to fines and imprisonment.
Computer Hacking
You may have heard about “computer hackers” who break into secure
data banks by using their own computer to call the computer that controls
access to the data bank. Classified or confidential information retrieved in
this way has been sold to intelligence agencies of other countries. Other
hackers have tried to break into computers to retrieve information for their
own amusement or as
a prank, or just to demonstrate that they can do it. Regardless of
the intent, this activity is illegal, and the government will prosecute anyone
who does it. Your university probably addresses this kind of activity in your
student handbook.
The punishment is likely similar to that for other criminal
activity, because that is exactly what it is.
Another illegal activity sometimes practiced by hackers is
attaching harmful code, called a virus
, to another program so that the
virus code copies itself throughout a computer’s disk memory. A virus can cause
sporadic activities to disrupt the operation of the host computer—for example,
unusual messages may appear on the
screen at certain times—or cause the host computer to erase
portions of its own disk memory, destroying valuable information and programs.
Viruses are spread from one computer to another in various ways—for example, if
you copy a file that originated
on another computer that has a virus, or if you open an e-mail
message that is sent from an infected computer. A computer worm is a virus that can replicate itself
on other network computers, causing these computers to send multiple messages over
the network to disrupt its operation or shut it down. Certainly, data theft
and virus propagation should not be considered harmless pranks;
they are illegal and carry serious penalties.
Plagiarism and Software Piracy
Using someone else’s programs without permission is also
unprofessional behavior.
Although it is certainly permissible to use modules from libraries
that have been developed for reuse by their own company’s programmers, you
cannot use another programmer’s personal programs or programs from another
company without getting
permission beforehand. Doing so could lead to a lawsuit, with you
or your company having to pay damages.
Modifying another student’s code and submitting it as your own is
a fraudulent practice—specifically, plagiarism—and is no different than copying
paragraphs of information from a book or journal article and calling it your
own. Most universities have severe penalties for plagiarism that may include
failing the course and/or being dismissed from the university. Be aware that
even if you modify the code slightly or substitute your own comments or
different variable names, you are still guilty of plagiarism if you are using
another person’s ideas and code. To avoid any question of
plagiarism, find out beforehand your instructor’s rules about
working with others on a project. If group efforts are not allowed, make sure
that you work independently and submit only your own code.
Many commercial software packages are protected by copyright laws
against software piracy —the practice of illegally copying software for use on another computer.
If you violate this law, your company or university can be fined heavily for
allowing this activity to occur. Besides the fact that software piracy is
against the
law, using software copied from another computer increases the
possibility that your computer will receive a virus. For all these reasons, you
should read the copyright restrictions on each software package and adhere to
them.
Misuse of a Computer Resource
Computer system access privileges or user account codes are
private property.
These privileges are usually granted for a specific purpose—for
example, for work to be done in a particular course or for work to be done
during the time you are a student at your university. The privilege should be
protected; it should not be loaned to
or shared with anyone else and should not be used for any purpose
for which it was not intended. When you leave the institution, this privilege
is normally terminated and any accounts associated with the privilege will be
closed.
Computers, computer programs, data, and access (account) codes are
like any other property. If they belong to someone else and you are not
explicitly given permission to use them, then do not use them. If you are
granted a use privilege for a specific purpose, do not abuse the privilege or
it will be taken away.
Legal issues aside, it is important that we apply the same
principles of right and wrong to computerized property and access rights as to
all other property rights and privileges. If you are not sure about the
propriety of something you want to do, ask first. As students and professionals
in computing, we set an example for others. If
we set a bad
example, others are sure to follow.
Chapter Review
1. The basic components of a computer are main memory and
secondary storage, the CPU, and input and output devices.
2. All data manipulated by a computer are represented digitally,
as base 2 numbers composed of strings of the digits 0 and 1.
3. Main memory is organized into individual storage locations called memory cells.
3. Main memory is organized into individual storage locations called memory cells.
■ Each
memory cell has a unique address.
■ A
memory cell is a collection of bytes; a byte is a collection of 8 bits.
■ A
memory cell is never empty, but its initial contents may be meaningless to your
program.
■ The
current contents of a memory cell are destroyed whenever new information is
stored in that cell.
■ Programs
must be
loaded into the memory of the computer before they can be executed.
■ Data
cannot be manipulated by the computer until they are first stored in memory.
4. Information in secondary storage is organized into files:
program files and data files. Secondary storage provides a low-cost means of
storing large quantities of information in semipermanent form.
5. A CPU runs a computer program by repeatedly fetching and
executing simple machine-code instructions.
6. Connecting computers in networks allows sharing of
resources—local resources on LANs and worldwide resources on a WAN such as the
Internet.
7. Programming languages range from machine language (meaningful
to a computer) to high-level language (meaningful to a programmer).
8. Several system programs are used to prepare a high-level
language program for execution. An editor enters a high-level language program
into a file. A compiler translates a high-level language program (the source
program) into machine language (the object program). The linker links this
object program to other object files, creating an executable file, and the
loader loads the executable file into memory. All of these programs are
combined in an integrated development environment (IDE).
9. Through the operating system, you can issue commands to the
computer and manage files.
10. Follow the first five steps of the software development method
to solve programming problems: (1) specify the problem, (2) analyze the
problem, (3) design the algorithm, (4) implement the algorithm, and (5) test
and verify the completed program. Write programs in a consistent style that is
easy to read, understand, and maintain.
11. Follow ethical standards of conduct in everything you do
pertaining to computers. This means do not copy software that is copyright
protected, do not hack into someone else’s computer, do not send files that may
be infected to others,
and do not submit someone else’s work as your own or lend your
work to another student.
No matter if some one searches for his necessary
ReplyDeletething, thus he/she desires to be available that
in detail, so that thing is maintained over here.
Feel free to surf to my blog vegetable juicing
Sweet blog! I found it while searching on Yahoo News.
ReplyDeleteDo you have any suggestions on how to get listed in Yahoo News?
I've been trying for a while but I never seem to get there! Many thanks
Feel free to surf to my webpage :: juicing for Cancer
It's genuinely very complicated in this busy life to listen news on TV, thus I simply use web for that reason, and get the most up-to-date news.
ReplyDeleteHere is my weblog - acne remedies
Link exchange is nothing else but it is just placing the
ReplyDeleteother person's website link on your page at proper place and other person will also do same in support of you.
my website; anxiety panic disorder
I visited multiple web sites but the audio feature for audio songs existing at this website is really marvelous.
ReplyDeleteReview my web site ... juicers reviews
An intriguing discussion is worth comment. I do think that you need
ReplyDeleteto write more on this subject matter, it might not be a
taboo matter but generally people do not talk about
such subjects. To the next! Cheers!!
My web-site - juicing for life
Having read this I thought it was very informative. I appreciate you taking the time and effort
ReplyDeleteto put this informative article together. I once again find myself spending a
lot of time both reading and commenting. But so what, it was still worth it!
My website - juicing diet
Spot on with this write-up, I actually believe this site needs
ReplyDeletea great deal more attention. I'll probably be back again to see more, thanks for the info!
Here is my web blog ... types of juicers