Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
100% found this document useful (4 votes)
20 views

(eBook PDF) Starting Out with Programming Logic and Design 4thpdf download

Ebook download

Uploaded by

olgothruaia
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (4 votes)
20 views

(eBook PDF) Starting Out with Programming Logic and Design 4thpdf download

Ebook download

Uploaded by

olgothruaia
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 46

(eBook PDF) Starting Out with Programming Logic

and Design 4th download

https://ebookluna.com/product/ebook-pdf-starting-out-with-
programming-logic-and-design-4th/

Download more ebook from https://ebookluna.com


We believe these products will be a great fit for you. Click
the link to download now, or visit ebookluna.com
to discover even more!

Starting Out With Programming Logic and Design, 6e 6th Edition Tony Gaddis
- eBook PDF

https://ebookluna.com/download/starting-out-with-programming-logic-and-
design-6e-ebook-pdf/

(eBook PDF) Starting Out with Python (4th Edition)

https://ebookluna.com/product/ebook-pdf-starting-out-with-python-4th-
edition/

Starting Out with Python 4th Edition (eBook PDF)

https://ebookluna.com/product/starting-out-with-python-4th-edition-ebook-
pdf/

(eBook PDF) Starting Out with Python, Global Edition, 4th Edition

https://ebookluna.com/product/ebook-pdf-starting-out-with-python-global-
edition-4th-edition/
Starting out with Visual C# 4th Edition by Tony Gaddis (eBook PDF)

https://ebookluna.com/product/starting-out-with-visual-c-4th-edition-by-
tony-gaddis-ebook-pdf/

(eBook PDF) Starting out with Visual C# 4th Edition by Tony Gaddis

https://ebookluna.com/product/ebook-pdf-starting-out-with-visual-c-4th-
edition-by-tony-gaddis/

(eBook PDF) Programming Logic & Design Comprehensive 9th Edition

https://ebookluna.com/product/ebook-pdf-programming-logic-design-
comprehensive-9th-edition/

(eBook PDF) Starting out with Visual C# 5th Edition

https://ebookluna.com/product/ebook-pdf-starting-out-with-visual-c-5th-
edition/

Programming Logic and Design, Comprehensive 9th Edition Joyce Farrell -


eBook PDF

https://ebookluna.com/download/programming-logic-and-design-
comprehensive-9th-edition-ebook-pdf/
Preface vii

Contents

Preface xiii
Acknowledgments xxi
About the Author xxiii

Chapter 1 Introduction to Computers and Programming 1


1.1 Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Hardware. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3 How Computers Store Data. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.4 How a Program Works. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
1.5 Types of Software. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Review Questions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

Chapter 2 Input, Processing, and Output 27


2.1 Designing a Program. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
2.2 Output, Input, and Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
2.3 Variable Assignment and Calculations . . . . . . . . . . . . . . . . . . . . . . . . . . 43
IN THE SPOTLIGHT: Calculating Cell Phone Overage Fees. . . . . . . . . . . . . . . . . . . 47
IN THE SPOTLIGHT: Calculating a Percentage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
IN THE SPOTLIGHT: Calculating an Average. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
IN THE SPOTLIGHT: Converting a Math Formula to a
Programming Statement. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
2.4 Variable Declarations and Data Types. . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
2.5 Named Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
2.6 Hand Tracing a Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
2.7 Documenting a Program. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
IN THE SPOTLIGHT: Using Named Constants, Style Conventions,
and Comments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
2.8 Designing Your First Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
Review Questions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Debugging Exercises. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Programming Exercises. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77

vii
viii Contents

Chapter 3 Modules 81
3.1 Introduction to Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
3.2 Defining and Calling a Module. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
IN THE SPOTLIGHT: Defining and Calling Modules. . . . . . . . . . . . . . . . . . . . . . . 90
3.3 Local Variables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
3.4 Passing Arguments to Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
IN THE SPOTLIGHT: Passing an Argument to a Module. . . . . . . . . . . . . . . . . . . 102
IN THE SPOTLIGHT: Passing an Argument by Reference. . . . . . . . . . . . . . . . . . . 108
3.5 Global Variables and Global Constants. . . . . . . . . . . . . . . . . . . . . . . . . 111
IN THE SPOTLIGHT: Using Global Constants. . . . . . . . . . . . . . . . . . . . . . . . . . . 112
Review Questions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
Debugging Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
Programming Exercises. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120

Chapter 4 Decision Structures and Boolean Logic 123


4.1 Introduction to Decision Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
IN THE SPOTLIGHT: Using the If-Then Statement. . . . . . . . . . . . . . . . . . . . . . 130
4.2 Dual Alternative Decision Structures. . . . . . . . . . . . . . . . . . . . . . . . . . . 133
IN THE SPOTLIGHT: Using the If-Then-Else Statement. . . . . . . . . . . . . . . . . 134
4.3 Comparing Strings. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
4.4 Nested Decision Structures. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
IN THE SPOTLIGHT: Multiple Nested Decision Structures . . . . . . . . . . . . . . . . . 146
4.5 The Case Structure. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
IN THE SPOTLIGHT: Using a Case Structure. . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
4.6 Logical Operators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
4.7 Boolean Variables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
Review Questions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
Debugging Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
Programming Exercises. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168

Chapter 5 Repetition Structures 171


5.1 Introduction to Repetition Structures. . . . . . . . . . . . . . . . . . . . . . . . . . 171
5.2 Condition-Controlled Loops: While, Do-While,
and Do-Until ����������������������������������������������������������������������������������� 172
IN THE SPOTLIGHT: Designing a While Loop. . . . . . . . . . . . . . . . . . . . . . . . . . 177
IN THE SPOTLIGHT: Designing a Do-While Loop . . . . . . . . . . . . . . . . . . . . . . 186
5.3 Count-Controlled Loops and the For Statement. . . . . . . . . . . . . . . . . 191
IN THE SPOTLIGHT: Designing a Count-Controlled Loop
with the For Statement. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
5.4 Calculating a Running Total. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
5.5 Sentinels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
IN THE SPOTLIGHT: Using a Sentinel. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
5.6 Nested Loops. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
Contents ix

Review Questions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220


Debugging Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
Programming Exercises. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224

Chapter 6 Functions 227


6.1 Introduction to Functions: Generating Random Numbers . . . . . . . . . . 227
IN THE SPOTLIGHT: Using Random Numbers. . . . . . . . . . . . . . . . . . . . . . . . . . 231
IN THE SPOTLIGHT: Using Random Numbers to Represent Other Values . . . . . 234
6.2 Writing Your Own Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
IN THE SPOTLIGHT: Modularizing with Functions. . . . . . . . . . . . . . . . . . . . . . . 242
6.3 More Library Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251
Review Questions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
Debugging Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264
Programming Exercises. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265

Chapter 7 Input Validation 269


7.1 Garbage In, Garbage Out. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
7.2 The Input Validation Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
IN THE SPOTLIGHT: Designing an Input Validation Loop . . . . . . . . . . . . . . . . . 272
7.3 Defensive Programming. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277
Review Questions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278
Debugging Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280
Programming Exercises. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281

Chapter 8 Arrays 283


8.1 Array Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283
IN THE SPOTLIGHT: Using Array Elements in a Math Expression. . . . . . . . . . . . 290
8.2 Sequentially Searching an Array. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297
8.3 Processing the Contents of an Array. . . . . . . . . . . . . . . . . . . . . . . . . . . 303
IN THE SPOTLIGHT: Processing an Array. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310
8.4 Parallel Arrays. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317
IN THE SPOTLIGHT: Using Parallel Arrays. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318
8.5 Two-Dimensional Arrays. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321
IN THE SPOTLIGHT: Using a Two-Dimensional Array. . . . . . . . . . . . . . . . . . . . 325
8.6 Arrays of Three or More Dimensions. . . . . . . . . . . . . . . . . . . . . . . . . . . 330
Review Questions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331
Debugging Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334
Programming Exercises. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335

Chapter 9 Sorting and Searching Arrays 339


