0% found this document useful (0 votes)
26 views42 pages

Farrell23936 1111823936 02 01 Chapter01

Uploaded by

phonezawh052
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views42 pages

Farrell23936 1111823936 02 01 Chapter01

Uploaded by

phonezawh052
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 42

Licensed to: iChapters User

Licensed to: iChapters User

Programming Logic and Design, © 2011 Course Technology, Cengage Learning


Comprehensive, Sixth Edition
ALL RIGHTS RESERVED. No part of this work covered by the copyright
Joyce Farrell
herein may be reproduced, transmitted, stored or used in any form or by
Executive Editor: Marie Lee any means—graphic, electronic, or mechanical, including but not limited
to photocopying, recording, scanning, digitizing, taping, Web distribution,
Acquisitions Editor: Amy Jollymore
information networks, or information storage and retrieval systems, except
Managing Editor: Tricia Coia as permitted under Section 107 or 108 of the 1976 United States Copyright
Developmental Editor: Dan Seiter Act—without the prior written permission of the publisher.
Content Project Manager: Jennifer Feltri
For product information and technology assistance, contact us at
Editorial Assistant: Zina Kresin Cengage Learning Customer & Sales Support, 1-800-354-9706
Marketing Manager: Bryant Chrzan For permission to use material from this text or product,
Art Director: Marissa Falco submit all requests online at cengage.com/permissions
Further permissions questions can be emailed to
Text Designer: Shawn Girsberger [email protected]
Cover Designer: Cabbage Design Company
Cover Image: iStockphoto Library of Congress Control Number: 2009938501
Print Buyer: Julio Esperas
ISBN-13: 978-0-5387-4476-8
Copy Editor: Michael Beckett
ISBN-10: 0-538-74476-6
Proofreader: Vicki Zimmer
Indexer: Alexandra Nickerson Course Technology
Compositor: Integra 20 Channel Center Street
Boston, MA 02210
USA

Some of the product names and company names used in this book have
been used for identification purposes only and may be trademarks or
registered trademarks of their respective manufacturers and sellers.

Course Technology, a part of Cengage Learning, reserves the right to revise


this publication and make changes from time to time in its content without
notice.

Cengage Learning is a leading provider of customized learning solutions with


office locations around the globe, including Singapore, the United Kingdom,
Australia, Mexico, Brazil, and Japan. Locate your local office at:
www.cengage.com/global

Cengage Learning products are represented in Canada by


Nelson Education, Ltd.

To learn more about Course Technology, visit


www.cengage.com/coursetechnology

Purchase any of our products at your local college store or at our preferred
online store www.ichapters.com

Printed in Canada
1 2 3 4 5 6 7 14 13 12 11 10

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Licensed to: iChapters User

An Overview of
CHAPTER 1
Computers and
Programming

In this chapter, you will learn about:

 Computer systems
 Simple program logic
 The steps involved in the program development cycle
 Pseudocode statements and flowchart symbols
 Using a sentinel value to end a program
 Programming and user environments
 The evolution of programming models

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Licensed to: iChapters User

CHAPTER 1 An Overview of Computers and Programming

Understanding Computer Systems


A computer system is a combination of all the components required
to process and store data using a computer. Every computer system
is composed of multiple pieces of hardware and software.

2 • Hardware is the equipment, or the physical devices, associated


with a computer. For example, keyboards, mice, speakers, and
printers are all hardware. The devices are manufactured differently
for large mainframe computers, laptops, and even smaller comput-
ers that are embedded into products such as cars and thermostats,
but the types of operations performed by different-sized comput-
ers are very similar. When you think of a computer, you often think
of its physical components first, but for a computer to be useful it
needs more than devices; a computer needs to be given instruc-
tions. Just as your stereo equipment does not do much until you
provide music, computer hardware needs instructions that control
how and when data items are input, how they are processed, and
the form in which they are output or stored.
• Software is computer instructions that tell the hardware what to do.
Software is programs: instructions written by programmers. You can
buy prewritten programs that are stored on a disk or that you down-
load from the Web. For example, businesses use word-processing
and accounting programs, and casual computer users enjoy pro-
grams that play music and games. Alternatively, you can write your
own programs. When you write software instructions, you are
programming. This book focuses on the programming process.

Software can be classified as application software or system software.


Application software comprises all the programs you apply to a task—
word-processing programs, spreadsheets, payroll and inventory programs,
and even games. System software comprises the programs that you use
to manage your computer, including operating systems such as Windows,
Linux, or UNIX. This book focuses on the logic used to write application software pro-
grams, although many of the concepts apply to both types of software.

Together, computer hardware and software accomplish three major


operations in most programs:
• Input—Data items enter the computer system and are put into mem-
ory, where they can be processed. Hardware devices that perform input
operations include keyboards and mice. Data items include all the text,
numbers, and other information that are processed by a computer.

In business, much of the data used is facts and figures about such entities as
products, customers, and personnel. However, data can also be items such
as the choices a player makes in a game or the notes required by a music-
playing program.

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Licensed to: iChapters User

Understanding Computer Systems

Many computer professionals distinguish between the terms data, which


describes items that are input, and information, which describes data items
that have been processed and sent to a device where people can read and
interpret them. For example, your name, Social Security number, and
hourly pay rate are data items when they are input to a program, but the
same items are information after they have been processed and output on your
paycheck. 3

• Processing—Processing data items may involve organizing or sorting


them, checking them for accuracy, or performing calculations with
them. The hardware component that performs these types of tasks is
the central processing unit, or CPU.
• Output—After data items have been processed, the resulting infor-
mation usually is sent to a printer, monitor, or some other output
device so people can view, interpret, and use the results.

Some people consider storage as a fourth major computer operation.


Instead of sending output to a device such as a printer, monitor, or speaker
where a person can interpret it, you sometimes store output on storage
devices, such as a disk or flash media. People cannot read data directly
from these storage devices, but the devices hold information for later
retrieval. When you send output to a storage device, sometimes it is used later as input
for another program.

You write computer instructions in a computer programming The instruc-


language, such as Visual Basic, C#, C++, or Java. Just as some tions you write
people speak English and others speak Japanese, programmers also using a pro-
gramming
write programs in different languages. Some programmers work
language are
exclusively in one language, whereas others know several program- called program code;
ming languages and use the one that is best suited to the task when you write instruc-
at hand. tions, you are coding the
program.
Every programming language has rules governing its word usage and
punctuation. These rules are called the language’s syntax. If you ask,
“How the geet too store do I?” in English, most people can figure
out what you probably mean, even though you have not used proper
English syntax—you have mixed up the word order, misspelled a
word, and used an incorrect word. However, computers are not
nearly as smart as most people; in this case, you might as well have
asked the computer, “Xpu mxv ort dod nmcad bf B?” Unless the
syntax is perfect, the computer cannot interpret the programming
language instruction at all.
When you write a program, you usually type its instructions using
a keyboard. When you type program instructions, they are stored
in computer memory, which is a computer’s temporary, internal

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Licensed to: iChapters User

CHAPTER 1 An Overview of Computers and Programming

Random storage. Internal storage is volatile—its contents are lost when the
access computer is turned off or loses power. Usually, you want to be able to
memory, or
retrieve and perhaps modify the stored instructions later, so you also
RAM, is a
form of inter-
store them on a permanent storage device, such as a disk. Permanent
nal, volatile memory. It is storage devices are nonvolatile—that is, their contents are persistent
hardware on which the and are retained even when power is lost.
4
programs that are cur-
After a computer program is stored in memory, it must be trans-
rently running and the
data items that are lated from your programming language statements to machine
currently being used language that represents the millions of on/off circuits within the
are stored for quick computer. Each programming language uses a piece of software,
access. called a compiler or an interpreter, to translate your program
code into machine language. Machine language is also called
binary language, and is represented as a series of 0s and 1s. The
The program compiler or interpreter that translates your code tells you if any
statements programming language component has been used incorrectly.
you write in a Syntax errors are relatively easy to locate and correct because
programming
the compiler or interpreter you use highlights every syntax error.
language are
known as source code.
If you write a computer program using a language such as C++
The translated machine but spell one of its words incorrectly or reverse the proper order
language statements are of two words, the software lets you know that it found a mistake
known as object code. by displaying an error message as soon as you try to translate the
program.

