Programming Logic and Design, Comprehensive [9 ed.] 1337102075, 9781337102070


114 85 2MB

English Pages [52] Year 2017

Report DMCA / Copyright

DOWNLOAD PDF FILE

Table of contents :
Brief Contents
Contents
Preface
Chapter 1 An Overview of Computers and Programming
Understanding Computer Systems
Understanding Simple Program Logic
Understanding the Program Development Cycle
Understanding the Problem
Planning the Logic
Coding the Program
Using Software to Translate the Program into Machine Language
Testing the Program
Putting the Program into Production
Maintaining the Program
Using Pseudocode Statements and Flowchart Symbols
Writing Pseudocode
Drawing Flowcharts
Repeating Instructions
Using a Sentinel Value to End a Program
Understanding Programming and User Environments
Understanding Programming Environments
Understanding User Environments
Understanding the Evolution of Programming Models
Chapter Summary
Key Terms
Exercises
Chapter 2 Elements of High-Quality Programs
Declaring and Using Variables and Constants
Understanding Data Types
Understanding Unnamed, Literal Constants
Working with Variables
Understanding a Declaration’s Data Type
Understanding a Declaration’s Identifier
Assigning Values to Variables
Declaring Named Constants
Performing Arithmetic Operations
The Integer Data Type
Understanding the Advantages of Modularization
Modularization Provides Abstraction
Modularization Helps Multiple Programmers to Work on a Problem
Modularization Allows You to Reuse Work
Modularizing a Program
Declaring Variables and Constants within Modules
Understanding the Most Common Configuration for Mainline Logic
Creating Hierarchy Charts
Features of Good Program Design
Using Program Comments
Choosing Identifiers
Designing Clear Statements
Writing Clear Prompts and Echoing Input
Maintaining Good Programming Habits
Chapter Summary
Key Terms
Exercises
Chapter 3 Understanding Structure
The Disadvantages of Unstructured Spaghetti Code
Understanding the Three Basic Structures
The Sequence Structure
The Selection Structure
The Loop Structure
Combining Structures
Using a Priming Input to Structure a Program
Understanding the Reasons for Structure
Recognizing Structure
Structuring and Modularizing Unstructured Logic
Chapter Summary
Key Terms
Exercises
Chapter 4 Making Decisions
The Selection Structure
Using Relational Comparison Operators
Avoiding a Common Error with Relational Operators
Understanding AND Logic
Nesting AND Decisions for Efficiency
Using the AND Operator
Avoiding Common Errors in an AND Selection
Understanding OR Logic
Writing OR Selections for Efficiency
Using the OR Operator
Avoiding Common Errors in an OR Selection
Understanding NOT Logic
Avoiding a Common Error in a NOT Expression
Making Selections within Ranges
Avoiding Common Errors When Using Range Checks
Understanding Precedence When Combining AND and OR Operators
Understanding the case Structure
Chapter Summary
Key Terms
Exercises
Chapter 5 Looping
Appreciating the Advantages of Looping
Using a Loop Control Variable
Using a Definite Loop with a Counter
Using an Indefinite Loop with a Sentinel Value
Understanding the Loop in a Program’s Mainline Logic
Nested Loops
Avoiding Common Loop Mistakes
Mistake: Failing to Initialize the Loop Control Variable
Mistake: Neglecting to Alter the Loop Control Variable
Mistake: Using the Wrong Type of Comparison When Testing the Loop Control Variable
Mistake: Including Statements Inside the Loop Body that Belong Outside the Loop
Using a for Loop
Using a Posttest Loop
Recognizing the Characteristics Shared ?by Structured Loops
Common Loop Applications
Using a Loop to Accumulate Totals
Using a Loop to Validate Data
Limiting a Reprompting Loop
Validating a Data Type
Validating Reasonableness and Consistency of Data
Comparing Selections and Loops
Chapter Summary
Key Terms
Exercises
Chapter 6
Storing Data in Arrays
How Arrays Occupy Computer Memory
How an Array Can Replace Nested Decisions
Using Constants with Arrays
Using a Constant as the Size of an Array
Using Constants as Array Element Values
Using a Constant as an Array Subscript
Searching an Array for an Exact Match
Using Parallel Arrays
Improving Search Efficiency
Searching an Array for a Range Match
Remaining within Array Bounds
Understanding Array Size
Understanding Subscript Bounds
Using a for Loop to Process an Array
Chapter Summary
Key Terms
Exercises
Chapter 7 File Handling and Applications
Understanding Computer Files
Organizing Files
Understanding the Data Hierarchy
Performing File Operations
Declaring a File Identifier
Opening a File
Reading Data from a File and Processing It
Writing Data to a File
Closing a File
A Program that Performs File Operations
Understanding Control Break Logic
Merging Sequential Files
Master and Transaction File Processing
Random Access Files
Chapter Summary
Key Terms
Exercises
Chapter 8 Advanced Data Handling Concepts
Understanding the Need for Sorting Data
Using the Bubble Sort Algorithm
Understanding Swapping Values
Understanding the Bubble Sort
Sorting Multifield Records
Sorting Data Stored in Parallel Arrays
Sorting Records as a Whole
Other Sorting Algorithms
Using Multidimensional Arrays
Using Indexed Files and Linked Lists
Using Indexed Files
Using Linked Lists
Chapter Summary
Key Terms
Exercises
Chapter 9 Advanced Modularization Techniques
The Parts of a Method
Using Methods with no Parameters
Creating Methods that Require Parameters
Creating Methods that Require Multiple Parameters
Creating Methods that Return a Value
Using an IPO Chart
Passing an Array to a Method
Overloading Methods
Avoiding Ambiguous Methods
Using Predefined Methods
Method Design Issues: Implementation Hiding, Cohesion, and Coupling
Understanding Implementation Hiding
Increasing Cohesion
Reducing Coupling
Understanding Recursion
Chapter Summary
Key Terms
Exercises
Chapter 10 Object-Oriented Programming
Principles of Object-Oriented Programming
Classes and Objects
Polymorphism
Inheritance
Encapsulation
Defining Classes and Creating Class Diagrams
Creating Class Diagrams
The Set Methods
The Get Methods
Work Methods
Understanding Public and Private Access
Organizing Classes
Understanding Instance Methods
Understanding Static Methods
Using Objects
Passing an Object to a Method
Returning an Object from a Method
Using Arrays of Objects
Chapter Summary
Key Terms
Exercises
Chapter 11 More Object-Oriented Programming ?Concepts
Understanding Constructors
Default Constructors
Non-default Constructors
Overloading Instance Methods and Constructors
Understanding Destructors
Understanding Composition
Understanding Inheritance
Understanding Inheritance Terminology
Accessing Private Fields and Methods ?of a Parent Class
Overriding Parent Class Methods in a Child Class
Using Inheritance to Achieve Good Software Design
An Example of Using Predefined Classes: ?Creating GUI Objects
Understanding Exception Handling
Drawbacks to Traditional Error-Handling Techniques
The Object-Oriented Exception-Handling Model
Using Built-in Exceptions and Creating Your Own Exceptions
Reviewing the Advantages of Object-Oriented Programming
Chapter Summary
Key Terms
Exercises
Chapter 12 Event-Driven GUI Programming, Multithreading, and Animation
Understanding Event-Driven Programming
User-Initiated Actions and GUI Components
Designing Graphical User Interfaces
The Interface Should Be Natural and Predictable
The Interface Should Be Attractive, Easy to Read, and Nondistracting
To Some Extent, It’s Helpful If the User Can Customize Your Applications
The Program Should Be Forgiving
The GUI Is Only a Means to an End
Developing an Event-Driven Application
Creating Wireframes
Creating Storyboards
Defining the Storyboard Objects in an Object Dictionary
Defining Connections Between the User Screens
Planning the Logic
Understanding Threads and Multithreading
Creating Animation
Chapter Summary
Key Terms
Exercises
Appendix A Understanding Numbering Systems and Computer Codes
Appendix B Solving Difficult Structuring Problems
Glossary
Index
Recommend Papers

