Loading...

Messages

Proposals

Stuck in your homework and missing deadline? Get urgent help in $10/Page with 24 hours deadline

Get Urgent Writing Help In Your Essays, Assignments, Homeworks, Dissertation, Thesis Or Coursework & Achieve A+ Grades.

Privacy Guaranteed - 100% Plagiarism Free Writing - Free Turnitin Report - Professional And Experienced Writers - 24/7 Online Support

Programmers usually use the word “write” to mean “produce hard copy output.”

17/12/2020 Client: saad24vbs Deadline: 7 Days

PROGRAMMING LOG IC


AND DES IGN


COMPREHENSIVE VERSION


Copyright 2012 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.


Copyright 2012 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.


PROGRAMMING LOGIC


AND DESIGN


COMPREHENSIVE VERSION


JOYCE FARRELL


Australia • Brazil • Japan • Korea • Mexico • Singapore • Spain • United Kingdom • United States


SEV ENTH ED I T I ON


Copyright 2012 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.


Copyright 2012 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.


This is an electronic version of the print textbook. Due to electronic rights restrictions, some third party content may be suppressed. Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. The publisher reserves the right to remove content from this title at any time if subsequent rights restrictions require it. For valuable information on pricing, previous editions, changes to current editions, and alternate formats, please visit www.cengage.com/highered to search by ISBN#, author, title, or keyword for materials in your areas of interest.


Programming Logic and Design,


Comprehensive version, Seventh Edition Joyce Farrell


Executive Editor: Marie Lee


Acquisitions Editor: Brandi Shailer


Senior Product Manager: Alyssa Pratt


Developmental Editor: Dan Seiter


Senior Content Project Manager: Catherine DiMassa


Associate Product Manager: Stephanie Lorenz


Associate Marketing Manager: Shanna Shelton


Art Director: Faith Brosnan


Text Designer: Shawn Girsberger


Cover Designer: Lisa Kuhn/Curio Press, LLC, www.curiopress.com


Image Credit: © Leigh Prather/Veer


Senior Print Buyer: Julio Esperas


Copy Editor: Michael Beckett


Proofreader: Kim Kosmatka


Indexer: Alexandra Nickerson


Compositor: Integra


© 2013 Course Technology, Cengage Learning.


ALL RIGHTS RESERVED. No part of this work covered by the copyright herein may be reproduced, transmitted, stored or used in any form or by any means— graphic, electronic, or mechanical, including but not limited to photocopying, recording, scanning, digitizing, taping, Web distribution, information networks, or information storage and retrieval systems, except as permitted under Section 107 or 108 of the 1976 United States Copyright Act—without the prior written permission of the publisher.


For product information and technology assistance, contact us at Cengage Learning Customer & Sales Support, www.cengage.com/support.


For permission to use material from this text or product, submit all requests online at cengage.com/permissions.


Further permissions questions can be emailed to permissionrequest@cengage.com.


Library of Congress Control Number: 2012930593


ISBN-13: 978-1-111-96975-2


Course Technology 20 Channel Center Street Boston, MA 02210 USA


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.cengagebrain.com


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.


Unless otherwise credited, all art © Cengage Learning, produced by Integra.


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.


Printed in the United States of America


1 2 3 4 5 6 7 16 15 14 13 12


Copyright 2012 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.


Brief Contents


Preface . . . . . . . . . . . . . . . . . . xviii


CHAPTER 1 An Overview of Computers and Programming . 1


CHAPTER 2 Elements of High-Qual ity Programs . . . . . . 37


CHAPTER 3 Understanding Structure . . . . . . . . . . . 83


CHAPTER 4 Making Decisions . . . . . . . . . . . . . 121


CHAPTER 5 Looping . . . . . . . . . . . . . . . . . 169


CHAPTER 6 Arrays . . . . . . . . . . . . . . . . . . 213


CHAPTER 7 Fi le Handl ing and Appl ications . . . . . . . 257


CHAPTER 8 Advanced Data Handl ing Concepts . . . . . 305


CHAPTER 9 Advanced Modularizat ion Techniques . . . . 355


CHAPTER 10 Object-Oriented Programming . . . . . . . 407


CHAPTER 11 More Object-Oriented Programming Concepts . . . . . . . . . . . . . . . . . 449


CHAPTER 12 Event-Driven GUI Programming, Mult ithreading, and Animation . . . . . . . 491


CHAPTER 13 System Modeling with the UML . . . . . . . 523


CHAPTER 14 Using Relat ional Databases . . . . . . . . 555


APPENDIX A Understanding Numbering Systems and Computer Codes . . . . . . . . . . . 601


APPENDIX B Flowchart Symbols . . . . . . . . . . . . 611


APPENDIX C Structures . . . . . . . . . . . . . . . . 612


APPENDIX D Solving Diff icult Structuring Problems . . . . 614


v


Copyright 2012 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.


APPENDIX E Creating Print Charts . . . . . . . . . . . 624


APPENDIX F Two Variat ions on the Basic Structures—case and do-while . . . 626


Glossary . . . . . . . . . . . . . . . . . 633


Index . . . . . . . . . . . . . . . . . . . 653


B R I E F C ON T EN T S


vi


Copyright 2012 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.


Contents


Preface . . . . . . . . . . . . . . . . . . xviii