Although there are differences in how compilers and interpreters work, their
basic function is the same—to translate your programming statements into
code the computer can use. When you use a compiler, an entire program is
translated before it can execute; when you use an interpreter, each instruc-
tion is translated just prior to execution. Usually, you do not choose which
type of translation to use—it depends on the programming language. However, there
are some languages for which both compilers and interpreters are available.

Only after program instructions are successfully translated to machine


code can the computer carry out the program instructions. When
instructions are carried out, a program runs, or executes. In a typical
program, some input will be accepted, some processing will occur,
and results will be output.

Besides the popular full-blown programming languages such as Java


and C++, many programmers use scripting languages (also called
scripting programming languages or script languages) such as Python,
Lua, Perl, and PHP. Scripts written in these languages usually can be typed
directly from a keyboard and are stored as text rather than as binary execut-
able files. Scripting language programs are interpreted line by line each time the
program executes, instead of being stored in a compiled (binary) form.

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Licensed to: iChapters User

Understanding Simple Program Logic

TWO TRUTHS & A LIE


Understanding Computer Systems

In each Two Truths and a Lie section, two of the numbered statements are true,
5
and one is false. Identify the false statement and explain why it is false.
1. Hardware is the equipment, or the devices, associated with a computer.
Software is computer instructions.
2. The grammar rules of a computer programming language are its syntax.
3. You write programs using machine language, and translation software con-
verts the statements to a programming language.

preter) converts the statements to machine language, which is 0s and 1s.