Programming Logic and Design, Comprehensive [9 ed.]
 1337102075, 9781337102070

  • 0 0 0
  • Like this paper and download? You can publish your own PDF file online for free in a few minutes! Sign Up
File loading please wait...
Citation preview

Get complete eBook Order by email at [email protected]

Get complete eBook Order by email at [email protected]

Get Complete eBook Download Link below for instant download

https://browsegrades.net/documents/2 86751/ebook-payment-link-for-instantdownload-after-payment Follow the Instructions for complete eBook Download by email.

Get complete eBook Order by email at [email protected]

NINTH EDITION

PROGRAMMING LOGIC AND DESIGN COMPREHENSIVE

JOYCE FARRELL

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

Get complete eBook Order by email at [email protected]

Get complete eBook Order by email at [email protected]

Brief Contents v

Pref ace ������� ��� �� ��� ��� ��� ���� �� ��� ��� ��� ������ ��� ��� xvi CHAPTER 1

An Over view of Computers and Programmi ng ��� 1

CHAPTER 2

Elem en t s o f Hi gh- Qual i ty Programs ����� ��� ���� ��� 38

CHAPTER 3

U n der s t an din g Structure ����� � ����� ��� ��� ��� ���� ��� 87

CHAPTER 4 M ak in g

Decis i ons ������ ��� ��� ��� � ����� ��� ��� ��� ���� � 124