CHAPTER 1 An Overview of Computers and Programming . 1


Understanding Computer Systems . . . . . . . . . . . . . . . 2 Understanding Simple Program Logic . . . . . . . . . . . . . 5 Understanding the Program Development Cycle . . . . . . . . . 7 Understanding the Problem . . . . . . . . . . . . . . . . . 8 Planning the Logic . . . . . . . . . . . . . . . . . . . . . 9 Coding the Program . . . . . . . . . . . . . . . . . . . . 10 Using Software to Translate the Program into Machine Language . 10 Testing the Program . . . . . . . . . . . . . . . . . . . . 12 Putting the Program into Production . . . . . . . . . . . . . 13 Maintaining the Program . . . . . . . . . . . . . . . . . . 13


Using Pseudocode Statements and Flowchart Symbols . . . . . . 14 Writing Pseudocode . . . . . . . . . . . . . . . . . . . . 15 Drawing Flowcharts . . . . . . . . . . . . . . . . . . . . 16 Repeating Instructions . . . . . . . . . . . . . . . . . . . 17


Using a Sentinel Value to End a Program . . . . . . . . . . . . 19 Understanding Programming and User Environments . . . . . . . 22 Understanding Programming Environments . . . . . . . . . . 22 Understanding User Environments . . . . . . . . . . . . . . 24


Understanding the Evolution of Programming Models . . . . . . . 25 Chapter Summary . . . . . . . . . . . . . . . . . . . . . . 27 Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . 28 Review Questions . . . . . . . . . . . . . . . . . . . . . . 31 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . 33 Find the Bugs . . . . . . . . . . . . . . . . . . . . . . . 35 Game Zone . . . . . . . . . . . . . . . . . . . . . . . . 35 Up for Discussion . . . . . . . . . . . . . . . . . . . . . 36


vii


Copyright 2012 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 2 Elements of High-Qual ity Programs . . . . . . 37


Declaring and Using Variables and Constants . . . . . . . . . . 38 Understanding Unnamed, Literal Constants and their


Data Types . . . . . . . . . . . . . . . . . . . . . . . 38 Working with Variables . . . . . . . . . . . . . . . . . . . 39 Naming Variables . . . . . . . . . . . . . . . . . . . . . 41 Assigning Values to Variables . . . . . . . . . . . . . . . . 42 Understanding the Data Types of Variables . . . . . . . . . . 43 Declaring Named Constants . . . . . . . . . . . . . . . . 44


Performing Arithmetic Operations . . . . . . . . . . . . . . . 45 Understanding the Advantages of Modularization . . . . . . . . . 48 Modularization Provides Abstraction . . . . . . . . . . . . . 49 Modularization Allows Multiple Programmers to


Work on a Problem . . . . . . . . . . . . . . . . . . . 50 Modularization Allows You to Reuse Work . . . . . . . . . . . 50


Modularizing a Program . . . . . . . . . . . . . . . . . . . 51 Declaring Variables and Constants within Modules . . . . . . . 55 Understanding the Most Common Configuration for Mainline Logic . 57


Creating Hierarchy Charts . . . . . . . . . . . . . . . . . . 61 Features of Good Program Design . . . . . . . . . . . . . . . 63 Using Program Comments . . . . . . . . . . . . . . . . . 64 Choosing Identifiers . . . . . . . . . . . . . . . . . . . . 66 Designing Clear Statements . . . . . . . . . . . . . . . . 68 Writing Clear Prompts and Echoing Input . . . . . . . . . . . 69 Maintaining Good Programming Habits . . . . . . . . . . . . 71


Chapter Summary . . . . . . . . . . . . . . . . . . . . . . 72 Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . 73 Review Questions . . . . . . . . . . . . . . . . . . . . . . 76 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . 79 Find the Bugs . . . . . . . . . . . . . . . . . . . . . . . 81 Game Zone . . . . . . . . . . . . . . . . . . . . . . . . 82 Up for Discussion . . . . . . . . . . . . . . . . . . . . . 82


CHAPTER 3 Understanding Structure . . . . . . . . . . . 83


The Disadvantages of Unstructured Spaghetti Code . . . . . . . 84 Understanding the Three Basic Structures . . . . . . . . . . . 86


viii


C O N T E N T S


Copyright 2012 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.


Using a Priming Input to Structure a Program . . . . . . . . . . 95 Understanding the Reasons for Structure . . . . . . . . . . . 101 Recognizing Structure . . . . . . . . . . . . . . . . . . . 102 Structuring and Modularizing Unstructured Logic . . . . . . . . 105 Chapter Summary . . . . . . . . . . . . . . . . . . . . . 110 Key Terms . . . . . . . . . . . . . . . . . . . . . . . . 111 Review Questions . . . . . . . . . . . . . . . . . . . . . 112 Exercises . . . . . . . . . . . . . . . . . . . . . . . . 114 Find the Bugs . . . . . . . . . . . . . . . . . . . . . . 118 Game Zone . . . . . . . . . . . . . . . . . . . . . . . 118 Up for Discussion . . . . . . . . . . . . . . . . . . . . 119


CHAPTER 4 Making Decisions . . . . . . . . . . . . . 121


Boolean Expressions and the Selection Structure . . . . . . . 122 Using Relational Comparison Operators . . . . . . . . . . . 126 Avoiding a Common Error with Relational Operators . . . . . 129