9.1 The Bubble Sort Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 339
IN THE SPOTLIGHT: Using the Bubble Sort Algorithm . . . . . . . . . . . . . . . . . . . . . 346
9.2 The Selection Sort Algorithm. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353
x Contents

9.3 The Insertion Sort Algorithm. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 359


9.4 The Binary Search Algorithm. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365
IN THE SPOTLIGHT: Using the Binary Search Algorithm. . . . . . . . . . . . . . . . . . . . 369
Review Questions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371
Debugging Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375
Programming Exercises. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375

Chapter 10 Files 377


10.1 Introduction to File Input and Output. . . . . . . . . . . . . . . . . . . . . . . . . . . 377
10.2 Using Loops to Process Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389
IN THE SPOTLIGHT: Working with Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 394
10.3 Using Files and Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 398
10.4 Processing Records. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 399
IN THE SPOTLIGHT: Adding and Displaying Records. . . . . . . . . . . . . . . . . . . . . . 404
IN THE SPOTLIGHT: Searching for a Record. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 408
IN THE SPOTLIGHT: Modifying Records. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 410
IN THE SPOTLIGHT: Deleting Records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 414
10.5 Control Break Logic. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 417
IN THE SPOTLIGHT: Using Control Break Logic. . . . . . . . . . . . . . . . . . . . . . . . . . 418
Review Questions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 424
Debugging Exercise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 427
Programming Exercises. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 427

Chapter 11 Menu-Driven Programs 431


11.1 Introduction to Menu-Driven Programs. . . . . . . . . . . . . . . . . . . . . . . . . . 431
11.2 Modularizing a Menu-Driven Program . . . . . . . . . . . . . . . . . . . . . . . . . . 442
11.3 Using a Loop to Repeat the Menu. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 447
IN THE SPOTLIGHT: Designing a Menu-Driven Program . . . . . . . . . . . . . . . . . . . 452
11.4 Multiple-Level Menus. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 466
Review Questions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 472
Programming Exercises. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 474

Chapter 12 Text Processing 477


12.1 Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 477
12.2 Character-by-Character Text Processing . . . . . . . . . . . . . . . . . . . . . . . . . 479
IN THE SPOTLIGHT: Validating a Password . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 482
IN THE SPOTLIGHT: Formatting and Unformatting Telephone Numbers . . . . . . . 488
Review Questions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 493
Debugging Exercises. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 495
Programming Exercises. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 496
Contents xi

Chapter 13 Recursion 499


13.1 Introduction to Recursion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 499
13.2 Problem Solving with Recursion. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 502
13.3 Examples of Recursive Algorithms. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 506
Review Questions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 516
Programming Exercises. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 519

Chapter 14 Object-Oriented Programming 521


14.1 Procedural and Object-Oriented Programming. . . . . . . . . . . . . . . . . . . . 521
14.2 Classes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 525
14.3 Using the Unified Modeling Language to Design Classes . . . . . . . . . . . . 536
14.4 Finding the Classes and Their Responsibilities in a Problem . . . . . . . . . . 539
IN THE SPOTLIGHT: Finding the Classes in a Problem . . . . . . . . . . . . . . . . . . . . . 539
IN THE SPOTLIGHT: Determining Class Responsibilities. . . . . . . . . . . . . . . . . . . . 543
14.5 Inheritance. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 549
14.6 Polymorphism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 557
Review Questions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 561
Programming Exercises. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 565

Chapter 15 GUI Applications and Event-Driven


Programming 567
15.1 Graphical User Interfaces. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 567
15.2 Designing the User Interface for a GUI Program. . . . . . . . . . . . . . . . . . . 570
IN THE SPOTLIGHT: Designing a Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 575
15.3 Writing Event Handlers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 577
IN THE SPOTLIGHT: Designing an Event Handler. . . . . . . . . . . . . . . . . . . . . . . . . 580
Review Questions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 582
Programming Exercises. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 584

Appendix A ASCII/Unicode Characters 587


Appendix B Flowchart Symbols 589
Appendix C Pseudocode Reference 591
Appendix D Converting Decimal Numbers to Binary 603
Appendix E Answers to Checkpoint Questions 605

Index 621
This page intentionally left blank
Preface

W
elcome to Starting Out with Programming Logic and Design, Fourth Edition.
This book uses a language-independent approach to teach programming
­concepts and problem-solving skills, without assuming any previous pro-
gramming experience. By using easy-to-understand pseudocode, flowcharts, and other
tools, the student learns how to design the logic of programs without the complication
of language syntax.
Fundamental topics such as data types, variables, input, output, control structures,
modules, functions, arrays, and files are covered as well as object-oriented concepts,
GUI development, and event-driven programming. As with all the books in the Starting
Out With . . . series, this text is written in clear, easy-to-understand language that stu-
dents find friendly and inviting.
Each chapter presents a multitude of program design examples. Short examples that
highlight specific programming topics are provided, as well as more involved examples
that focus on problem solving. Each chapter includes at least one In the Spotlight sec-
tion that provides step-by-step analysis of a specific problem and demonstrates a solu-
tion to that problem.
This book is ideal for a programming logic course that is taught as a precursor to a
language-specific introductory programming course, or for the first part of an intro-
ductory programming course in which a specific language is taught.

Changes in the Fourth Edition


This book’s pedagogy, organization, and clear writing style remain the same as in the
previous edition. Many improvements have been made, which are summarized here:
● An explanation of read-only memory, or ROM, has been added to Chapter 1.
● The section on secondary storage in Chapter 1 has been updated to include a
discussion on cloud storage.
● IPO charts are now introduced in Chapter 2.
● A discussion about adding parentheses to a math expression to enhance the
expression’s clarity, even when they are unnecessary to get the correct result, has
been added to Chapter 2.
● Off-page connectors for flowcharts have been introduced in Chapter 2, and
added to the flowchart reference in Appendix B.
● A discussion on easier maintenance as an additional benefit of modularization
has been added to Chapter 3.
● A cautionary warning about the use of reference variables has been added to
Chapter 3.
● The section on local variables in Chapter 3 has been expanded with an additional
example and a diagram showing the scope of two variables with the same name
in different modules.
xiii
xiv Preface

● A discussion on how the order of subexpressions in a compound Boolean expres-


sion can affect code efficiency in a language that performs short-circuit evalua-
tion has been added to Chapter 4.
● A discussion on how and why statements that call functions are written differ-
ently than statements that call modules has been added to Chapter 6.
● A discussion on how some of the more popular languages always pass arrays by
reference has been added to Chapter 8.
● A new and better example of control-break processing has been added to
­Chapter 10.
● Appendix D is a new appendix on converting decimal numbers to binary.
● New motivational programming exercises have been added to several chapters.
● The book’s Language Reference Guides have been updated. All of the book’s
Language Reference Guides are available on the book’s resource site at www.
pearsonhighered.com/gaddis.
● A new application, Flowgorithm, is available to support the book. Flowgorithm
is free software that allows you to create programs using simple flowcharts. It
may be downloaded from www.flowgorithm.org.

Brief Overview of Each Chapter


Chapter 1: Introduction to Computers and Programming
This chapter begins by giving a concise and easy-to-understand explanation of how
computers work, how data is stored and manipulated, and why we write programs in
high-level languages.

Chapter 2: Input, Processing, and Output


This chapter introduces the program development cycle, data types, variables, and
sequence structures. The student learns to use pseudocode and flowcharts to design simple
programs that read input, perform mathematical operations, and produce screen output.

Chapter 3: Modules
This chapter demonstrates the benefits of modularizing programs and using the t­ op-down
design approach. The student learns to define and call modules, pass arguments to mod-
ules, and use local variables. Hierarchy charts are introduced as a design tool.

Chapter 4: Decision Structures and Boolean Logic


In this chapter students explore relational operators and Boolean expressions and are
shown how to control the flow of a program with decision structures. The If-Then,
If-Then-Else, and If-Then-Else  If statements are covered. Nested decision struc-
tures, logical operators, and the case structure are also discussed.

Chapter 5: Repetition Structures