CHAPTER 5

Lo o pin g ��������� ��� ������ ��� ��� ��� � ����� ��� ��� ��� ���� � 176

CHAPTER 6

Ar r ays �� ��������� ��� ������ ��� ��� ��� � ����� ��� ��� ��� ���� � 227

CHAPTER 7

F ile Han dlin g and Appl i cati ons����� ��� ��� ��� ���� � 272

CHAPTER 8

Advan ced Data Handl i ng Concepts  ��� � �� � �� � �� � �� 321

CHAPTER 9

Advan ced M o dul ari z ati on Techni ques ����� ���� � 366

CHAPTER 10

Object -Or ien t ed Programmi ng ����� ��� ������ ��� �� 420

CHAPTER 11

M o re Object -Ori ented Programmi ng Co n cept s �� ���� ��� �� ��� ��� ��� ���� �� ��� ��� ��� ������ ��� �� 464

CHAPTER 12

Even t -Dr iven G UI Programmi ng, M u lt it h readin g, and Ani mati on�� ��� ��� ������ ��� �� 507

APPENDIX A

U n der s t an din g Numberi ng Sy stems an d Co m pu t er Codes����� ��� ��� ��� ��� ��� ������ ��� �� 539

APPENDIX B

So lvin g Dif f icul t Structuri ng Probl ems  ��� ��� �� 547

Glo s s ar y ��� ������ �� ��� ��� ��� ��� ��� ��� ��� ��� ���� �� ��� �� 556 In dex�� ���� �� ������� ��� �� ��� ��� ��� ���� �� ��� ��� ��� ������ �� 571

Get complete eBook Order by email at [email protected]

Get complete eBook Order by email at [email protected]

Contents vii

Pref ace ������� ��� �� ��� ��� ��� ���� �� ��� ��� ��� ������ ��� ��� xvi CHAPTER 1

An Over view of Computers and Programmi ng ��� 1 Understanding Computer Systems��������������������������������������� 2 Understanding Simple Program Logic ���������������������������������� 5 Understanding the Program Development Cycle��������������������� 8 Understanding the Problem ��������������������������������������������� 8 Planning the Logic ��������������������������������������������������������10 Coding the Program �����������������������������������������������������10 Using Software to Translate the Program into Machine Language ������������������������������������������������������������������11 Testing the Program �����������������������������������������������������12 Putting the Program into Production��������������������������������13 Maintaining the Program������������������������������������������������14 Using Pseudocode Statements and Flowchart Symbols ���������15 Writing Pseudocode ������������������������������������������������������15 Drawing Flowcharts ������������������������������������������������������17 Repeating Instructions ��������������������������������������������������19 Using a Sentinel Value to End a Program�����������������������������20 Understanding Programming and User Environments ������������23 Understanding Programming Environments�����������������������23 Understanding User Environments�����������������������������������25 Understanding the Evolution of Programming Models������������27 Chapter Summary �����������������������������������������������������������28 Key Terms�����������������������������������������������������������������������29 Exercises �����������������������������������������������������������������������32