Understanding AND Logic . . . . . . . . . . . . . . . . . 129 Nesting AND Decisions for Efficiency . . . . . . . . . . . . 132 Using the AND Operator . . . . . . . . . . . . . . . . . 134 Avoiding Common Errors in an AND Selection . . . . . . . . 136


Understanding OR Logic . . . . . . . . . . . . . . . . . . 138 Writing OR Decisions for Efficiency . . . . . . . . . . . . . 140 Using the OR Operator . . . . . . . . . . . . . . . . . . 141 Avoiding Common Errors in an OR Selection . . . . . . . . 143


Making Selections within Ranges . . . . . . . . . . . . . . 148 Avoiding Common Errors When Using Range Checks . . . . . 150


Understanding Precedence When Combining AND and OR Operators . . . . . . . . . . . . . . . . . . . . 154


Chapter Summary . . . . . . . . . . . . . . . . . . . . . 157 Key Terms . . . . . . . . . . . . . . . . . . . . . . . . 158 Review Questions . . . . . . . . . . . . . . . . . . . . . 159 Exercises . . . . . . . . . . . . . . . . . . . . . . . . 162 Find the Bugs . . . . . . . . . . . . . . . . . . . . . . 167 Game Zone . . . . . . . . . . . . . . . . . . . . . . . 167 Up for Discussion . . . . . . . . . . . . . . . . . . . . 168


ix


Copyright 2012 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 5 Looping . . . . . . . . . . . . . . . . . 169


Understanding the Advantages of Looping . . . . . . . . . . 170 Using a Loop Control Variable . . . . . . . . . . . . . . . . 171 Using a Definite Loop with a Counter . . . . . . . . . . . . 172 Using an Indefinite Loop with a Sentinel Value . . . . . . . . 173 Understanding the Loop in a Program’s Mainline Logic . . . . 175


Nested Loops . . . . . . . . . . . . . . . . . . . . . . 177 Avoiding Common Loop Mistakes . . . . . . . . . . . . . . 183 Mistake: Neglecting to Initialize the Loop Control Variable . . . 183 Mistake: Neglecting to Alter the Loop Control Variable . . . . 185 Mistake: Using the Wrong Comparison with the Loop Control


Variable . . . . . . . . . . . . . . . . . . . . . . . 186 Mistake: Including Statements Inside the Loop


that Belong Outside the Loop . . . . . . . . . . . . . . 187 Using a for Loop . . . . . . . . . . . . . . . . . . . . . 192 Common Loop Applications . . . . . . . . . . . . . . . . . 194 Using a Loop to Accumulate Totals . . . . . . . . . . . . 194 Using a Loop to Validate Data . . . . . . . . . . . . . . . 198 Limiting a Reprompting Loop . . . . . . . . . . . . . . . 200 Validating a Data Type . . . . . . . . . . . . . . . . . . 202 Validating Reasonableness and Consistency of Data . . . . . 203


Chapter Summary . . . . . . . . . . . . . . . . . . . . . 205 Key Terms . . . . . . . . . . . . . . . . . . . . . . . . 205 Review Questions . . . . . . . . . . . . . . . . . . . . . 206 Exercises . . . . . . . . . . . . . . . . . . . . . . . . 209 Find the Bugs . . . . . . . . . . . . . . . . . . . . . . 211 Game Zone . . . . . . . . . . . . . . . . . . . . . . . 211 Up for Discussion . . . . . . . . . . . . . . . . . . . . 212


CHAPTER 6 Arrays . . . . . . . . . . . . . . . . . . 213


Storing Data in Arrays . . . . . . . . . . . . . . . . . . . 214 How Arrays Occupy Computer Memory . . . . . . . . . . . 214


How an Array Can Replace Nested Decisions . . . . . . . . . 216 Using Constants with Arrays . . . . . . . . . . . . . . . . 224 Using a Constant as the Size of an Array . . . . . . . . . . 224 Using Constants as Array Element Values . . . . . . . . . . 225 Using a Constant as an Array Subscript . . . . . . . . . . 225


x


C ON T E N T S


Copyright 2012 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.


Searching an Array for an Exact Match . . . . . . . . . . . . 226 Using Parallel Arrays . . . . . . . . . . . . . . . . . . . . 230 Improving Search Efficiency . . . . . . . . . . . . . . . . 234


Searching an Array for a Range Match . . . . . . . . . . . . 237 Remaining within Array Bounds . . . . . . . . . . . . . . . 241 Using a for Loop to Process Arrays . . . . . . . . . . . . . 244 Chapter Summary . . . . . . . . . . . . . . . . . . . . . 245 Key Terms . . . . . . . . . . . . . . . . . . . . . . . . 246 Review Questions . . . . . . . . . . . . . . . . . . . . . 246 Exercises . . . . . . . . . . . . . . . . . . . . . . . . 249 Find the Bugs . . . . . . . . . . . . . . . . . . . . . . 253 Game Zone . . . . . . . . . . . . . . . . . . . . . . . 253 Up for Discussion . . . . . . . . . . . . . . . . . . . . 255


CHAPTER 7 Fi le Handl ing and Applicat ions . . . . . . . 257