This chapter shows the student how to use loops to create repetition structures. The
While, Do-While, Do-Until, and For loops are presented. Counters, accumulators,
running totals, and sentinels are also discussed.
Preface xv

Chapter 6: Functions
This chapter begins by discussing common library functions, such as those for generat-
ing random numbers. After learning how to call library functions and how to use
­values returned by functions, the student learns how to define and call his or her
own functions.

Chapter 7: Input Validation


This chapter discusses the importance of validating user input. The student learns to
write input validation loops that serve as error traps. Defensive programming and the
importance of anticipating obvious as well as unobvious errors is discussed.

Chapter 8: Arrays
In this chapter the student learns to create and work with one- and two-dimensional
arrays. Many examples of array processing are provided including examples illustrat-
ing how to find the sum, average, and highest and lowest values in an array, and how
to sum the rows, columns, and all elements of a two-dimensional array. Programming
techniques using parallel arrays are also demonstrated.

Chapter 9: Sorting and Searching Arrays


In this chapter the student learns the basics of sorting arrays and searching for data
stored in them. The chapter covers the bubble sort, selection sort, insertion sort, and
binary search algorithms.

Chapter 10: Files


This chapter introduces sequential file input and output. The student learns to read
and write large sets of data, store data as fields and records, and design programs
that work with both files and arrays. The chapter concludes by discussing control
break processing.

Chapter 11: Menu-Driven Programs


In this chapter the student learns to design programs that display menus and execute
tasks according to the user’s menu selection. The importance of modularizing a menu-
driven program is also discussed.

Chapter 12: Text Processing


This chapter discusses text processing at a detailed level. Algorithms that step through
the individual characters in a string are discussed, and several common library func-
tions for character and text processing are introduced.

Chapter 13: Recursion


This chapter discusses recursion and its use in problem solving. A visual trace of recur-
sive calls is provided, and recursive applications are discussed. Recursive algorithms
for many tasks are presented, such as finding factorials, finding a greatest common
denominator (GCD), summing a range of values in an array, and performing a binary
search. The classic Towers of Hanoi example is also presented.
xvi Preface

Chapter 14: Object-Oriented Programming


This chapter compares procedural and object-oriented programming practices. It cov-
ers the fundamental concepts of classes and objects. Fields, methods, access specifica-
tion, constructors, accessors, and mutators are discussed. The student learns how to
model classes with UML and how to find the classes in a particular problem.

Chapter 15: GUI Applications and Event-Driven Programming


This chapter discusses the basic aspects of designing a GUI application. Building graphical
user interfaces with visual design tools (such as Visual Studio® or NetBeans™) is discussed.
The student learns how events work in a GUI application and how to write event handlers.

Appendix A: ASCII/Unicode Characters


This appendix lists the ASCII character set, which is the same as the first 127 Unicode
character codes.

Appendix B: Flowchart Symbols


This appendix shows the flowchart symbols that are used in this book.

Appendix C: Pseudocode Reference


This appendix provides a quick reference for the pseudocode language that is used in
the book.

Appendix D: Converting Decimal Numbers to Binary


This appendix uses a simple tutorial to demonstrate how to convert a decimal number
to binary.

Appendix E: Answers to Checkpoint Questions


This appendix provides answers to the Checkpoint questions that appear throughout
the text.

Organization of the Text


The text teaches programming logic and design in a step-by-step manner. Each chap-
ter covers a major set of topics and builds knowledge as students progress through
the book. Although the chapters can be easily taught in their existing sequence, there
is some flexibility. Figure P-1 shows chapter dependencies. Each box represents a
chapter or a group of chapters. A chapter to which an arrow points must be covered
before the chapter from which the arrow originates. The dotted line indicates that
only a portion of Chapter 10 depends on information presented in Chapter 8.

Features of the Text


Concept Statements. Each major section of the text starts with a concept state-
ment. This statement concisely summarizes the main point of the section.
Preface xvii

Figure P-1 Chapter dependencies

Example Programs. Each chapter has an abundant number of complete and partial
example programs, each designed to highlight the current topic. Pseudocode, flow-
charts, and other design tools are used in the example programs.
In the Spotlight. Each chapter has one or more In the
Spotlight case studies that provide detailed, step-by-step
analysis of problems, and show the student how to
solve them.
VideoNotes. A series of online videos, developed specifically for this book, are avail-
able for viewing at www.pearsonhighered.com/gaddis. Icons appear throughout the
VideoNote
text alerting the student to videos about specific topics.

NOTE: Notes appear at several places throughout the text. They are short expla-
nations of interesting or often misunderstood points relevant to the topic at hand.

TIP: Tips advise the student on the best techniques for approaching different pro-
gramming or animation problems.
xviii Preface

WARNING! Warnings caution students about programming techniques or prac-


tices that can lead to malfunctioning programs or lost data.

Programming Language Companions. Many of the pseudocode programs


shown in this book have also been written in Java, Python, and Visual Basic. These
programs appear in the programming language companions that are available at www.
pearsonhighered.com/gaddis. Icons appear next to each pseudocode program that
also appears in the language companions.
Checkpoints. Checkpoints are questions placed at intervals throughout each chapter.
They are designed to query the student’s knowledge quickly after learning a new topic.
Review Questions. Each chapter presents a thorough and diverse set of Review
Questions and exercises. They include Multiple Choice, True/False, Short Answer, and
Algorithm Workbench.
Debugging Exercises. Most chapters provide a set of debugging exercises in which
the student examines a set of pseudocode algorithms and identifies logical errors.
Programming Exercises. Each chapter offers a pool of Programming Exercises
designed to solidify the student’s knowledge of the topics currently being studied.

Supplements
Student Online Resources
Many student resources are available for this book from the publisher. The following
items are available on the Gaddis Series resource page at www.pearsonhighered.
com/gaddis:

• Access to the book’s companion VideoNotes


An extensive series of online VideoNotes have been developed to accompany this
text. Throughout the book, VideoNote icons alert the student to videos covering spe-
cific topics. Additionally, one programming exercise at the end of each chapter has an
accompanying VideoNote explaining how to develop the problem’s solution.

• A
 ccess to the Language Companions for Python, Java, Visual
Basic, and C++
Programming language companions specifically designed to accompany the Fourth
Edition of this textbook are available for download. The companions introduce the
Java™, Python®, Visual Basic®, and C++ programming languages, and correspond
on a chapter-by-chapter basis with the textbook. Many of the pseudocode programs
that appear in the textbook also appear in the companions, implemented in a spe-
cific programming language.

• A link to download the Flowgorithm flowcharting application


Flowgorithm is a free application, developed by Devin Cook at Sacramento State
University, which allows you to create programs using simple flowcharts. It supports
Preface xix

the flowcharting conventions used in this textbook, as well as several other standard
conventions. When you create a flowchart with Flowgorithm, you can execute the
program and generate Gaddis Pseudocode. You can also generate source code in Java,
Python, Visual Basic, C#, Ruby, JavaScript, and several other languages. For more
information, see www.flowgorithm.org.

• A link to download the RAPTOR flowcharting environment


RAPTOR is a flowchart-based programming environment developed by the US Air
Force Academy Department of Computer Science.

