< previous page page_14 next page >

Page 14
(instructions) in C++ and other languages: sequentially, conditionally, repetitively, and with subprograms (see Figure 1-7). A sequence is a series of statements that are executed one after another. Selection, the conditional structure, executes different statements depending on certain conditions. The repetitive structure, the loop, repeats statements while certain conditions are met. And the subprogram allows us to structure a program by breaking it into smaller units.
Assume you're driving a car. Going down a straight stretch of road is like following a sequence of instructions. When you come to a fork in the road, you must decide which way to go and then take one or the other branch of the fork. This is what the computer does when it encounters a selection (sometimes called a branch or decision) in a program. Sometimes you have to go around the block several times to find a place to park. The computer does the same sort of thing when it encounters a loop in a program.
A subprogram is a process that consists of multiple steps. Every day, for example, you follow a procedure to get from home to work. It makes sense, then, for someone to give you directions to a meeting by saying, Go to the office, then go four blocks west, without listing all the steps you have to take to get to the office. Subprograms allow us to write parts of our programs separately and then assemble them into final form. They can greatly simplify the task of writing large programs.
What Is a Computer?
You can learn a programming language, how to write programs, and how to run (execute) these programs without knowing much about computers. But if you know something about the parts of a computer, you can better understand the effect of each instruction in a programming language.
There are six basic components in most computers: the memory unit, the arithmetic/logic unit, the control unit, input devices, output devices, and auxiliary storage devices. Figure 1-8 is a stylized diagram of the basic components of a computer.
The memory unit is an ordered sequence of storage cells, each capable of holding a piece of data. It is like an old-fashioned post office with pigeonholes for mail. Each memory cell has a distinct address to which we refer in order to store information into it or retrieve information from it. These storage cells are called memory cells, or memory locations.* The memory unit holds data (input data or the product of computation) and instructions (programs), as shown in Figure 1-9.
3e26ecb1b6ac508ae10a0e39d2fb98b2.gif 3e26ecb1b6ac508ae10a0e39d2fb98b2.gif
*The memory unit is also referred to as RAM, an acronym for random access memory (because we can access any location at random).

 
< previous page page_14 next page >