Understanding Computer Files . . . . . . . . . . . . . . . 258 Organizing Files . . . . . . . . . . . . . . . . . . . . . 259


Understanding the Data Hierarchy . . . . . . . . . . . . . . 260 Performing File Operations . . . . . . . . . . . . . . . . . 261 Declaring a File . . . . . . . . . . . . . . . . . . . . . 261 Opening a File . . . . . . . . . . . . . . . . . . . . . 262 Reading Data from a File . . . . . . . . . . . . . . . . . 262 Writing Data to a File . . . . . . . . . . . . . . . . . . 264 Closing a File . . . . . . . . . . . . . . . . . . . . . . 264 A Program that Performs File Operations . . . . . . . . . . 264


Understanding Sequential Files and Control Break Logic . . . . 267 Understanding Control Break Logic . . . . . . . . . . . . 268


Merging Sequential Files . . . . . . . . . . . . . . . . . . 273 Master and Transaction File Processing . . . . . . . . . . . 281 Random Access Files . . . . . . . . . . . . . . . . . . . 290 Chapter Summary . . . . . . . . . . . . . . . . . . . . . 292 Key Terms . . . . . . . . . . . . . . . . . . . . . . . . 293 Review Questions . . . . . . . . . . . . . . . . . . . . . 295 Exercises . . . . . . . . . . . . . . . . . . . . . . . . 299 Find the Bugs . . . . . . . . . . . . . . . . . . . . . . 302 Game Zone . . . . . . . . . . . . . . . . . . . . . . . 302 Up for Discussion . . . . . . . . . . . . . . . . . . . . 303


xi


Copyright 2012 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 8 Advanced Data Handl ing Concepts . . . . . 305


Understanding the Need for Sorting Data . . . . . . . . . . . 306 Using the Bubble Sort Algorithm . . . . . . . . . . . . . . . 307 Understanding Swapping Values . . . . . . . . . . . . . . 308 Understanding the Bubble Sort . . . . . . . . . . . . . . 309 Sorting a List of Variable Size . . . . . . . . . . . . . . . 318 Refining the Bubble Sort to Reduce Unnecessary


Comparisons . . . . . . . . . . . . . . . . . . . . . 322 Refining the Bubble Sort to Eliminate Unnecessary


Passes . . . . . . . . . . . . . . . . . . . . . . . 324 Sorting Multifield Records . . . . . . . . . . . . . . . . . 326 Sorting Data Stored in Parallel Arrays . . . . . . . . . . . 326 Sorting Records as a Whole . . . . . . . . . . . . . . . 328


Using the Insertion Sort Algorithm . . . . . . . . . . . . . . 329 Using Multidimensional Arrays . . . . . . . . . . . . . . . . 333 Using Indexed Files and Linked Lists . . . . . . . . . . . . . 340 Using Indexed Files . . . . . . . . . . . . . . . . . . . 340 Using Linked Lists . . . . . . . . . . . . . . . . . . . . 342


Chapter Summary . . . . . . . . . . . . . . . . . . . . . 345 Key Terms . . . . . . . . . . . . . . . . . . . . . . . . 346 Review Questions . . . . . . . . . . . . . . . . . . . . . 347 Exercises . . . . . . . . . . . . . . . . . . . . . . . . 350 Find the Bugs . . . . . . . . . . . . . . . . . . . . . . 352 Game Zone . . . . . . . . . . . . . . . . . . . . . . . 353 Up for Discussion . . . . . . . . . . . . . . . . . . . . 354


CHAPTER 9 Advanced Modularization Techniques . . . . 355


Using Methods with No Parameters . . . . . . . . . . . . . 356 Creating Methods that Require Parameters . . . . . . . . . . 358 Creating Methods that Require Multiple Parameters . . . . . 364


Creating Methods that Return a Value . . . . . . . . . . . . 366 Using an IPO Chart . . . . . . . . . . . . . . . . . . . 372


Passing an Array to a Method . . . . . . . . . . . . . . . . 373 Overloading Methods . . . . . . . . . . . . . . . . . . . 380 Avoiding Ambiguous Methods . . . . . . . . . . . . . . . 383


Using Predefined Methods . . . . . . . . . . . . . . . . . 386


xii


C O N T E N T S


Copyright 2012 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.


Method Design Issues: Implementation Hiding, Cohesion, and Coupling . . . . . . . . . . . . . . . . . . . . . . 388 Understanding Implementation Hiding . . . . . . . . . . . 388 Increasing Cohesion . . . . . . . . . . . . . . . . . . . 388 Reducing Coupling . . . . . . . . . . . . . . . . . . . 389


Understanding Recursion . . . . . . . . . . . . . . . . . . 390 Chapter Summary . . . . . . . . . . . . . . . . . . . . . 395 Key Terms . . . . . . . . . . . . . . . . . . . . . . . . 396 Review Questions . . . . . . . . . . . . . . . . . . . . . 397 Exercises . . . . . . . . . . . . . . . . . . . . . . . . 400 Find the Bugs . . . . . . . . . . . . . . . . . . . . . . 404 Game Zone . . . . . . . . . . . . . . . . . . . . . . . 404 Up for Discussion . . . . . . . . . . . . . . . . . . . . 405


CHAPTER 10 Object-Oriented Programming . . . . . . . 407