Instructor Resources
The following supplements are available to qualified instructors only:
• Answers to all of the Review Questions
• Solutions for the Programming Exercises
• PowerPoint® presentation slides for each chapter
• Test bank
Visit the Pearson Instructor Resource Center ( http://www.pearsonhighered.
com/irc) or send an email to computing@aw.com for information on how to access
them.
This page intentionally left blank
Discovering Diverse Content Through
Random Scribd Documents
either side, in a large wavy mass, and lay upon the broad white
collar that turned over his narrow and close-buttoned cassock. His
upper lip was shaded with a small quantity of the blackest hair; a
tuft of the same filled the indenture beneath his under lip, and thus
the pallor of his long thin cheeks, and of his high forehead, appeared
more deadly. His pale hand, which held a closed volume, was
pressed against his bosom; and he stood so very motionless, and so
deeply absorbed in meditation, that a less healthy fancy than that of
Juxon would have deemed him some ghostly visitant, permitted,
during the witching hour of night, to haunt that holy place. The slow
heavy tread of a man in arms, turning the distant corner of the
church, warned Juxon to conceal himself; and passing quickly round
under the altar window to the other side, he came to the small door
of the chancel. It stood ajar; and pushing it gently, he entered, and
again closing it, found himself in the presence of the venerable
stranger, and alone with him. He turned at the sound of Juxon’s
entrance without abruptness or discomposure; but as the light
showed him an unknown face, and an athletic form in garments
dusty with travel, he demanded of him in a tone of authority how he
had come thither, and what was his business.
“But yesterday,” said Juxon, “I might have asked that question
of thee: but a day has brought forth a sudden change; and the
shepherd must enter his own fold by stealth, or with the permission
of others.”
“I understand thee. Thou art the minister of this place: thou
hast nothing to fear: I have watched in thy sanctuary, and no one
has violated or defiled it. You may go home to your own chamber in
peace: it was allotted as my quarter by the commander of this band,
but I resolved to keep a vigil here, and would continue it alone. Go,
and God speed thee. We shall march in the morning; and I pray that
you may be kept safe in all future visitations.”
“March!—have I heard aright? Does such an one as you march
in the ranks of rebels? Does a minister of the Gospel preach war, and
that against the Lord’s anointed?”
“Against the person of the King we do not war: we fight against
his false and dangerous friends. The sword of the Lord is with us,
and it must go through the land; but we march as mourners to the
field of blood. Witness these walls that have heard my groanings,
yon tomb that has been watered by my tears. In that tomb lie the
ashes of my grandfather, who was the first Protestant of his race.
The Reformation, begun by the godly men of that day, has never yet
been completed: that work remains for us.”
“Miserable delusion!” cried Juxon aloud; “miserable delusion! Is
it by kindling and diffusing the false fire of fanaticism? is it in arms?
is it by a path of blood that you move? Then is your work a work of
evil, and your light darkness.”
“So called they the work and the light of our forefathers, when
they led them forth, and burned them at the stake. You have a zeal
for the church, but not according to knowledge. I have heard of you
from your friend Cuthbert Noble.”
“Call him not friend of mine: give to all things their right names.
He that stands in arms against his king is a traitor; and if he had lain
in my heart’s core, I would pluck him out, and cast him from me.”
At this moment, a man in arms entered the small door of the
chancel, and taking off his steel cap, advanced towards Juxon, and
put forth his hand:—it was Cuthbert Noble. He was much altered in
his appearance: his countenance was severe and sad, but resolute
withal; and his corslet, with the broad buff girdle beneath, had
produced a change in his aspect and bearing incredible to the mind
of Juxon, if he had not witnessed it with his eyes.
“Do you refuse my hand? do you turn away from me, Juxon? I
have not deserved this at your hands,” said Cuthbert, still stretching
forth his hand. Juxon turned his face and looked steadfastly upon
him.
“Cuthbert,” said he with a slow, grave utterance, “I and your
revered father are upon the same side, and we fill the same sacred
office. Even now, perhaps, his fold is broken into by some furious
zealots, who will not show the same lingering compunction which is
now, for a moment, sparing mine. No, Cuthbert, the hand that
grasps a sword, and wields it against my king, shall never more be
clasped with friendliness by me.”
Cuthbert’s hand fell down, and his knees shook, and his whole
frame trembled with the strength of his emotion.
“Dare to repent,” added Juxon, observing the internal struggle,
—“dare to repent. Here in the house of God, and before the altar of
God, lay down the arms of rebellion, and go home to comfort, and, if
possible, to protect, your father and mother.”
What effect this appeal might have had upon Cuthbert had he
been alone with Juxon, and subjected to all the strength with which
it would have been urged home upon him, we cannot say; for it was
no sooner spoken, than the Puritan chaplain fell upon his knees, and
poured forth a prayer for the cause of the Parliament, which, by its
solemn tone and intense fervency, commanded the silent and
breathless attention of both. It was evident that this petitioner, with
an enthusiasm that has been felt perhaps in common by some of
every creed and party under the cope of heaven, identified the
particular cause which he himself had espoused with that of truth
and of God. Before he had uttered the first brief sentence of
adoration, Cuthbert had fallen down in a lowly posture of worship,—
and his spirit was soon carried by his leader in prayer whithersoever
he would.
Juxon leaned his head against the wall where he stood, and
kept his eyes fixed on them. He had before him one of those rarely
endowed beings on whom gifts without measure had been poured:—
for a quarter of an hour he listened, with a painful and solemn
interest, to a flow of real eloquence. The petitions touched in
succession every point at issue. They justified, as by divine
command, the appeal to arms, and proclaimed the end thereof to be
reformation and peace. They recognised the sacredness of the King’s
anointed head; and they ended in a prophetic anticipation of the
days of millennial glory, and the universal reign of a manifested God.
In the course of the prayer he had not forgotten to pray for all
mankind, and especially for all those enemies who now stood
opposed to them in the present contest, and again in a yet more
especial manner for the near and dear relations, whose wishes and
entreaties they were now called on to resist, and whose hearts they
might now afflict. Painting this resistance most truly, as the highest
order of self-denial, he urged it as a sacred duty, and a sacrifice well
pleasing to the Lord.
Juxon saw by the expression of Cuthbert’s mouth the new and
stronger resolutions he was making;—nor did it surprise him to see
that, when they rose together at the conclusion of this fervent
prayer, the chaplain took Cuthbert by the hand, that was passively
yielded, and led him forth from the church without either of them
addressing one word to himself. They looked at him, indeed, with
seriousness, if not with compassion, and they moved their lips, but
the whispered ejaculations of their hearts had no voice; and their
departing footsteps were the only sounds that broke the silence of
the place and of the hour.
CHAP. VII.
Thy friend put in thy bosom: wear his eyes,
Still in thy heart, that he may see what’s there.
Herbert.

By the care of Juxon, who had written to an old college servant of