CHAPTER 2

Elem en t s o f Hi gh- Qual i ty Programs ����� ��� ���� ��� 38 Declaring and Using Variables and Constants�����������������������39 Understanding Data Types ���������������������������������������������39 Understanding Unnamed, Literal Constants�����������������������39 Working with Variables ��������������������������������������������������40 Understanding a Declaration’s Data Type��������������������������41

Get complete eBook Order by email at [email protected]

Get complete eBook Order by email at [email protected] CONTENTS  Understanding a Declaration’s Identifier ���������������������������42 Assigning Values to Variables �����������������������������������������45 Declaring Named Constants��������������������������������������������46 Performing Arithmetic Operations ��������������������������������������47 The Integer Data Type ���������������������������������������������������50 Understanding the Advantages of Modularization �����������������51 Modularization Provides Abstraction��������������������������������52 Modularization Helps Multiple Programmers to Work on a Problem��������������������������������������������������������������53 Modularization Allows You to Reuse Work��������������������������53 Modularizing a Program ������������������������������������������������54 Declaring Variables and Constants within Modules�����������������58 Understanding the Most Common Configuration for Mainline Logic�����������������������������������������������������������60 Creating Hierarchy Charts ���������������������������������������������64 Features of Good Program Design��������������������������������������66 Using Program Comments ���������������������������������������������67 Choosing Identifiers������������������������������������������������������69 Designing Clear Statements��������������������������������������������71 Writing Clear Prompts and Echoing Input��������������������������72 Maintaining Good Programming Habits��������������������������������74 Chapter Summary �����������������������������������������������������������75 Key Terms�����������������������������������������������������������������������76 Exercises �����������������������������������������������������������������������79

viii

CHAPTER 3

U n der s t an din g Structure ����� � ����� ��� ��� ��� ���� ��� 87 The Disadvantages of Unstructured Spaghetti Code��������������88 Understanding the Three Basic Structures ��������������������������90 The Sequence Structure ������������������������������������������������90 The Selection Structure��������������������������������������������������91 The Loop Structure ������������������������������������������������������92 Combining Structures ���������������������������������������������������93 Using a Priming Input to Structure a Program�����������������������99 Understanding the Reasons for Structure��������������������������� 106 Recognizing Structure���������������������������������������������������� 107 Structuring and Modularizing Unstructured Logic ��������������� 110 Chapter Summary ��������������������������������������������������������� 115 Key Terms��������������������������������������������������������������������� 115 Exercises ��������������������������������������������������������������������� 117

Get complete eBook Order by email at [email protected]

Get complete eBook Order by email at [email protected]  CHAPTER 4

CONTENTS

M ak in g Decis ions ������ ��� ��� ��� � ����� ��� ��� ��� ���� � 124 The Selection Structure�������������������������������������������������� 125 Using Relational Comparison Operators ���������������������������� 129 Avoiding a Common Error with Relational Operators��������� 133 Understanding AND Logic������������������������������������������������ 134 Nesting AND Decisions for Efficiency ���������������������������� 137 Using the AND Operator ���������������������������������������������� 139 Avoiding Common Errors in an AND Selection������������������ 141 Understanding OR Logic ������������������������������������������������� 143 Writing OR Selections for Efficiency ������������������������������ 145 Using the OR Operator ������������������������������������������������ 147 Avoiding Common Errors in an OR Selection������������������� 147 Understanding NOT Logic������������������������������������������������ 153 Avoiding a Common Error in a NOT Expression ��������������� 154 Making Selections within Ranges ������������������������������������� 155 Avoiding Common Errors When Using Range Checks ������� 157 Understanding Precedence When Combining AND and OR Operators��������������������������������������������������� 160 Understanding the case Structure ���������������������������������� 163 Chapter Summary ��������������������������������������������������������� 165 Key Terms��������������������������������������������������������������������� 166 Exercises ��������������������������������������������������������������������� 167