Principles of Object-Oriented Programming . . . . . . . . . . 408 Classes and Objects . . . . . . . . . . . . . . . . . . . 408 Polymorphism . . . . . . . . . . . . . . . . . . . . . 412 Inheritance . . . . . . . . . . . . . . . . . . . . . . . 413 Encapsulation . . . . . . . . . . . . . . . . . . . . . . 414


Defining Classes and Creating Class Diagrams . . . . . . . . 415 Creating Class Diagrams . . . . . . . . . . . . . . . . . 417 The Set Methods . . . . . . . . . . . . . . . . . . . . 420 The Get Methods . . . . . . . . . . . . . . . . . . . . 421 Work Methods . . . . . . . . . . . . . . . . . . . . . 422


Understanding Public and Private Access . . . . . . . . . . . 424 Organizing Classes . . . . . . . . . . . . . . . . . . . . 428 Understanding Instance Methods . . . . . . . . . . . . . . 429 Understanding Static Methods . . . . . . . . . . . . . . . 434 Using Objects . . . . . . . . . . . . . . . . . . . . . . . 436 Chapter Summary . . . . . . . . . . . . . . . . . . . . . 440 Key Terms . . . . . . . . . . . . . . . . . . . . . . . . 440 Review Questions . . . . . . . . . . . . . . . . . . . . . 442 Exercises . . . . . . . . . . . . . . . . . . . . . . . . 445 Find the Bugs . . . . . . . . . . . . . . . . . . . . . . 447 Game Zone . . . . . . . . . . . . . . . . . . . . . . . 447 Up for Discussion . . . . . . . . . . . . . . . . . . . . 447


xiii


Copyright 2012 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 11 More Object-Oriented Programming Concepts 449


Understanding Constructors . . . . . . . . . . . . . . . . 450 Default Constructors . . . . . . . . . . . . . . . . . . . 450 Nondefault Constructors . . . . . . . . . . . . . . . . . 453 Overloading Methods and Constructors . . . . . . . . . . . 453


Understanding Destructors . . . . . . . . . . . . . . . . . 456 Understanding Composition . . . . . . . . . . . . . . . . . 458 Understanding Inheritance . . . . . . . . . . . . . . . . . 459 Understanding Inheritance Terminology . . . . . . . . . . . 462 Accessing Private Fields and Methods of a Parent Class . . . 465 Using Inheritance to Achieve Good Software Design . . . . . 470


An Example of Using Predefined Classes: Creating GUI Objects . 472 Understanding Exception Handling . . . . . . . . . . . . . . 473 Drawbacks to Traditional Error-Handling Techniques . . . . . 473 The Object-Oriented Exception-Handling Model . . . . . . . . 475 Using Built-in Exceptions and Creating Your Own Exceptions . . 477


Reviewing the Advantages of Object-Oriented Programming . . . 479 Chapter Summary . . . . . . . . . . . . . . . . . . . . . 479 Key Terms . . . . . . . . . . . . . . . . . . . . . . . . 480 Review Questions . . . . . . . . . . . . . . . . . . . . . 482 Exercises . . . . . . . . . . . . . . . . . . . . . . . . 485 Find the Bugs . . . . . . . . . . . . . . . . . . . . . . 489 Game Zone . . . . . . . . . . . . . . . . . . . . . . . 489 Up for Discussion . . . . . . . . . . . . . . . . . . . . 490


CHAPTER 12 Event-Driven GUI Programming, Mult ithreading, and Animation . . . . . . . 491


Understanding Event-Driven Programming . . . . . . . . . . . 492 User-Initiated Actions and GUI Components . . . . . . . . . . 495 Designing Graphical User Interfaces . . . . . . . . . . . . . 498 The Interface Should Be Natural and Predictable . . . . . . . 498 The Interface Should Be Attractive, Easy to Read, and


Nondistracting . . . . . . . . . . . . . . . . . . . . 499 To Some Extent, It’s Helpful If the User Can Customize Your


Applications . . . . . . . . . . . . . . . . . . . . . 500 The Program Should Be Forgiving . . . . . . . . . . . . . 500 The GUI Is Only a Means to an End . . . . . . . . . . . . . 500


xiv


C O N T E N T S


Copyright 2012 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.


Developing an Event-Driven Application . . . . . . . . . . . . 501 Creating Storyboards . . . . . . . . . . . . . . . . . . 502 Defining the Storyboard Objects in an Object Dictionary . . . . 502 Defining Connections Between the User Screens . . . . . . . 503 Planning the Logic . . . . . . . . . . . . . . . . . . . . 504


Understanding Threads and Multithreading . . . . . . . . . . 509 Creating Animation . . . . . . . . . . . . . . . . . . . . 512 Chapter Summary . . . . . . . . . . . . . . . . . . . . . 515 Key Terms . . . . . . . . . . . . . . . . . . . . . . . . 516 Review Questions . . . . . . . . . . . . . . . . . . . . . 517 Exercises . . . . . . . . . . . . . . . . . . . . . . . . 520 Find the Bugs . . . . . . . . . . . . . . . . . . . . . . 520 Game Zone . . . . . . . . . . . . . . . . . . . . . . . 521 Up for Discussion . . . . . . . . . . . . . . . . . . . . 522


CHAPTER 13 System Modeling with the UML . . . . . . . 523