Christ-church, a lodging was provided for Sir Oliver Heywood and his
party in a retired street at Oxford; and, having accomplished their
journey without any accident, they took possession of their new
abode early in September. The house though small was clean, and
by no means incommodious; but a part of it was already in the
occupation of another lodger. However, he was a quiet man, and was
employed all day in his labours, as a painter of coloured glass,
having been engaged to execute the windows of a chapel then
building at University College. Moreover, he was a Fleming, and
spoke English so imperfectly that he could not understand what was
said to him, except on the most common and necessary matters. But
Sir Oliver, who suffered great pain with his gout, and was really
mortified at not being able to join the army, began to show a
fretfulness and discontent at his position, very trying to Katharine
and all about him. He was perpetually finding fault with every thing,
and every person; and his anger at the language of alarm and
doubt, which he found prevalent at Oxford, knew no bounds. The
secret of all this peevishness lay deeper than his gouty sufferings;
for, upon the very day of his arrival, he read in “The Perfect Diurnall”
that two squadrons of horse under Sergeant Major Francis Heywood
had joined the head quarters of the Lord Say, who was the Lord
Lieutenant of Oxfordshire, and stoutly opposed to the King. Nor was
this the simple announcement; but the news went on to say, that
these horsemen were well accoutred, and disciplined very exactly
under the training of Sergeant Major Heywood, a soldier of excellent
promise, who had served under the great Gustavus, and was nearly
allied to Sir Oliver Heywood of Milverton House, Warwickshire. The
old gentleman cursed and swore heartily when he first read this
aloud to Katharine and the Lamberts, but he never afterwards
named the subject or Francis; however, the thought lay rankling
under every expression of anger which daily events drew forth.
The cloisters and the groves on the banks of the Isis were no
longer the solemn and silent haunts of peaceful, meditative scholars,
—they now echoed to the harsh beating of drums; and the young
students, instead of pacing slowly in their black academic habits,
were dressed in the garb of soldiers, with blue scarfs suspended
across their bodies from the shoulder, and with pikes in their hands.
At a convocation held in July the University had, with one consent,
voted his Majesty all the public money which they had in hand; and,
besides this, several of the colleges, as well as private persons, sent
in their plate and their ready money also. This act of the
convocation, however, was immediately pronounced null and void by
Parliament; and any such actions were forbidden for the future. This
proclamation pronounced those criminal who had been concerned in
advising this diversion of the treasures of their colleges, and
commanded each society to secure its own. It also ordered that the
Dean of Christ-church, the President of Magdalen, and the Provost of
Queen’s, who had been most active in this matter, should be seized
and brought to the bar of the House to answer for their conduct. But
this could not be accomplished, because the High Sheriff and the
Mayor of Oxford, acting upon the commission of array, had called
out the train bands of the city, and the scholars had taken arms. To
support this show of resistance, Sir John Biron marched to Oxford,
and took possession of it for the King. Sir John had with him about
five hundred horse; and thus he secured the contributions for the
King’s service, and was enabled, though compelled soon afterwards
to retire from the city, to carry a considerable portion of it safe to the
royal quarters. It was during the period that Oxford was thus held
for the King that Sir Oliver and his family came there to reside. They
were visited by several of the stanch Royalists and their ladies: these
visitors consisted for the most part of the troubled and alarmed
clergy, who were connected by office with the University. To some of
their wives it was a delight to have a new family into whose ears
they might pour all the bitter scandals against the Nonconformists,
and others of the Parliament party, which they eagerly collected and
minutely detailed. Nor was there any deficiency in spirit; for some of
them went so far as to declare that, happen what might, nothing
should make them stir from their own houses; that their husbands
might run away if they pleased; but no canting Roundheads should
ever eject them from their own arm chairs; and generally concluded
by observing, that if their husbands were not such a poor set of
creatures, they would drive the odious Lord Say out of the county;
and that, as it was, there was no chance whatever of his getting into
the city. Then they reckoned upon their fingers,—the five hundred
men of Sir John Biron, and the four hundred pikes of the train
bands, and the two hundred scholars with pikes, and the fifty
doctors and masters of arts that had horses and pistols, and spirit to
use them. Mrs. Veal, the lady of a doctor of Christ-church, was the
most eloquent in these invectives, and the most exact in these
calculations; and, to her honour be it spoken, she kept her word;
and when the day of trial came, and Oxford was abandoned to the
Parliamentarians, she would not accompany her husband, but
remained obstinately fixed in her own arm-chair, and most
successfully defended her house with a scolding tongue.
Amid all these bitter and uncongenial elements Katharine
Heywood was perplexed and troubled, and found little rest for her
spirit, save that which passeth man’s understanding, and that which
she found in the affectionate friendship of Jane Lambert. Nothing
more cruelly jarred her feelings than the language in which, by
common consent, almost all around her seemed to talk of the
Parliamentarians. Her own loyalty was firm and pure, but it was of
an exalted character; and under no circumstances could it have
stooped to so low a hatred of the persons, or to so mean an opinion
of the motives, of the King’s enemies, as that generally entertained
and daily expressed before her. She did every thing which it was in
the power of a daughter to do for the comfort and tranquillity of her
father, but her efforts were not very successful.
As soon as it became known that the Lord Say was advancing
upon Oxford with superior forces, and that Sir John Biron was about
to retire upon Worcester, nothing would pacify Sir Oliver but an
endeavour to accompany that movement. However, the means of
conveyance were not to be obtained for money, and he was
compelled to remain where he was.
On the morning of the 14th of September the greatest possible
consternation prevailed in the city; and early in the forenoon a
strong body of horse, headed by the Lord Say, marched into the
University. His first act was to cause all the colleges to be strictly
searched for plate and arms, and to secure whatever plate had not
been hidden, or despatched under escort of Sir John Biron. He also
broke into their treasuries, but found little in them, save in that of
Christ-church, where, after a day’s labour, and breaking through a
plastered wall to an iron chest, he discovered in the bottom thereof
a groat and a halter;—a pleasant surprize for a man of his morose
temper, and provided for him by the wit of the doctor’s lady who has
been mentioned above.
It was not till late in the evening of the 14th that Sir Oliver and
his daughter got any distinct information of what was passing. Their
street was retired; not a soldier entered it; nor a sound, save that of
trumpets from the market-place, reached their anxious ears. The
worthy knight forbade Katharine and Jane to leave the house, and
old Philip the butler was not at all inclined to volunteer any inquiries.
But the Flemish painter had been absent from a very early hour; on
which account Sir Oliver charitably pronounced him a Dutch
Presbyterian rascal, who had been acting as a spy for the
Roundheads. It was in vain that Katharine observed that he was an
artist employed by a college upon its chapel windows: the knight
pronounced him a foreign scoundrel, gone to join in the plunder.
Towards evening the painter returned, and came to their apartment,
to tell them in his broken stammering language, with tears in his
eyes, that a fine young officer, who spoke Dutch, had saved all his
painted glass from being broken, and had put a safeguard at all the
chapels.
The officer of whom the painter related this was no other than
Francis Heywood. The throb of Katharine’s heart told her so at the
instant, but it was confirmed to her afterwards.
It was the habit of Katharine and Jane to walk daily in the
afternoon in the fair meadows on the banks of the river to which
they had quick and easy access, from the retired quarter in which
they dwelt, without passing through any of the more public streets
of the town.
Their friendship had strengthened under all the adverse and
anxious circumstances of the times; and the piety of Jane had
become so deepened by her constant intercourse with Katharine that
their spirits held communion together in these walks, whether they
conversed or were silent.
The arrival of the Parliamentarians put a stop to these rambles
for the first few days after they took possession of the city; but, by
the strictness of their discipline and the quietness of their behaviour
towards the citizens of the place, confidence was soon restored, and
the people went about the streets and ventured into the
neighbouring fields as usual.
It was on a fine glowing afternoon, about a week after the
entrance of Lord Say’s horsemen, that Katharine and Jane went forth
together to their favourite meadow. The sun had such power, that,
instead of keeping the open and more public path, they confined
themselves to a short and shady promenade beneath a few stately
trees on the margin of the river. No one chanced to be in the
meadow but themselves: the glorious hues of autumn were already
beginning to tinge the tops of trees, and the hedge rows were
blushing with bird fruit. In the distance, too, on the low hills, the
naked and yellow stubble of the corn fields told that the harvest was
ended, and the season of the last fruits was come. The friends were
carrying forward their hopes and fears as to the future, and were
comforting themselves with the vain hope that, even yet, before the
fall of the leaf, some change for the better might come.
It was rumoured that, through the Lord Falkland, who was
highly considered by many of the Parliamentary leaders, and who
was known to be a Royalist far too generous and right minded to
wish well to despotic government, expectations of a reconciliation
between the King and his Commons were yet entertained. But
Katharine, though she wished not to depress her more sanguine
friend, could not but fear that these rumours of peace were
begotten rather of the wishes of those who uttered them than of
their judgment: that too many resolute men were on horseback and
in arms; and that they would assuredly draw the sword and try the
issues of battle. As thus they walked together, softened by the
repose and beauty of the scene around, Jane ventured upon a
theme which seldom or ever passed her lips. She spoke of love, and
of its many crosses; but withal that better it was to love, though life
were passed separated from the object of it, than not to feel so
sweet an influence.
“It is true, Jane,” said Katharine mournfully, “it is most true; yet
misplaced affections do greatly wear the spirit.”
“You do not mean misplaced, dear cousin, surely; but fixed
hopelessly on one most worthy of our love. Such is your destiny, for
Francis is a noble being. You never told me of the first growth of
your attachment: how did it first spring? what moved you? did he
woo you? Love, they say, does ever beget love; but yet, methinks,
nothing of outward show or manliest beauty, no mere words of
admiration, would have availed to fix any man firmly in a heart like
yours.”
“Albeit the subject pains me, I will tell thee, Jane. Yes, he is
worthy of a woman’s love. From his first youth he has been, as thou
knowest well, a soldier. It was his father’s pride to see him, when
but a stripling, not so tall as the boy Arthur, intrusted with a
standard in the day of battle. In his first field, a bullet struck him
down upon his knees; still, with uplifted arms, he waved his ensign,
and strove to keep his place in the close ranks, till faint with pain he
fell: but, even then, he grasped the colour staff so firmly, that a
stout lieutenant, who, for its safety, took it from him, was forced to
bruise his boyish hands ere they would let go their sacred charge.
On the morrow, as he lay upon his bloody straw in the field hospital,
the great Gustavus gave him the Iron Cross of Honour, and with it a
commission in his guard of horse,—rewards for this first proof of
constancy.
“This, at our table, his father did relate with such a pride as
doth become a parent. Francis the while coloured a little, and looked
down for modesty, but said nothing. I felt hot tears upon my cheek;
and when they drank his health, and I did pledge him, he saw those
tears. Such was the birth of our attachment; and kind words, and
gentle actions, and books, and music, and many things, did feed it,
till it grew to love; and then came trouble. Thou knowest well the
bitter feud that blazed forth suddenly between our fathers. The
quarrel was of public matters; for my father never knew nor even
guessed our love. ’Tis long, long past that blissful season: let’s talk
of it no more.”
“Thank you, dear Katharine,” said Jane, with swimming eyes
and faltering tongue; “I feel for you. I love you so, it was but right to
tell me this. You wish for silence; be it so: for the world I would not
pain you.” Their conversation dropped, and they gave themselves to
the grave thoughts it had called up.
It had been late in the afternoon before they came out: evening
drew on; and the sun was setting in a fine autumnal sky, when they
were surprised by the sound of approaching voices: as they became
more distinct, Jane observed that they must proceed from some
persons on the river or on the opposite bank. They went to a tree
near the water, and there, concealed by the overhanging branches,
they saw a small boat dropping down the stream, and gliding to the
very bank on which they stood. It came close, but neither of the
persons in it stepped ashore: they continued talking in a foreign
language, and comparing a distant outline of ground with papers
which they held in their hands. Their backs were towards Katharine
and Jane; but these almost immediately recognised one as the
Flemish painter, who lodged in the same house with them, the other
was a tall stately man in a helmet and a buff war coat, with an
orange scarf depending from his right shoulder. The heart of
Katharine throbbed violently. Under the disguise of a foreign tongue,
she was not certain about the voice; but she thought it was that of
Francis. He lifted his helmet from his head, and turned to catch the
evening breeze. It was her cousin. Her cheek became deadly pale:
she trembled excessively, and caught at the trunk of the tree for
support. A sudden exclamation from Jane Lambert gave alarm.
Francis sprang instantly to the shore, eager to quiet any fears which
he might innocently have caused. Nor was the surprise greater to
them than to himself, when he saw Katharine Heywood and Jane
Lambert before him.
CHAP. VIII.
My true love hath my heart, and I have his.
Sidney.