CHAPTER 5 Lo o pin g

��������� ��� ������ ��� ��� ��� � ����� ��� ��� ��� ���� � 176

Appreciating the Advantages of Looping ��������������������������� 177 Using a Loop Control Variable������������������������������������������ 179 Using a Definite Loop with a Counter������������������������������ 179 Using an Indefinite Loop with a Sentinel Value ���������������� 181 Understanding the Loop in a Program’s Mainline Logic������ 183 Nested Loops ��������������������������������������������������������������� 185 Avoiding Common Loop Mistakes ������������������������������������ 190 Mistake: Failing to Initialize the Loop Control Variable ������ 190 Mistake: Neglecting to Alter the Loop Control Variable������ 191 Mistake: Using the Wrong Type of Comparison When Testing the Loop Control Variable ������������������������������� 192 Mistake: Including Statements Inside the Loop Body that Belong Outside the Loop ������������������������������������� 194 Using a for Loop ���������������������������������������������������������� 199 Using a Posttest Loop ��������������������������������������������������� 201 Recognizing the Characteristics Shared by Structured Loops ���������������������������������������������������� 203

Get complete eBook Order by email at [email protected]

ix

Get complete eBook Order by email at [email protected] CONTENTS

 Common Loop Applications��������������������������������������������� 205 Using a Loop to Accumulate Totals ������������������������������� 205 Using a Loop to Validate Data��������������������������������������� 209 Limiting a Reprompting Loop ��������������������������������������� 209 Validating a Data Type ������������������������������������������������ 212 Validating Reasonableness and Consistency of Data��������� 213 Comparing Selections and Loops������������������������������������� 214 Chapter Summary ��������������������������������������������������������� 218 Key Terms��������������������������������������������������������������������� 218 Exercises ��������������������������������������������������������������������� 220

x

CHAPTER 6

Ar r ays �� ������ ������ ������ ��� ��� ��� � ����� ��� ��� ��� ���� � 227 Storing Data in Arrays���������������������������������������������������� 228 How Arrays Occupy Computer Memory��������������������������� 228 How an Array Can Replace Nested Decisions��������������������� 231 Using Constants with Arrays ������������������������������������������� 238 Using a Constant as the Size of an Array������������������������ 238 Using Constants as Array Element Values ���������������������� 239 Using a Constant as an Array Subscript ������������������������� 239 Searching an Array for an Exact Match������������������������������ 240 Using Parallel Arrays������������������������������������������������������ 244 Improving Search Efficiency������������������������������������������ 248 Searching an Array for a Range Match������������������������������ 250 Remaining within Array Bounds���������������������������������������� 255 Understanding Array Size��������������������������������������������� 255 Understanding Subscript Bounds ���������������������������������� 255 Using a for Loop to Process an Array������������������������������ 258 Chapter Summary ��������������������������������������������������������� 260 Key Terms��������������������������������������������������������������������� 261 Exercises ��������������������������������������������������������������������� 261

CHAPTER 7

F ile Han dlin g and Appl i cati ons����� ��� ��� ��� ���� � 272 Understanding Computer Files ���������������������������������������� 273 Organizing Files ��������������������������������������������������������� 274 Understanding the Data Hierarchy������������������������������������ 275 Performing File Operations ��������������������������������������������� 277 Declaring a File Identifier��������������������������������������������� 277 Opening a File������������������������������������������������������������ 278 Reading Data from a File and Processing It��������������������� 278 Writing Data to a File��������������������������������������������������� 281 Closing a File������������������������������������������������������������� 281

Get complete eBook Order by email at [email protected]

Get complete eBook Order by email at [email protected] 

CONTENTS

