Tools For Structured and Object Oriented Design 7th Edition Marilyn Bohl 2024 scribd download
Tools For Structured and Object Oriented Design 7th Edition Marilyn Bohl 2024 scribd download
com
https://ebookfinal.com/download/tools-for-structured-and-
object-oriented-design-7th-edition-marilyn-bohl/
OR CLICK BUTTON
DOWNLOAD EBOOK
https://ebookfinal.com/download/object-oriented-and-classical-
software-engineering-7th-edition-stephen-r-schach/
ebookfinal.com
https://ebookfinal.com/download/object-oriented-design-in-java-1st-
edition-stephen-gilbert/
ebookfinal.com
https://ebookfinal.com/download/practical-object-oriented-design-with-
uml-2nd-edition-mark-priestley/
ebookfinal.com
https://ebookfinal.com/download/head-first-object-oriented-analysis-
and-design-1st-edition-brett-d-mclaughlin/
ebookfinal.com
Object Oriented Construction Handbook Developing
Application Oriented Software with the Tools Materials
Approach 1st Edition Heinz Zã¼Llighoven
https://ebookfinal.com/download/object-oriented-construction-handbook-
developing-application-oriented-software-with-the-tools-materials-
approach-1st-edition-heinz-za%c2%bcllighoven/
ebookfinal.com
https://ebookfinal.com/download/object-oriented-javascript-2nd-
edition-stoyan-stefanov/
ebookfinal.com
https://ebookfinal.com/download/object-oriented-javascript-3rd-
edition-ved-antani/
ebookfinal.com
https://ebookfinal.com/download/object-oriented-programming-and-java-
second-edition-danny-poo/
ebookfinal.com
Tools for Structured
and Object-Oriented Design
This page intentionally left blank
Tools for Structured
and Object-Oriented Design
An Introduction to Programming Logic
Seventh Edition
Marilyn Bohl
Maria Rynn
Northern Virginia Community College
All rights reserved. No part of this book may be reproduced, in any form or by any means, without permission in writing from
the publisher.
ISBN 0-13-119445-3
978-0-13-119445-8
Preface xiii
Part One
Structured Programming Concepts 1
1 Introduction to Structured Design 3
Objectives 3
Introduction 3
System Development Life Cycle 4
Analyze the Current System 4
Define the New System Requirements 4
Design the New System 5
Develop the New System 6
Implement the New System 12
Structured Programming 12
Basic Control Structures 13
Key Terms 15
Exercises 15
4 DOWHILE Control
Structure—Counter-Controlled Loops 59
Objectives 59
Introduction 59
Problem (Adding Six Numbers) 61
Simulation (Adding Six Numbers) 62
The DOWHILE Loop 63
DOWHILE Pseudocode 65
Counter-Controlled Loops 65
Sample Problem 4.1 Payroll with Counter Loop 66
Sample Problem 4.2 Averaging Problem with Counter Loop 68
Header Record Logic 68
Sample Problem 4.3 Payroll with Header Record 71
Sample Problem 4.4 Averaging Problem with Header Record 73
The No-Data Condition 74
Proper Programs 76
Enrichment Visual Basic 77
Key Terms 79
Exercises 79
6 Modularization 107
Objectives 107
Introduction 107
Structure Charts 110
Sample Problem 6.1 Averaging Problem Using Modules 113
Sample Problem 6.2 Defective Parts
with Multiple Headings Using Modules 117
Sample Problem 6.3 Credits Problem Using Modules 121
Enrichment Visual Basic 125
Key Terms 127
Exercises 127
Part Two
Object-Oriented Programming Concepts 221
10 Introduction to Object-Oriented Design 223
Objectives 223
Introduction 223
Objects and Classes 224
Object-Oriented Design 224
GradeBook Class 226
Encapsulation and Data Hiding 226
GradeBook Class Pseudocode 227
Driver Program—GradeBook Example 229
Constrictors 230
Overloading 232
Destructors 234
Sample Problem 10.1 Determining the Perimeter 234
Sample Problem 10.2 Determining the Perimeter and
Area with Parameters and Return Values 235
Key Terms 238
Exercises 238
11 Inheritance 241
Objectives 241
Introduction 241
Generalization/Specialization 242
Inheritance 242
Class Hierarchy 243
Polymorphism 244
Employee Class 245
Faculty Subclass 245
Staff Subclass 247
Driver Program—Employee Example 250
Contents xi
Part Three
Applications 283
13 Array Applications 285
Objectives 285
Introduction 285
Table Lookups 285
Sample Problem 13.1 Table-Lookup Example 286
Binary Searches 292
Sample Problem 13.2 Binary Search Example 293
Sorting Lists 301
Exchanging Values 302
Sample Problem 13.3 Sort Example 303
Key Terms 307
Exercises 307
Index 375
Preface
Tools for Structured and Object-Oriented Design: An Introduction to Program-
ming Logic, Seventh Edition, teaches program design in a well-thought-out,
language-independent manner. This text assumes no previous programming
background. It can be used as the main text in a programming logic class or as a
supplement in any beginning programming class.
xiii
xiv Preface
illustrations and additional exercises are included in this edition. The Instructor’s
Manual contains the objectives and key terms listed in the textbook as well as
suggested teaching strategies. Solutions to all end-of-chapter exercises are in-
cluded in the Instructor’s Manual. At the end of the Instructor’s Manual you can
find a correlation guide that tells you whether the questions at the end of each
chapter are new for the seventh edition, unchanged from the sixth edition, or mod-
ified from the sixth edition. The correlation guide also lists changes to the objec-
tives, key terms and figures that were made to the seventh edition.
The text comes with an accompanying CD with Microsoft Visual Basic 2005 Ex-
press Edition. An accompanying online site, www.prenhall.com/bohl-rynn, pro-
vides the source code for all the Visual Basic examples in the enrichment sections of
the text. The Visual Basic source code is contained in a zip file called Visual Basic
Source Code.zip. Be sure to preserve the file structure when you unzip the file. Once
unzipped, all required files for each chapter are contained in a folder identified by
the chapter number. To run one of the programs, make sure you first install Visual
Basic 2005 Express Edition. Then double-click the solution file for the program you
want to execute. The solution file for each chapter is located in the folder for that
chapter. Solution files have the extension .sln.
This online site also includes resources for instructors including the Instructor’s
Manual, the test bank of 450 true/false and multiple choice questions including
answers, and the PowerPoint slides of all textbook figures.
Acknowledgments This book would not exist today if it were not for the hard work of many people.
We would like to thank: Paula Worthington, Northern Virginia Community Col-
lege; Terry A. Puperi, Belmont Technical College; Alireza Fazelpour, Palm
Beach Community College, Boca Campus; Gene Robeen, Lewis & Clark Com-
munity College, Godfrey; Jay Benson, Anne Arundel Community College;
Krysten Hall, Anne Arundel Community College; and Mary Ellen Vitrano, Palm
Beach Community College.
We hope that all who use this book will find it provides a clear, systematic,
and direct approach to problem-solving. We welcome your comments and
suggestions.
Marilyn Bohl
Maria Rynn
bohl-rynn@prenhall.com
This page intentionally left blank
Tools for Structured
and Object-Oriented Design
This page intentionally left blank
Part 1
Structured
Programming
Concepts
1
This page intentionally left blank
Introduction to
Structured Design 1
Objectives Upon completion of this chapter you should be able to
■ Name and identify the six steps in the system development life cycle.
■ Name and identify some of the tools and methodologies used in the
languages.
■ Define what is meant by event-driven programming.
information system.
■ Name the three basic control structures of structured programming.
Introduction We live today in a business world. Goods and services are bought and sold,
distributed, produced, and created worldwide at incredible rates. Some businesses
are international conglomerates; others are small mom-and-pop shops. The
success of any business depends, for the most part, on how well the business is
run. Every business uses one or more systems to produce its end products or
services. A system is a combination of people, equipment, and procedures that
work together to perform a specific function. A system can be manually operated
or computer-assisted. A computer-based information system is a system in
which some of the procedures are performed by a computer. Since desktop
computers, laptop computers, and a wide range of handheld computing
3
4 Chapter 1
devices are readily available, even small businesses are using computers or
are looking into converting their manual systems to computer-based ones.
Such a conversion is not an easy task, but it can be simplified by following a
series of well-defined steps.
System The system development life cycle (SDLC) (see Figure 1–1) is a series of
Development well-defined steps that should be followed when a system is created or
Life Cycle changed. The SDLC represents the big picture of what happens during system
creation or modification. In this chapter, we outline the steps in the SDLC and
identify the ones on which this book focuses.
Figure 1–1
System Development Life 1. Analyze the current system.
Cycle (SDLC) 2. Define the new system requirements.
3. Design the new system.
4. Develop the new system.
5. Implement the new system.
6. Evaluate the new system.
Introduction to Structured Design 5
Figure 1–2
System Flowchart
PAYROLL TIME
MASTER SHEETS
FILE
PAYROLL
PROGRAM
PAYROLL PAYROLL
PAYCHECKS SUMMARY EXCEPTION
REPORT REPORT
6 Chapter 1
control over the processes of system development (to avoid large budget
overruns; to avoid projects that are months or years late or never completed
at all); to improve software development productivity (especially in busi-
nesses with not enough trained people to do all the necessary development);
to make the developer’s job easier (manual drawing of system flowcharts, for
example, can be very tedious); and to improve program quality (a program
that is used to direct airplanes in flight or to maintain a hospital’s life-support
system must be right). The term computer-assisted software engineering
(CASE) has been coined to refer to the automation of tools, methods, and
procedures for system development. The widespread availability of comput-
ers has accelerated the trend toward the use of CASE. By increasing your
basic analysis and design skills through study of this book, you can enable
yourself to make effective use of the ever-increasing array of CASE tools in
the marketplace.
Review the Program Requirements In the first step of the program devel-
opment cycle, the software developer reviews the requirements defined in the
second step of the SDLC. If anything is unclear at this point, the developer asks
for more information from the system analyst who wrote the original require-
ment, from the system designer, or even from a future user of the program (such
as a store buyer). The developer must not make unfounded assumptions. It is
just as useless to solve the wrong problem correctly as it is to solve the right
problem incorrectly.
Develop the Program Logic In this step, the actual processing steps within
each program in the system are developed. We shall focus on this step through-
out this book. Just as there are tools to use in the design of a system, there are
tools to use in the design of a program. Two common tools discussed in de-
tail in this book are program flowcharts and pseudocode. Like system
flowcharts, program flowcharts contain standard symbols. These symbols
graphically depict the problem-solving logic within a program. Pseudocode
consists of English-language statements that describe the processing steps of
Figure 1–3
Program Development Cycle 1. Review the input, processing, output, and storage
(PDC) requirements.
2. Develop the logic for the program.
3. Write the program using a programming language.
4. Test and debug the program.
5. Complete the program documentation.
Introduction to Structured Design 7
Figure 1–4
Program Flowchart and
START
Pseudocode Start
Read employee data
Compute gross pay
READ
Compute deductions
EMPLOYEE Compute net pay
DATA Write employee paycheck
Stop
COMPUTE
GROSS PAY
COMPUTE
DEDUCTIONS
COMPUTE
NET PAY
WRITE
EMPLOYEE
PAYCHECK
STOP
8 Chapter 1
Figure 1–5
Structure Chart PAYROLL
PROGRAM
A000
Language, or UML (see Figure 1–6). Notice that the names of the modules
at the second and third levels on the structure chart in Figure 1–5 contain
verbs (Read, Compute, Write). The names of the classes represented by the
rectangles in Figure 1–6 do not contain verbs; they are nouns. That is one
clue to a major difference between procedure-oriented design and object-
oriented design. Procedure-oriented design, discussed in Parts 1 and 3 of
this text, emphasizes processes. Object-oriented design, discussed in Part 2,
emphasizes data.
Once the design of a program has been completed, it should be reviewed by a
small group of developers, designers, and analysts. In this way, potential prob-
lems that might have gone unnoticed by the person who designed the program
surface early in the program development cycle. (It is always easier to find some-
one else’s error than to locate your own.) The goal of the review is to ensure that
high-quality software is produced. A good program is reliable, producing what it
is expected to produce. In other words, it works!
Another characteristic of high-quality software is ease of use. As a user,
you want programs to be user friendly. For example, assume you are about to
use a program to compute the average of a series of numbers. You select the
program and cause it to be executed. An empty box appears on the display
Figure 1–6
UML Class Diagram
Customer Order
Header Body
TotalCost LineItem
Introduction to Structured Design 9
screen (see Figure 1–7). What should you do? It is not clear whether you
should type in all of the numbers or only one number at a time. If you type in
all the numbers, should they be separated by spaces or commas? You cannot
tell from the screen. Now, suppose you select and execute another program to
compute an average. This time a message on the screen tells you exactly what
to do (see Figure 1–8). Which program would you rather use? Which one is
user friendly?
Both Figures 1–7 and 1–8 are examples of what is called a graphical user in-
terface (GUI). Graphical user interfaces make it easier for the user to interact
with the computer. They present information in an easy-to-use point-and-click
fashion. For example, once the user enters a number in the box in Figure 1–8,
the user can click the OK button using some type of pointing device. Common
pointing devices include mice, track balls, and touch pads. If the display
screen is a touch screen the user can simply touch the appropriate portion of
the screen lightly with his or her finger. Thus, a GUI minimizes the amount of
typing required by presenting the user with choices from which desired op-
tions can be selected by point-and-click actions.
What about ease of use from a software developer’s point of view? Although
a developer does not use a program in the same sense that a user does, he or she
must be able to understand the steps in the design if modifications are required.
Consider a program that handles income tax calculations based on current tax
laws. What happens when some of these laws change? The program will have
to be modified to reflect the changes. In all probability, the person modifying
the program will not be the one who wrote it originally, so the program logic
must be clear and easy to follow. This textbook discusses methodologies that
are used to design reliable, well-written programs.
Figure 1–7
Sample Input Screen (Not
User-Friendly)
Figure 1–8
Sample Input Screen (User-
Friendly)
10 Chapter 1
Write the Program After the program logic has been developed, it must be
expressed in a programming-language form. The selection of the language de-
pends on the type of application and on the software development tools avail-
able. In the past, scientific and mathematical applications were written in
FORTRAN. Most business applications were written in COBOL because it is
oriented to business use. Then structured languages such as Pascal and C were
used more frequently because they contain language elements that closely parallel
the structures used in program design. A developer who uses these procedure-
oriented language codes the specific steps in the problem-solving process. Pro-
grams in which the primary focus during development is on the processing steps
in a program are called procedure-driven programs.
In addition to this traditional procedural approach, another approach to pro-
gram development using fourth-generation languages (4GLs) has become
common. Most 4GLs are nonprocedural languages; a developer using a 4GL
defines what needs to be done, not how. For example, many popular software
packages (word processors, electronic spreadsheets, and database managers, to
name a few) contain programming statements that can be used alone or in com-
bination (macros and programs) to accomplish a task more efficiently. Even
personal computer (PC) users will find that a strong base in programming logic
can be a tremendous help when using a particular package to implement
decision-making activities.
With the increased use of applications containing graphical user interfaces,
visual languages such as Visual Basic and Visual C++ have become popular.
These languages support the concept of event-driven programming. An event-
driven program is designed to respond to actions that occur when the program
is executing. The actions can be initiated by the computer or by a user. For ex-
ample, when the user clicks the OK button illustrated in Figure 1–8, a click
event is triggered. The software developer must design the logic associated
with that click event. We will see many examples of event-driven programs in the
Visual Basic examples later in this book.
Finally, widespread use of the Internet and the World Wide Web have been
accompanied by rapid growth in the use of the Java programming language.
Java is often described as similar to C++ but without some of C++’s complex
programming constructs. Java and C++ are object-oriented languages. Java
and C++ developers deal with classes and objects, which are instances of those
classes, as discussed in Part 2. More and more Web users are creating their own
display screen designs, or Web pages. Web pages are becoming increasingly
more sophisticated as users learn to use Web-authoring tools. Small segments
of Java code, called Java applets, are commonly embedded in Web pages to
create exciting and dynamic Internet-based applications.
Thus, an understanding of programming logic is important in computer-
related jobs. Some developers write programs using procedural or event-
driven programming languages; some use object-oriented languages; some
use popular software packages as tools; some use previously written pro-
grams as applications. Many users write programs designed for the Web.
This is not to say that anyone can program. Training in program design and
the use of the tools is necessary. The amount of detailed logic that users
need differs according to what they do. Many of the CASE tools include
basic tutorials and online help systems designed to help users, analysts,
designers, and developers use the applications and tools effectively (see
Figure 1–9).
Introduction to Structured Design 11
Figure 1–9
Online Help Screen
Test and Debug the Program In this step, the program is checked for errors
(bugs) and tested with sample data to see whether actual results produced by
the program match expected results. Two main categories of errors may exist in a
program: syntax errors and logic errors. Syntax errors occur when the developer
does not follow the rules of the language he or she is using. For example, many
statements in C must end with semicolons. If the developer forgets to enter a
semicolon, he or she makes a syntax error. Such errors are usually easy to find
and eliminate. A logic error occurs when a step in the program logic is incor-
rect. For example, an averaging program will produce the wrong answer if the
sum of the numbers to be averaged is divided by a number other than the total
count of numbers. Such errors are not always easy to detect. The developer
may need to go back and review the logic created in the second step of the pro-
gram development cycle in order to locate the error.
The program also must be tested thoroughly with computer help using sim-
ple data. Every possible condition should be tested, if feasible. For example, if
a payroll program computes an employee’s pay at time and a half for all hours
worked over 40, the program should be tested using data values that are less
than 40 hours, exactly 40 hours, and greater than 40 hours. The program also
should be designed to handle input data that is invalid. For example, an hours
value that is less than 0 in the payroll example should be detected and noted in
an error message or on an input exception report.
The programs, modules, or classes that make up a system should first be
tested individually to make sure that each works correctly. This is called unit
testing. Then the programs, modules, or classes should be tested together as a
system, either entirely or in part. This is called system testing, or integration.
The more thorough the unit testing is, the more likely that the integration will
proceed successfully. All too often, the unit testing is not adequate, or verbal or
written communications among designers and developers do not occur as
needed. In such situations, the integration of the system components becomes
a tedious, time-consuming sequence of dos and redos.
12 Chapter 1
Evaluate the New System In the sixth step of the SDLC, the new system is
evaluated to determine whether it is meeting the required objectives. If some of
the objectives are not being met, parts of the system may have to be modified.
In any case, a system evaluation report should be prepared for management. It
is likely to serve as one input to a subsequent system development life cycle.
Structured As stated earlier, this text will focus on the second step of the program devel-
Programming opment cycle, developing the program logic. There are many ways to solve a
problem, particularly a complex one. There are usually many correct solutions;
however, some are more desirable than others. In this text, we will adhere to the
principles of a methodology called structured programming, a technique that
has proven to be very effective in solving problems as well as in modifying solu-
tions. The principles of structured programming are fundamental to procedure-
oriented programming (Parts 1 and 3 of this book). They are also relevant to
object-oriented programming (Part 2). That is why we need to look at them
now, at the outset of our discussion of program design.
Structured programming is the ability to express a problem solution using
only three basic patterns of logic. These patterns are referred to as control
structures. The patterns are based on the computer’s ability to execute instruc-
tions in a step-by-step, sequential manner; its ability to make decisions; and its
ability to repeat instructions. The theoretical framework for this approach is
usually traced to a paper by C. Bohm and G. Jacopini, initially published in
Italian in 1965, and then republished in English in 1966.1 Their “structure the-
orem,” which appears in that paper, is generally accepted as a proof of the
claim that the three structures are sufficient for programming. In addition, as
1
C. Bohm and G. Jacopini, “Flow Diagrams, Turing Machines and Languages with Only Two Formation
Rules,” Communications of the ACM 9,5 (May 1966): 366–71.
Introduction to Structured Design 13
early as 1965, Professor E.W. Dijkstra of The Netherlands insisted that programs
using definite structuring were easier to write, read, and verify.2 There is a vast
amount of literature documenting numerous program development projects in
which this does, indeed, appear to be the case. This information is as relevant
today as it was more than 40 years ago.
The following sections will use familiar examples to illustrate the three patterns
of structured programming. They should give you a sense of how each structure
works. The next several chapters will teach you how to use each structure to solve
specific, well-defined problems.
Figure 1–10
SIMPLE SEQUENCE: An 1. Proceed down Main Street for two miles.
Example 2. Turn left on Ocean Drive.
3. Proceed on Ocean Drive for three blocks to the fork.
4. At the fork, take Swan Street to the left.
5. Proceed two blocks.
6. House is second on the left (246 Swan Street).
2
Among Dijkstra’s writings on the subject are “GOTO Statement Considered Harmful,” Letter to the Editor,
Communications of the ACM 11,3 (March 1968): 147–48; “The Structure of the Multiprogramming System,”
Communications of the ACM 11,5 (May 1968): 341–46; and “Structured Programming,” in J.N. Buxton and B.
Randell, eds., Software Engineering Techniques (NATO Scientific Affairs Division: Brussels 39, Belgium, April
1970): 84–88.
14 Chapter 1
Figure 1–11
IFTHENELSE: An Example 1. Proceed down Main Street for two miles.
2. Turn left on Ocean Drive.
3. Proceed on Ocean Drive for three blocks to the fork.
4. IF left turn at fork is blocked THEN
Take right turn at fork onto Eagle Street.
Proceed five blocks.
Turn left at Clifton Avenue.
Proceed three blocks.
Turn left at Circle Drive.
Proceed two blocks.
Turn left at Swan Street.
House is fourth on the right (246 Swan Street).
ELSE
At the fork, take Swan Street to the left.
Proceed two blocks.
House is second on the left (246 Swan Street).
ENDIF
Figure 1–12
DOWHILE: Example 1 Wash hair.
Rinse.
Repeat.
Figure 1–13
DOWHILE: Example 2 1. Wash hair.
2. Rinse hair.
3. Repeat from Step 1.
Figure 1–14
DOWHILE: Example 3 DOWHILE hair is not clean
Wash hair.
Rinse hair.
ENDDO
Introduction to Structured Design 15
and indentation that identify a DOWHILE control structure. The two indented
steps represent what needs to be done, and the first statement (DOWHILE) spec-
ifies the condition necessary to continue processing. We will explore DOWHILE
loops in more detail in Chapters 4 and 5.
structure.
■ Define the terms information processing and information-processing
system.
■ Identify, and use in program design, the terminal interrupt, general I/O,
statements.
■ Distinguish between input and output, and explain why input and output
Introduction A computer is an extremely powerful, fast machine. In less than a second, it can
perform difficult calculations that otherwise would take days, months, or years
to perform. Yet a computer has no magical power; it is only a tool. It cannot
decide to act. It can do only what it is told to do. We can direct the computer to
do what we want by specifying our needs in a discrete step-by-step manner.
Specifically, we can develop an algorithm, which is a step-by-step procedure to
solve a problem.
A computer cannot act independently; it has no intelligence of its own. For
this reason, any algorithm used to direct a computer must be set up to identify
all aspects of a processing situation and to present, in detail, all steps to be
performed.
The algorithm must meet the following requirements:
■ Use operations from only a given set of basic operations
■ Produce the problem solution, or answer, in a finite number of such
operations
17
18 Chapter 2
Figure 2–1
Wake-Up Algorithm
START
GET OUT 1
OF BED
EAT 2
BREAKFAST
BRUSH 3
TEETH
TAKE 4
SHOWER
GET 5
DRESSED
STOP
SIMPLE SEQUENCE Control Structure 19
Data Hierarchy Before we look at our first formal algorithm, we will discuss some terms asso-
ciated with the structure of the data processed by algorithms. The four terms,
file, record, field, and character, make up what is known as the data hierar-
chy. This hierarchy defines how data is structured for use in the algorithms that
we will explore.
FILE A file is a collection of related data or facts. For
example, payroll facts for all employees in a company
form a payroll file. All the data in Figure 2–2
represents a payroll file.
RECORD A record is a collection of data, or facts, about a
single entity in the file. For example, payroll facts
for a single employee in a company form a payroll
record. Each line in Figure 2–2 represents one
payroll record.
FIELD A field is any single piece of data, or fact, about a
single entity (record) in a file. For example, an em-
ployee number might be one of the fields in a payroll
record. The employee number 06337 represents a
field in the first payroll record in Figure 2–2.
20 Chapter 2
Figure 2–2
Data Hierarchy EMPLOYEE EMPLOYEE EMPLOYEE PAY CITY STATE
NUMBER LAST NAME FIRST NAME RATE
Field
Character
Sales Application Consider the sales operations of a large department store. A sales manager del-
egates responsibilities to supervisors in various departments. Each supervisor
Example submits a weekly sales report that is checked against inventory changes and
then used as the basis for figuring commissions. Each supervisor is confronted
with the task of preparing the weekly sales report for his or her department. In
some stores, each supervisor may be asked to develop his or her own proce-
dure. In other stores, the sales manager develops a detailed set of instructions
for each supervisor. In either case, the supervisor starts with the sales data
available (the input), thinks about the weekly sales report that is needed (the
output), and plans how to prepare the report on the basis of the sales data (the
process).
Figure 2–3
Sales Problem (System
Flowchart) WEEKLY WEEKLY
SALES
SALES SALES
DATA
PROGRAM REPORT
SIMPLE SEQUENCE Control Structure 21
Figure 2–4
Sales Problem (Program
Flowchart) START
READ 1
REGSALES,
SALESALES
REGCOM = 2
REGSALES
∗ .06
SALESCOM = 3
SALESALES
∗ .03
PAY =
REGCOM + 4
SALESCOM
+ 400
WRITE 5
PAY
STOP
SIMPLE SEQUENCE Control Structure 23
In Step 1 the word READ is followed by the words REGSALES and SALE-
SALES. These words are names for variables. Variables are data items whose
values may change, or vary, during processing. We create variable names to
represent, or refer to, these data items.
One common mistake is to put specific data right in a program, such as:
READ
$1000,
$3000
This step may tell the reader that the salesperson sold $1000 worth of regular
items and $3000 worth of sale items. These numbers, although correct for one
employee, are likely to need changing each time the program is run because each
employee’s sales data is likely to differ. This problem is handled by the use of
variables. The variable names are place-holders for the specific data values. The
value of a variable can change each time a program is run, or even within one run
of the same program. Think of a mailbox: The address (variable name) is always
the same, but the mail (content) is different every day.
When a variable is used in conjunction with a READ statement, we can as-
sume that the value of the variable is now known to the computer; this is
called a defined value. The use of variables helps to ensure that the program
is data independent, which means that the program will perform the re-
quired processing steps on any set of input data. Figure 2–5 shows a snapshot
of the computer’s memory at this point. We refer to the figure as a memory
diagram. On the left is a list of all the variable names referenced in the algo-
rithm. The boxes on the right represent the actual values that these variable
names refer to in the computer’s memory. At this point REGSALES and
SALESALES represent values that were input in Step 1. Actually, these two
amounts can be any numbers equal to the values of whatever was sold. In our
example, we will assume that the regular sales amount (REGSALES) was
$1000.00 and the reduced sales amount (SALESALES) was $3000.00. Only
the values of REGSALES and SALESALES are defined to the computer at
this point.
In Step 2 of the algorithm, the regular commission is computed. Because
this step involves arithmetic, it is represented by a process symbol, not by an
I/O symbol. In this step, we are illustrating the use of an important fundamen-
tal statement—the assignment statement. This statement is commonly used
Figure 2–5
Sales Problem—Memory REGSALES 1000
Diagram 1
SALESALES 3000
REGCOM
SALESCOM
PAY
24 Chapter 2
Figure 2–6
Sales Problem—Memory REGSALES 1000
Diagram 2
SALESALES 3000
REGCOM 60
SALESCOM
PAY
SIMPLE SEQUENCE Control Structure 25
Figure 2–7
Sales Problem—Memory REGSALES 1000
Diagram 3
SALESALES 3000
REGCOM 60
SALESCOM 90
PAY
Figure 2–8
Sales Problem—Memory REGSALES 1000
Diagram 4
SALESALES 3000
REGCOM 60
SALESCOM 90
PAY 550
must be output from the computer to a printer. We show this operation in Step
5, again using an I/O symbol, with the word WRITE indicating output. Words
such as OUTPUT, PRINT, or DISPLAY also can be used. The current value of
a variable can be output, provided it has been defined, either by being input or
by being computed. We see here that PAY was computed in Step 4.
Throughout this process, several variable names have been introduced. Usually,
variable names are chosen by the software developer or development team. It is a
wise idea to choose descriptive names, such as SALES, instead of S. Descriptive
variable names make the algorithm (in flowchart form and later in programming-
language form) much more self-documenting and easier to read.
Design When the developer is satisfied that all processing steps have been identified and
Verification provided for, the solution algorithm should be verified. The objective is to prevent
errors from occurring, or, if some have already occurred, to detect and eliminate
them as soon as possible. In the past, a major portion of a developer’s time was
spent, not in program design and coding, but rather in debugging and testing.
Today, many computer professionals insist that this need not be the case: A pro-
gram can be written correctly, so that it executes properly the first time it is run. A
careful, early verification of the program design, or solution algorithm, is an es-
sential step in achieving this objective.
Under one approach to verification of design, the design documentation is
distributed to selected reviewers, who are asked to study it and respond within a
set time. Each reviewer is directed to note, individually, any required changes,
additions, and deletions. This approach is known as an informal design review.
Another approach is the use of structured walkthroughs. At this point in
algorithm development, the walkthrough is a formal design review. Here, the
design documentation is made available to several people selected to serve as
members of a review team. After the reviewers have had time to prepare, they
meet together with the developer and a moderator for an established period,
usually about two hours. Each reviewer is expected to have studied the design
26 Chapter 2
Problem:
The International Broadcasting Company wants a computer program that will
accept a temperature reading expressed in Fahrenheit degrees as input, con-
vert the value to Celsius degrees, and provide both the Fahrenheit value and
the Celsius value as output for its hourly weather report.
Solution:
The system flowchart for this application is shown at the left in Figure 2–9. A
program flowchart representation of the solution algorithm, showing how the
problem is to be solved, is given at the right.
The terminal interrupt symbol containing START identifies the beginning of
the program. First, the Fahrenheit value (FARENHT) is read as input. Figure
2–10 shows a memory diagram assuming an input value of 77 degrees.
In the next step, a familiar mathematical formula is executed to convert this
value from Fahrenheit to Celsius. This formula contains three constants (32,
5, and 9) and several mathematical operators. The computer evaluates mathe-
matical expressions in a specific order. All multiplication and division opera-
tions are evaluated first, in a left-to-right order. Next, all addition and
subtraction operations are evaluated, again from left to right. We can place
parentheses around part of an expression if we want the computer to evaluate
that part first. If there are several sets of parentheses, the innermost parenthe-
ses are evaluated first. Figure 2–11 shows how two expressions, one with
parentheses and one without parentheses, are evaluated. Notice that the
results are different.
In Sample Problem 2.1, parentheses are placed around the expression
FARENHT–32 because the subtraction needs to be done before the multipli-
cation. Without the parentheses, first the 32 would have been multiplied by 5,
then that result would have been divided by 9, and then that result would have
SIMPLE SEQUENCE Control Structure 27
Figure 2–9
Temperature Conversion SYSTEM PROGRAM
Problem FLOWCHART FLOWCHART
START
FAHREN-
HEIT READ
TEMPERA- FARENHT
TURES
TEMPERATURE CELSIUS =
CONVERSION (FARENHT
PROGRAM – 32) ∗ 5 / 9
CELSIUS WRITE
TEMPERA- FARENHT,
TURES CELSIUS
STOP
Figure 2–10
Temperature Conversion FARENHT 77
Problem—Memory
Diagram 1 CELSIUS
Figure 2–11
Expression Evaluation Expression—no parentheses Expression—with parentheses
3 + 5 * 2 - 8/4 (3 + 5) * 2 - 8/4
3 + 10 - 8/4 8 * 2 - 8/4
3 + 10 - 2 16 - 8/4
13 - 2 16 - 2
11 14
been subtracted from the current value of the variable FARENHT. This
sequence of operations would have produced an incorrect result.
Figure 2–12 shows a memory diagram after the value of CELSIUS has
been computed correctly.
Figure 2–12
Temperature Conversion FARENHT 77
Problem—Memory
Diagram 2 CELSIUS 25
(continued)
28 Chapter 2
The two temperatures, FARENHT and CELSIUS, are then written as output.
Notice that the value of the variable FARENHT is not computed in the algo-
rithm. However, because it is input, it is known to the computer (look again at
Figure 2–10). At this point, the computer provides two numbers as output
without identifying them. In Chapter 3, we will discuss how to label output
values. Finally, program execution is terminated.
When the computer executes this simple sequence of basic operation, it
will provide the solution to this temperature conversion problem.
Problem:
A major department store needs a program to prepare a monthly bill for each
customer. For simplicity, let us assume that each customer purchases (at most)
one type of item each month. For each purchase, there will be four input values:
customer name, item, quantity purchased, and price. The output will be the cus-
tomer’s monthly bill after a 10 percent discount is taken before taxes, and a 5
percent sales tax is added.
Solution:
The system flowchart to represent this billing problem appears in Figure
2–13. The program flowchart for the billing program to provide the solution
appears in Figure 2–14.
Four values are input in the first step on the program flowchart. Figure
2–15 shows a memory diagram after four specific values have been read during
processing.
Notice that both AMTOD and DISCOUNT must be defined before they
can be used on the right-hand side of an assignment statement. The next two
steps on the flowchart compute these values. The results are illustrated in
Figure 2–16.
Figure 2–13
Billing Problem (System
Flowchart) CUSTOMER
BILLING
DATA
MONTHLY
BILLING
PROGRAM
MONTHLY
BILL
SIMPLE SEQUENCE Control Structure 29
Figure 2–14
Billing Problem (Program
Flowchart) START
READ
NAME,
ITEM, QTY,
PRICE
AMTOD =
QTY *
PRICE
DISCOUNT =
AMTOD
* .10
SUBBILL =
AMTOD -
DISCOUNT
TAXES =
SUBBILL
* .05
BILL =
SUBBILL
+ TAXES
WRITE
NAME,
ITEM,
BILL
STOP
Figure 2–15
Billing Problem—Memory NAME MR. JOHN LEE
Diagram 1
ITEM SCARF
QTY 2
PRICE 19.50
AMTOD
DISCOUNT
SUBBILL
TAXES
BILL
Figure 2–16
Billing Problem—Memory NAME MR. JOHN LEE
Diagram 2
ITEM SCARF
QTY 2
PRICE 19.50
AMTOD 39.00
DISCOUNT 3.90
SUBBILL
TAXES
BILL
and the tax percent (.05). Could we have represented this data by variables in-
stead? (See Exercise 12.) Also, why do you think the billing data was not con-
stant? Can you think of some general criteria that might determine when data
used in a program should be constant and when it should be allowed to vary, that
is, to be represented by variables?
Finally, think about the following questions: What happens within the com-
puter during the stages of input? Processing? Output? Do you think each stage
is necessary in every algorithm? We answer many of these questions, and
more, in future chapters.
Flowcharting A tool that may be provided for the software developer’s use is a flowcharting
Tools template. The template is a plastic or metallic card containing flowcharting
symbols as cutout forms (see Figure 2–17). The developer can easily trace the
outlines of the symbols needed for both system and program flowcharts. The
flowcharting symbols on the template generally comply with the American
National Standards Institute (ANSI) and International Standards Organization
(ISO) recommendations summarized in Appendix A.
SIMPLE SEQUENCE Control Structure 31
1 2 3 4 5 6 7 8 9
9
I N CH ES i n te n th s
PROCESS INPUT/OUTPUT DOCUMENT MANUAL INPUT PREPARATION MERGE
8
COMMUNICATION LINK
7
* Offline Storage
* Command annotation
* Predefined Process EXTRACT
6
MANUAL INPUT
METRIC (1 milimeter = 0.394 inch)
5
* Sort
* Collate
4
CONNECTOR
* Magnetic Tape * Core
TRANSMITTAL
ONLINE STORAGE KEYING TAPE
3
OFFPAGE
PUNCHED CARD PUNCHED TAPE CONNECTOR
TERMINAL INTERRUPT
2
*Composite Symbol (see envelope for details) FLOWCHART TEMPLATE GX20-8020-1 UM 010
I N C H ES i n e i gh th s
1 2 3 5 6 7 8 9
Figure 2–17
Flowcharting Template (Source: Reprint Courtesy of International Business Machines Corporation, copyright
© International Business Machines Corportaion)
Most people start at our website which has the main PG search
facility: www.gutenberg.org.