Understanding System Modeling . . . . . . . . . . . . . . . 524 What Is the UML? . . . . . . . . . . . . . . . . . . . . . 525 Using UML Use Case Diagrams . . . . . . . . . . . . . . . 527 Using UML Class and Object Diagrams . . . . . . . . . . . . 533 Using Other UML Diagrams . . . . . . . . . . . . . . . . . 537 Sequence Diagrams . . . . . . . . . . . . . . . . . . . 537 Communication Diagrams . . . . . . . . . . . . . . . . 538 State Machine Diagrams . . . . . . . . . . . . . . . . . 539 Activity Diagrams . . . . . . . . . . . . . . . . . . . . 540 Component and Deployment Diagrams . . . . . . . . . . . 542 Profile Diagrams . . . . . . . . . . . . . . . . . . . . 544 Diagramming Exception Handling . . . . . . . . . . . . . 544


Deciding When to Use the UML and Which UML Diagrams to Use . 546 Chapter Summary . . . . . . . . . . . . . . . . . . . . . 547 Key Terms . . . . . . . . . . . . . . . . . . . . . . . . 548 Review Questions . . . . . . . . . . . . . . . . . . . . . 549 Exercises . . . . . . . . . . . . . . . . . . . . . . . . 552 Find the Bugs . . . . . . . . . . . . . . . . . . . . . . 553 Game Zone . . . . . . . . . . . . . . . . . . . . . . . 553 Up for Discussion . . . . . . . . . . . . . . . . . . . . 554


xv


Copyright 2012 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 14 Using Relat ional Databases . . . . . . . . 555


Understanding Relational Database Fundamentals . . . . . . . 556 Creating Databases and Table Descriptions . . . . . . . . . . 558 Identifying Primary Keys . . . . . . . . . . . . . . . . . . 560 Understanding Database Structure Notation . . . . . . . . . . 563 Working with Records within Tables . . . . . . . . . . . . . 564 Creating Queries . . . . . . . . . . . . . . . . . . . . . 565 Understanding Relationships between Tables . . . . . . . . . 568 Understanding One-To-Many Relationships . . . . . . . . . . 569 Understanding Many-To-Many Relationships . . . . . . . . . 569 Understanding One-To-One Relationships . . . . . . . . . . 573


Recognizing Poor Table Design . . . . . . . . . . . . . . . 574 Understanding Anomalies, Normal Forms, and Normalization . . 576 First Normal Form . . . . . . . . . . . . . . . . . . . . 578 Second Normal Form . . . . . . . . . . . . . . . . . . 579 Third Normal Form . . . . . . . . . . . . . . . . . . . 582


Database Performance and Security Issues . . . . . . . . . . 585 Providing Data Integrity . . . . . . . . . . . . . . . . . 585 Recovering Lost Data . . . . . . . . . . . . . . . . . . 586 Avoiding Concurrent Update Problems . . . . . . . . . . . 586 Providing Authentication and Permissions . . . . . . . . . . 586 Providing Encryption . . . . . . . . . . . . . . . . . . . 587


Chapter Summary . . . . . . . . . . . . . . . . . . . . . 587 Key Terms . . . . . . . . . . . . . . . . . . . . . . . . 589 Review Questions . . . . . . . . . . . . . . . . . . . . . 591 Exercises . . . . . . . . . . . . . . . . . . . . . . . . 594 Find the Bugs . . . . . . . . . . . . . . . . . . . . . . 598 Game Zone . . . . . . . . . . . . . . . . . . . . . . . 598 Up for Discussion . . . . . . . . . . . . . . . . . . . . 598


APPENDIX A Understanding Numbering Systems and Computer Codes . . . . . . . . . . . . 601


APPENDIX B Flowchart Symbols . . . . . . . . . . . . . 611


APPENDIX C Structures . . . . . . . . . . . . . . . . . 612


xvi


C O N T E N T S


Copyright 2012 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.


APPENDIX D Solving Diff icult Structuring Problems . . . . 614


APPENDIX E Creating Print Charts . . . . . . . . . . . . 624


APPENDIX F Two Variat ions on the Basic Structures—case and do-while . . . . . . . . . . . . . . . 626


Glossary . . . . . . . . . . . . . . . . . . 633


Index . . . . . . . . . . . . . . . . . . . . 653


xvii


Copyright 2012 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.


Preface


Programming Logic and Design, Comprehensive, Seventh Edition provides the beginning programmer with a guide to developing structured program logic. This textbook assumes no programming language experience. The writing is nontechnical and emphasizes good programming practices. The examples are business examples; they do not assume mathematical background beyond high school business math. Additionally, the examples illustrate one or two major points; they do not contain so many features that students become lost following irrelevant and extraneous details.


The examples in this book have been created to provide students with a sound background in logic, no matter what programming languages they eventually use to write programs. This book can be used in a stand-alone logic course that students take as a prerequisite to a programming course, or as a companion book to an introductory programming text using any programming language.


Organization and Coverage Programming Logic and Design, Comprehensive, Seventh Edition introduces students to programming concepts and enforces good style and logical thinking. General programming concepts are introduced in Chapter 1. Chapter 2 discusses using data and introduces two important concepts: modularization and creating high-quality programs. It is important to emphasize these topics early so that students start thinking in a modular way and concentrate on making their programs efficient, robust, easy to read, and easy to maintain.