A Program that Performs File Operations������������������������ 282 Understanding Control Break Logic ���������������������������������� 285 Merging Sequential Files ������������������������������������������������ 290 Master and Transaction File Processing ���������������������������� 299 Random Access Files������������������������������������������������������ 308 Chapter Summary ��������������������������������������������������������� 309 Key Terms��������������������������������������������������������������������� 310 Exercises ��������������������������������������������������������������������� 312 CHAPTER 8

Advan ced Data Handl i ng Concepts  ��� � �� � �� � �� � �� 321 Understanding the Need for Sorting Data��������������������������� 322 Using the Bubble Sort Algorithm��������������������������������������� 324 Understanding Swapping Values������������������������������������ 324 Understanding the Bubble Sort ������������������������������������� 325 Sorting Multifield Records ���������������������������������������������� 340 Sorting Data Stored in Parallel Arrays ��������������������������� 340 Sorting Records as a Whole������������������������������������������ 341 Other Sorting Algorithms ������������������������������������������������ 342 Using Multidimensional Arrays������������������������������������������ 345 Using Indexed Files and Linked Lists��������������������������������� 351 Using Indexed Files ���������������������������������������������������� 352 Using Linked Lists ������������������������������������������������������ 353 Chapter Summary ��������������������������������������������������������� 356 Key Terms��������������������������������������������������������������������� 357 Exercises ��������������������������������������������������������������������� 358

CHAPTER 9

Advan ced M o dul ari z ati on Techni ques ����� ���� � 366 The Parts of a Method ��������������������������������������������������� 367 Using Methods with no Parameters ���������������������������������� 368 Creating Methods that Require Parameters������������������������ 371 Creating Methods that Require Multiple Parameters ��������� 377 Creating Methods that Return a Value������������������������������� 379 Using an IPO Chart������������������������������������������������������ 384 Passing an Array to a Method������������������������������������������ 386 Overloading Methods������������������������������������������������������ 394 Avoiding Ambiguous Methods ��������������������������������������� 397 Using Predefined Methods ���������������������������������������������� 400 Method Design Issues: Implementation Hiding, Cohesion, and Coupling��������������������������������������������������������������� 402 Understanding Implementation Hiding ���������������������������� 402 Increasing Cohesion ��������������������������������������������������� 403 Reducing Coupling������������������������������������������������������ 404 Understanding Recursion������������������������������������������������ 405

Get complete eBook Order by email at [email protected]

xi

Get complete eBook Order by email at [email protected] CONTENTS

 Chapter Summary ��������������������������������������������������������� 410 Key Terms��������������������������������������������������������������������� 411 Exercises ��������������������������������������������������������������������� 412

xii

CHAPTER 10

Object -Or ien t ed Programmi ng ����� ��� ������ ��� �� 420 Principles of Object-Oriented Programming������������������������ 421 Classes and Objects ��������������������������������������������������� 421 Polymorphism ������������������������������������������������������������ 424 Inheritance ���������������������������������������������������������������� 426 Encapsulation ������������������������������������������������������������ 426 Defining Classes and Creating Class Diagrams ������������������ 428 Creating Class Diagrams ��������������������������������������������� 430 The Set Methods��������������������������������������������������������� 433 The Get Methods��������������������������������������������������������� 434 Work Methods������������������������������������������������������������ 435 Understanding Public and Private Access��������������������������� 437 Organizing Classes��������������������������������������������������������� 440 Understanding Instance Methods ������������������������������������� 441 Understanding Static Methods������������������������������������������ 447 Using Objects ��������������������������������������������������������������� 448 Passing an Object to a Method ������������������������������������� 449 Returning an Object from a Method ������������������������������� 450 Using Arrays of Objects ���������������������������������������������� 453 Chapter Summary ��������������������������������������������������������� 455 Key Terms��������������������������������������������������������������������� 456 Exercises ��������������������������������������������������������������������� 458

CHAPTER 11

