Just Enough Programming Logic and Design 1st Edition Joyce Farrell 2024 scribd download
Just Enough Programming Logic and Design 1st Edition Joyce Farrell 2024 scribd download
com
https://ebookname.com/product/just-enough-programming-logic-
and-design-1st-edition-joyce-farrell/
OR CLICK BUTTON
DOWNLOAD EBOOK
https://ebookname.com/product/programming-logic-and-design-
comprehensive-6th-edition-joyce-farrell/
ebookname.com
https://ebookname.com/product/java-programming-5th-edition-joyce-
farrell/
ebookname.com
https://ebookname.com/product/object-oriented-programming-using-c-
fourth-edition-joyce-farrell/
ebookname.com
https://ebookname.com/product/electronics-projects-for-dummies-1st-
edition-earl-boysen/
ebookname.com
Theory of Mind in Middle Childhood and Adolescence
Integrating Multiple Perspectives 1st Edition Rory T.
Devine
https://ebookname.com/product/theory-of-mind-in-middle-childhood-and-
adolescence-integrating-multiple-perspectives-1st-edition-rory-t-
devine/
ebookname.com
https://ebookname.com/product/the-oxford-handbook-of-political-
psychology-3rd-edition-leonie-huddy/
ebookname.com
https://ebookname.com/product/pudd-nhead-wilson-webster-s-chinese-
traditional-thesaurus-edition-mark-twain/
ebookname.com
https://ebookname.com/product/biophilia-edward-o-wilson/
ebookname.com
Contemporary Ergonomics and Human Factors 2014 Proceedings
of the international conference on Ergonomics Human
Factors 2014 Southampton UK 7 10 April 2014 1st Edition
Sarah Sharples
https://ebookname.com/product/contemporary-ergonomics-and-human-
factors-2014-proceedings-of-the-international-conference-on-
ergonomics-human-factors-2014-southampton-uk-7-10-april-2014-1st-
edition-sarah-sharples/
ebookname.com
JUST ENOUGH PROGRAMMING
LOGIC AND DESIGN
This page intentionally left blank
JUST ENOUGH
PROGRAMMING
LOGIC AND DESIGN
J O Y C E FA R R E L L
Australia • Brazil • Japan • Korea • Mexico • Singapore • Spain • United Kingdom • United States
Just Enough Programming © 2010 Course Technology, Cengage Learning
Logic and Design
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
any means graphic, electronic, or mechanical, including but not limited to
Executive Editor: Marie Lee
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: Dean Robbins Act, without the prior written permission of the publisher.
Course Technology
20 Channel Center Street
Boston, MA 02210
USA
Printed in Canada
1 2 3 4 5 6 7 14 13 12 11 10
Brief Contents
v
Preface . . . . . . . . . . . . . . . . . . x
CHAPTER 1 An Overview of Computers and Logic . . . . 1
CHAPTER 2 U n d e r s t a n d i n g S t r u c t u re . . . . . . . . . . 3 1
CHAPTER 3 Making Decisions . . . . . . . . . . . . . 65
CHAPTER 4 Looping . . . . . . . . . . . . . . . . 109
CHAPTER 5 Arrays . . . . . . . . . . . . . . . . . 142
CHAPTER 6 Using Methods . . . . . . . . . . . . . 171
CHAPTER 7 O b j e c t - O r i e n t e d P ro g r a m m i n g . . . . . . . 2 0 4
APPENDIX A Understanding Numbering Systems
and Computer Codes. . . . . . . . . . . 224
APPENDIX B Tw o S p e c i a l S t r u c t u re s —c a s e
and do-while . . . . . . . . . . . . . 229
Index . . . . . . . . . . . . . . . . . 235
Contents
vi
Preface . . . . . . . . . . . . . . . . . . x
CHAPTER 2 U n d e r s t a n d i n g S t r u c t u re . . . . . . . . . . 3 1
Understanding Unstructured Spaghetti Code . . . . . . . . . 32
Understanding the Three Basic Structures:
Sequence, Selection, and Loop . . . . . . . . . . . . . . 34
Using the Priming Input. . . . . . . . . . . . . . . . . . . 42
Understanding the Reasons for Structure . . . . . . . . . . 49
CONTENTS
CHAPTER 7 O b j e c t - O r i e n t e d P ro g r a m m i n g . . . . . . . 2 0 4
An Overview of Some Principles of Object-Oriented
Programming . . . . . . . . . . . . . . . . . . . . . 205
Defining a Class . . . . . . . . . . . . . . . . . . . . . 206
Instantiating an Object . . . . . . . . . . . . . . . . . . 208
Understanding Public and Private Access . . . . . . . . . 210 ix
Understanding Inheritance . . . . . . . . . . . . . . . . 213
Understanding Polymorphism . . . . . . . . . . . . . . . 214
Understanding Encapsulation . . . . . . . . . . . . . . . 215
Advantages of Object-Oriented Programming . . . . . . . 217
Review Questions . . . . . . . . . . . . . . . . . . . . 218
Find the Bugs . . . . . . . . . . . . . . . . . . . . . . 220
Exercises . . . . . . . . . . . . . . . . . . . . . . . . 221
APPENDIX B Tw o S p e c i a l S t r u c t u re s —c a s e
and do-while . . . . . . . . . . . . . 229
Index . . . . . . . . . . . . . . . . . 235
Preface
x
Acknowledgments
I would like to thank all of the people who helped to make this book
a reality, especially Dean Robbins, Development Editor, whose atten-
tion to detail has made this a quality textbook. Thanks also to Tricia
Coia, Managing Editor, and Amy Jollymore, Acquisitions Editor, for
their support of this project. I am always grateful to Green Pen QA,
Technical Editors, for their expertise. I also appreciate the helpful
comments from Ann Shaffer throughout this book’s development.
Finally, thanks to Matt Hutchinson and Anupriya Tyagi, who master-
minded the process of turning the manuscript into a printed book.
I thank the reviewers who provided helpful and insightful comments
during the development of this book, including Katie Danko, Grand
Rapids Community College; Dawn Pantaleo, Kalamazoo Valley
Community College; Marie Pullan, Farmingdale State College; and
John Thacher, Gwinnett Technical College. As always, thanks to my
husband, Geoff, for his constant support.
—Joyce Farrell
An Overview
CHAPTER 1
of Computers
and Logic
Understanding Computer
Components and Operations
Hardware and software are the two major components of any com-
puter system.
2 Hardware is the equipment, or the devices, associated with a com-
puter. For a computer to be useful, however, it needs more than
equipment; a computer needs to be given instructions. Just as your
stereo equipment does not do much until you provide music on a CD
or tape, 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 can Software is computer instructions; software tells the hardware what
be classified to do. Software is programs; instruction sets written by program-
as application mers. You can buy prewritten programs (such as Microsoft Word,
software or iTunes, or Halo) that are stored on a disk or that you download from
system soft- the Web. Alternately, you can write your own programs. When you
ware. Application soft-
write software instructions, you are programming.
ware comprises all the
programs you apply to a Together, computer hardware and software accomplish three major
task—word-processing operations:
programs, spreadsheets,
payroll and inventory • Input—Hardware devices that perform input operations include
programs, and even keyboards and mice. Through these devices, data, or facts, enter
games. System software the computer system.
comprises the programs
you use to manage your • Processing—Processing data items may involve organizing them,
computer, including oper- checking them for accuracy, or performing mathematical opera-
ating systems, such as tions on them. The hardware component that performs these sorts
Windows, Linux, or UNIX. of tasks is the central processing unit, or CPU.
• Output—After data items have been processed, the resulting infor-
Data items mation usually is sent to a printer, monitor, or some other output
include all the device so people can view, interpret, and use the results. Sometimes,
text, numbers,
you store output on hardware, such as a disk or flash media. People
and other
information
cannot read data directly from these storage devices, but the devices
that are processed by hold information for later retrieval. When you send output to a stor-
a computer. However, age device, sometimes it later is used as input for another program.
many computer profes-
You write computer instructions in a computer programming
sionals reserve the term
“information” for data language, such as Visual Basic, C#, C++, or Java. Just as some people
items that have been speak English and others speak Japanese, programmers also write
processed. For example, programs in different languages. Some programmers work exclusively
your name, Social in one language, whereas others know several and use the one that
Security number, and seems most appropriate for the task at hand.
hourly pay rate are data
items, but your paycheck No matter which programming language a computer programmer
holds information. uses, the language has rules governing its word usage and punctuation.
Understanding Computer Components and Operations
These rules are called the language’s syntax. If you ask, “How the geet The instruc-
too store do I?” in English, most people can figure out what you proba- tions you write
bly mean, even though you have not used proper English syntax—you are called
have mixed up the word order, misspelled a word, and used the wrong program
code; when
word. However, computers are not nearly as smart as most people;
you write a program,
with a computer, you might as well have asked, “Xpu mxv ot dodnm you are coding the pro- 3
cadf B?” Unless the syntax is perfect, the computer cannot interpret gram. Program code is
the programming language instruction at all. also called source code.
Stir
Add two eggs
Don’t Do It
Add a gallon of gasoline Don’t bake a cake
like this!
Bake at 350 degrees for 45 minutes
Add three cups of flour
The dangerous cake-baking instructions are shown with a warning
icon. You will see this icon when a table or figure contains a program-
ming practice that is being used as an example of what not to do.
Even though the cake-baking instructions use correct English
spelling and grammar, the instructions are out of sequence, some
CHAPTER 1 An Overview of Computers and Logic
must obtain a number for input, and that the computer must obtain
it before multiplying it by 2—remains the same regardless of any spe-
cific input hardware device. The same is true in your daily life. If your
boss says to you, “Get Joe Parker’s phone number for me,” it does not
really matter where the number comes from. For example, you might
look it up in a phone book, consult your cell phone’s record of stored
5
numbers, search for the number on the Internet, or phone a friend
who knows the number.
The step that occurs when the arithmetic is performed to double
originalNumber is an example of a processing step. Mathematical
operations are not the only kind of processing, but they are very typi-
cal. After you write a program, the program can be used on comput-
ers of different brand names, sizes, and speeds. When you make a
phone call, your message gets through whether you use a land line or
a cell phone, and it doesn’t matter whether your cell phone is made
by Motorola, Nokia, or Samsung. Similarly, whether you use an IBM, A computer
Macintosh, Linux, or UNIX operating system, and whether you use system needs
a personal computer that sits on your desk or a mainframe that costs both internal
hundreds of thousands of dollars and resides in a special building in a memory and
university, multiplying by 2 is the same process. The hardware is not external stor-
age. Internal memory
important; the logical process is.
is needed to run the
In the number-doubling program, the Output calculatedAnswer programs, but internal
statement represents an output operation. Within a particular memory is volatile—that
is, its contents are lost
program, this statement could cause the output to appear on the
every time the computer
monitor (which might be a flat panel screen or a cathode-ray tube),
loses power. External
or the output could go to a printer (which could be laser or ink- storage (such as a disk)
jet), or the output could be written to a disk or CD. The logic of the provides a nonvolatile (or
process called Output is the same no matter what hardware device persistent) medium.
you use.
To use a computer program, you must first load it into the computer’s
memory. Memory is the internal storage in a computer, often called Computer
main memory or random access memory (RAM). You might type memory con-
a program’s instructions into memory from the keyboard, or you sists of millions
might load a program that has already been written and stored on a of numbered
disk. Either way, a copy of the instructions must be placed in memory locations
where data can be stored.
before the program can be run.
Every named item such as
Once you have a copy of a program in memory, you want to exe- originalNumber has a
cute, or run, the program. When you run the number-doubling pro- specific numeric address
associated with it. Every
gram, it requires a piece of data—a value for originalNumber. The
time you refer to a named
originalNumber—for example, 8—is also placed in main memory at
item within a program, the
a specific location that the program will call originalNumber. Then, computer retrieves the
and only then, can the calculatedAnswer, in this case 16, be calcu- value at the associated
lated and output. memory location.
CHAPTER 1 An Overview of Computers and Logic
Understand
the problem
will lead from the available input to the desired output. Planning
a program’s logic includes thinking carefully about all the possible
data values a program might encounter and how you want the pro-
gram to handle each scenario. The process of walking through a
program’s logic on paper before you actually write the program is
called desk-checking. You will learn more about planning the logic
8
later; in fact, this book focuses on this crucial step almost exclusively.
Using pseudocode involves writing down all the steps you will use
in a program. Usually, programmers preface their pseudocode state-
ments with a beginning statement like start and end them with a
terminating statement 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 punctua-
tion such as periods 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 capitalize 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, you might prefer, for example, to use the
terms begin and end instead of start and stop. Instead of writing
input originalNumber, many pseudocode developers would write
get originalNumber or read originalNumber. Instead of writing
output calculatedAnswer, many pseudocode developers would
write display calculatedAnswer or write calculatedAnswer.
The point is, the pseudocode statements mean 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 specific syntax will
be required. For example, if you use the C# programming language,
you will code Console.Write(calculatedAnswer);. The capitaliza-
tion, exact use of words, and punctuation are important in the C#
statement; they are not important in the pseudocode statement.
Random documents with unrelated
content Scribd suggests to you:
The Project Gutenberg eBook of The Customs
Lounge
This ebook is for the use of anyone anywhere in the United States
and most other parts of the world at no cost and with almost no
restrictions whatsoever. You may copy it, give it away or re-use it
under the terms of the Project Gutenberg License included with this
ebook or online at www.gutenberg.org. If you are not located in the
United States, you will have to check the laws of the country where
you are located before using this eBook.
Language: English
Nask went off to the kasser dispenser and his place was taken by
Brif, the head Inspector, who had been listening.
"Un-edge yourself, Sprim," smiled Brif, contracting one of his heads.
"I have good news, rare news and fine news. The Four Council
decision just came down to us. Earthers are now to be routed
through Livestock instead of Immigration beginning very soon."
A cheer went up from the little group of Customs and Immigration
officials. The one Livestock Inspector in the lounge groaned in
despair.
Old Inspector Flimp seemed bothered.
"They've made themselves a mistake," he sputtered. "Earthers can
be clever and tricky even after they're altered. Why, I seen them pull
every trick in the book coming through here. Did I ever tell you
about the stunted one with an artificial head who tried to pass
himself off as a rest-park planner? Well, it seems that...."
Two young, but large inspectors sneaked away from the group when
they saw old Flimp was launched into one of his dull yarns again.
Outside the lounge, after a quick look up and down the hall, they
ducked into the robot-cleaner storage closet.
"Boy," gasped the shorter inspector. "I had to get out of there.
Besides the torture of listening to that two-headed monster babble
on and on about how he outwitted earthers when he was still able to
move around, this miserable thing has started to come loose again."
He gave an impatient wrench to his left head, and it wobbled
enough to expose some of the delicate wires that the earth robotic
engineer had labored over so many hours.
The other began tightening straps and buckles for him.
"There," he said finally. "You look like one of the boys again."
Laughing together, the earthers went back into the Customs Lounge.
*** END OF THE PROJECT GUTENBERG EBOOK THE CUSTOMS
LOUNGE ***
Updated editions will replace the previous one—the old editions will
be renamed.
1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside the
United States, check the laws of your country in addition to the
terms of this agreement before downloading, copying, displaying,
performing, distributing or creating derivative works based on this
work or any other Project Gutenberg™ work. The Foundation makes
no representations concerning the copyright status of any work in
any country other than the United States.
1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if you
provide access to or distribute copies of a Project Gutenberg™ work
in a format other than “Plain Vanilla ASCII” or other format used in
the official version posted on the official Project Gutenberg™ website
(www.gutenberg.org), you must, at no additional cost, fee or
expense to the user, provide a copy, a means of exporting a copy, or
a means of obtaining a copy upon request, of the work in its original
“Plain Vanilla ASCII” or other form. Any alternate format must
include the full Project Gutenberg™ License as specified in
paragraph 1.E.1.
• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”
• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.
1.F.
1.F.4. Except for the limited right of replacement or refund set forth
in paragraph 1.F.3, this work is provided to you ‘AS-IS’, WITH NO
OTHER WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.
Please check the Project Gutenberg web pages for current donation
methods and addresses. Donations are accepted in a number of
other ways including checks, online payments and credit card
donations. To donate, please visit: www.gutenberg.org/donate.
Most people start at our website which has the main PG search
facility: www.gutenberg.org.