When the painter, who followed Francis Heywood from the boat, saw
the affecting situation of the parties, and discerned clearly, at a
glance, that they were not only well acquainted with each other, but
apparently suffering from very deep and embarrassing emotions, he
withdrew. There was a something in this meeting of Francis and
Katharine, under present circumstances, so mournful, that Jane
Lambert, from a sympathy with their sacred feelings, walked to a
short distance from the spot, and left them together. They stood
alone; they were both pale; both trembling; the greeting of the
embrace, and the utterance of each other’s names, had already
passed in the presence of Jane. Silence was first broken by Francis.
“I bless the leading of my better angel for bringing me here this
evening. Oh, Katharine, how I have longed for an interview with
you: that blessing is come; it is a boon of Providence; we meet
again: once more I have heard your lips pronounce my name; once
more I gaze upon the living form which has dwelt with me as a
bright shadow; the comfort of my wanderings and toils; the
cherished idol of my lonesome hours; the household image that
gladdened my solitary lodging. Nay, do not seek to silence me; do
not avert your eyes from me; let not displeasure cloud your glorious
brow. I have loved you long, faithfully, and well. I hail this meeting
as an omen of Heaven’s favour: the hour will come that I may dare
ask thee of thy father without shame or fear.”
“Francis, that hour will never come; it was an unhappy hour in
which we first became acquainted.”
“Oh, say not so: from that sweet hour I date a happiness that
cannot die: why look so grave upon me? You cannot quench my
love:—it grew as does the flower which with a constancy looks ever
to the sun. Thou art a sun to me; and till I am cut down by the swift
scythe of war, or wither in decay, thus will it ever be.”
“Oh, Francis, who hath bewitched you? Why did you return to
England? Why did you leave the green savannas of the New World,
and your pure and peaceful labours, for scenes of strife and of
rebellion? Away—afar—separated from me by the stormy ocean—
and too painfully conscious myself that the course of our true love
never could run smooth—I had a comfort in your absence. We are
divided in time, was my thought—but not for ever. There is a high
and distant region, where we may meet again to part no more;—but
now, Francis—it is not too late—put off these arms—return to
America. Here, now, let us take our last and long farewell. Return to
your father, and give me back the happiness of knowing that he who
loves me may be, without a crime, beloved again. Yes—I have loved
you well. I have known that our union was impossible:—to honour a
parent’s will is the duty of a child. But hear me, Francis:—if all such
obstacles were by some magic power removed,—if fortune crowned
you with all those gifts of wealth and station, which so generally
secure the consent of fathers and the approval of the world,—never
would I accept the hand of that man, who had raised his sword
against his king.”
While Katharine was delivering this earnest, fond remonstrance,
with all the tenderness of a woman, but with a tone of decision
towards the close at once solemn and mournful, Francis stood pale
and attentive, with eyes that regarded her countenance admiringly.
He remained silent for more than a minute after she had ceased
from speaking, as if waiting to hear more; then coming closer to her,
he took her hand, gazed on her with intense affection, and slowly
answered,—
“With due deliberation of my deed, I took commission of the
Parliament, and swore the oath prescribed; and I will keep it,
Katharine, as a soldier should. You live at home, as women use to
do, and therefore cannot know the truth of this great nation’s
quarrel with its king. Spirits there are in this bad world, to whom
their own security and peace bring no content, while any are
debarred a common right. Such lead the people now; such, standing
up in arms, demand for all, true liberty—and I am with them. The
anointed head of England’s king is to me, as to you, sacred, and I
would defend it from the swords of my own squadrons should any
dare to threaten it. You have none near you, my beloved Katharine,
to show you things in their true colours, and your gentle and pious
fear of evil misleads your better judgment.”
“Francis, I thank God I live apart from the great world, and hear
but little of their teaching; but this I know, nations are families, and
he that slays his brother in any quarrel commits a sin, and he that
puts forth his hand against a nation’s father is tempted to a crime so
like to parricide, that the laws do visit treason with the same
punishment. I’ll pray for thee, cousin,—pray that some power divine
may turn thy deceived heart,—may touch it with the spirit of peace,
and love, and holy fear. Lay not the flattering unction to your soul,
that the cause of true religion, or of true liberty, can be promoted by
the sword of rebellion. It will turn into your own generous bosom
hereafter, and pierce you through with sorrows.”
“Well, Katharine, a nation is a family; but if some of the children
do poison a father’s mind against others, and these last rise up to
punish their treachery, at whose door lieth the sin?”
“My heart is too heavy, Francis, to deal with you in argument.
Sure I am, that you feel persuaded in your own mind of the truth of
that view which lures you on to misery. Oh, that I could move thee.
Francis, from the tender age at which I kneeled upon a mother’s lap,
and lisped my infant prayer, I was taught to love and to reverence
the church in which I was baptized; to worship in her courts; to
kneel before her altars; and now I may not see her in the dust
without a pang.”
“Katharine, I would sooner this arm should rot than that it
should violate a church, or desecrate one pillar of the temple; but all
that are called Israel are not Israel. There are unseemly spots upon
the raiment of the King’s daughter. She will come forth more glorious
for purification. Fear not, my gentle cousin, fear not, all will yet be
well.”
“Not so—not so; my heart more truly tells some fatal end. What
scarf is that upon thy shoulder? Where is thy king? Doth not his
sacred head even now pillow upon thorns? His throne! his crown!
where are they? by whom assailed? by whom defended?”
“The true enemies of the King, the true foes of the church, are
gathered about the royal person; have poisoned his ear; have turned
the generous blood of a princely heart to the black and bitter stream
that swells the veins of tyrants. The best friends both of the church
and of the King march to free them and to reinstate them in the love
of all the people.”
“Oh, that it were so, Francis—were truly so! Is Falkland in your
ranks? Oh, that I had a tongue of persuasion to win you back again!
Oh, that you were riding among your king’s defenders!”
“Katharine, by the sweet sacredness of my deep and constant
love for you, ask me not that which I could never do with honour.
Beneath the cope of heaven there walks no being whose wish is
such a law to me as thine. My services are pledged—my colours
chosen. My heart is in the cause. If thou couldst give to me thy
precious self in marriage, as the mighty price of my desertion, I
were unworthy of thee—we should be unworthy of each other. Our
fall would be beyond the common lapse of false mankind. Even in
our wedding garments our love would die.”
“Lord of my constant heart, forget my words:—I know not what
they meant—I know not how I spake them. Sorrow, and fear, and
love, and dark forebodings, do half bewilder me. I would not have
thee other than thou art in any thing. Thy heart is no traitor’s heart.
Delusion, bright as is the garment of an archangel, goes before
thee; and in Heaven’s chosen squadrons you shall be one day
marshalled. Whene’er thou fallest in the battle, I shall know it:—the
stars will tell it me: Francis, thou wilt be taken away from me,—I
know it:—a presage dark and cold overshadows me.”
“Nay, love, that fear is idle; ’tis a passing weakness. Nor time,
nor space, nor life, nor death, can e’er divide our loves. In all I think,
in all I do, you are present with me. Spirits are not confined:—in
lonely forest haunts, across the wide Atlantic, I have had thee with
me, Katharine, visibly with me; and I do know by the mysterious
sympathy between us, that thou hast seen me sit with thee, beneath
thy favourite cedar, when ocean rolled between us. This is the high
and glorious privilege of love like ours. Come to my heart:—be
folded there in one such fond embrace as may live in memory’s cup
to be a daily nectar.” He pressed her majestic form to his manly
breast, and bowed his head upon her shoulder. Just then a trumpet
sounded from the city. He strained her yet closer to his heart, then
cast his eyes around with eager glance, and made signal with his
hand till Jane observed him and came up:—to her he passed his pale
and silent charge with soft and reverent action, and, with the quick
farewell of soldiers’ partings, broke suddenly away.
CHAP. IX.
He calls us rebels, traitors; and will scourge with haughty
arms this hateful name in us.
Henry IV.