M o re Object -Ori ented Programmi ng Co n cept s �� ������� �� ��� ��� ��� ���� �� ��� ��� ��� ������ ��� �� 464 Understanding Constructors ������������������������������������������� 465 Default Constructors��������������������������������������������������� 466 Non-default Constructors��������������������������������������������� 468 Overloading Instance Methods and Constructors ������������� 469 Understanding Destructors ��������������������������������������������� 472 Understanding Composition��������������������������������������������� 474 Understanding Inheritance ���������������������������������������������� 475 Understanding Inheritance Terminology��������������������������� 478 Accessing Private Fields and Methods of a Parent Class������������������������������������������������������ 481 Overriding Parent Class Methods in a Child Class������������ 486

Get complete eBook Order by email at [email protected]

Get complete eBook Order by email at [email protected] 

CONTENTS

Using Inheritance to Achieve Good Software Design��������� 486 An Example of Using Predefined Classes: Creating GUI Objects ��������������������������������������������������� 487 Understanding Exception Handling������������������������������������ 488 Drawbacks to Traditional Error-Handling Techniques��������� 489 The Object-Oriented Exception-Handling Model���������������� 491 Using Built-in Exceptions and Creating Your Own Exceptions ������������������������������������������������ 493 Reviewing the Advantages of Object-Oriented Programming 494 Chapter Summary ��������������������������������������������������������� 495 Key Terms��������������������������������������������������������������������� 496 Exercises ��������������������������������������������������������������������� 497 CHAPTER 12

Even t -Dr iven G UI Programmi ng, M u lt it h readin g, and Ani mati on�� ��� ��� ������ ��� �� 507 Understanding Event-Driven Programming ������������������������� 508 User-Initiated Actions and GUI Components������������������������ 511 Designing Graphical User Interfaces��������������������������������� 514 The Interface Should Be Natural and Predictable������������� 514 The Interface Should Be Attractive, Easy to Read, and Nondistracting ��������������������������������������������������� 515 To Some Extent, It’s Helpful If the User Can Customize Your Applications������������������������������������������������������ 516 The Program Should Be Forgiving ��������������������������������� 516 The GUI Is Only a Means to an End��������������������������������� 516 Developing an Event-Driven Application������������������������������ 517 Creating Wireframes ��������������������������������������������������� 518 Creating Storyboards��������������������������������������������������� 518 Defining the Storyboard Objects in an Object Dictionary��� 519 Defining Connections Between the User Screens������������� 520 Planning the Logic ������������������������������������������������������ 520 Understanding Threads and Multithreading ������������������������ 525 Creating Animation��������������������������������������������������������� 528 Chapter Summary ��������������������������������������������������������� 531 Key Terms��������������������������������������������������������������������� 532 Exercises ��������������������������������������������������������������������� 533

Get complete eBook Order by email at [email protected]

xiii

Get complete eBook Order by email at [email protected] CONTENTS

xiv



APPENDIX A

U n der s t an din g Numberi ng Sy stems an d Co m pu t er Codes����� ��� ��� ��� ��� ��� ������ ��� �� 539

APPENDIX B

So lvin g Dif f icul t Structuri ng Probl ems  ��� ��� �� 547

Glo s s ar y ��� ��� ��� �� ��� ��� ��� ��� ��� ��� ��� ��� ���� �� ��� �� 556 In dex�� ���� �� ��� ���� ��� �� ��� ��� ��� ���� �� ��� ��� ��� ������ �� 571

Get complete eBook Order by email at [email protected]

Get complete eBook Order by email at [email protected]

CHAPTER

An Overview of Computers and Programming

1

Upon completion of this chapter, you will be able to: Describe computer systems Understand simple program logic List the steps involved in the program development cycle Write pseudocode statements and draw flowchart symbols Use a sentinel value to end a program Understand programming and user environments Describe the evolution of programming models

Get complete eBook Order by email at [email protected]

Get complete eBook Order by email at [email protected] CHAPTER 1

An Overview of Computers and Programming

Understanding Computer Systems

2