Chapter 3 covers the key concepts of structure, including what structure is, how to recognize it, and most importantly, the advantages to writing structured programs. This chapter’s content is unique among programming texts. The early overview of structure presented here gives students a solid foundation in thinking in a structured way.


Chapters 4, 5, and 6 explore the intricacies of decision making, looping, and array manipulation. Chapter 7 provides details of file handling so students can create programs that process a significant amount of data.


In Chapters 8 and 9, students learn more advanced techniques in array manipulation and modularization. Chapters 10 and 11 provide a thorough yet accessible introduction to concepts and terminology used in object-oriented programming. Students learn about classes, objects, instance and static class members, constructors, destructors, inheritance, and the advantages of object-oriented thinking.


xviii


Copyright 2012 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 12 explores additional object-oriented programming issues: event-driven GUI programming, multithreading, and animation. Chapter 13 discusses system design issues and details the features of the Unified Modeling Language. Chapter 14 is a thorough introduction to important database concepts that business programmers should understand.


The first three appendices give students summaries of numbering systems, flowchart symbols, and structures. Additional appendices allow students to gain extra experience with structuring large unstructured programs, creating print charts, and understanding posttest loops and case structures.


Programming Logic and Design combines text explanation with flowcharts and pseudocode examples to provide students with alternative means of expressing structured logic. Numerous detailed, full-program exercises at the end of each chapter illustrate the concepts explained within the chapter, and reinforce understanding and retention of the material presented.


Programming Logic and Design distinguishes itself from other programming logic books in the following ways:


l It is written and designed to be non-language specific. The logic used in this book can be applied to any programming language.


l The examples are everyday business examples; no special knowledge of mathematics, accounting, or other disciplines is assumed.


l The concept of structure is covered earlier than in many other texts. Students are exposed to structure naturally, so they will automatically create properly designed programs.


l Text explanation is interspersed with both flowcharts and pseudocode so students can become comfortable with these logic development tools and understand their interrelationship. Screen shots of running programs also are included, providing students with a clear and concrete image of the programs’ execution.


l Complex programs are built through the use of complete business examples. Students see how an application is constructed from start to finish instead of studying only segments of programs.


Organization and Coverage


xix


Copyright 2012 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.


Features This text focuses on helping students become better programmers and understand the big picture in program development through a variety of key features. In addition to chapter Objectives, Summaries, and Key Terms, these useful features will help students regardless of their learning style.


The use of flowcharts is excellent. This is a must-have book for learning programming logic before tackling the various languages.


—Lori Selby, University of Arkansas at Monticello


FLOWCHARTS, figures, and illustrations provide


learning experience. the reader with a visual


VIDEO LESSONS help explain important chapter concepts. Videos are part of the text’s enhanced CourseMate site.


NOTES provide additional information— for example, another location in the book that expands on a topic, or a common error to watch out for.


xx


Copyright 2012 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.


TWO TRUTHS & A LIE mini quizzes appear after each chapter section, with answers provided. The quiz contains three statements based on the preceding section of text—two statements are true and one is false. Answers give immediate feedback without “giving away” answers to the multiple-choice questions and programming problems later in the chapter. Students also have the option to take these quizzes electronically through the enhanced CourseMate site.


THE DON’T DO IT ICON illustrates how NOT to do something—for example, having a dead code path in a program. This icon provides a visual jolt to the student,


are NOT to be emulated and making students more careful to recognize problems in existing code.


xxi


Copyright 2012 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.


Assessment


The material is very well written, clearly presented, and up to date. All explanations are very solid, and Farrell’s language is clean, cogent, and easy to follow.


—Judy Woodruff, Indiana University-Purdue University Indianapolis


EXERCISES provide opportunities to practice concepts. These exercises


to explore logical programming concepts. Each exercise can


pseudocode, or both. In addition, instructors can assign the exercises as programming problems to be coded and executed in a particular programming language.


REVIEW QUESTIONS test student comprehension of the major ideas and techniques presented. Twenty questions follow each chapter.


xxii


Copyright 2012 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.


DEBUGGING EXERCISES are included with each chapter because examining programs critically and closely is a crucial programming skill. Students can download these exercises at www.cengagebrain.com and through the CourseMate available for this text. These files are also available to instructors through the Instructor Resources CD and login.cengage.com.


GAME ZONE EXERCISES are included at the end of each chapter. Students can create games as an additional entertaining way to understand key programming concepts.


ESSAY QUESTIONS present personal and ethical issues that programmers must consider. These questions can be used for written assignments or as a starting point for classroom discussion.


xxiii

Homework is Completed By:

Writer Writer Name Amount Client Comments & Rating
Instant Homework Helper

ONLINE

Instant Homework Helper

$36

She helped me in last minute in a very reasonable price. She is a lifesaver, I got A+ grade in my homework, I will surely hire her again for my next assignments, Thumbs Up!

Order & Get This Solution Within 3 Hours in $25/Page

Custom Original Solution And Get A+ Grades

  • 100% Plagiarism Free
  • Proper APA/MLA/Harvard Referencing
  • Delivery in 3 Hours After Placing Order
  • Free Turnitin Report
  • Unlimited Revisions
  • Privacy Guaranteed

Order & Get This Solution Within 6 Hours in $20/Page

