In this
chapter, we examine a way to separate a block of code from the main part of a
program. This is a useful thing to do because, as programs become larger, the code
gets more cumbersome unless it is organized in some manner. When we looked
at design in Chapter 5, we considered why it was useful to organize a program.
A function is a separate block of code within a program. Beyond organization
considerations, it is useful to have functions for other reasons. If you have
a task that you need to do repeatedly, then putting that task into a function
will save you the problem of repeating that code throughout your program.
In order for a function to execute, it needs to be called. We will look at how to call a
function and also how to send and retrieve data from a function.
Hardware and Software
A
computer is usually hooked up to a printer, an external drive, and various other
peripheral devices, such as scanners, modems, and so on. All the physical components
of a computer make up its hardware. Think of the word ‘‘hardware’’ as
describing those parts of a computer that are hard or can be touched. You can
touch
a printer, but you cannot touch programs that are running on a computer. Programs
represent software. Any programs,
whether they are commercial programs, games,
word processing applications, or programs that make the computer itself
operate, are all examples of software. Programs
are sets of steps that tell a computer what to do. There are directions for
everything that happens in the computer. For example, saving a file on the hard
drive occurs because inside the computer a program is ‘‘telling’’ the computer to
save a file rather than delete it. Saving a file, printing a file, or deleting
it are
just a few of the programs called system programs. They are also referred to as the
operating system. These programs allow
the computer to handle its basic operations:
opening and closing files and saving or deleting files. Likewise, getting an
application, such as Microsoft Word, to open up and start running is the task
of the operating system. Application
programs are programs sold on the market, for example,
WinZip, iTunes,
Microsoft Office, Adobe Acrobat, Skype, and so on. The word ‘‘application’’ refers
to a set of programs ‘‘applied’’ to some real-life task tomake it easier to do.
Some of the earliest application programs—such as Microsoft Word, Word-
Perfect,
and ClarisWorks—were created to facilitate typing long documents.
T i p
System software
is the set of programs that enables the computer to store data, retrieve data,
save files,
delete files, and, generally, allow the computer to operate application
programs.
Let’s look at a list of the main parts of a computer:
- Keyboard
- Mouse
- Printer
- Hard drive
- External drive
- RAM (random access memory)
- CPU (computer processing unit)
The Keyboard, Mouse, and
Printer
The
keyboard is used to communicate with the
computer; so is the mouse.
The keyboard
is used for typed commands, while the mouse is used for ‘‘clicking’’ and interacting
with the graphical user interface (GUI). The printer delivers on paper what’s
on the screen.
Hard Drive vs. External Drive
The
hard drive is the internal memory of a computer.
Application programs are saved
here, as are system files. Think of the hard drive as the permanent storage space
a computer has. A house with a basement and an attic has much more storage
area than an apartment with only closets for storage. Computers with a large
hard drive, for example, 500 gigabytes (GB), are in demand because of their capacity
to save very large applications. Metrowerks CodeWarrior, for example, needs
at least 300 megabytes (MB) of storage space. Devices known as solid state drives
can provide more portable hard memory using flash technology.
An
external drive is used to expand storage
capacity outside of the computer itself. As
recently as the early 1990s, many personal computers had little memory in the hard
drive, necessitating storage outside of the computer. Memory needed for application
programs at that time was not what it is today. Although internal hard drive
capacities are much greater today than in the past, there are still many uses for
external drives, such as flash drives for storing pictures, video clips, and so
on.
RAM: Random Access Memory
The RAM is really the workspace
for the computer. Think of the RAM as a large table onto which you place many different things. If you have only a
small workspace, you can’t open too many things at once because they won’t
fit on the table. For example, if your operating system uses 128 MB, while
Microsoft Office
uses 256 MB and Adobe Acrobat uses 128 MB, you could have both
applications open at the same time as the operating system (a total of 512 MB) if
your computer has 1 GB of RAM. Now if you run a game, such as Master of Defense, you’ll need another 128 MB just for that application. (Compare that
with Battleground, which requires 512 MB!) Again, running the operating system alone with that game brings your total to 642 MB; and that’s why you want
a computer with a good size RAM, like 1 GB, if you usually play such games.
Opening several applications at once and not running out of memory is desirable. RAM is temporary memory and is lost once the computer is turned off.
The term volatile is used to describe this memory,
since anything not saved will be lost in a sudden, abrupt fashion. For example, when a plug is suddenly pulled
on a machine or if you have to reset your computer for some reason,
everything in
the RAM will be lost. Fortunately, there is always a ‘‘backup plan’’ for storage on a
computer and this is
called a swap file.
The swap file is memory taken from the hard disk space as well as from the RAM in case of an emergency. It is used only in the
event that the RAM
becomes exhausted and some emergency storage is needed.
ROM, or read-only memory, is memory that’s not lost when the machine is turned
off. Certain instructions for the computer are permanently etched onto a chip
at the time the computer is manufactured. Thus ROM is permanent memory and is
never lost.
CPU: Central Processing Unit
The main part of the computer is the central
processing unit, or CPU. This is where the computer stores, processes, and retrieves data. The CPU
manages all the functions of the computer, including processing
data—manipulating data by sending it from one place to another or by performing some math on
the data.
The CPU contains the arithmetic/logic unit, or ALU, and the control unit of a computer. The CPU is found within the system unit and should not be
confused with it. The system unit houses the internal pieces of the computer
like the motherboard, the internal memory, and so on.
The ALU: Arithmetic/Logic Unit
The ALU affects programmers the
most. When you write a program for a computer, its ALU will be called into use to perform some math (the
arithmetic part) or to evaluate a decision (the logic part) by the programmer.
That’s why we need the arithmetic/logic unit. The logic portion is the part of
the unit that
can handle decisions. Most interesting programs need the ability to
make a decision.
The Control Unit
The control unit of the CPU is used to regulate program flow. This
unit executes statements in sequence and will only repeat steps or skip steps if
programmed todo so. If you write a program putting a number like 5 into a holder
called x and decide to increase the value of x from 5 to 7, the ALU will be
used to do this task. If you want to print the message ‘‘I have had enough!’’
250 times on a computer screen, then the control unit will have to do work
because the programmer is asking the computer to do something over and over.
Thus the programmer controls how long or how many times the computer does something; in this case,
printing a
message 250 times. I mentioned earlier that the computer can store,
process, and retrieve data, and the CPU will handle that work.
Posted by 09.22 and have
0
comments
, Published at