A computer system is a combination of all the components required to process and store data using a computer. Every computer system is composed of multiple pieces of hardware and software. •• Hardware is the equipment, or the physical devices, associated with a computer. For example, keyboards, mice, speakers, and printers are all hardware. The devices are manufactured differently for computers of varying sizes—for example, large mainframes, laptops, and very small devices embedded into products such as telephones, cars, and thermostats. The types of operations performed by differentsized computers, however, are very similar. Computer hardware needs instructions that control its operations, including how and when data items are input, how they are processed, and the form in which they are output or stored. •• Software is computer instructions that tells the hardware what to do. Software is programs, which are instruction sets written by programmers. You can buy prewritten programs that are stored on a disk or that you download from the Web. For example, businesses use wordprocessing and accounting programs, and casual computer users enjoy programs that play music and games. Alternatively, you can write your own programs. When you write software instructions, you are programming. This book focuses on the programming process. Software can be classified into two broad types: •• Application software comprises all the programs you apply to a task, such as wordprocessing programs, spreadsheets, payroll and inventory programs, and games. When you hear people say they have “downloaded an app onto a mobile device,” they are simply using an abbreviation of application software. •• System software comprises the programs that you use to manage your computer, including operating systems such as Windows, Linux, or UNIX for larger computers and Google Android and Apple iOS for smartphones. This book focuses on the logic used to write application software programs, although many of the concepts apply to both types of software. Together, computer hardware and software accomplish three major operations in most programs: •• Input: Data items enter the computer system and are placed in memory, where they can be processed. Data items include all the text, numbers, and other raw material that are entered into and processed by a computer. Hardware devices that perform input operations include keyboards and mice. In business, many of the data items used are facts and figures about such entities as products, customers, and personnel. Data, however, also can include items such as images, sounds, and a user’s mouse or finger-swiping movements. •• Processing: Processing data items may involve organizing or sorting them, checking them for accuracy, or performing calculations with them. The hardware component that performs these types of tasks is the central processing unit, or CPU. Some devices, such as tablets and smartphones, usually contain multiple processors, and efficiently using several CPUs requires special programming techniques.

Get complete eBook Order by email at [email protected]

Get complete eBook Order by email at [email protected] Understanding Computer Systems

•• Output: After data items have been processed, the resulting information usually is sent to a printer, monitor, or some other output device so people can view, interpret, and use the results. Programming professionals often use the term data for input items, but use the term information for data items that have been processed and output. Sometimes you place output on storage devices, such as your hard drive, flash media, or a cloud-based device. (The cloud refers to devices at remote locations accessed through the Internet.) People cannot read data directly from these storage devices, but the devices hold information for later retrieval. When you send output to a storage device, sometimes it is used later as input for another program. You write computer instructions in a computer programming language such as Visual Basic, C#, C++, or Java. Just as some people speak English and others speak Japanese, programmers write programs in different languages. Some programmers work exclusively in one language, whereas others know several and use the one that is best suited to the task at hand. The instructions you write using a programming language are called program code; when you write instructions, you are coding the program. Every programming language has rules governing its word usage and punctuation. These rules are called the language’s syntax. Mistakes in a language’s usage are syntax errors. If you ask, “How the geet too store do I?” in English, most people can figure out what you probably mean, even though you have not used proper English syntax—you have mixed up the word order, misspelled a word, and used an incorrect word. However, computers are not nearly as smart as most people; in this case, you might as well have asked the computer, “Xpu mxv ort dod nmcad bf B?” Unless the syntax is perfect, the computer cannot interpret the programming language instruction at all. Figure 1-1 shows how the statement that displays the word Hello on a single line on a computer monitor looks in some common programming languages. Notice that the syntax of some languages require that a statement start with an uppercase letter, while the syntax of others does not. Notice that some languages end statements with a semicolon, some with a period, and some with no ending punctuation at all. Also notice that different verbs are used to mean display, and that some are spelled like their like English word counterparts, while others like cout and System.out.println are not regular English words. The different formats you see are just a hint of the various syntaxes used by languages. Language

Statement that displays Hello on a single line

Java

System.out.println(“Hello);

C++

cout