Custom Original Solution And Get A+ Grades

  • 100% Plagiarism Free
  • Proper APA/MLA/Harvard Referencing
  • Delivery in 6 Hours After Placing Order
  • Free Turnitin Report
  • Unlimited Revisions
  • Privacy Guaranteed

Order & Get This Solution Within 12 Hours in $15/Page

Custom Original Solution And Get A+ Grades

  • 100% Plagiarism Free
  • Proper APA/MLA/Harvard Referencing
  • Delivery in 12 Hours After Placing Order
  • Free Turnitin Report
  • Unlimited Revisions
  • Privacy Guaranteed

6 writers have sent their proposals to do this homework:

Helping Hand
Best Coursework Help
University Coursework Help
Homework Guru
Top Essay Tutor
Writer Writer Name Offer Chat
Helping Hand

ONLINE

Helping Hand

I am an Academic writer with 10 years of experience. As an Academic writer, my aim is to generate unique content without Plagiarism as per the client’s requirements.

$230 Chat With Writer
Best Coursework Help

ONLINE

Best Coursework Help

I am an Academic writer with 10 years of experience. As an Academic writer, my aim is to generate unique content without Plagiarism as per the client’s requirements.

$230 Chat With Writer
University Coursework Help

ONLINE

University Coursework Help

Hi dear, I am ready to do your homework in a reasonable price.

$232 Chat With Writer
Homework Guru

ONLINE

Homework Guru

Hi dear, I am ready to do your homework in a reasonable price and in a timely manner.

$232 Chat With Writer
Top Essay Tutor

ONLINE

Top Essay Tutor

I have more than 12 years of experience in managing online classes, exams, and quizzes on different websites like; Connect, McGraw-Hill, and Blackboard. I always provide a guarantee to my clients for their grades.

$235 Chat With Writer

Let our expert academic writers to help you in achieving a+ grades in your homework, assignment, quiz or exam.

Similar Homework Questions

Questioon - Huish episcopi primary school - Aws elasticsearch developer guide - The shabbat by marjane satrapi - Auto trail owners club - What outlanders have diamond llama - Impressions of feminism past and present - Romeo and juliet short answer questions - Queen mab speech analysis - +91-8890675453 love marriage problem solution IN Hapur - Nonequivalent control group design - Phan thiet central market - Inches per revolution chart - MyPlate Guidelines EXAMPLE Meal - How to structure an extended response - Experiment 3. Separation of the Components of a Mixture - Discussion- Finance- 1 page – APA Format - Access Control and SSO - Individual Paper 2 - One flew over the cuckoo's nest title meaning - Mother and daughter jewelers breaches its lease - Discussion Topic - What number i am - Cyber security mini project proposal and materials needed - Love em liver cookies coles - Acid base titration lab conclusion - +27737189846®Abu Dhabi WORKING=SAFE MISOPROSTOL & MIFEPRISTONE FOR SALE Abu Dhabi®BUY MIFEGEST KIT, - Wii mega drive emulator - Bev marks queen mattress - Dresser masoneilan control valve handbook - Carlsberg elephant dan murphy - Ionic vs covalent properties - Case Study paper - What happened to carrie pitezel - Module 07 Quiz - Inventory carry cost capsim - The sliders a and b are connected - Poe trial of ascendancy locked door - Determine if bond is polar or nonpolar - Cloud computing - Physics - Basic principles of communication - The power of thinking differently - Newcrest mining annual report 2017 - Community Health SLP 2 - Nursing - The weighted average cost of capital for a wholesaler - Assignment Statistics - Broken hill credit union internet banking - Post- tania - How to make a basic website using notepad - The mediocre teacher tells - Legal aid qld caboolture - Paragraph - Ruby tuesday code of conduct - Transit money law society nsw - As9102 rev c forms - Fsh fes10 electric strike manual - Organizational behavior 18th edition apa citation - IT-project management - What is the mass of a mole of copper - Grand videoke symphony 3 pro song list - Sociological imagination definition c wright mills - MKTG - Three defective electric toothbrushes were accidentally shipped to a drugstore - 133 moverly road south coogee - There is no single accepted definition of authentic leadership. - Francois truffaut auteur theory essay - Bunsen burner non luminous flame - Peer response - Disaster managment - Program files x86 google drive googledrivesync exe - There are many ways to train a fly- 2009 Pitman - The tensile strength of portland cement is being studied - Case study related to international human resource management - Local lion boone north carolina - What happens if you mix hydrogen and oxygen - English 4 1.10 - Discussion on e-bussiness - Adolescent adult sensory profile - Necessary edges arts empathy and education - Nickel and dimed serving in florida - Collision theory gizmo worksheet answers - Balloon circumference vs temperature experiment - The bearing from winston salem north carolina to danville - Bennett model of cultural competence - What are the characteristics of chemical equilibrium - Grand canyon university religion - Ctecs workplace readiness skills practice test - When will cheques be phased out in australia - Sporlan bulletin 10 9 - Quotes 12 angry men - Transas 4000 ecdis user manual - Ccna course in gujranwala - Calculate the five profitability ratios listed above for adrian express - Financial markets and institutions test bank chapter 5 - Laboratory report gram staining exercise 7 - Chris van allsburg illustration style - If capital markets are efficient then - Deere company case study analysis