On the cold foggy evening of October the 22d, 1642, the brigade of
foot to which the regiment of Cuthbert Noble belonged took up its
ground for the night in an open field to the north of the village of
Keinton, in which the Earl of Essex fixed his head-quarters. The
armies of the King and the Parliament had been several days on the
march, both moving in the same direction, on lines of route some
twenty miles asunder. Both the King and Essex were well resolved to
fight a battle when the fit opportunity should offer; and it was the
common talk of the soldiers on both sides that they should soon
come to blows. Nevertheless, there was little thought in either camp
that they were on the very eve of an engagement, or, indeed, that
the main bodies lay so convenient to each other as to fight on the
morrow. As soon as the guards were posted, the pikemen and
musketeers of Maxwell’s regiment piled their arms in ranks, and
were allowed to make such fires as they could. The country being
open, and bare of wood, these fires were comfortless and short
lived. By a flickering flame, fed with the small wood of the few
bushes that grew near, Cuthbert Noble and Randal ate a slender
supper of dry bread and salt herring, which they washed down with
a weak draught of cold mixture, but faintly tinged with strong
waters. “The Saxons,” said Randal, who was a very hardy man, “call
this month the wine month, or Wyn Monath; certainly there must
have been milder seasons in England formerly than we experience
now; for it is impossible to fancy a vintage during such sharp frosts
as these.”—“Yes,” said Cuthbert, “yes.” Randal smiled at a reply
which bespoke inattention and discomposure, then added, “Master
Cuthbert, I counted on seeing you a little proud of your first night in
camp: we must all endure hardness as good soldiers.”
“True,” answered Cuthbert, recovering himself: “what is a little
cold and a little hunger compared to what thousands of Christian
men have in all ages endured, and do in all ages endure for the
truth? It is a great cause—a holy cause. I was only thinking at the
moment that it is a pity we had not taken a little better care of our
bread and of that bottle of strong waters: there is a loaf missing,
and the bottle is almost empty. But what petty trifles these are; how
much below the dignity of our nature: you are right, Randal; I am,
and I ought to be, happy; see how comfortable the Colonel has
made himself;” so saying, he pointed to where Maxwell sat, near the
only good fire on the ground, with a few officers round him. He was
enveloped in a large cloak,—a fur cap was drawn over his ears,—he
was leaning with his back against a pack-saddle; and as the smoke
of his pipe issued in warm clouds from his mouth he looked as much
at his ease as if seated in a chimney corner by the brightest fireside
in the kingdom.
“Ay,” said Randal, “he is an old campaigner, and use is second
nature; for myself, as long as I am warmly clad, for no other comfort
do I care: I hate a pipe, and am not fond of a fire.” Now Randal was
wrapped up in an outer coat of the thickest woollen; and Cuthbert
himself, being also clothed in a large warm mantle, checked his
disposition to complain, and, after a little conversation of a better
kind, they both composed themselves to sleep. About two or three
hours after he had lain down he was awakened by a sensation of
extreme cold. He instantly discovered the cause: his mantle had
been stripped off, and he was left without any other covering than
the clothes in which he stood. Most of the camp fires were already
extinguished, or only emitted a very faint light from the expiring
embers. The stars in the deep blue sky above shone with the most
vivid lustre: the fog had disappeared; and through the clear gloom
of night he could see outlines of the piles of arms and of the groups
of sleeping soldiers. Immediately near him lay Randal in a profound
sleep: lifting a half-burned brand, he saw by the light which it gave
as he waved it around that the mantle was nowhere near the spot.
He went among the groups which were not far off to search for it;
but the growl and the curse of a brawny pikeman, over whom he
chanced to stumble, deterred him from his pursuit; and he had no
other resource than to pace up and down in a vacant space of
ground, that he might keep himself warm by exertion. In vain he
tried to raise his mind to heavenly contemplations; in vain he sought
to warm his zeal by picturing the sad and severe sublimities of battle
and of victory; and the price of blood which he might soon be called
upon, and which he was ready to pay, for the triumph of his cause.
For great sacrifices he was eager; for petty troubles he was wholly
unprepared; therefore the night wore away in coldness and
discontent.
Just as the day was breaking, he observed a man, in the garb of
a Puritan, riding leisurely along the lines, and apparently taking a
very particular notice of the position and number of the troops. What
it was in the manner of the man that awakened the suspicions of
Cuthbert is uncertain, but he felt impelled to go closer, and examine
him. Accordingly, he crossed towards the quarter-guard, where he
observed him stop and enter into conversation with the sergeant.
The man’s back was towards Cuthbert,—thus he was able to
approach the quarter-guard without being perceived by the stranger.
No sooner did Cuthbert catch the tone of his voice than he
immediately recognised it to be that of the roguish hypocrite who
had slept in the same chamber with him at the inn in Aylesbury, two
years before, and had stolen his purse and the horse lent him by Sir
Oliver Heywood. The knave, not recollecting Cuthbert in his new
dress, continued to pursue his inquiries after he came up in the
same canting phraseology, and even addressed some questions to
Cuthbert himself; but the latter, suddenly seizing the bridle of his
beast, directed the sergeant to pull him out of his saddle, which was
instantly and adroitly done, and gave him in charge as a thief and a
horse-stealer, and on suspicion of being a spy. The wretch was so
panic-stricken that he made no effort to conceal or destroy any of
the proofs which were found upon him, when they proceeded to
search his person. These papers consisted of a letter to Prince
Rupert—another, without a signature, saying that two squadrons of
the Parliamentarian horse were prepared to desert as soon as the
armies met—and a third, containing an accurate return of the
strength of Essex’s main body, and an estimate of the numbers left
behind in garrisons, and on other duties. He was taken before
Colonel Maxwell; by him sent forthwith to the Earl of Essex, who,
having gotten all the information which the confused hypocrite could
give, directed him to be hanged in front of the lines, before the
troops marched. The rogue died like a dog and a dastard, imploring
mercy with loud and feverish howls, till, the noose being fastened
tight about his neck, and made secure to a strong branch on the
only tree near the camp, the forage cart, on which he had been
dragged beneath it, was driven away, and he suddenly fell, and
swung slowly to and fro before the silent and stern battalions which
were assembled upon the ground in arms.
Such was the Sabbath morning of October the 23d,—far
different in prospect and in promise from those of his youthful days
at Cheddar. The distant sound of trumpets told that the divisions of
horse were already in motion; the drums beat; many a shrill fife
pierced the ear; and the columns of foot slowly followed. The army
had scarcely advanced a mile before the troops were halted; and
they could all distinctly see a fair body of horse on the top of a high
level, called Edge Hill, not more than a good mile in front. At the
same moment, the Earl of Essex rode past Maxwell’s regiment, and
said, in the hearing of Cuthbert,—
“Maxwell, I shall give you plenty of work to-day, for I know I
may reckon on your regiment safely.”
“My Lord, we’re all ready and willing,” was the Colonel’s brief
reply.
The order now came for drawing up the army in order of battle.
Near Keinton, on the right, were some hedges and enclosures:
among these were placed the musketeers and pikemen; and one of
the most important posts was assigned to the regiment in which
Cuthbert served. There were not above two regiments of horse in
this wing, where the ground was narrowest; but in the left wing was
placed a thousand horse under Ramsey. The reserve of horse was
commanded by the Earl of Bedford, assisted by Sir William Balfour:
between the Parliamentarians and the royal position, on Edge Hill, it
was a fair open country. Essex having thus chosen his ground, stood
still in a defensive posture, and directed three cannon to be
discharged as a defiance and a challenge to the royal army: they
answered readily on their part with two shot from a battery of field
guns on the brow of their position. However, many of their foot
regiments were quartered seven or eight miles from the main body,
and had that distance to march to the rendezvous. It was past one
of the clock before the King’s forces marched down the hill, with the
King’s standard waving in the centre of his regiment of guards. They
made a very fine and gallant appearance, especially their horse.
Their trumpets sounded out in the distance, very grand to hear, and
those upon Essex’s left wing sounded also. It was a glorious sight to
see the royal forces move steadily on, in two lines, with bodies of
reserve. They numbered not less than eighteen thousand men, and
the army of Essex was very little superior in strength; for two of his
best regiments of foot, and one of his horse regiments, were a day’s
march behind him. However, the Parliament soldiers were no less
ready for the fray than their eager adversaries.
During the solemn pause before the battle, while the hosts were
drawing up face to face, and the dispositions for the attack were
completing, Cuthbert felt an unaccountable sadness on his spirits.
He could well imagine, from all that he heard and saw, that the
feelings of a true soldier, standing opposite an army of hostile
invaders, and about to fight for the altars and the hearths of his
native land, must be of a most exalted and enviable description,—
but how different were his. The royal standard of England was
floating in the adverse line, and English voices were marshalling it
for the onset: his own pupil, young Arthur Heywood, was riding in
those ranks.
“Remember, men,” said the commanding voice of Maxwell, “to
be silent and steady: wait for the order: reserve your fire to the last
moment, musketeers; and keep your ranks, pikemen, when it comes
to the push. By God’s help, we’ll drive them up that hill in worse
order than they are coming down.”
In another minute there broke a sudden flash from the enemy’s
line: close followed the white smoke and the thundering echo; and,
by the very side of Cuthbert, a sergeant was struck down dead.
“Pick up Sergeant Bond’s partisan,” said the sergeant-major of
the regiment as he was passing by: “pick it up, you Tibbs,” he
repeated, in a sharp cold tone, to a supernumerary sergeant
attached to the same company, and who had only a sword.
“Is this the glorious battle death?” said Cuthbert to himself,—but
he had no leisure for thought: the roar of shotted guns began on
both sides, and the battle fiercely opened. The musketeers of the
regiment were thrown out towards a hedge, a little in front of the
ground occupied by the pikemen; and a canopy of smoke soon rose
above them all, veiling the golden sun and the blue heavens, and
giving to all the forms and faces of those around, whether friends or
foes, a shadowy indistinctness.
In the midst of all this apparent confusion, governing
commands were given by beat of drum, or by the swift and
intelligent service of chosen aides, or by the personal presence and
loud voice, at the particular point were they were needed, of Essex
himself, who commanded and fought with his foot throughout the
day. Captain Ruddiman, who commanded the company of pikemen
to which Cuthbert belonged, did not appear to relish the cannon
balls; feeling very naturally, that however ready and able to
encounter the Royalists at close quarters, there was no mode of
guarding against a round iron shot; nor was he much better pleased
with the spitting and whistling of musket-balls. However, being a
very brave man, he stood them all as steady as a signpost, and
rebuked Lieutenant Sippets for bobbing up and down in a very
unsoldier-like fashion. Meanwhile Cuthbert was expressly called by
Maxwell to go to the front, and take charge of a company of
musketeers, the officers of which were all killed or wounded. He ran
eagerly forward and was soon hotly engaged; but the royal dragoons
coming up to the support of their foot, and both forcing their way on
with ardour, the musketeers were withdrawn by Maxwell behind the
reserve of pikemen; and these moving up in good and compact
order soon came to a gallant push of pike, and drove back the
enemy with severe loss; at the same time the musketeers stoutly
supported the push of pike with their clubbed muskets, and made a
bloody carnage in the royal ranks. In this mêlée Cuthbert owed his
life to that expertness at the sword exercise for which he was
indebted to the lessons of George Juxon; for by a dexterous parry he
beat off the assault of a stout Royalist officer, who ran at him as he
was grasping at a colour, the bearer of which had stumbled, and,
killing him by a home thrust through the body, succeeded in taking
the colour.
In the pause which followed on the repulse of this attack
Cuthbert received the high praise of Maxwell, and the honest
congratulations of Captain Ruddiman, who, at close quarters, had
himself done good service among the Royalists, making not a few
bite the dust beneath the blows of a heavy poll-axe which he had
found upon the field. Both parties now for awhile took wind and
breath; but soon again the horse of Essex’s right wing was led by Sir
William Balfour against the point of the King’s left. Their squadrons
passed the flank of Maxwell’s regiment, as they advanced at a walk
to take their ground before they formed up for the charge; and
Francis Heywood, already distinguished by his brilliant conduct at
the unfortunate affair of Pershore, passed so close to Cuthbert that
they shook hands. It scarcely seemed a minute from this friendly
greeting ere their trumpets sounded the charge, and with a
desperate fury they galloped towards the enemy. The first line broke
before them: the second was staggered; but two regiments of the
royal dragoons, in reserve, came swiftly to their aid, and by the fire
of their long carbines struck down a great many of the Parliament
horse, and following this up by a charge, compelled them to wheel
about. The royal foot now advanced again, and made a furious
attack upon the right of Essex, and pushed up to the very mouths of
his cannon, and drove away the gunners and spiked several of the
guns; but this artillery was valiantly won back by the
Parliamentarians: and the brigade of foot in which Maxwell’s
regiment fought actually charged the royal dragoons with their pikes,
and drove them back in disorder, with the loss of a great many men
and horses. It so happened, in this last movement, that when the
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookluna.com

You might also like