such as Visual Basic or Java, and a translation program (called a compiler or inter-
The false statement is #3. You write programs using a programming language

Understanding Simple Program Logic


A program with syntax errors cannot execute. A program with no syntax The dangerous
errors can execute, but might contain logical errors, and produce incor- cake-baking
rect output as a result. For a program to work properly, you must give the instructions
are shown with
instructions to the computer in a specific sequence, you must not leave
a Don’t Do It
any instructions out, and you must not add extraneous instructions. By icon. You will see this icon
doing this, you are developing the logic of the computer program. when the book contains
an unrecommended pro-
Suppose you instruct someone to
gramming practice that is
make a cake as follows: used as an example of
Don’t Do It
Get a bowl what not to do.
Don't bake a cake like
Stir this! If you misspell
Add two eggs
a program-
Add a gallon of gasoline
ming language
Bake at 350 degrees for 45 minutes
Add three cups of flour word, you
commit a
Even though you have used the English language syntax correctly, the syntax error, but if you
cake-baking instructions are out of sequence, some instructions are use an otherwise correct
missing, and some instructions belong to procedures other than baking word that does not make
sense in the current con-
a cake. If you follow these instructions, you are not going to make an edi-
text, programmers say
ble cake, and you most likely will end up with a disaster. Logical errors you have committed a
are much more difficult to locate than syntax errors—it is easier for you semantic error. Either
to determine whether “eggs” is spelled incorrectly in a recipe than it is way, the program will not
for you to tell if there are too many eggs or if they are added too soon. execute.

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Licensed to: iChapters User

CHAPTER 1 An Overview of Computers and Programming

After you learn Just as baking directions can be given correctly in Mandarin, Urdu,
French, you or Spanish, the same program logic can be expressed in any number
automatically
of programming languages. Because this book is not concerned with
know, or can
easily figure
any specific language, the programming examples could have been
out, many Spanish words. written in Visual Basic, C++, or Java. For convenience, this book uses
Similarly, after you learn instructions written in English!
6
one programming lan-
Most simple computer programs include steps that perform input,
guage, it is much easier
to understand several processing, and output. Suppose you want to write a computer
other languages. program to double any number you provide. You can write such a
program in a programming language such as Visual Basic or Java,
but if you were to write it using English-like statements, it would
You will learn look like this:
about the odd
input myNumber
elimination of
set myAnswer = myNumber * 2
the space
output myAnswer
between
words like my and The number-doubling process includes three instructions:
Number in Chapter 2.
• The instruction to input myNumber is an example of an input
operation. When the computer interprets this instruction, it
knows to look to an input device to obtain a number. When you
work in a specific programming language, you write instructions
that tell the computer which device to access for input. For exam-
ple, when a user enters a number as data for a program, the user
might click on the number with a mouse, type it from a keyboard,
or speak it into a microphone. Logically, however, it doesn’t really
matter which hardware device is used, as long as the computer
knows to look for a number. When the number is retrieved from
an input device, it is placed in the computer’s memory at the
location named myNumber. The location myNumber is a variable. A
variable is a named memory location whose value can vary—for
example, the value of myNumber might be 3 when the program is
used for the first time and 45 when it is used the next time.

From a logical perspective, when you input a value, the hardware device is
irrelevant. The same is true in your daily life. If you follow the instruction “Get
eggs for the cake,” it does not really matter if you purchase them from a
store or harvest them from your own chickens—you get the eggs either way.
There might be different practical considerations to getting the eggs, just as
there are for getting data from a large database as opposed to an inexperienced user.
For now, this book is only concerned with the logic of the operation, not the minor
Programmers details.
use an aster-
isk to indicate
multiplication.
• The instruction set myAnswer = myNumber * 2 is an example
You will learn of a processing operation. Mathematical operations are not the
more about arithmetic only kind of processing operations, but they are very typical. As
statements in Chapter 2. with input operations, the type of hardware used for processing

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Licensed to: iChapters User

Understanding Simple Program Logic

is irrelevant—after you write a program, it can be used on comput-


ers of different brand names, sizes, and speeds. The instruction
takes the value stored in memory at the myNumber location, mul-
tiplies it by 2, and stores the result in another memory location
named myAnswer.
• In the number-doubling program, the output myAnswer instruc- 7
tion is an example of an output operation. Within a particular
program, this statement could cause the output to appear on the
monitor (which might be a flat-panel plasma screen or a cathode-
ray tube), or the output could go to a printer (which could be laser
or ink-jet), or the output could be written to a disk or DVD. The
logic of the output process is the same no matter what hardware Watch the
device you use. When this instruction executes, the value stored video A Simple
in memory at the location named myAnswer is sent to an output Program.
device.

Computer memory consists of millions of numbered locations where data


can be stored. The memory location of myNumber has a specific numeric
address—for example, 48604. Your program associates myNumber with
that address. Every time you refer to myNumber within a program, the com-
puter retrieves the value at the associated memory location. When you write
programs, you seldom need to be concerned with the value of the memory address;
instead, you simply use the easy-to-remember name you created.

Computer programmers often refer to memory addresses using hexadeci-


mal notation, or base 16. Using this system, they might use a value like
42FF01A to refer to a memory address. Despite the use of letters, such an
address is still a hexadecimal number. Appendix A contains information on
this numbering system.

TWO TRUTHS & A LIE


Understanding Simple Program Logic

1. A program with syntax errors can execute but might produce incorrect results.
2. Although the syntax of programming languages differs, the same program
logic can be expressed in different languages.
3. Most simple computer programs include steps that perform input, process-
ing, and output.

program with no syntax errors can execute, but might produce incorrect results.
The false statement is #1. A program with syntax errors cannot execute; a

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Licensed to: iChapters User

CHAPTER 1 An Overview of Computers and Programming

Understanding the Program


Development Cycle
A programmer’s job involves writing instructions (such as those in
the doubling program in the preceding section), but a professional
8
programmer usually does not just sit down at a computer keyboard
and start typing. Figure 1-1 illustrates the program development
cycle, which can be broken down into at least seven steps:
1. Understand the problem.
2. Plan the logic.
3. Code the program.
4. Use software (a compiler or interpreter) to translate the
program into machine language.
5. Test the program.
6. Put the program into production.
7. Maintain the program.

Understand
the problem

Maintain the Plan the


program logic

Put the program Write the


into production code

Test the Translate the


program code

Figure 1-1 The program development cycle

Understanding the Problem


Professional computer programmers write programs to satisfy the
needs of others, called users or end users. Examples could include a
Human Resources department that needs a printed list of all employ-
ees, a Billing department that wants a list of clients who are 30 or
more days overdue on their payments, and an Order department that

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Licensed to: iChapters User

Understanding the Program Development Cycle

needs a Web site to provide buyers with an online shopping cart in The term end
which to gather their orders. Because programmers are providing a user distin-
guishes those
service to these users, programmers must first understand what the
who actually
users want. Although when a program runs, you usually think of the use and ben-
logic as a cycle of input-processing-output operations; when you efit from a software prod-
plan a program, you think of the output first. After you understand uct from others in an
9
what the desired result is, you can plan what to input and process to organization who might
achieve it. purchase, install, or have
other contact with the
Suppose the director of Human Resources says to a programmer, software.
“Our department needs a list of all employees who have been here
over five years, because we want to invite them to a special thank-you
dinner.” On the surface, this seems like a simple request. An experi-
enced programmer, however, will know that the request is incom-
plete. For example, you might not know the answers to the following
questions about which employees to include:
• Does the director want a list of full-time employees only, or a list
of full- and part-time employees together?
• Does she want people who have worked for the company on a
month-to-month contractual basis over the past five years, or only
regular, permanent employees?
• Do the listed employees need to have worked for the organization
for five years as of today, as of the date of the dinner, or as of some
other cutoff date?
• What about an employee who, for example, worked three years,
took a two-year leave of absence, and has been back for three years?
The programmer cannot make any of these decisions; the user (in this
case, the Human Resources director) must address these questions.
More decisions still might be required. For example:
• What data should be included for each listed employee? Should
the list contain both first and last names? Social Security numbers?
Phone numbers? Addresses?
• Should the list be in alphabetical order? Employee ID number
order? Length-of-service order? Some other order?
• Should the employees be grouped by any criteria, such as depart-
ment number or years of service?
Several pieces of documentation are often provided to help the pro-
grammer understand the problem. Documentation consists of all the
supporting paperwork for a program; it might include items such
as original requests for the program from users, sample output, and
descriptions of the data items available for input.

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Licensed to: iChapters User

CHAPTER 1 An Overview of Computers and Programming

Watch the video Really understanding the problem may be one of the most difficult
The Program aspects of programming. On any job, the description of what the user
Development
needs may be vague—worse yet, users may not really know what they
Cycle, Part 1.
want, and users who think they know frequently change their minds
after seeing sample output. A good programmer is often part coun-
selor, part detective!
10

You may hear


programmers
Planning the Logic
refer to The heart of the programming process lies in planning the program’s
planning a logic. During this phase of the process, the programmer plans the
program as
steps of the program, deciding what steps to include and how to order
“developing an algorithm.”
An algorithm is the
them. You can plan the solution to a problem in many ways. The two
sequence of steps neces- most common planning tools are flowcharts and pseudocode. Both
sary to solve any problem. tools involve writing the steps of the program in English, much as you
would plan a trip on paper before getting into the car or plan a party
theme before shopping for food and favors.
You will learn
more about
The programmer shouldn’t worry about the syntax of any particu-
flowcharts lar language at this point, but should focus on figuring out what
and pseudo- sequence of events will lead from the available input to the desired
code later in output. Planning the logic includes thinking carefully about all the
this chapter. possible data values a program might encounter and how you want
the program to handle each scenario. The process of walking through
a program’s logic on paper before you actually write the program is
In addition to called desk-checking. You will learn more about planning the logic
flowcharts and
throughout this book; in fact, the book focuses on this crucial step
pseudocode,
programmers
almost exclusively.
use a variety
of other tools to help in
program development. Coding the Program
One such tool is an IPO
After the logic is developed, only then can the programmer write
chart, which delineates
input, processing, and
the program. Hundreds of programming languages are available.
output tasks. Some Programmers choose particular languages because some have built-in
object-oriented program- capabilities that make them more efficient than others at handling
mers also use TOE certain types of operations. Despite their differences, programming
charts, which list tasks, languages are quite alike in their basic capabilities—each can handle
objects, and events. input operations, arithmetic processing, output operations, and other
standard functions. The logic developed to solve a programming
problem can be executed using any number of languages. Only after
choosing a language must the programmer be concerned with proper
punctuation and the correct spelling of commands—in other words,
using the correct syntax.
Some very experienced programmers can successfully combine
logic planning and program coding in one step. This may work for

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Licensed to: iChapters User

Understanding the Program Development Cycle

planning and writing a very simple program, just as you can plan and
write a postcard to a friend using one step. A good term paper or a
Hollywood screenplay, however, needs planning before writing—and
so do most programs.
Which step is harder: planning the logic or coding the program?
Right now, it may seem to you that writing in a programming lan- 11
guage is a very difficult task, considering all the spelling and syntax
rules you must learn. However, the planning step is actually more
difficult. Which is more difficult: thinking up the twists and turns to
the plot of a best-selling mystery novel, or writing a translation of an
existing novel from English to Spanish? And who do you think gets
paid more, the writer who creates the plot or the translator? (Try
asking friends to name any famous translator!)

Using Software to Translate the Program


into Machine Language
Even though there are many programming languages, each computer When you
knows only one language: its machine language, which consists of 1s learn the syn-
tax of a pro-
and 0s. Computers understand machine language because they are
gramming
made up of thousands of tiny electrical switches, each of which can
language, the
be set in either the on or off state, which is represented by a 1 or 0, commands you learn will
respectively. work on any machine on
which the language soft-
Languages like Java or Visual Basic are available for programmers
ware has been installed.
because someone has written a translator program (a compiler or However, your com-
interpreter) that changes the programmer’s English-like high-level mands are translated to
programming language into the low-level machine language that machine language, which
the computer understands. If you write a programming language differs depending on your
statement incorrectly (for example, by misspelling a word, using a computer make and
word that doesn’t exist in the language, or using “illegal” grammar), model.
the translator program doesn’t know how to proceed and issues
an error message identifying a syntax error, which is a misuse of a
language’s grammar rules. Although making errors is never desirable,
syntax errors are not a major concern to programmers, because the
compiler or interpreter catches every syntax error and displays a mes-
sage that notifies you of the problem. The computer will not execute a
program that contains even one syntax error.
Typically, a programmer develops a program’s logic, writes the code, Watch the video
and compiles the program, receiving a list of syntax errors. The pro- The Program
grammer then corrects the syntax errors and compiles the program Development
Cycle, Part 2.
again. Correcting the first set of errors frequently reveals new errors
that originally were not apparent to the compiler. For example, if you
could use an English compiler and submit the sentence “The dg chase

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Licensed to: iChapters User

CHAPTER 1 An Overview of Computers and Programming

the cat,” the compiler at first might point out only one syntax error.
The second word, “dg,” is illegal because it is not part of the English
After a pro- language. Only after you corrected the word to “dog” would the com-
gram has piler find another syntax error on the third word, “chase,” because it is
been trans- the wrong verb form for the subject “dog.” This doesn’t mean “chase”
lated into is necessarily the wrong word. Maybe “dog” is wrong; perhaps the
12 machine lan- subject should be “dogs,” in which case “chase” is right. Compilers
guage, the machine lan-
don’t always know exactly what you mean, nor do they know what the
guage program is saved
and can be run any num-
proper correction should be, but they do know when something is
ber of times without wrong with your syntax.
repeating the translation
When writing a program, a programmer might need to recompile the
step. You only need to
retranslate your code if
code several times. An executable program is created only when the
you make changes to code is free of syntax errors. When you run an executable program, it
your source code typically also might require input data. Figure 1-2 shows a diagram of
statements. this entire process.

Data that the


program uses

If there are no
Write and correct Compile the syntax errors Executable
the program code program program

If there are
syntax errors

List of Program
syntax output
error
messages

Figure 1-2 Creating an executable program

Testing the Program


A program that is free of syntax errors is not necessarily free of logi-
cal errors. A logical error results when you use a syntactically correct
statement but use the wrong one for the current context. For exam-
ple, the English sentence “The dog chases the cat,” although syntacti-
cally perfect, is not logically correct if the dog chases a ball or the cat
is the aggressor.

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Licensed to: iChapters User

Understanding the Program Development Cycle

Once a program is free of syntax errors, the programmer can


test it—that is, execute it with some sample data to see whether
the results are logically correct. Recall the number-doubling
program:
input myNumber
set myAnswer = myNumber * 2
13
output myAnswer

If you execute the program, provide the value 2 as input to the pro-
gram, and the answer 4 is displayed, you have executed one successful
test run of the program.
However, if the answer 40 is displayed, maybe the program contains
a logical error. Maybe the second line of code was mistyped with an
extra zero, so that the program reads:
input myNumber Don’t Do It
set myAnswer = myNumber * 20 The programmer typed
output myAnswer "20" instead of "2".
The process
Placing 20 instead of 2 in the
of finding and
multiplication statement caused a logical error. Notice that nothing is correcting
syntactically wrong with this second program—it is just as reasonable program
to multiply a number by 20 as by 2—but if the programmer intends errors is
only to double myNumber, then a logical error has occurred. called debugging.

Programs should be tested with many sets of data. For example, if


you write the program to double a number, then enter 2 and get an
output value of 4, that doesn’t
necessarily mean you have
a correct program. Perhaps Don’t Do It
you have typed this program The programmer typed
by mistake: "+" instead of "*".
input myNumber
set myAnswer = myNumber + 2
output myAnswer

An input of 2 results in an answer of 4, but that doesn’t mean your


program doubles numbers—it actually only adds 2 to them. If you test
your program with additional data and get the wrong answer—for
example, if you enter 7 and get an answer of 9—you know there is a
problem with your code.
Selecting test data is somewhat of an art in itself, and it should be
done carefully. If the Human Resources department wants a list
of the names of five-year employees, it would be a mistake to test
the program with a small sample file of only long-term employees.
If no newer employees are part of the data being used for testing,
you do not really know if the program would have eliminated them

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Licensed to: iChapters User

CHAPTER 1 An Overview of Computers and Programming

from the five-year list. Many companies do not know that their
software has a problem until an unusual circumstance occurs—for
Chapter 4
contains more
example, the first time an employee has more than nine depen-
information on dents, the first time a customer orders more than 999 items at a
testing time, or when (as well-documented in the popular press) a new
programs. century begins.
14

Putting the Program into


Production
Once the program is tested adequately, it is ready for the organi-
zation to use. Putting the program into production might mean
simply running the program once, if it was written to satisfy a
user’s request for a special list. However, the process might take
months if the program will be run on a regular basis, or if it is one
of a large system of programs being developed. Perhaps data-entry
people must be trained to prepare the input for the new program;
users must be trained to understand the output; or existing data
in the company must be changed to an entirely new format to
accommodate this program. Conversion, the entire set of actions
an organization must take to switch over to using a new pro-
gram or set of programs, can sometimes take months or years to
accomplish.

Maintaining the Program


After programs are put into production, making necessary
changes is called maintenance. Maintenance can be required for
many reasons: new tax rates are legislated, the format of an input
file is altered, or the end user requires additional information
not included in the original output specifications, to name a few.
Frequently, your first programming job will require maintaining
Watch the video previously written programs. When you maintain the programs
The Program others have written, you will appreciate the effort the original pro-
Development grammer put into writing clear code, using reasonable variable
Cycle, Part 3.
names, and documenting his or her work. When you make changes
to existing programs, you repeat the development cycle. That is, you
must understand the changes, then plan, code, translate, and test
them before putting them into production. If a substantial number
of program changes are required, the original program might be
retired, and the program development cycle might be started for a
new program.

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Licensed to: iChapters User

Using Pseudocode Statements and Flowchart Symbols

TWO TRUTHS & A LIE


Understanding the Program Development Cycle

1. Understanding the problem that must be solved can be one of the most dif-
15
ficult aspects of programming.
2. The two most commonly used logic-planning tools are flowcharts and
pseudocode.
3. Flowcharting a program is a very different process if you use an older
programming language instead of a newer one.

to solve a programming problem can be executed using any number of languages.


processing, output operations, and other standard functions. The logic developed
quite alike in their basic capabilities—each can handle input operations, arithmetic
The false statement is #3. Despite their differences, programming languages are

Using Pseudocode Statements


and Flowchart Symbols
When programmers plan the logic for a solution to a programming
problem, they often use one of two tools: pseudocode (pronounced
“sue-doe-code”) or flowcharts. Pseudocode is an English-like repre-
sentation of the logical steps it takes to solve a problem. A flowchart
is a pictorial representation of the same thing. Pseudo is a prefix that
means “false,” and to code a program means to put it in a programming
language; therefore, pseudocode simply means “false code,” or sentences
that appear to have been written in a computer programming language
but do not necessarily follow all the syntax rules of any specific language.

Writing Pseudocode
You have already seen examples of statements that represent pseudo-
code earlier in this chapter, and there is nothing mysterious about
them. The following five statements constitute a pseudocode repre-
sentation of a number-doubling problem:
start
input myNumber
set myAnswer = myNumber * 2
output myAnswer
stop

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Licensed to: iChapters User

CHAPTER 1 An Overview of Computers and Programming

Using pseudocode involves writing down all the steps you will use in
a program. Usually, programmers preface their pseudocode with a
beginning statement like start and end it with a terminating state-
ment like stop. The statements between start and stop look like
English and are indented slightly so that start and stop stand out.
Most programmers do not bother with punctuation such as periods
16
at the end of pseudocode statements, although it would not be wrong
to use them if you prefer that style. Similarly, there is no need to capi-
talize the first word in a sentence, although you might choose to do
so. This book follows the conventions of using lowercase letters for
verbs that begin pseudocode statements and omitting periods at the
end of statements.
Pseudocode is fairly flexible because it is a planning tool, and not the
final product. Therefore, for example, you might prefer any of the
following:
• Instead of start and stop, some pseudocode developers would
use the terms begin and end.
• Instead of writing input myNumber, some developers would write
get myNumber or read myNumber.

• Instead of writing set myAnswer = myNumber * 2, some develop-


ers would write calculate myAnswer = myNumber times 2 or
compute myAnswer as myNumber doubled.

• Instead of writing output myAnswer, many pseudocode devel-


opers would write display myAnswer, print myAnswer, or
write myAnswer.

The point is, the pseudocode statements are instructions to retrieve


an original number from an input device and store it in memory
where it can be used in a calculation, and then to get the calculated
answer from memory and send it to an output device so a person can
see it. When you eventually convert your pseudocode to a specific
programming language, you do not have such flexibility because spe-
cific syntax will be required. For example, if you use the C# program-
ming language and write the statement to output the answer, you will
code the following:
Console.Write (myAnswer);

The exact use of words, capitalization, and punctuation are important


in the C# statement, but not in the pseudocode statement.

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Licensed to: iChapters User

Using Pseudocode Statements and Flowchart Symbols

Drawing Flowcharts
Some professional programmers prefer writing pseudocode to
drawing flowcharts, because using pseudocode is more similar to
writing the final statements in the programming language. Others
prefer drawing flowcharts to represent the logical flow, because flow-
charts allow programmers to visualize more easily how the program You can draw 17
statements will connect. Especially for beginning programmers, flow- a flowchart by
charts are an excellent tool to help them visualize how the statements hand or use
software,
in a program are interrelated.
such as
When you create a flowchart, you draw geometric shapes that contain Microsoft Word and
the individual statements and that are connected with arrows. You Microsoft PowerPoint,
that contains flowcharting
use a parallelogram to represent
tools. You can use sev-
an input symbol, which indicates input myNumber eral other software pro-
an input operation. You write an grams, such as Visio and
input statement in English inside the Visual Logic, specifically
parallelogram, as shown in Figure 1-3. Figure 1-3 Input symbol to create flowcharts.

Arithmetic operation statements


are examples of processing. In a set myAnswer =
flowchart, you use a rectangle as the myNumber * 2
processing symbol that contains a
processing statement, as shown in Because the
Figure 1-4 Processing symbol
Figure 1-4. parallelogram
is used for
To represent an output state-
both input and
ment, you use the same symbol as output myAnswer output, it is
for input statements—the output often called
symbol is a parallelogram, as shown the input/output
in Figure 1-5. Figure 1-5 Output symbol symbol or I/O symbol.

Some software programs that use flowcharts (such as Visual Logic) use
a left-slanting parallelogram to represent output. As long as the flowchart
creator and the flowchart reader are communicating, the actual shape
used is irrelevant. This book will follow the most standard convention
of always using the right-slanting parallelogram for both input and output.

Appendix B
To show the correct sequence of these statements, you use arrows, or
contains a
flowlines, to connect the steps. Whenever possible, most of a flow- summary of
chart should read from top to bottom or from left to right on a page. all the flow-
That’s the way we read English, so when flowcharts follow this con- chart symbols
vention, they are easier for us to understand. you will see in this book.

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Licensed to: iChapters User

CHAPTER 1 An Overview of Computers and Programming

Programmers To be complete, a flowchart should include two more elements:


seldom create terminal symbols, or start/stop symbols, at each end. Often, you
both pseudo-
place a word like start or begin in the first terminal symbol and a
code and a
word like end or stop in the other. The standard terminal symbol is
flowchart for
the same problem. You shaped like a racetrack; many programmers refer to this shape as a
usually use one or the lozenge, because it resembles the shape of the medication you might
18
other. In a large program, use to soothe a sore throat. Figure 1-6 shows a complete flowchart
you might even prefer to for the program that doubles a number, and the pseudocode for the
use pseudocode for same problem. You can see from the figure that the flowchart and
some parts and draw a pseudocode statements are the same—only the presentation format
flowchart for others.
differs.

Flowchart Pseudocode

start

input myNumber

start
input myNumber
set myAnswer =
set myAnswer = myNumber * 2
myNumber * 2
output myAnswer
stop

output myAnswer

stop

Figure 1-6 Flowchart and pseudocode of program that doubles a number

Repeating Instructions
After the flowchart or pseudocode has been developed, the
programmer only needs to: (1) buy a computer, (2) buy a language
compiler, (3) learn a programming language, (4) code the pro-
gram, (5) attempt to compile it, (6) fix the syntax errors, (7) com-
pile it again, (8) test it with several sets of data, and (9) put it into
production.
“Whoa!” you are probably saying to yourself. “This is simply not worth
it! All that work to create a flowchart or pseudocode, and then all those
other steps? For five dollars, I can buy a pocket calculator that will

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Licensed to: iChapters User

Using Pseudocode Statements and Flowchart Symbols

double any number for me instantly!” You are absolutely right. If this When you tell
were a real computer program, and all it did was double the value of a a friend how
to get to your
number, it would not be worth the effort. Writing a computer program
house, you
would be worthwhile only if you had many—let’s say 10,000—numbers might write a
to double in a limited amount of time—let’s say the next two minutes. series of instructions or
you might draw a map.
Unfortunately, the number-doubling program represented in 19
Pseudocode is similar to
Figure 1-6 does not double 10,000 numbers; it doubles only one. You
written, step-by-step
could execute the program 10,000 times, of course, but that would instructions; a flowchart,
require you to sit at the computer and tell it to run the program over like a map, is a visual
and over again. You would be better off with a program that could representation of the
process 10,000 numbers, one after the other. same thing.

One solution is to write the program shown in Figure 1-7 and execute
the same steps 10,000 times. Of course, writing this program would
be very time consuming; you might as well buy the calculator.

start
input myNumber
set myAnswer = myNumber * 2
output myAnswer
input myNumber
set myAnswer = myNumber * 2
output myAnswer Don’t Do It
input myNumber You would never want to
set myAnswer = myNumber * 2 write such a repetitious
output myAnswer list of instructions.
…and so on for 9,997 more times

Figure 1-7 Inefficient pseudocode for program that doubles 10,000 numbers

A better solution is to have the computer execute the same set of


three instructions over and over again, as shown in Figure 1-8. The
repetition of a series of steps is called a loop. With this approach, the
computer gets a number, doubles it, displays the answer, and then
starts over again with the first instruction. The same spot in memory,
called myNumber, is reused for the second number and for any subse-
quent numbers. The spot in memory named myAnswer is reused each
time to store the result of the multiplication operation. The logic illus-
trated in the flowchart in Figure 1-8 contains a major problem—the
sequence of instructions never ends. This programming situation is
known as an infinite loop—a repeating flow of logic with no end. You
will learn one way to handle this problem later in this chapter; you
will learn a superior way in Chapter 3.

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Licensed to: iChapters User

CHAPTER 1 An Overview of Computers and Programming

start

input myNumber

20 Don’t Do It
set myAnswer = This logic saves
myNumber * 2 steps, but it has a
fatal flaw – it never
ends.
output myAnswer

Figure 1-8 Flowchart of infinite number-doubling program

TWO TRUTHS & A LIE


Using Pseudocode Statements and Flowchart Symbols

1. When you draw a flowchart, you use a parallelogram to represent an input


operation.
2. When you draw a flowchart, you use a parallelogram to represent a process-
ing operation.
3. When you draw a flowchart, you use a parallelogram to represent an output
operation.

represent a processing operation.


The false statement is #2. When you draw a flowchart, you use a rectangle to

Using a Sentinel Value to End


a Program
The logic in the flowchart for doubling numbers, shown in Figure 1-8,
has a major flaw—the program contains an infinite loop. If, for exam-
ple, the input numbers are being entered at the keyboard, the program
will keep accepting numbers and outputting doubles forever. Of course,
the user could refuse to type any more numbers. But the computer is
very patient, and if you refuse to give it any more numbers, it will sit
and wait forever. When you finally type a number, the program will
double it, output the result, and wait for another. The program cannot
Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Licensed to: iChapters User

Using a Sentinel Value to End a Program

progress any further while it is waiting for input; meanwhile, the pro-
gram is occupying computer memory and tying up operating system
resources. Refusing to enter any more numbers is not a practical solu-
tion. Another way to end the program is simply to turn off the com-
puter. But again, that’s neither the best way nor an elegant solution.
A superior way to end the program is to set a predetermined value for 21
myNumber that means “Stop the program!” For example, the program-
mer and the user could agree that the user will never need to know
the double of 0, so the user could enter a 0 to stop. The program could
then test any incoming value contained in myNumber and, if it is a 0,
stop the program. Testing a value is also called making a decision.
You represent a decision in a flowchart by drawing a decision symbol,
which is shaped like a diamond. The diamond usually contains a
question, the answer to which is one of two mutually exclusive
options—often yes or no. All good computer questions have only A yes-or-no
decision is
two mutually exclusive answers, such as yes and no or true and false.
called a
For example, “What day of the year is your birthday?” is not a good binary deci-
computer question because there are 366 possible answers. However, sion, because
“Is your birthday June 24?” is a good computer question because, for there are two possible
everyone in the world, the answer is either yes or no. outcomes.

The question to stop the doubling program should be “Is the value
of myNumber just entered equal to 0?” or “myNumber = 0?” for short. The
complete flowchart will now look like the one shown in Figure 1-9.

start Don’t Do It
This logic is not
structured; you will
learn about structure
input myNumber in Chapter 3.

myNumber Yes
stop
= 0?

No

set myAnswer =
myNumber times 2

output myAnswer

Figure 1-9 Flowchart of number-doubling program with sentinel value of 0


Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Licensed to: iChapters User

CHAPTER 1 An Overview of Computers and Programming

One drawback to using 0 to stop a program, of course, is that it won’t


work if the user does need to find the double of 0. In that case, some
other data-entry value that the user will never need, such as 999 or –1,
could be selected to signal that the program should end. A preselected
value that stops the execution of a program is often called a dummy
value because it does not represent real data, but just a signal to stop.
22
Sometimes, such a value is called a sentinel value because it repre-
sents an entry or exit point, like a sentinel who guards a fortress.
Not all programs rely on user data entry from a keyboard; many read
data from an input device, such as a disk. When organizations store
data on a disk or other storage device, they do not commonly use
a dummy value to signal the end of the file. For one thing, an input
record might have hundreds of fields, and if you store a dummy record
in every file, you are wasting a large quantity of storage on “nondata.”
Additionally, it is often difficult to choose sentinel values for fields
in a company’s data files. Any balanceDue, even a zero or a negative
number, can be a legitimate value, and any customerName, even “ZZ”,
could be someone’s name. Fortunately, programming languages can
recognize the end of data in a file automatically, through a code that
is stored at the end of the data. Many programming languages use the
term eof (for “end of file”) to refer to this marker that automatically
acts as a sentinel. This book, therefore, uses eof to indicate the end of
data whenever using a dummy value is impractical or inconvenient. In
the flowchart shown in Figure 1-10, the eof question is shaded.

start Don’t Do It
This logic is not
structured; you will
learn about structure
input myNumber in Chapter 3.

Yes
eof? stop

No

set myAnswer =
myNumber times 2

output myAnswer

Figure 1-10 Flowchart using eof

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Licensed to: iChapters User

Understanding Programming and User Environments

TWO TRUTHS & A LIE


Using a Sentinel Value to End a Program

1. A program that contains an infinite loop is one that never ends.


23
2. A preselected value that stops the execution of a program is often called a
dummy value or a sentinel value.
3. Many programming languages use the term fe (for “file end”) to refer to a
marker that automatically acts as a sentinel.

a file sentinel.
The false statement is #3. The term eof (for “end of file”) is the common term for

Understanding Programming
and User Environments
Many approaches can be used to write and execute a computer pro-
gram. When you plan a program’s logic, you can use a flowchart or
pseudocode, or a combination of the two. When you code the pro-
gram, you can type statements into a variety of text editors. When
your program executes, it might accept input from a keyboard,
mouse, microphone, or any other input device, and when you provide
a program’s output, you might use text, images, or sound. This section
describes the most common environments you will encounter as a
new programmer.

Understanding Programming Environments


When you plan the logic for a computer program, you can use paper
and pencil to create a flowchart, or you might use software that
allows you to manipulate flowchart shapes. If you choose to write
pseudocode, you can do so by hand or by using a word-processing
program. To enter the program into a computer so you can trans-
late and execute it, you usually use a keyboard to type program
statements into an editor. You can type a program into one of the
following:
• A plain text editor
• A text editor that is part of an integrated development
environment

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Licensed to: iChapters User

CHAPTER 1 An Overview of Computers and Programming

A text editor is a program that you use to create simple text files. It
is similar to a word processor, but without as many features. You can
use a text editor such as Notepad that is included with Microsoft
Windows. Figure 1-11 shows a C# program in Notepad that accepts
a number and doubles it. An advantage to using a simple text editor
to type and save a program is that the completed program does not
24
require much disk space for storage. For example, the file shown in
Figure 1-11 occupies only 314 bytes of storage.

This line contains a


prompt that tells the user
what to enter. You will
learn more about prompts
in Chapter 2.

Figure 1-11 A C# number-doubling program in Notepad

You can use the editor of an integrated development environment


(IDE) to enter your program. An IDE is a software package that pro-
vides an editor, compiler, and other programming tools. For example,
Figure 1-12 shows a C# program in the Microsoft Visual Studio IDE,
an environment that contains tools useful for creating programs in
Visual Basic, C++, and C#.

Figure 1-12 A C# number-doubling program in Visual Studio

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Licensed to: iChapters User

Understanding Programming and User Environments

Using an IDE is helpful to programmers because IDEs usually provide


features similar to those you find in many word processors. In particu-
lar, an IDE’s editor commonly includes such features as the following:
• It uses different colors to display various language components,
making elements like data types easier to identify.
25
• It highlights syntax errors visually for you.
• It employs automatic statement completion; when you start to type
a statement, the IDE suggests a likely completion, which you can
accept with a keystroke.
• It provides tools that allow you to step through a program’s execu-
tion one statement at a time so you can more easily follow the pro-
gram’s logic and determine the source of any errors.
When you use the IDE to create and save a program, you occupy
much more disk space than when using a plain text editor. For exam-
ple, the program in Figure 1-12 occupies more than 49,000 bytes of
disk space.
Although various programming environments might look different
and offer different features, the process of using them is very similar.
When you plan the logic for a program using pseudocode or a flow-
chart, it does not matter which programming environment you will
use to write your code, and when you write the code in a program-
ming language, it does not matter which environment you use to
write it.

Understanding User Environments


A user might execute a program you have written in any number
of environments. For example, a user might execute the number-
doubling program from a command line like the one shown in
Figure 1-13. A command line is a location on your computer screen
at which you type text entries to communicate with the computer’s
operating system. In the program in Figure 1-13, the user is asked for
a number, and the results are displayed.

Figure 1-13 Executing a number-doubling program in a


command-line environment

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Licensed to: iChapters User

CHAPTER 1 An Overview of Computers and Programming

Many programs are not run at the command line in a text environ-
ment, but are run using a graphical user interface, or GUI (pro-
nounced “gooey”), which allows users to interact with a program in
a graphical environment. When running a GUI program, the user
might type input into a text box or use a mouse or other pointing
device to select options on the screen. Figure 1-14 shows a number-
26
doubling program that performs exactly the same task as the one in
Figure 1-13, but this program uses a GUI.

Figure 1-14 Executing a number-doubling program


in a GUI environment

A command-line program and a GUI program might be written in


the same programming language. (For example, the programs shown
in Figures 1-13 and 1-14 were both written using C#.) However, no
matter which environment is used to write or execute a program, the
logical process is the same. The two programs in Figures 1-13 and
1-14 both accept input, perform multiplication, and perform output.
In this book, you will not concentrate on which environment is used
to type a program’s statements, nor will you care about the type of
environment the user will see. Instead, you will be concerned with the
logic that applies to all programming situations.

TWO TRUTHS & A LIE


Understanding Programming and User Environments

1. You can type a program into an editor that is part of an integrated develop-
ment environment, but using a plain text editor provides you with more pro-
gramming help.
2. When a program runs from the command line, a user types text to provide input.
3. Although GUI and command-line environments look different, the logic
processes of input, processing, and output apply to both program types.

programming help than a plain text editor.


The false statement is #1. An integrated development environment provides more

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Licensed to: iChapters User

Understanding the Evolution of Programming Models

Understanding the Evolution


of Programming Models
People have been writing modern computer programs since the
1940s. The oldest programming languages required programmers to
work with memory addresses and to memorize awkward codes asso- 27
ciated with machine languages. Newer programming languages look
much more like natural language and are easier to use, partly because
they allow programmers to name variables instead of using awkward Ada Byron
memory addresses. Also, newer programming languages allow pro- Lovelace pre-
grammers to create self-contained modules or program segments dicted the
that can be pieced together in a variety of ways. The oldest computer development
programs were written in one piece, from start to finish, but modern of software in
1843; she is often
programs are rarely written that way—they are created by teams of
regarded as the first pro-
programmers, each developing reusable and connectable program grammer. The basis for
procedures. Writing several small modules is easier than writing one most modern software
large program, and most large tasks are easier when you break the was proposed by Alan
work into units and get other workers to help with some of the units. Turing in 1935.

Currently, two major models or paradigms are used by programmers


to develop programs and their procedures. One technique, proce- You will learn
dural programming, focuses on the procedures that programmers to create pro-
create. That is, procedural programmers focus on the actions that gram modules
are carried out—for example, getting input data for an employee and in Chapter 2.
writing the calculations needed to produce a paycheck from the data.
Procedural programmers would approach the job of producing a pay-
check by breaking down the process into manageable subtasks.
The other popular programming model, object-oriented
programming, focuses on objects, or “things,” and describes their
features (or attributes) and their behaviors. For example, object- You can write
oriented programmers might design a payroll application by think- a procedural
ing about employees and paychecks, and describing their attributes program in
(e.g. employees have names and Social Security numbers, and pay- any language
checks have names and check amounts). Then the programmers that supports
would think about the behaviors of employees and paychecks, such as object orientation. The
employees getting raises and adding dependents and paychecks being opposite is not always
true.
calculated and output. Object-oriented programmers would then
build applications from these entities.
With either approach, procedural or object oriented, you can produce a Object-
correct paycheck, and both models employ reusable program modules. oriented
The major difference lies in the focus the programmer takes during the programming
employs a
earliest planning stages of a project. For now, this book focuses on pro-
large vocabu-
cedural programming techniques. The skills you gain in programming lary; you can learn this
procedurally—declaring variables, accepting input, making decisions, terminology in Chapter 10
producing output, and so on—will serve you well whether you eventually of the comprehensive
write programs in a procedural or object-oriented fashion, or in both. version of this book.

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Licensed to: iChapters User

CHAPTER 1 An Overview of Computers and Programming

TWO TRUTHS & A LIE


Understanding the Evolution of Programming Models

1. The oldest computer programs were written in many separate modules.


28
2. Procedural programmers focus on actions that are carried out by a program.
3. Object-oriented programmers focus on a program’s objects and their attri-
butes and behaviors.

newer programs are divided into modules.


The false statement is #1. The oldest programs were written in a single piece;

Chapter Summary
• Together, computer hardware (physical devices) and software
(instructions) accomplish three major operations: input, processing,
and output. You write computer instructions in a computer pro-
gramming language that requires specific syntax; the instructions
are translated into machine language by a compiler or interpreter.
When both the syntax and logic of a program are correct, you can
run, or execute, the program to produce the desired results.
• For a program to work properly, you must develop correct logic.
Logical errors are much more difficult to locate than syntax errors.
• A programmer’s job involves understanding the problem, plan-
ning the logic, coding the program, translating the program into
machine language, testing the program, putting the program into
production, and maintaining it.
• When programmers plan the logic for a solution to a program-
ming problem, they often use flowcharts or pseudocode. When
you draw a flowchart, you use parallelograms to represent input
and output operations, and rectangles to represent processing.
Programmers also use decisions to control repetition of instruc-
tion sets.
• To avoid creating an infinite loop when you repeat instructions,
you can test for a sentinel value. You represent a decision in a
flowchart by drawing a diamond-shaped symbol that contains a
question, the answer to which is either yes or no.

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Licensed to: iChapters User

Key Terms

• You can type a program into a plain text editor or one that is part
of an integrated development environment. When a program’s
data values are entered from a keyboard, they can be entered at the
command line in a text environment or in a GUI. Either way, the
logic is similar.
• Procedural and object-oriented programmers approach problems 29
differently. Procedural programmers concentrate on the actions
performed with data. Object-oriented programmers focus on
objects and their behaviors and attributes.

Key Terms
A computer system is a combination of all the components required
to process and store data using a computer.
Hardware is the collection of physical devices that comprise a com-
puter system.
Software consists of the programs that tell the computer what to do.
Programs are sets of instructions for a computer.
Programming is the act of developing and writing programs.
Application software comprises all the programs you apply
to a task.
System software comprises the programs that you use to manage
your computer.
Input describes the entry of data items into computer memory using
hardware devices such as keyboards and mice.
Data items include all the text, numbers, and other information pro-
cessed by a computer.
Processing data items may involve organizing them, checking them
for accuracy, or performing mathematical operations on them.
The central processing unit, or CPU, is the hardware component that
processes data.
Output describes the operation of retrieving information from mem-
ory and sending it to a device, such as a monitor or printer, so people
can view, interpret, and work with the results.
Storage devices are types of hardware equipment, such as disks, that
hold information for later retrieval.
Programming languages, such as Visual Basic, C#, C++, Java,
or COBOL, are used to write programs.

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Licensed to: iChapters User

CHAPTER 1 An Overview of Computers and Programming

Program code is the set of instructions a programmer writes in a


programming language.
Coding the program is the act of writing programming language
instructions.
The syntax of a language is its grammar rules.
30
Computer memory is the temporary, internal storage within a
computer.
Volatile describes storage whose contents are lost when power
is lost.
Nonvolatile describes storage whose contents are retained when
power is lost.
Random access memory (RAM) is temporary, internal computer
storage.
Machine language is a computer’s on/off circuitry language.
A compiler or interpreter translates a high-level language into
machine language and tells you if you have used a programming
language incorrectly.
Binary language is represented using a series of 0s and 1s.
Source code is the statements a programmer writes in a program-
ming language.
Object code is translated machine language.
To run or execute a program is to carry out its instructions.
Scripting languages (also called scripting programming lan-
guages or script languages) such as Python, Lua, Perl, and PHP
are used to write programs that are typed directly from a keyboard.
Scripting languages are stored as text rather than as binary execut-
able files.
A logical error occurs when incorrect instructions are performed, or
when instructions are performed in the wrong order.
You develop the logic of the computer program when you give
instructions to the computer in a specific sequence, without omitting
any instructions or adding extraneous instructions.
A semantic error occurs when a correct word is used in an incorrect
context.
A variable is a named memory location whose value can vary.
The program development cycle consists of the steps that occur
during a program’s lifetime.

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Licensed to: iChapters User

Key Terms

Users (or end users) are people who employ and benefit from com-
puter programs.
Documentation consists of all the supporting paperwork for a
program.
An algorithm is the sequence of steps necessary to solve any
31
problem.
An IPO chart is a program development tool that delineates input,
processing, and output tasks.
A TOE chart is a program development tool that lists tasks, objects,
and events.
Desk-checking is the process of walking through a program solution
on paper.
A high-level programming language supports English-like syntax.
Machine language is the low-level language made up of 1s and 0s
that the computer understands.
A syntax error is an error in language or grammar.
Debugging is the process of finding and correcting program errors.
Conversion is the entire set of actions an organization must take to
switch over to using a new program or set of programs.
Maintenance consists of all the improvements and corrections made
to a program after it is in production.
Pseudocode is an English-like representation of the logical steps it
takes to solve a problem.
A flowchart is a pictorial representation of the logical steps it takes to
solve a problem.
An input symbol indicates an input operation and is represented by a
parallelogram in flowcharts.
A processing symbol indicates a processing operation and is repre-
sented by a rectangle in flowcharts.
An output symbol indicates an output operation and is represented
by a parallelogram in flowcharts.
An input/output symbol or I/O symbol is represented by a parallelo-
gram in flowcharts.
Flowlines, or arrows, connect the steps in a flowchart.
A terminal symbol, or start/stop symbol, is used at each end of a
flowchart. Its shape is a lozenge.

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Licensed to: iChapters User

CHAPTER 1 An Overview of Computers and Programming

A loop is a repetition of a series of steps.


An infinite loop occurs when repeating logic cannot end.
Making a decision is the act of testing a value.
A decision symbol is shaped like a diamond and used to represent
32 decisions in flowcharts.
A binary decision is a yes-or-no decision with two possible outcomes.
A dummy value is a preselected value that stops the execution of a
program.
A sentinel value is a preselected value that stops the execution of a
program.
The term eof means “end of file.”
A text editor is a program that you use to create simple text files; it is
similar to a word processor, but without as many features.
An integrated development environment (IDE) is a software package
that provides an editor, compiler, and other programming tools.
Microsoft Visual Studio IDE is a software package that contains useful
tools for creating programs in Visual Basic, C++, and C#.
A command line is a location on your computer screen at which
you type text entries to communicate with the computer’s operating
system.
A graphical user interface, or GUI (pronounced “gooey”), allows
users to interact with a program in a graphical environment.
Procedural programming is a programming model that focuses on
the procedures that programmers create.
Object-oriented programming is a programming model that focuses
on objects, or “things,” and describes their features (or attributes) and
their behaviors.

Review Questions
1. Computer programs are also known as .
a. hardware
b. software
c. data
d. information

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Licensed to: iChapters User

Review Questions

2. The major computer operations include .


a. hardware and software
b. input, processing, and output
c. sequence and looping
33
d. spreadsheets, word processing, and data
communications

3. Visual Basic, C++, and Java are all examples of computer


.
a. operating systems
b. hardware
c. machine languages
d. programming languages

4. A programming language’s rules are its .


a. syntax
b. logic
c. format
d. options

5. The most important task of a compiler or interpreter


is to .
a. create the rules for a programming language
b. translate English statements into a language the computer
can understand, such as Java
c. translate programming language statements into machine
language
d. execute machine language programs to perform useful
tasks

6. Which of the following is temporary, internal storage?


a. CPU
b. hard disk
c. keyboard
d. memory

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Licensed to: iChapters User

CHAPTER 1 An Overview of Computers and Programming

7. Which of the following pairs of steps in the programming


process is in the correct order?
a. code the program, plan the logic
b. test the program, translate it into machine language
34 c. put the program into production, understand the
problem
d. code the program, translate it into machine
language

8. The programmer’s most important task before planning the


logic of a program is to .
a. decide which programming language to use
b. code the problem
c. train the users of the program
d. understand the problem

9. The two most commonly used tools for planning a program’s


logic are .
a. flowcharts and pseudocode
b. ASCII and EBCDIC
c. Java and Visual Basic
d. word processors and spreadsheets

10. Writing a program in a language such as C++ or Java is


known as the program.
a. translating
b. coding
c. interpreting
d. compiling

11. An English-like programming language such as Java or Visual


Basic is a programming language.
a. machine-level
b. low-level
c. high-level
d. binary-level

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Licensed to: iChapters User

Review Questions

12. Which of the following is an example of a syntax error?


a. producing output before accepting input
b. subtracting when you meant to add
c. misspelling a programming language word
35
d. all of the above

13. Which of the following is an example of a logical error?


a. performing arithmetic with a value before
inputting it
b. accepting two input values when a program requires
only one
c. dividing by 3 when you meant to divide by 30
d. all of the above

14. The parallelogram is the flowchart symbol representing


.
a. input
b. output
c. both a and b
d. none of the above

15. In a flowchart, a rectangle represents .


a. input
b. a sentinel
c. a question
d. processing

16. In flowcharts, the decision symbol is a .


a. parallelogram
b. rectangle
c. lozenge
d. diamond

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Licensed to: iChapters User

CHAPTER 1 An Overview of Computers and Programming

17. The term “eof” represents .


a. a standard input device
b. a generic sentinel value
c. a condition in which no more memory is available for
36 storage
d. the logical flow in a program

18. When you use an IDE instead of a simple text editor to


develop a program, .
a. the logic is more complicated
b. the logic is simpler
c. the syntax is different
d. some help is provided

19. When you write a program that will run in a GUI environ-
ment as opposed to a command-line environment,
.
a. the logic is very different
b. some syntax is different
c. you do not need to plan the logic
d. users are more confused

20. As compared to procedural programming, with object-


oriented programming .
a. the programmer’s focus differs
b. you cannot use some languages, such as Java
c. you do not accept input
d. you do not code calculations; they are created
automatically

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Licensed to: iChapters User

Exercises

Exercises
1. Match the definition with the appropriate term.
1. Computer system devices a. compiler
2. Another word for programs b. syntax 37
3. Language rules c. logic
4. Order of instructions d. hardware
5. Language translator e. software

2. In your own words, describe the steps to writing a computer


program.

3. Match the term with the appropriate shape.

1. Input A.

2. Processing B.

3. Output C.

4. Decision D.

5. Terminal E.

4. Draw a flowchart or write pseudocode to represent the logic


of a program that allows the user to enter a value. The pro-
gram multiplies the value by 10 and outputs the result.

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Licensed to: iChapters User

CHAPTER 1 An Overview of Computers and Programming

5. Draw a flowchart or write pseudocode to represent the logic


of a program that allows the user to enter a value for the
radius of a circle. The program calculates the diameter by
multiplying the radius by 2, and then calculates the circumfer-
ence by multiplying the diameter by 3.14. The program out-
puts both the diameter and the circumference.
38
6. Draw a flowchart or write pseudocode to represent the logic
of a program that allows the user to enter two values. The
program outputs the sum of the two values.

7. Draw a flowchart or write pseudocode to represent the logic


of a program that allows the user to enter three values. The
values represent hourly pay rate, the number of hours worked
this pay period, and percentage of gross salary that is with-
held. The program multiplies the hourly pay rate by the num-
ber of hours worked, giving the gross pay. Then, it multiplies
the gross pay by the withholding percentage, giving the with-
holding amount. Finally, it subtracts the withholding amount
from the gross pay, giving the net pay after taxes. The pro-
gram outputs the net pay.

Find the Bugs

8. Since the early days of computer programming, program


errors have been called “bugs.” The term is often said to have
originated from an actual moth that was discovered trapped
in the circuitry of a computer at Harvard University in 1945.
Actually, the term “bug” was in use prior to 1945 to mean
trouble with any electrical apparatus; even during Thomas
Edison’s life, it meant an “industrial defect.” However, the
term “debugging” is more closely associated with correcting
program syntax and logic errors than with any other type of
trouble.

Your student disk contains files named DEBUG01-01.txt,


DEBUG01-02.txt, and DEBUG01-03.txt. Each file starts with
some comments that describe the problem. Comments are lines
that begin with two slashes (//). Following the comments, each
file contains pseudocode that has one or more bugs you must
find and correct.

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Licensed to: iChapters User

Exercises

Game Zone
9. In 1952, A. S. Douglas wrote his University of Cambridge
Ph.D. dissertation on human-computer interaction, and
created the first graphical computer game—a version of
Tic-Tac-Toe. The game was programmed on an EDSAC 39
vacuum-tube mainframe computer. The first computer game
is generally assumed to be “Spacewar!”, developed in 1962 at
MIT; the first commercially available video game was “Pong,”
introduced by Atari in 1972. In 1980, Atari’s “Asteroids”
and “Lunar Lander” became the first video games to be
registered with the U. S. Copyright Office. Throughout the
1980s, players spent hours with games that now seem very
simple and unglamorous; do you recall playing “Adventure,”
“Oregon Trail,” “Where in the World Is Carmen Sandiego?,”
or “Myst”?
Today, commercial computer games are much more complex;
they require many programmers, graphic artists, and tes-
ters to develop them, and large management and marketing
staffs are needed to promote them. A game might cost many
millions of dollars to develop and market, but a successful
game might earn hundreds of millions of dollars. Obviously,
with the brief introduction to programming you have had
in this chapter, you cannot create a very sophisticated game.
However, you can get started.
Mad Libs© is a children’s game in which players provide a
few words that are then incorporated into a silly story. The
game helps children understand different parts of speech
because they are asked to provide specific types of words. For
example, you might ask a child for a noun, another noun, an
adjective, and a past-tense verb. The child might reply with
such answers as “table,” “book,” “silly,” and “studied.” The newly
created Mad Lib might be:
Mary had a little table
Its book was silly as snow
And everywhere that Mary studied
The table was sure to go.
Create the logic for a Mad Lib program that accepts five
words from input, then creates and displays a short story or
nursery rhyme that uses those words.

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
CHAPTER 1 An Overview of Computers and Programming

Up for Discussion
10. Which is the better tool for learning programming—
flowcharts or pseudocode? Cite any educational research you
can find.
40
11. What is the image of the computer programmer in popular
culture? Is the image different in books than in TV shows and
movies? Would you like that image for yourself?

Copyright 2011 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.

You might also like