SlideShare une entreprise Scribd logo
Programming Logic And Design Comprehensive 6th
Edition 6th Edition Joyce Farrell download
https://ebookbell.com/product/programming-logic-and-design-
comprehensive-6th-edition-6th-edition-joyce-farrell-2422158
Explore and download more ebooks at ebookbell.com
Here are some recommended products that we believe you will be
interested in. You can click the link to download.
Programming Logic And Design Comprehensive 6th Edition Joyce Farrell
https://ebookbell.com/product/programming-logic-and-design-
comprehensive-6th-edition-joyce-farrell-4586394
Programming Logic And Design Comprehensive 9th Edition 9th Edition
Joyce Farrell
https://ebookbell.com/product/programming-logic-and-design-
comprehensive-9th-edition-9th-edition-joyce-farrell-37513870
Programming Logic And Design Comprehensive 7th Edition Joyce Farrell
https://ebookbell.com/product/programming-logic-and-design-
comprehensive-7th-edition-joyce-farrell-4054238
Programming Logic And Design Comprehensive 8th Edition Joyce Farrell
https://ebookbell.com/product/programming-logic-and-design-
comprehensive-8th-edition-joyce-farrell-4950652
Programming Logic And Design Comprehensive 8th Joyce Farrell
https://ebookbell.com/product/programming-logic-and-design-
comprehensive-8th-joyce-farrell-5551838
Starting Out With Programming Logic And Design 6e 6th Tony Gaddis
https://ebookbell.com/product/starting-out-with-programming-logic-and-
design-6e-6th-tony-gaddis-54522858
C Programs To Accompany Programming Logic And Design 1st Edition Jo
Ann Smith
https://ebookbell.com/product/c-programs-to-accompany-programming-
logic-and-design-1st-edition-jo-ann-smith-2371708
Just Enough Programming Logic And Design 1st Edition Joyce Farrell
https://ebookbell.com/product/just-enough-programming-logic-and-
design-1st-edition-joyce-farrell-2454550
Starting Out With Programming Logic And Design 3rd Edition Tony Gaddis
https://ebookbell.com/product/starting-out-with-programming-logic-and-
design-3rd-edition-tony-gaddis-4577402
Programming Logic And Design Comprehensive 6th Edition 6th Edition Joyce Farrell
Programming Logic And Design Comprehensive 6th Edition 6th Edition Joyce Farrell
PROGRAMMING LOGIC
AND DESIGN
COMPREHENSIVE
This page intentionally left blank
S I X T H E D I T I O N
PR OGRAMMING LOGIC
AND DESIGN
COMPREHENSIVE
JO YCE FARRELL
Australia • Brazil • Japan • Korea • Mexico • Singapore • Spain • United Kingdom • United States
This is an electronic version of the print textbook. Due to electronic rights restrictions, some third party content may
be suppressed. Editorial review has deemed that any suppressed content does not materially affect the overall
learning experience. The publisher reserves the right to remove content from this title at any time if subsequent rights
restrictions require it. For valuable information on pricing, previous editions, changes to current editions, and
alternate formats, please visit www.cengage.com/highered to search by ISBN#, author, title, or keyword for
materials in your areas of interest.
© 2011 Course Technology, Cengage Learning
ALL RIGHTS RESERVED. No part of this work covered by the copyright
herein may be reproduced, transmitted, stored or used in any form or by
any means—graphic, electronic, or mechanical, including but not limited
to photocopying, recording, scanning, digitizing, taping, Web distribution,
information networks, or information storage and retrieval systems, except
as permitted under Section 107 or 108 of the 1976 United States Copyright
Act—without the prior written permission of the publisher.
Library of Congress Control Number: 2009938501
ISBN-13: 978-0-5387-4476-8
ISBN-10: 0-538-74476-6
Course Technology
20 Channel Center Street
Boston, MA 02210
USA
Some of the product names and company names used in this book have
been used for identification purposes only and may be trademarks or
registered trademarks of their respective manufacturers and sellers.
Course Technology, a part of Cengage Learning, reserves the right to revise
this publication and make changes from time to time in its content without
notice.
Cengage Learning is a leading provider of customized learning solutions with
office locations around the globe, including Singapore, the United Kingdom,
Australia, Mexico, Brazil, and Japan. Locate your local office at:
www.cengage.com/global
Cengage Learning products are represented in Canada by
Nelson Education, Ltd.
To learn more about Course Technology, visit
www.cengage.com/coursetechnology
Purchase any of our products at your local college store or at our preferred
online store www.ichapters.com
Programming Logic and Design,
Comprehensive, Sixth Edition
Joyce Farrell
Executive Editor: Marie Lee
Acquisitions Editor: Amy Jollymore
Managing Editor: Tricia Coia
Developmental Editor: Dan Seiter
Content Project Manager: Jennifer Feltri
Editorial Assistant: Zina Kresin
Marketing Manager: Bryant Chrzan
Art Director: Marissa Falco
Text Designer: Shawn Girsberger
Cover Designer: Cabbage Design Company
Cover Image: iStockphoto
Print Buyer: Julio Esperas
Copy Editor: Michael Beckett
Proofreader: Vicki Zimmer
Indexer: Alexandra Nickerson
Compositor: Integra
Printed in Canada
1 2 3 4 5 6 7 14 13 12 11 10
For product information and technology assistance, contact us at
Cengage Learning Customer & Sales Support, 1-800-354-9706
For permission to use material from this text or product,
submit all requests online at cengage.com/permissions
Further permissions questions can be emailed to
permissionrequest@cengage.com
Brief Contents
Preface . . . . . . . . . . . . . . . . . xvi
CHAPTER 1 An Overview of Computers and Programming . . 1
CHAPTER 2 Working with Data, Creating Modules,
and Designing High-Quality Programs . . . . 41
CHAPTER 3 Understanding Structure . . . . . . . . . . 92
CHAPTER 4 Making Decisions . . . . . . . . . . . . 133
CHAPTER 5 Looping . . . . . . . . . . . . . . . . 184
CHAPTER 6 Arrays . . . . . . . . . . . . . . . . . 228
CHAPTER 7 File Handling and Applications . . . . . . 276
CHAPTER 8 Advanced Array Concepts, Indexed Files,
and Linked Lists. . . . . . . . . . . . . 325
CHAPTER 9 Advanced Modularization Techniques . . . . 370
CHAPTER 10 Object-Oriented Programming . . . . . . . 426
CHAPTER 11 More Object-Oriented Programming
Concepts . . . . . . . . . . . . . . . . 469
CHAPTER 12 Event-Driven GUI Programming,
Multithreading, and Animation . . . . . . . 515
CHAPTER 13 System Modeling with the UML . . . . . . 550
CHAPTER 14 Using Relational Databases . . . . . . . . 585
APPENDIX A Understanding Numbering Systems
and Computer Codes. . . . . . . . . . . 637
APPENDIX B Flowchart Symbols . . . . . . . . . . . 646
v
APPENDIX C Structures . . . . . . . . . . . . . . . 647
APPENDIX D Solving Difficult Structuring Problems . . . 649
APPENDIX E Creating Print Charts . . . . . . . . . . 658
APPENDIX F Two Variations on the Basic Structures—
case and do-while . . . . . . . . . . 660
Glossary . . . . . . . . . . . . . . . . 666
Index . . . . . . . . . . . . . . . . . 681
B R I E F C O N T E N T S
vi
Contents
Preface . . . . . . . . . . . . . . . . . xvi
CHAPTER 1 An Overview of Computers
and Programming . . . . . . . . . . . . . 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 . . . . . . . . . . . .14
Maintaining the Program . . . . . . . . . . . . . . . . .14
Using Pseudocode Statements and Flowchart Symbols . . . .15
Writing Pseudocode . . . . . . . . . . . . . . . . . . .15
Drawing Flowcharts . . . . . . . . . . . . . . . . . . .17
Repeating Instructions . . . . . . . . . . . . . . . . . .18
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
Review Questions . . . . . . . . . . . . . . . . . . . . .32
Exercises . . . . . . . . . . . . . . . . . . . . . . . . .37
CHAPTER 2 Working with Data, Creating Modules,
and Designing High-Quality Programs . . . . . . 41
Declaring and Using Variables and Constants. . . . . . . . .42
vii
Working with Variables . . . . . . . . . . . . . . . . . .42
Naming Variables . . . . . . . . . . . . . . . . . . . .44
Understanding Unnamed, Literal Constants
and their Data Types . . . . . . . . . . . . . . . . . .45
Understanding the Data Types of Variables . . . . . . . . .46
Declaring Named Constants. . . . . . . . . . . . . . . .47
Assigning Values to Variables . . . . . . . . . . . . . . . .48
Performing Arithmetic Operations . . . . . . . . . . . . .49
Understanding the Advantages of Modularization . . . . . . . 52
Modularization Provides Abstraction . . . . . . . . . . . .53
Modularization Allows Multiple Programmers
to Work on a Problem. . . . . . . . . . . . . . . . . .54
Modularization Allows You to Reuse Your Work . . . . . . .54
Modularizing a Program . . . . . . . . . . . . . . . . . .55
Declaring Variables and Constants
within Modules . . . . . . . . . . . . . . . . . . . . .59
Understanding the Most Common Configuration
for Mainline Logic . . . . . . . . . . . . . . . . . . . .61
Creating Hierarchy Charts . . . . . . . . . . . . . . . . .66
Features of Good Program Design. . . . . . . . . . . . . .68
Using Program Comments . . . . . . . . . . . . . . . .69
Choosing Identifiers . . . . . . . . . . . . . . . . . . .71
Designing Clear Statements. . . . . . . . . . . . . . . .72
Writing Clear Prompts and Echoing Input . . . . . . . . . .74
Maintaining Good Programming Habits . . . . . . . . . . .76
Chapter Summary . . . . . . . . . . . . . . . . . . . . .77
Key Terms . . . . . . . . . . . . . . . . . . . . . . . .78
Review Questions . . . . . . . . . . . . . . . . . . . . .82
Exercises . . . . . . . . . . . . . . . . . . . . . . . . .86
CHAPTER 3 Understanding Structure . . . . . . . . . . 92
Understanding Unstructured Spaghetti Code . . . . . . . . .93
Understanding the Three Basic Structures . . . . . . . . . .95
Using a Priming Input to Structure a Program . . . . . . . 103
Understanding the Reasons for Structure . . . . . . . . . 110
Recognizing Structure . . . . . . . . . . . . . . . . . . 111
Structuring and Modularizing Unstructured Logic . . . . . . 115
Chapter Summary . . . . . . . . . . . . . . . . . . . . 121
Key Terms . . . . . . . . . . . . . . . . . . . . . . . 122
Review Questions . . . . . . . . . . . . . . . . . . . . 123
Exercises . . . . . . . . . . . . . . . . . . . . . . . . 127
C O N T E N T S
viii
CHAPTER 4 Making Decisions . . . . . . . . . . . . 133
Evaluating Boolean Expressions to Make Comparisons . . . 134
Using Relational Comparison Operators . . . . . . . . . . 137
Avoiding a Common Error with Relational Operators . . . . 141
Understanding AND Logic . . . . . . . . . . . . . . . . 141
Nesting AND Decisions for Efficiency . . . . . . . . . . 144
Using the AND Operator . . . . . . . . . . . . . . . . 146
Avoiding Common Errors in an AND Selection. . . . . . . 148
Understanding OR Logic . . . . . . . . . . . . . . . . . 150
Writing OR Decisions for Efficiency . . . . . . . . . . . 152
Using the OR Operator . . . . . . . . . . . . . . . . . 153
Avoiding Common Errors in an OR Selection . . . . . . . 155
Making Selections within Ranges . . . . . . . . . . . . . 159
Avoiding Common Errors When Using Range Checks . . . 162
Understanding Precedence When Combining
AND and OR Operators . . . . . . . . . . . . . . . . . 166
Chapter Summary . . . . . . . . . . . . . . . . . . . . 169
Key Terms . . . . . . . . . . . . . . . . . . . . . . . 170
Review Questions . . . . . . . . . . . . . . . . . . . . 171
Exercises . . . . . . . . . . . . . . . . . . . . . . . . 177
CHAPTER 5 Looping . . . . . . . . . . . . . . . . 184
Understanding the Advantages of Looping . . . . . . . . . 185
Using a Loop Control Variable. . . . . . . . . . . . . . . 186
Using a Definite Loop with a Counter . . . . . . . . . . 187
Using an Indefinite Loop with a Sentinel Value . . . . . . 188
Understanding the Loop in a Program’s Mainline Logic. . . 190
Nested Loops . . . . . . . . . . . . . . . . . . . . . . 192
Avoiding Common Loop Mistakes . . . . . . . . . . . . . 196
Mistake: Neglecting to Initialize the
Loop Control Variable . . . . . . . . . . . . . . . . . 197
Mistake: Neglecting to Alter the
Loop Control Variable . . . . . . . . . . . . . . . . . 198
Mistake: Using the Wrong Comparison with the
Loop Control Variable . . . . . . . . . . . . . . . . . 200
Mistake: Including Statements Inside the Loop
that Belong Outside the Loop . . . . . . . . . . . . . 201
Using a for Loop . . . . . . . . . . . . . . . . . . . . 206
Common Loop Applications . . . . . . . . . . . . . . . . 208
Using a Loop to Accumulate Totals . . . . . . . . . . . 208
Using a Loop to Validate Data . . . . . . . . . . . . . . 211
Limiting a Reprompting Loop . . . . . . . . . . . . . . 213
ix
C O N T E N T S
Validating a Data Type . . . . . . . . . . . . . . . . . 215
Validating Reasonableness and Consistency of Data . . . . 216
Chapter Summary . . . . . . . . . . . . . . . . . . . . 217
Key Terms . . . . . . . . . . . . . . . . . . . . . . . 218
Review Questions . . . . . . . . . . . . . . . . . . . . 219
Exercises . . . . . . . . . . . . . . . . . . . . . . . . 223
CHAPTER 6 Arrays . . . . . . . . . . . . . . . . . 228
Understanding Arrays and How They Occupy
Computer Memory . . . . . . . . . . . . . . . . . . . 229
How Arrays Occupy Computer Memory. . . . . . . . . . 229
Manipulating an Array to Replace Nested Decisions . . . . . 232
Using Constants with Arrays . . . . . . . . . . . . . . . 240
Using a Constant as the Size of an Array . . . . . . . . . 240
Using Constants as Array Element Values . . . . . . . . 241
Using a Constant as an Array Subscript . . . . . . . . . 241
Searching an Array . . . . . . . . . . . . . . . . . . . 242
Using Parallel Arrays . . . . . . . . . . . . . . . . . . . 246
Improving Search Efficiency. . . . . . . . . . . . . . . 251
Searching an Array for a Range Match . . . . . . . . . . . 254
Remaining within Array Bounds . . . . . . . . . . . . . . 258
Using a for Loop to Process Arrays . . . . . . . . . . . 261
Chapter Summary . . . . . . . . . . . . . . . . . . . . 262
Key Terms . . . . . . . . . . . . . . . . . . . . . . . 263
Review Questions . . . . . . . . . . . . . . . . . . . . 264
Exercises . . . . . . . . . . . . . . . . . . . . . . . . 268
CHAPTER 7 File Handling and Applications . . . . . . 276
Understanding Computer Files . . . . . . . . . . . . . . 277
Organizing Files . . . . . . . . . . . . . . . . . . . . 278
Understanding the Data Hierarchy . . . . . . . . . . . . . 279
Performing File Operations . . . . . . . . . . . . . . . . 280
Declaring a File . . . . . . . . . . . . . . . . . . . . 280
Opening a File . . . . . . . . . . . . . . . . . . . . . 281
Reading Data From a File . . . . . . . . . . . . . . . . 281
Writing Data to a File . . . . . . . . . . . . . . . . . . 283
Closing a File . . . . . . . . . . . . . . . . . . . . . 283
A Program that Performs File Operations. . . . . . . . . 283
Understanding Sequential Files and Control Break Logic . . . 286
Understanding Control Break Logic . . . . . . . . . . . 287
Merging Sequential Files . . . . . . . . . . . . . . . . . 293
Master and Transaction File Processing . . . . . . . . . . 303
x
C O N T E N T S
Random Access Files . . . . . . . . . . . . . . . . . . 311
Chapter Summary . . . . . . . . . . . . . . . . . . . . 313
Key Terms . . . . . . . . . . . . . . . . . . . . . . . 314
Review Questions . . . . . . . . . . . . . . . . . . . . 316
Exercises . . . . . . . . . . . . . . . . . . . . . . . . 320
CHAPTER 8 Advanced Array Concepts, Indexed Files,
and Linked Lists. . . . . . . . . . . . . 325
Understanding the Need for Sorting Records . . . . . . . . 326
Understanding How to Swap Two Values . . . . . . . . . . 327
Using a Bubble Sort . . . . . . . . . . . . . . . . . . . 329
Sorting a List of Variable Size. . . . . . . . . . . . . . 337
Refining the Bubble Sort to Reduce Unnecessary
Comparisons. . . . . . . . . . . . . . . . . . . . . 341
Refining the Bubble Sort to Eliminate Unnecessary
Passes . . . . . . . . . . . . . . . . . . . . . . . 343
Other Sorts . . . . . . . . . . . . . . . . . . . . . . 345
Using Multidimensional Arrays . . . . . . . . . . . . . . 345
Using Indexed Files and Linked Lists. . . . . . . . . . . . 352
Using Indexed Files . . . . . . . . . . . . . . . . . . 352
Using Linked Lists . . . . . . . . . . . . . . . . . . . 354
Chapter Summary . . . . . . . . . . . . . . . . . . . . 357
Key Terms . . . . . . . . . . . . . . . . . . . . . . . 358
Review Questions . . . . . . . . . . . . . . . . . . . . 359
Exercises . . . . . . . . . . . . . . . . . . . . . . . . 364
CHAPTER 9 Advanced Modularization Techniques . . . . 370
Using Methods with No Parameters . . . . . . . . . . . . 371
Creating Methods that Require a Single Parameter . . . . . 374
Creating Methods that Require Multiple Parameters . . . . . 379
Creating Methods that Return a Value . . . . . . . . . . . 381
Using an IPO Chart . . . . . . . . . . . . . . . . . . . 387
Passing an Array to a Method . . . . . . . . . . . . . . . 388
Overloading Methods. . . . . . . . . . . . . . . . . . . 395
Avoiding Ambiguous Methods . . . . . . . . . . . . . . . 398
Using Predefined Methods . . . . . . . . . . . . . . . . 401
Method Design Issues: Implementation Hiding, Cohesion,
and Coupling . . . . . . . . . . . . . . . . . . . . . 403
Understanding Implementation Hiding . . . . . . . . . . 403
Increasing Cohesion . . . . . . . . . . . . . . . . . . 404
Reducing Coupling . . . . . . . . . . . . . . . . . . . 405
Understanding Recursion . . . . . . . . . . . . . . . . . 407
xi
C O N T E N T S
Chapter Summary . . . . . . . . . . . . . . . . . . . . 411
Key Terms . . . . . . . . . . . . . . . . . . . . . . . 413
Review Questions . . . . . . . . . . . . . . . . . . . . 415
Exercises . . . . . . . . . . . . . . . . . . . . . . . . 419
CHAPTER 10 Object-Oriented Programming . . . . . . . 426
Principles of Object-Oriented Programming. . . . . . . . . 427
Classes and Objects . . . . . . . . . . . . . . . . . . 427
Polymorphism . . . . . . . . . . . . . . . . . . . . . 430
Inheritance . . . . . . . . . . . . . . . . . . . . . . 431
Encapsulation . . . . . . . . . . . . . . . . . . . . . 432
Defining Classes and Creating Class Diagrams . . . . . . . 433
Creating Class Diagrams . . . . . . . . . . . . . . . . 435
The Set Methods. . . . . . . . . . . . . . . . . . . . 438
The Get Methods. . . . . . . . . . . . . . . . . . . . 440
Work Methods . . . . . . . . . . . . . . . . . . . . . 440
Understanding Public and Private Access . . . . . . . . . 442
Organizing Classes . . . . . . . . . . . . . . . . . . . 446
Understanding Instance Methods . . . . . . . . . . . . . 447
Understanding Static Methods . . . . . . . . . . . . . . 453
Using Objects . . . . . . . . . . . . . . . . . . . . . . 455
Chapter Summary . . . . . . . . . . . . . . . . . . . . 459
Key Terms . . . . . . . . . . . . . . . . . . . . . . . 460
Review Questions . . . . . . . . . . . . . . . . . . . . 462
Exercises . . . . . . . . . . . . . . . . . . . . . . . . 466
CHAPTER 11 More Object-Oriented Programming
Concepts . . . . . . . . . . . . . . . . 469
An Introduction to Constructors . . . . . . . . . . . . . . 470
Constructors with Parameters. . . . . . . . . . . . . . 473
Overloading Class Methods and Constructors. . . . . . . 473
Understanding Destructors . . . . . . . . . . . . . . . . 476
Understanding Composition. . . . . . . . . . . . . . . . 478
Understanding Inheritance . . . . . . . . . . . . . . . . 479
Understanding Inheritance Terminology . . . . . . . . . 481
Accessing Private Members of a Parent Class . . . . . . 484
Using Inheritance to Achieve Good Software Design . . . . 490
One Example of Using Predefined Classes:
Creating GUI Objects . . . . . . . . . . . . . . . . . . 491
Understanding Exception Handling. . . . . . . . . . . . . 493
Drawbacks to Traditional Error-Handling Techniques . . . . 493
The Object-Oriented Exception Handling Model . . . . . . 495
xii
C O N T E N T S
Using Built-in Exceptions and Creating Your Own
Exceptions. . . . . . . . . . . . . . . . . . . . . . 498
Reviewing the Advantages of Object-Oriented
Programming . . . . . . . . . . . . . . . . . . . . . 499
Chapter Summary . . . . . . . . . . . . . . . . . . . . 500
Key Terms . . . . . . . . . . . . . . . . . . . . . . . 502
Review Questions . . . . . . . . . . . . . . . . . . . . 503
Exercises . . . . . . . . . . . . . . . . . . . . . . . . 508
CHAPTER 12 Event-Driven GUI Programming,
Multithreading, and Animation . . . . . . . 515
Understanding Event-Driven Programming . . . . . . . . . 516
User-Initiated Actions and GUI Components. . . . . . . . . 519
Designing Graphical User Interfaces . . . . . . . . . . . . 523
The Interface Should Be Natural and Predictable . . . . . 523
The Interface Should Be Attractive, Easy to Read, and
Nondistracting . . . . . . . . . . . . . . . . . . . . 524
To Some Extent, It’s Helpful If the User Can
Customize Your Applications. . . . . . . . . . . . . . 524
The Program Should Be Forgiving . . . . . . . . . . . . 525
The GUI Is Only a Means to an End . . . . . . . . . . . 525
The Steps to Developing an Event-Driven Application . . . . 526
Creating Storyboards. . . . . . . . . . . . . . . . . . 527
Defining the Storyboard’s Objects in
an Object Dictionary . . . . . . . . . . . . . . . . . 527
Defining Connections Between the User Screens . . . . . 528
Planning the Logic . . . . . . . . . . . . . . . . . . . 529
Understanding Multithreading . . . . . . . . . . . . . . . 535
Creating Animation. . . . . . . . . . . . . . . . . . . . 537
Chapter Summary . . . . . . . . . . . . . . . . . . . . 540
Key Terms . . . . . . . . . . . . . . . . . . . . . . . 541
Review Questions . . . . . . . . . . . . . . . . . . . . 542
Exercises . . . . . . . . . . . . . . . . . . . . . . . . 546
CHAPTER 13 System Modeling with the UML . . . . . . 550
Understanding the Need for System Modeling . . . . . . . 551
What is the UML? . . . . . . . . . . . . . . . . . . . . 552
Using Use Case Diagrams . . . . . . . . . . . . . . . . 554
Using Class and Object Diagrams . . . . . . . . . . . . . 560
Using Sequence and Communication Diagrams . . . . . . . 564
Using State Machine Diagrams . . . . . . . . . . . . . . 566
Using Activity Diagrams . . . . . . . . . . . . . . . . . 567
xiii
C O N T E N T S
Using Component, Deployment, and Profile Diagrams . . . . 570
Diagramming Exception Handling . . . . . . . . . . . . . 572
Deciding When to Use the UML and Which
UML Diagrams to Use . . . . . . . . . . . . . . . . . 573
Chapter Summary . . . . . . . . . . . . . . . . . . . . 575
Key Terms . . . . . . . . . . . . . . . . . . . . . . . 576
Review Questions . . . . . . . . . . . . . . . . . . . . 578
Exercises . . . . . . . . . . . . . . . . . . . . . . . . 582
CHAPTER 14 Using Relational Databases . . . . . . . . 585
Understanding Relational Database Fundamentals. . . . . . 586
Creating Databases and Table Descriptions . . . . . . . . 588
Identifying Primary Keys . . . . . . . . . . . . . . . . . 591
Understanding Database Structure Notation . . . . . . . . 594
Adding, Deleting, Updating, and Sorting Records
within Tables. . . . . . . . . . . . . . . . . . . . . . 595
Sorting the Records in a Table . . . . . . . . . . . . . 596
Creating Queries. . . . . . . . . . . . . . . . . . . . . 596
Understanding Relationships Between Tables . . . . . . . . 600
Understanding One-to-Many Relationships . . . . . . . . 600
Understanding Many-to-Many Relationships . . . . . . . . 601
Understanding One-to-One Relationships . . . . . . . . . 606
Recognizing Poor Table Design . . . . . . . . . . . . . . 607
Understanding Anomalies, Normal Forms,
and Normalization . . . . . . . . . . . . . . . . . . . 609
First Normal Form . . . . . . . . . . . . . . . . . . . 610
Second Normal Form . . . . . . . . . . . . . . . . . . 612
Third Normal Form . . . . . . . . . . . . . . . . . . . 615
Database Performance and Security Issues . . . . . . . . 618
Providing Data Integrity. . . . . . . . . . . . . . . . . 618
Recovering Lost Data . . . . . . . . . . . . . . . . . 619
Avoiding Concurrent Update Problems . . . . . . . . . . 619
Providing Authentication and Permissions . . . . . . . . 620
Providing Encryption . . . . . . . . . . . . . . . . . . 620
Chapter Summary . . . . . . . . . . . . . . . . . . . . 621
Key Terms . . . . . . . . . . . . . . . . . . . . . . . 622
Review Questions . . . . . . . . . . . . . . . . . . . . 625
Exercises . . . . . . . . . . . . . . . . . . . . . . . . 630
xiv
C O N T E N T S
APPENDIX A Understanding Numbering Systems
and Computer Codes. . . . . . . . . . . 637
APPENDIX B Flowchart Symbols . . . . . . . . . . . 646
APPENDIX C Structures . . . . . . . . . . . . . . . 647
APPENDIX D Solving Difficult Structuring Problems . . . 649
APPENDIX E Creating Print Charts . . . . . . . . . . 658
APPENDIX F Two Variations on the Basic Structures—
case and do-while . . . . . . . . . . 660
Glossary . . . . . . . . . . . . . . . . 666
Index . . . . . . . . . . . . . . . . . 681
xv
C O N T E N T S
Preface
Programming Logic and Design, Comprehensive, Sixth Edition
provides the beginning programmer with a guide to developing
structured program logic. This textbook assumes no programming
language experience. The writing is nontechnical and emphasizes
good programming practices. The examples are business examples;
they do not assume mathematical background beyond high school
business math. Additionally, the examples illustrate one or two major
points; they do not contain so many features that students become
lost following irrelevant and extraneous details.
The examples in Programming Logic and Design have been created to
provide students with a sound background in logic, no matter what
programming languages they eventually use to write programs. This
book can be used in a stand-alone logic course that students take as a
prerequisite to a programming course, or as a companion book to an
introductory programming text using any programming language.
Organization and Coverage
Programming Logic and Design, Comprehensive, Sixth Edition
introduces students to programming concepts and enforces good
style and logical thinking. General programming concepts are intro-
duced in Chapter 1. Chapter 2 discusses using data and introduces
two important concepts: modularization and creating high-quality
programs. It is important to emphasize these topics early so that
students start thinking in a modular way and concentrate on making
their programs efficient, robust, easy to read, and easy to maintain.
Chapter 3 covers the key concepts of structure, including what
structure is, how to recognize it, and most importantly, the advan-
tages to writing structured programs. This early overview gives
students a solid foundation for thinking in a structured way before
they have to manage the details of the structures.
Chapters 4, 5, and 6 explore the intricacies of decision making, looping,
and array manipulation. Chapter 7 provides details of file handling so
students can create programs that handle a significant amount of data.
xvi
In Chapters 8 and 9, students learn more advanced techniques in
array manipulation and modularization. Chapters 10 and 11 provide
a thorough, yet accessible, introduction to concepts and terminology
used in object-oriented programming. Students learn about classes,
objects, instance and static class members, constructors, destructors,
inheritance, and the advantages provided by object-oriented thinking.
Chapter 12 explores additional object-oriented programming issues:
event-driven GUI programming, multithreading, and animation.
Chapter 13 discusses system design issues and details the features of
the Unified Modeling Language. Chapter 14 is a thorough introduc-
tion to the most important database concepts business programmers
should understand.
The first three appendices give students summaries of numbering
systems, flowchart symbols, and structures. Additional appendices
allow students to gain extra experience with structuring large
unstructured programs, creating print charts, and understanding
posttest loops and case structures.
Programming Logic and Design combines text explanation with
flowcharts and pseudocode examples to provide students with
alternative means of expressing structured logic. Numerous detailed,
full-program exercises at the end of each chapter illustrate the
concepts explained within the chapter, and reinforce understanding
and retention of the material presented.
Programming Logic and Design distinguishes itself from other
programming logic books in the following ways:
It is written and designed to be non-language specific. The logic
•
used in this book can be applied to any programming language.
The examples are everyday business examples; no special knowledge
•
of mathematics, accounting, or other disciplines is assumed.
The concept of structure is covered earlier than in many other
•
texts. Students are exposed to structure naturally, so they will
automatically create properly designed programs.
Text explanation is interspersed with flowcharts and pseudocode
•
so students can become comfortable with both logic development
tools and understand their interrelationship. Screen shots of
running programs also are included, providing students with a
clear and concrete image of the programs’ execution.
Complex programs are built through the use of complete business
•
examples. Students see how an application is constructed from
start to finish instead of studying only segments of programs.
xvii
P R E FA C E
Features
This edition of the text includes many features to help students
become better programmers and understand the big picture in
program development. Many new features have been added, and the
popular features from the first five editions are still included.
Features maintained from previous editions include:
OBJECTIVES Each chapter begins with a list of objectives so the
student knows the topics that will be presented in the chapter. In
addition to providing a quick reference to topics covered, this feature
provides a useful study aid.
FLOWCHARTS This book has plenty of figures and illustrations,
including flowcharts, which provide the reader with a visual learning
experience, rather than one that involves simply studying text. You
can see examples of flowcharts beginning in Chapter 1.
PSEUDOCODE This book also includes numerous examples of
pseudocode, which illustrate correct usage of the programming logic
and design concepts being taught.
NOTES These tips provide additional information—for
example, another location in the book that expands on a topic,
or a common error to watch out for.
THE DON’T DO IT ICON It is sometimes illustrative to
show an example of how NOT to do something—for
example, having a dead code path in a program. However,
students do not always read carefully and sometimes use logic similar
to that shown in what is intended to be a “bad” example. When the
instructor is critical, the frustrated student says, “But that’s how they
did it in the book!” Therefore, although the text will continue to
describe bad examples, and the captions for the related figures will
mention that they are bad examples, the book also includes a “Don’t
Do It” icon near the offending section of logic. This icon provides a
visual jolt to the student, emphasizing that particular figures are NOT
to be emulated.
THE TWO TRUTHS AND A LIE QUIZ This quiz appears after each
chapter section, with answers provided. The quiz contains three
statements based on the preceding section of text—two true and one
false. Over the years, students have requested answers to problems,
but we have hesitated to distribute them in case instructors want
to use problems as assignments or test questions. These true-false
mini-quizzes provide students with immediate feedback as they read,
without “giving away” answers to the multiple-choice questions and
programming problems later in the chapter.
xviii
P R E FA C E
GAME ZONE EXERCISES These exercises are included at the
end of each chapter. Students can create games as an
additional entertaining way to understand key concepts
presented in the chapter.
CHAPTER SUMMARIES Following each chapter is a summary that
recaps the programming concepts and techniques covered in the
chapter. This feature provides a concise means for students to review
and check their understanding of the main points in each chapter.
KEY TERMS Each chapter lists key terms and their definitions; the list
appears in the order the terms are encountered in the chapter. Along
with the chapter summary, the list of key terms provides a snapshot
overview of a chapter’s main ideas. A glossary at the end of the book lists
all the key terms in alphabetical order, along with working definitions.
DEBUGGING EXERCISES Because examining programs
critically and closely is a crucial programming skill, each
chapter includes a “Find the Bugs” section in which program-
ming examples are presented that contain syntax errors and logical
errors for the student to find and correct.
REVIEW QUESTIONS Twenty multiple-choice review questions
appear at the end of every chapter to allow students to test their
comprehension of the major ideas and techniques presented.
EXERCISES Multiple end-of-chapter flowcharting and pseudocoding
exercises are included so students have more opportunities to practice
concepts as they learn them. These exercises increase in difficulty and
are designed to allow students to explore logical programming concepts.
Each exercise can be completed using flowcharts, pseudocode, or both.
In addition, instructors can assign the exercises as programming prob-
lems to be coded and executed in a particular programming language.
ESSAY QUESTIONS Each chapter contains an “Up For
Discussion” section in which questions present personal and
ethical issues that programmers must consider. These ques-
tions can be used for written assignments or as a starting point for
classroom discussions.
New to this Edition!
VIDEO LESSONS Each chapter is accompanied by two or
more video lessons that help explain an important chapter
concept. A listing of the videos provided can be found on
the inside back cover of this text. These videos are designed
and narrated by the author and are available for free with a new book.
(They can also be purchased separately at iChapters.com.)
xix
P R E FA C E
If you have a new book, it will contain a URL and PIN code. Once you
go to this URL and enter your PIN code, follow the prompts to locate
the videos for this text. If you are a user of an online course cartridge,
such as BlackBoard, WebCT, or Angel, you will also have access to
these videos through that platform.
INCREASED EMPHASIS ON MODULARITY From the second chapter,
students are encouraged to write code in concise, easily manageable,
and reusable modules. Instructors have found that modularization
is a technique that should be encouraged early to instill good habits
and a clearer understanding of structure. This edition explains
modularization early, using global variables instead of local passed
and returned values, and saves parameter passing for later when the
student has become more adept.
CLEARER EXPLANATIONS This edition has been rewritten to
provide clearer, simpler explanations that are appropriate for the
beginning programming student. As a result of the new, cleaner
approach, the length of the book has been reduced.
NEW APPENDICES FOR EASY REFERENCE New appendices
have been added that cover numbering systems, flowchart symbols,
and structures.
DECREASED EMPHASIS ON CONTROL BREAKS Professional
programmers should understand control break logic, but creating
such logic is not as common a task as it was years ago. Therefore, the
topic is still covered briefly as part of the file-handling chapter, but
with reduced emphasis from previous editions of the book.
Instructor Resources
The following supplemental materials are available when this
book is used in a classroom setting. All of the instructor resources
available with this book are provided to the instructor on a single
CD-ROM.
ELECTRONIC INSTRUCTOR’S MANUAL The Instructor’s Manual
that accompanies this textbook provides additional instructional
material to assist in class preparation, including items such as Sample
Syllabi, Chapter Outlines, Technical Notes, Lecture Notes, Quick
Quizzes, Teaching Tips, Discussion Topics, and Key Terms.
EXAMVIEW® This textbook is accompanied by ExamView, a powerful
testing software package that allows instructors to create and admin-
ister printed, computer (LAN-based), and Internet exams. ExamView
includes hundreds of questions that correspond to the topics covered in
this text, enabling students to generate detailed study guides that include
page references for further review. The computer-based and Internet
xx
P R E FA C E
testing components allow students to take exams at their computers,
and save the instructor time by grading each exam automatically.
POWERPOINT PRESENTATIONS This book comes with Microsoft
PowerPoint© slides for each chapter. These are included as a teach-
ing aid for classroom presentation, to make available to students
on your network for chapter review, or to be printed for classroom
distribution. Instructors can add their own slides for additional topics
they introduce to the class.
SOLUTIONS Suggested solutions to Review Questions and Exercises
are provided on the Instructor Resources CD and may also be found
on the Course Technology Web site at www.cengage.com/coursetech-
nology. The solutions are password protected.
DISTANCE LEARNING Course Technology offers WebCT© and
Blackboard© courses for this text to provide the most complete and
dynamic learning experience possible. When you add online content
to one of your courses, you’re adding a lot: automated tests, topic
reviews, quick quizzes, and additional case projects with solutions.
For more information on how to bring distance learning to your
course, contact your Course Technology sales representative.
Software Options
You have the option to bundle software with your text! Please contact
your Course Technology sales representative for more information.
MICROSOFT® OFFICE VISIO® PROFESSIONAL Visio is a
diagramming program that helps users create flowcharts and
diagrams easily while working through the text, enabling them to
visualize concepts and learn more effectively.
VISUAL LOGIC™ This simple but powerful tool teaches program-
ming logic and design without traditional high-level programming
language syntax. Visual Logic uses flowcharts to explain essential
programming concepts, including variables, input, assignment, out-
put, conditions, loops, procedures, graphics, arrays, and files. It also
has the ability to interpret and execute flowcharts, providing students
with immediate and accurate feedback about their solutions. By exe-
cuting student solutions, Visual Logic combines the power of a high-
level language with the ease and simplicity of flowcharts.
Acknowledgments
I would like to thank all of the people who helped to make this book
a reality, especially Dan Seiter, Development Editor, whose hard work
and attention to detail have made this a high-quality textbook. I have
xxi
P R E FA C E
worked with Dan for many years now, and he is indispensable in pro-
ducing accurate and approachable technical instruction. Thanks also
to Tricia Coia, Managing Editor; Amy Jollymore, Acquisitions Editor;
Jennifer Feltri, Content Project Manager; and Green Pen QA, Technical
Editors. I am grateful to be able to work with so many fine people who
are dedicated to producing high-quality instructional materials.
I am grateful to the many reviewers who provided helpful and
insightful comments during the development of this book, including
Gilbert Armour, Virginia Western Community College; John Buerck,
Saint Louis University; Karen Cummings, McLennan Community
College; Clara Groeper, Illinois Central College; and Jeff Hedrington,
Colorado Technical University.
Thanks, too, to my husband, Geoff, and our daughters, Andrea and
Audrey, for their support. This book, as were all its previous editions,
is dedicated to them.
–Joyce Farrell
xxii
P R E FA C E
About the Inside Front Cover
Check out our interviews with recent graduates who are now
working in the IT field. One is featured on the inside front cover
of this book. If you know people who recently landed a job in IT,
we’d like to interview them too! Send your suggestions via e-mail to
Amy Jollymore, Acquisitions Editor, at Amy.Jollymore@Cengage.com. xxiii
P R E FA C E
This page intentionally left blank
C H A P T E R 1
An Overview of
Computers and
Programming
In this chapter, you will learn about:
Computer systems

Simple program logic

The steps involved in the program development cycle

Pseudocode statements and flowchart symbols

Using a sentinel value to end a program

Programming and user environments

The evolution of programming models

Understanding Computer Systems
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 large mainframe computers, laptops, and even smaller comput-
ers that are embedded into products such as cars and thermostats,
but the types of operations performed by different-sized comput-
ers are very similar. When you think of a computer, you often think
of its physical components first, but for a computer to be useful it
needs more than devices; a computer needs to be given instruc-
tions. Just as your stereo equipment does not do much until you
provide music, computer hardware needs instructions that control
how and when data items are input, how they are processed, and
the form in which they are output or stored.
Software
• is computer instructions that tell the hardware what to do.
Software is programs: instructions written by programmers. You can
buy prewritten programs that are stored on a disk or that you down-
load from the Web. For example, businesses use word-processing
and accounting programs, and casual computer users enjoy pro-
grams 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 as application software or system software.
Application software comprises all the programs you apply to a task—
word-processing programs, spreadsheets, payroll and inventory programs,
and even games. System software comprises the programs that you use
to manage your computer, including operating systems such as Windows,
Linux, or UNIX. This book focuses on the logic used to write application software pro-
grams, 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 put into mem-
ory, where they can be processed. Hardware devices that perform input
operations include keyboards and mice. Data items include all the text,
numbers, and other information that are processed by a computer.
In business, much of the data used is facts and figures about such entities as
products, customers, and personnel. However, data can also be items such
as the choices a player makes in a game or the notes required by a music-
playing program.
2
C H A P T E R 1 An Overview of Computers and Programming
Many computer professionals distinguish between the terms data, which
describes items that are input, and information, which describes data items
that have been processed and sent to a device where people can read and
interpret them. For example, your name, Social Security number, and
hourly pay rate are data items when they are input to a program, but the
same items are information after they have been processed and output on your
paycheck.
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.
Output
• —After data items have been processed, the resulting infor-
mation usually is sent to a printer, monitor, or some other output
device so people can view, interpret, and use the results.
Some people consider storage as a fourth major computer operation.
Instead of sending output to a device such as a printer, monitor, or speaker
where a person can interpret it, you sometimes store output on storage
devices, such as a disk or flash media. 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 also
write programs in different languages. Some programmers work
exclusively in one language, whereas others know several program-
ming languages and use the one that is best suited to the task
at hand.
Every programming language has rules governing its word usage and
punctuation. These rules are called the language’s syntax. 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.
When you write a program, you usually type its instructions using
a keyboard. When you type program instructions, they are stored
in computer memory, which is a computer’s temporary, internal
The instruc-
tions you write
using a pro-
gramming
language are
called program code;
when you write instruc-
tions, you are coding the
program.
3
Understanding Computer Systems
storage. Internal storage is volatile—its contents are lost when the
computer is turned off or loses power. Usually, you want to be able to
retrieve and perhaps modify the stored instructions later, so you also
store them on a permanent storage device, such as a disk. Permanent
storage devices are nonvolatile—that is, their contents are persistent
and are retained even when power is lost.
After a computer program is stored in memory, it must be trans-
lated from your programming language statements to machine
language that represents the millions of on/off circuits within the
computer. Each programming language uses a piece of software,
called a compiler or an interpreter, to translate your program
code into machine language. Machine language is also called
binary language, and is represented as a series of 0s and 1s. The
compiler or interpreter that translates your code tells you if any
programming language component has been used incorrectly.
Syntax errors are relatively easy to locate and correct because
the compiler or interpreter you use highlights every syntax error.
If you write a computer program using a language such as C++
but spell one of its words incorrectly or reverse the proper order
of two words, the software lets you know that it found a mistake
by displaying an error message as soon as you try to translate the
program.
Although there are differences in how compilers and interpreters work, their
basic function is the same—to translate your programming statements into
code the computer can use. When you use a compiler, an entire program is
translated before it can execute; when you use an interpreter, each instruc-
tion is translated just prior to execution. Usually, you do not choose which
type of translation to use—it depends on the programming language. However, there
are some languages for which both compilers and interpreters are available.
Only after program instructions are successfully translated to machine
code can the computer carry out the program instructions. When
instructions are carried out, a program runs, or executes. In a typical
program, some input will be accepted, some processing will occur,
and results will be output.
Besides the popular full-blown programming languages such as Java
and C++, many programmers use scripting languages (also called
scripting programming languages or script languages) such as Python,
Lua, Perl, and PHP. Scripts written in these languages usually can be typed
directly from a keyboard and are stored as text rather than as binary execut-
able files. Scripting language programs are interpreted line by line each time the
program executes, instead of being stored in a compiled (binary) form.
Random
access
memory, or
RAM, is a
form of inter-
nal, volatile memory. It is
hardware on which the
programs that are cur-
rently running and the
data items that are
currently being used
are stored for quick
access.
The program
statements
you write in a
programming
language are
known as source code.
The translated machine
language statements are
known as object code.
4
C H A P T E R 1 An Overview of Computers and Programming
TWO TRUTHS & A LIE
Understanding Computer Systems
In each Two Truths and a Lie section, two of the numbered statements are true,
and one is false. Identify the false statement and explain why it is false.
1. Hardware is the equipment, or the devices, associated with a computer.
Software is computer instructions.
2. The grammar rules of a computer programming language are its syntax.
3. You write programs using machine language, and translation software con-
verts the statements to a programming language.
The
false
statement
is
#3.
You
write
programs
using
a
programming
language
such
as
Visual
Basic
or
Java,
and
a
translation
program
(called
a
compiler
or
inter-
preter)
converts
the
statements
to
machine
language,
which
is
0s
and
1s.
Understanding Simple Program Logic
A program with syntax errors cannot execute. A program with no syntax
errors can execute, but might contain logical errors, and produce incor-
rect output as a result. For a program to work properly, you must give the
instructions to the computer in a specific sequence, you must not leave
any instructions out, and you must not add extraneous instructions. By
doing this, you are developing the logic of the computer program.
Suppose you instruct someone to
make a cake as follows:
Get a bowl
Stir
Add two eggs
Add a gallon of gasoline
Bake at 350 degrees for 45 minutes
Add three cups of flour
Even though you have used the English language syntax correctly, the
cake-baking instructions are out of sequence, some instructions are
missing, and some instructions belong to procedures other than baking
a cake. If you follow these instructions, you are not going to make an edi-
ble cake, and you most likely will end up with a disaster. Logical errors
are much more difficult to locate than syntax errors—it is easier for you
to determine whether “eggs” is spelled incorrectly in a recipe than it is
for you to tell if there are too many eggs or if they are added too soon.
The dangerous
cake-baking
instructions
are shown with
a Don’t Do It
icon. You will see this icon
when the book contains
an unrecommended pro-
gramming practice that is
used as an example of
what not to do.
If you misspell
a program-
ming language
word, you
commit a
syntax error, but if you
use an otherwise correct
word that does not make
sense in the current con-
text, programmers say
you have committed a
semantic error. Either
way, the program will not
execute.
Don’t Do It
Don't bake a cake like
this!
5
Understanding Simple Program Logic
Just as baking directions can be given correctly in Mandarin, Urdu,
or Spanish, the same program logic can be expressed in any number
of programming languages. Because this book is not concerned with
any specific language, the programming examples could have been
written in Visual Basic, C++, or Java. For convenience, this book uses
instructions written in English!
Most simple computer programs include steps that perform input,
processing, and output. Suppose you want to write a computer
program to double any number you provide. You can write such a
program in a programming language such as Visual Basic or Java,
but if you were to write it using English-like statements, it would
look like this:
input myNumber
set myAnswer = myNumber * 2
output myAnswer
The number-doubling process includes three instructions:
The instruction to
• input myNumber is an example of an input
operation. When the computer interprets this instruction, it
knows to look to an input device to obtain a number. When you
work in a specific programming language, you write instructions
that tell the computer which device to access for input. For exam-
ple, when a user enters a number as data for a program, the user
might click on the number with a mouse, type it from a keyboard,
or speak it into a microphone. Logically, however, it doesn’t really
matter which hardware device is used, as long as the computer
knows to look for a number. When the number is retrieved from
an input device, it is placed in the computer’s memory at the
location named myNumber. The location myNumber is a variable. A
variable is a named memory location whose value can vary—for
example, the value of myNumber might be 3 when the program is
used for the first time and 45 when it is used the next time.
From a logical perspective, when you input a value, the hardware device is
irrelevant. The same is true in your daily life. If you follow the instruction “Get
eggs for the cake,” it does not really matter if you purchase them from a
store or harvest them from your own chickens—you get the eggs either way.
There might be different practical considerations to getting the eggs, just as
there are for getting data from a large database as opposed to an inexperienced user.
For now, this book is only concerned with the logic of the operation, not the minor
details.
The instruction
• set myAnswer = myNumber * 2 is an example
of a processing operation. Mathematical operations are not the
only kind of processing operations, but they are very typical. As
with input operations, the type of hardware used for processing
After you learn
French, you
automatically
know, or can
easily figure
out, many Spanish words.
Similarly, after you learn
one programming lan-
guage, it is much easier
to understand several
other languages.
You will learn
about the odd
elimination of
the space
between
words like my and
Number in Chapter 2.
Programmers
use an aster-
isk to indicate
multiplication.
You will learn
more about arithmetic
statements in Chapter 2.
6
C H A P T E R 1 An Overview of Computers and Programming
is irrelevant—after you write a program, it can be used on comput-
ers of different brand names, sizes, and speeds. The instruction
takes the value stored in memory at the myNumber location, mul-
tiplies it by 2, and stores the result in another memory location
named myAnswer.
In the number-doubling program, the
• output myAnswer instruc-
tion is an example of an output operation. Within a particular
program, this statement could cause the output to appear on the
monitor (which might be a flat-panel plasma screen or a cathode-
ray tube), or the output could go to a printer (which could be laser
or ink-jet), or the output could be written to a disk or DVD. The
logic of the output process is the same no matter what hardware
device you use. When this instruction executes, the value stored
in memory at the location named myAnswer is sent to an output
device.
Computer memory consists of millions of numbered locations where data
can be stored. The memory location of myNumber has a specific numeric
address—for example, 48604. Your program associates myNumber with
that address. Every time you refer to myNumber within a program, the com-
puter retrieves the value at the associated memory location. When you write
programs, you seldom need to be concerned with the value of the memory address;
instead, you simply use the easy-to-remember name you created.
Computer programmers often refer to memory addresses using hexadeci-
mal notation, or base 16. Using this system, they might use a value like
42FF01A to refer to a memory address. Despite the use of letters, such an
address is still a hexadecimal number. Appendix A contains information on
this numbering system.
TWO TRUTHS & A LIE
Understanding Simple Program Logic
1. A program with syntax errors can execute but might produce incorrect results.
2. Although the syntax of programming languages differs, the same program
logic can be expressed in different languages.
3. Most simple computer programs include steps that perform input, process-
ing, and output.
The
false
statement
is
#1.
A
program
with
syntax
errors
cannot
execute;
a
program
with
no
syntax
errors
can
execute,
but
might
produce
incorrect
results.
Watch the
video A Simple
Program.
7
Understanding Simple Program Logic
Understanding the Program
Development Cycle
A programmer’s job involves writing instructions (such as those in
the doubling program in the preceding section), but a professional
programmer usually does not just sit down at a computer keyboard
and start typing. Figure 1-1 illustrates the program development
cycle, which can be broken down into at least seven steps:
1. Understand the problem.
2. Plan the logic.
3. Code the program.
4. Use software (a compiler or interpreter) to translate the
program into machine language.
5. Test the program.
6. Put the program into production.
7. Maintain the program.
Understand
the problem
Test the
program
Put the program
into production
Maintain the
program
Plan the
logic
Translate the
code
Write the
code
Figure 1-1 The program development cycle
Understanding the Problem
Professional computer programmers write programs to satisfy the
needs of others, called users or end users. Examples could include a
Human Resources department that needs a printed list of all employ-
ees, a Billing department that wants a list of clients who are 30 or
more days overdue on their payments, and an Order department that
8
C H A P T E R 1 An Overview of Computers and Programming
needs a Web site to provide buyers with an online shopping cart in
which to gather their orders. Because programmers are providing a
service to these users, programmers must first understand what the
users want. Although when a program runs, you usually think of the
logic as a cycle of input-processing-output operations; when you
plan a program, you think of the output first. After you understand
what the desired result is, you can plan what to input and process to
achieve it.
Suppose the director of Human Resources says to a programmer,
“Our department needs a list of all employees who have been here
over five years, because we want to invite them to a special thank-you
dinner.” On the surface, this seems like a simple request. An experi-
enced programmer, however, will know that the request is incom-
plete. For example, you might not know the answers to the following
questions about which employees to include:
Does the director want a list of full-time employees only, or a list
•
of full- and part-time employees together?
Does she want people who have worked for the company on a
•
month-to-month contractual basis over the past five years, or only
regular, permanent employees?
Do the listed employees need to have worked for the organization
•
for five years as of today, as of the date of the dinner, or as of some
other cutoff date?
What about an employee who, for example, worked three years,
•
took a two-year leave of absence, and has been back for three years?
The programmer cannot make any of these decisions; the user (in this
case, the Human Resources director) must address these questions.
More decisions still might be required. For example:
What data should be included for each listed employee? Should
•
the list contain both first and last names? Social Security numbers?
Phone numbers? Addresses?
Should the list be in alphabetical order? Employee ID number
•
order? Length-of-service order? Some other order?
Should the employees be grouped by any criteria, such as depart-
•
ment number or years of service?
Several pieces of documentation are often provided to help the pro-
grammer understand the problem. Documentation consists of all the
supporting paperwork for a program; it might include items such
as original requests for the program from users, sample output, and
descriptions of the data items available for input.
The term end
user distin-
guishes those
who actually
use and ben-
efit from a software prod-
uct from others in an
organization who might
purchase, install, or have
other contact with the
software.
9
Understanding the Program Development Cycle
Really understanding the problem may be one of the most difficult
aspects of programming. On any job, the description of what the user
needs may be vague—worse yet, users may not really know what they
want, and users who think they know frequently change their minds
after seeing sample output. A good programmer is often part coun-
selor, part detective!
Planning the Logic
The heart of the programming process lies in planning the program’s
logic. During this phase of the process, the programmer plans the
steps of the program, deciding what steps to include and how to order
them. You can plan the solution to a problem in many ways. The two
most common planning tools are flowcharts and pseudocode. Both
tools involve writing the steps of the program in English, much as you
would plan a trip on paper before getting into the car or plan a party
theme before shopping for food and favors.
The programmer shouldn’t worry about the syntax of any particu-
lar language at this point, but should focus on figuring out what
sequence of events will lead from the available input to the desired
output. Planning the logic includes thinking carefully about all the
possible data values a program might encounter and how you want
the program to handle each scenario. The process of walking through
a program’s logic on paper before you actually write the program is
called desk-checking. You will learn more about planning the logic
throughout this book; in fact, the book focuses on this crucial step
almost exclusively.
Coding the Program
After the logic is developed, only then can the programmer write
the program. Hundreds of programming languages are available.
Programmers choose particular languages because some have built-in
capabilities that make them more efficient than others at handling
certain types of operations. Despite their differences, programming
languages are quite alike in their basic capabilities—each can handle
input operations, arithmetic processing, output operations, and other
standard functions. The logic developed to solve a programming
problem can be executed using any number of languages. Only after
choosing a language must the programmer be concerned with proper
punctuation and the correct spelling of commands—in other words,
using the correct syntax.
Some very experienced programmers can successfully combine
logic planning and program coding in one step. This may work for
Watch the video
The Program
Development
Cycle, Part 1.
You may hear
programmers
refer to
planning a
program as
“developing an algorithm.”
An algorithm is the
sequence of steps neces-
sary to solve any problem.
You will learn
more about
flowcharts
and pseudo-
code later in
this chapter.
In addition to
flowcharts and
pseudocode,
programmers
use a variety
of other tools to help in
program development.
One such tool is an IPO
chart, which delineates
input, processing, and
output tasks. Some
object-oriented program-
mers also use TOE
charts, which list tasks,
objects, and events.
10
C H A P T E R 1 An Overview of Computers and Programming
planning and writing a very simple program, just as you can plan and
write a postcard to a friend using one step. A good term paper or a
Hollywood screenplay, however, needs planning before writing—and
so do most programs.
Which step is harder: planning the logic or coding the program?
Right now, it may seem to you that writing in a programming lan-
guage is a very difficult task, considering all the spelling and syntax
rules you must learn. However, the planning step is actually more
difficult. Which is more difficult: thinking up the twists and turns to
the plot of a best-selling mystery novel, or writing a translation of an
existing novel from English to Spanish? And who do you think gets
paid more, the writer who creates the plot or the translator? (Try
asking friends to name any famous translator!)
Using Software to Translate the Program
into Machine Language
Even though there are many programming languages, each computer
knows only one language: its machine language, which consists of 1s
and 0s. Computers understand machine language because they are
made up of thousands of tiny electrical switches, each of which can
be set in either the on or off state, which is represented by a 1 or 0,
respectively.
Languages like Java or Visual Basic are available for programmers
because someone has written a translator program (a compiler or
interpreter) that changes the programmer’s English-like high-level
programming language into the low-level machine language that
the computer understands. If you write a programming language
statement incorrectly (for example, by misspelling a word, using a
word that doesn’t exist in the language, or using “illegal” grammar),
the translator program doesn’t know how to proceed and issues
an error message identifying a syntax error, which is a misuse of a
language’s grammar rules. Although making errors is never desirable,
syntax errors are not a major concern to programmers, because the
compiler or interpreter catches every syntax error and displays a mes-
sage that notifies you of the problem. The computer will not execute a
program that contains even one syntax error.
Typically, a programmer develops a program’s logic, writes the code,
and compiles the program, receiving a list of syntax errors. The pro-
grammer then corrects the syntax errors and compiles the program
again. Correcting the first set of errors frequently reveals new errors
that originally were not apparent to the compiler. For example, if you
could use an English compiler and submit the sentence “The dg chase
When you
learn the syn-
tax of a pro-
gramming
language, the
commands you learn will
work on any machine on
which the language soft-
ware has been installed.
However, your com-
mands are translated to
machine language, which
differs depending on your
computer make and
model.
Watch the video
The Program
Development
Cycle, Part 2.
11
Understanding the Program Development Cycle
the cat,” the compiler at first might point out only one syntax error.
The second word, “dg,” is illegal because it is not part of the English
language. Only after you corrected the word to “dog” would the com-
piler find another syntax error on the third word, “chase,” because it is
the wrong verb form for the subject “dog.” This doesn’t mean “chase”
is necessarily the wrong word. Maybe “dog” is wrong; perhaps the
subject should be “dogs,” in which case “chase” is right. Compilers
don’t always know exactly what you mean, nor do they know what the
proper correction should be, but they do know when something is
wrong with your syntax.
When writing a program, a programmer might need to recompile the
code several times. An executable program is created only when the
code is free of syntax errors. When you run an executable program, it
typically also might require input data. Figure 1-2 shows a diagram of
this entire process.
Write and correct
the program code
Compile the
program
Executable
program
Data that the
program uses
List of
syntax
error
messages
Program
output
If there are no
syntax errors
If there are
syntax errors
Figure 1-2 Creating an executable program
Testing the Program
A program that is free of syntax errors is not necessarily free of logi-
cal errors. A logical error results when you use a syntactically correct
statement but use the wrong one for the current context. For exam-
ple, the English sentence “The dog chases the cat,” although syntacti-
cally perfect, is not logically correct if the dog chases a ball or the cat
is the aggressor.
After a pro-
gram has
been trans-
lated into
machine lan-
guage, the machine lan-
guage program is saved
and can be run any num-
ber of times without
repeating the translation
step. You only need to
retranslate your code if
you make changes to
your source code
statements.
12
C H A P T E R 1 An Overview of Computers and Programming
Once a program is free of syntax errors, the programmer can
test it—that is, execute it with some sample data to see whether
the results are logically correct. Recall the number-doubling
program:
input myNumber
set myAnswer = myNumber * 2
output myAnswer
If you execute the program, provide the value 2 as input to the pro-
gram, and the answer 4 is displayed, you have executed one successful
test run of the program.
However, if the answer 40 is displayed, maybe the program contains
a logical error. Maybe the second line of code was mistyped with an
extra zero, so that the program reads:
input myNumber
set myAnswer = myNumber * 20
output myAnswer
Placing 20 instead of 2 in the
multiplication statement caused a logical error. Notice that nothing is
syntactically wrong with this second program—it is just as reasonable
to multiply a number by 20 as by 2—but if the programmer intends
only to double myNumber, then a logical error has occurred.
Programs should be tested with many sets of data. For example, if
you write the program to double a number, then enter 2 and get an
output value of 4, that doesn’t
necessarily mean you have
a correct program. Perhaps
you have typed this program
by mistake:
input myNumber
set myAnswer = myNumber + 2
output myAnswer
An input of 2 results in an answer of 4, but that doesn’t mean your
program doubles numbers—it actually only adds 2 to them. If you test
your program with additional data and get the wrong answer—for
example, if you enter 7 and get an answer of 9—you know there is a
problem with your code.
Selecting test data is somewhat of an art in itself, and it should be
done carefully. If the Human Resources department wants a list
of the names of five-year employees, it would be a mistake to test
the program with a small sample file of only long-term employees.
If no newer employees are part of the data being used for testing,
you do not really know if the program would have eliminated them
The process
of finding and
correcting
program
errors is
called debugging.
Don’t Do It
The programmer typed
"20" instead of "2".
Don’t Do It
The programmer typed
"+" instead of "
*".
13
Understanding the Program Development Cycle
from the five-year list. Many companies do not know that their
software has a problem until an unusual circumstance occurs—for
example, the first time an employee has more than nine depen-
dents, the first time a customer orders more than 999 items at a
time, or when (as well-documented in the popular press) a new
century begins.
Putting the Program into
Production
Once the program is tested adequately, it is ready for the organi-
zation to use. Putting the program into production might mean
simply running the program once, if it was written to satisfy a
user’s request for a special list. However, the process might take
months if the program will be run on a regular basis, or if it is one
of a large system of programs being developed. Perhaps data-entry
people must be trained to prepare the input for the new program;
users must be trained to understand the output; or existing data
in the company must be changed to an entirely new format to
accommodate this program. Conversion, the entire set of actions
an organization must take to switch over to using a new pro-
gram or set of programs, can sometimes take months or years to
accomplish.
Maintaining the Program
After programs are put into production, making necessary
changes is called maintenance. Maintenance can be required for
many reasons: new tax rates are legislated, the format of an input
file is altered, or the end user requires additional information
not included in the original output specifications, to name a few.
Frequently, your first programming job will require maintaining
previously written programs. When you maintain the programs
others have written, you will appreciate the effort the original pro-
grammer put into writing clear code, using reasonable variable
names, and documenting his or her work. When you make changes
to existing programs, you repeat the development cycle. That is, you
must understand the changes, then plan, code, translate, and test
them before putting them into production. If a substantial number
of program changes are required, the original program might be
retired, and the program development cycle might be started for a
new program.
Chapter 4
contains more
information on
testing
programs.
Watch the video
The Program
Development
Cycle, Part 3.
14
C H A P T E R 1 An Overview of Computers and Programming
TWO TRUTHS & A LIE
Understanding the Program Development Cycle
1. Understanding the problem that must be solved can be one of the most dif-
ficult aspects of programming.
2. The two most commonly used logic-planning tools are flowcharts and
pseudocode.
3. Flowcharting a program is a very different process if you use an older
programming language instead of a newer one.
The
false
statement
is
#3.
Despite
their
differences,
programming
languages
are
quite
alike
in
their
basic
capabilities—each
can
handle
input
operations,
arithmetic
processing,
output
operations,
and
other
standard
functions.
The
logic
developed
to
solve
a
programming
problem
can
be
executed
using
any
number
of
languages.
Using Pseudocode Statements
and Flowchart Symbols
When programmers plan the logic for a solution to a programming
problem, they often use one of two tools: pseudocode (pronounced
“sue-doe-code”) or flowcharts. Pseudocode is an English-like repre-
sentation of the logical steps it takes to solve a problem. A flowchart
is a pictorial representation of the same thing. Pseudo is a prefix that
means “false,” and to code a program means to put it in a programming
language; therefore, pseudocode simply means “false code,” or sentences
that appear to have been written in a computer programming language
but do not necessarily follow all the syntax rules of any specific language.
Writing Pseudocode
You have already seen examples of statements that represent pseudo-
code earlier in this chapter, and there is nothing mysterious about
them. The following five statements constitute a pseudocode repre-
sentation of a number-doubling problem:
start
input myNumber
set myAnswer = myNumber * 2
output myAnswer
stop
15
Using Pseudocode Statements and Flowchart Symbols
Using pseudocode involves writing down all the steps you will use in
a program. Usually, programmers preface their pseudocode with a
beginning statement like start and end it with a terminating state-
ment like stop. The statements between start and stop look like
English and are indented slightly so that start and stop stand out.
Most programmers do not bother with punctuation such as periods
at the end of pseudocode statements, although it would not be wrong
to use them if you prefer that style. Similarly, there is no need to capi-
talize the first word in a sentence, although you might choose to do
so. This book follows the conventions of using lowercase letters for
verbs that begin pseudocode statements and omitting periods at the
end of statements.
Pseudocode is fairly flexible because it is a planning tool, and not the
final product. Therefore, for example, you might prefer any of the
following:
Instead of
• start and stop, some pseudocode developers would
use the terms begin and end.
Instead of writing
• input myNumber, some developers would write
get myNumber or read myNumber.
Instead of writing
• set myAnswer = myNumber * 2, some develop-
ers would write calculate myAnswer = myNumber times 2 or
compute myAnswer as myNumber doubled.
Instead of writing
• output myAnswer, many pseudocode devel-
opers would write display myAnswer, print myAnswer, or
write myAnswer.
The point is, the pseudocode statements are instructions to retrieve
an original number from an input device and store it in memory
where it can be used in a calculation, and then to get the calculated
answer from memory and send it to an output device so a person can
see it. When you eventually convert your pseudocode to a specific
programming language, you do not have such flexibility because spe-
cific syntax will be required. For example, if you use the C# program-
ming language and write the statement to output the answer, you will
code the following:
Console.Write (myAnswer);
The exact use of words, capitalization, and punctuation are important
in the C# statement, but not in the pseudocode statement.
16
C H A P T E R 1 An Overview of Computers and Programming
Drawing Flowcharts
Some professional programmers prefer writing pseudocode to
drawing flowcharts, because using pseudocode is more similar to
writing the final statements in the programming language. Others
prefer drawing flowcharts to represent the logical flow, because flow-
charts allow programmers to visualize more easily how the program
statements will connect. Especially for beginning programmers, flow-
charts are an excellent tool to help them visualize how the statements
in a program are interrelated.
When you create a flowchart, you draw geometric shapes that contain
the individual statements and that are connected with arrows. You
use a parallelogram to represent
an input symbol, which indicates
an input operation. You write an
input statement in English inside the
parallelogram, as shown in Figure 1-3.
Arithmetic operation statements
are examples of processing. In a
flowchart, you use a rectangle as the
processing symbol that contains a
processing statement, as shown in
Figure 1-4.
To represent an output state-
ment, you use the same symbol as
for input statements—the output
symbol is a parallelogram, as shown
in Figure 1-5.
Some software programs that use flowcharts (such as Visual Logic) use
a left-slanting parallelogram to represent output. As long as the flowchart
creator and the flowchart reader are communicating, the actual shape
used is irrelevant. This book will follow the most standard convention
of always using the right-slanting parallelogram for both input and output.
To show the correct sequence of these statements, you use arrows, or
flowlines, to connect the steps. Whenever possible, most of a flow-
chart should read from top to bottom or from left to right on a page.
That’s the way we read English, so when flowcharts follow this con-
vention, they are easier for us to understand.
You can draw
a flowchart by
hand or use
software,
such as
Microsoft Word and
Microsoft PowerPoint,
that contains flowcharting
tools. You can use sev-
eral other software pro-
grams, such as Visio and
Visual Logic, specifically
to create flowcharts.
Because the
parallelogram
is used for
both input and
output, it is
often called
the input/output
symbol or I/O symbol.
Appendix B
contains a
summary of
all the flow-
chart symbols
you will see in this book.
input myNumber
Figure 1-3 Input symbol
set myAnswer =
myNumber * 2
Figure 1-4 Processing symbol
output myAnswer
Figure 1-5 Output symbol
17
Using Pseudocode Statements and Flowchart Symbols
To be complete, a flowchart should include two more elements:
terminal symbols, or start/stop symbols, at each end. Often, you
place a word like start or begin in the first terminal symbol and a
word like end or stop in the other. The standard terminal symbol is
shaped like a racetrack; many programmers refer to this shape as a
lozenge, because it resembles the shape of the medication you might
use to soothe a sore throat. Figure 1-6 shows a complete flowchart
for the program that doubles a number, and the pseudocode for the
same problem. You can see from the figure that the flowchart and
pseudocode statements are the same—only the presentation format
differs.
start
Flowchart Pseudocode
stop
input myNumber
output myAnswer
set myAnswer =
myNumber * 2
start
input myNumber
set myAnswer = myNumber * 2
output myAnswer
stop
Figure 1-6 Flowchart and pseudocode of program that doubles a number
Repeating Instructions
After the flowchart or pseudocode has been developed, the
programmer only needs to: (1) buy a computer, (2) buy a language
compiler, (3) learn a programming language, (4) code the pro-
gram, (5) attempt to compile it, (6) fix the syntax errors, (7) com-
pile it again, (8) test it with several sets of data, and (9) put it into
production.
“Whoa!” you are probably saying to yourself. “This is simply not worth
it! All that work to create a flowchart or pseudocode, and then all those
other steps? For five dollars, I can buy a pocket calculator that will
Programmers
seldom create
both pseudo-
code and a
flowchart for
the same problem. You
usually use one or the
other. In a large program,
you might even prefer to
use pseudocode for
some parts and draw a
flowchart for others.
18
C H A P T E R 1 An Overview of Computers and Programming
double any number for me instantly!” You are absolutely right. If this
were a real computer program, and all it did was double the value of a
number, it would not be worth the effort. Writing a computer program
would be worthwhile only if you had many—let’s say 10,000—numbers
to double in a limited amount of time—let’s say the next two minutes.
Unfortunately, the number-doubling program represented in
Figure 1-6 does not double 10,000 numbers; it doubles only one. You
could execute the program 10,000 times, of course, but that would
require you to sit at the computer and tell it to run the program over
and over again. You would be better off with a program that could
process 10,000 numbers, one after the other.
One solution is to write the program shown in Figure 1-7 and execute
the same steps 10,000 times. Of course, writing this program would
be very time consuming; you might as well buy the calculator.
Figure 1-7 Inefficient pseudocode for program that doubles 10,000 numbers
start
input myNumber
set myAnswer = myNumber * 2
output myAnswer
input myNumber
set myAnswer = myNumber * 2
output myAnswer
input myNumber
set myAnswer = myNumber * 2
output myAnswer
…and so on for 9,997 more times
A better solution is to have the computer execute the same set of
three instructions over and over again, as shown in Figure 1-8. The
repetition of a series of steps is called a loop. With this approach, the
computer gets a number, doubles it, displays the answer, and then
starts over again with the first instruction. The same spot in memory,
called myNumber, is reused for the second number and for any subse-
quent numbers. The spot in memory named myAnswer is reused each
time to store the result of the multiplication operation. The logic illus-
trated in the flowchart in Figure 1-8 contains a major problem—the
sequence of instructions never ends. This programming situation is
known as an infinite loop—a repeating flow of logic with no end. You
will learn one way to handle this problem later in this chapter; you
will learn a superior way in Chapter 3.
When you tell
a friend how
to get to your
house, you
might write a
series of instructions or
you might draw a map.
Pseudocode is similar to
written, step-by-step
instructions; a flowchart,
like a map, is a visual
representation of the
same thing.
Don’t Do It
You would never want to
write such a repetitious
list of instructions.
19
Using Pseudocode Statements and Flowchart Symbols
start
input myNumber
output myAnswer
set myAnswer =
myNumber * 2
Don’t Do It
This logic saves
steps, but it has a
fatal flaw – it never
ends.
Figure 1-8 Flowchart of infinite number-doubling program
TWO TRUTHS & A LIE
Using Pseudocode Statements and Flowchart Symbols
1. When you draw a flowchart, you use a parallelogram to represent an input
operation.
2. When you draw a flowchart, you use a parallelogram to represent a process-
ing operation.
3. When you draw a flowchart, you use a parallelogram to represent an output
operation.
The
false
statement
is
#2.
When
you
draw
a
fl
owchart,
you
use
a
rectangle
to
represent
a
processing
operation.
Using a Sentinel Value to End
a Program
The logic in the flowchart for doubling numbers, shown in Figure 1-8,
has a major flaw—the program contains an infinite loop. If, for exam-
ple, the input numbers are being entered at the keyboard, the program
will keep accepting numbers and outputting doubles forever. Of course,
the user could refuse to type any more numbers. But the computer is
very patient, and if you refuse to give it any more numbers, it will sit
and wait forever. When you finally type a number, the program will
double it, output the result, and wait for another. The program cannot
20
C H A P T E R 1 An Overview of Computers and Programming
progress any further while it is waiting for input; meanwhile, the pro-
gram is occupying computer memory and tying up operating system
resources. Refusing to enter any more numbers is not a practical solu-
tion. Another way to end the program is simply to turn off the com-
puter. But again, that’s neither the best way nor an elegant solution.
A superior way to end the program is to set a predetermined value for
myNumber that means “Stop the program!” For example, the program-
mer and the user could agree that the user will never need to know
the double of 0, so the user could enter a 0 to stop. The program could
then test any incoming value contained in myNumber and, if it is a 0,
stop the program. Testing a value is also called making a decision.
You represent a decision in a flowchart by drawing a decision symbol,
which is shaped like a diamond. The diamond usually contains a
question, the answer to which is one of two mutually exclusive
options—often yes or no. All good computer questions have only
two mutually exclusive answers, such as yes and no or true and false.
For example, “What day of the year is your birthday?” is not a good
computer question because there are 366 possible answers. However,
“Is your birthday June 24?” is a good computer question because, for
everyone in the world, the answer is either yes or no.
The question to stop the doubling program should be “Is the value
of myNumber just entered equal to 0?” or “myNumber = 0?” for short. The
complete flowchart will now look like the one shown in Figure 1-9.
stop
myNumber
= 0?
Yes
No
start
input myNumber
output myAnswer
set myAnswer =
myNumber times 2
Don’t Do It
This logic is not
structured; you will
learn about structure
in Chapter 3.
Figure 1-9 Flowchart of number-doubling program with sentinel value of 0
A yes-or-no
decision is
called a
binary deci-
sion, because
there are two possible
outcomes.
21
Using a Sentinel Value to End a Program
One drawback to using 0 to stop a program, of course, is that it won’t
work if the user does need to find the double of 0. In that case, some
other data-entry value that the user will never need, such as 999 or –1,
could be selected to signal that the program should end. A preselected
value that stops the execution of a program is often called a dummy
value because it does not represent real data, but just a signal to stop.
Sometimes, such a value is called a sentinel value because it repre-
sents an entry or exit point, like a sentinel who guards a fortress.
Not all programs rely on user data entry from a keyboard; many read
data from an input device, such as a disk. When organizations store
data on a disk or other storage device, they do not commonly use
a dummy value to signal the end of the file. For one thing, an input
record might have hundreds of fields, and if you store a dummy record
in every file, you are wasting a large quantity of storage on “nondata.”
Additionally, it is often difficult to choose sentinel values for fields
in a company’s data files. Any balanceDue, even a zero or a negative
number, can be a legitimate value, and any customerName, even “ZZ”,
could be someone’s name. Fortunately, programming languages can
recognize the end of data in a file automatically, through a code that
is stored at the end of the data. Many programming languages use the
term eof (for “end of file”) to refer to this marker that automatically
acts as a sentinel. This book, therefore, uses eof to indicate the end of
data whenever using a dummy value is impractical or inconvenient. In
the flowchart shown in Figure 1-10, the eof question is shaded.
stop
eof?
Yes
No
start
input myNumber
output myAnswer
set myAnswer =
myNumber times 2
Don’t Do It
This logic is not
structured; you will
learn about structure
in Chapter 3.
Figure 1-10 Flowchart using eof
22
C H A P T E R 1 An Overview of Computers and Programming
TWO TRUTHS & A LIE
Using a Sentinel Value to End a Program
1. A program that contains an infinite loop is one that never ends.
2. A preselected value that stops the execution of a program is often called a
dummy value or a sentinel value.
3. Many programming languages use the term fe (for “file end”) to refer to a
marker that automatically acts as a sentinel.
The
false
statement
is
#3.
The
term
eof
(for
“end
of
fi
le”)
is
the
common
term
for
a
fi
le
sentinel.
Understanding Programming
and User Environments
Many approaches can be used to write and execute a computer pro-
gram. When you plan a program’s logic, you can use a flowchart or
pseudocode, or a combination of the two. When you code the pro-
gram, you can type statements into a variety of text editors. When
your program executes, it might accept input from a keyboard,
mouse, microphone, or any other input device, and when you provide
a program’s output, you might use text, images, or sound. This section
describes the most common environments you will encounter as a
new programmer.
Understanding Programming Environments
When you plan the logic for a computer program, you can use paper
and pencil to create a flowchart, or you might use software that
allows you to manipulate flowchart shapes. If you choose to write
pseudocode, you can do so by hand or by using a word-processing
program. To enter the program into a computer so you can trans-
late and execute it, you usually use a keyboard to type program
statements into an editor. You can type a program into one of the
following:
A plain text editor
•
A text editor that is part of an integrated development
•
environment
23
Understanding Programming and User Environments
A text editor is a program that you use to create simple text files. It
is similar to a word processor, but without as many features. You can
use a text editor such as Notepad that is included with Microsoft
Windows. Figure 1-11 shows a C# program in Notepad that accepts
a number and doubles it. An advantage to using a simple text editor
to type and save a program is that the completed program does not
require much disk space for storage. For example, the file shown in
Figure 1-11 occupies only 314 bytes of storage.
This line contains a
prompt that tells the user
what to enter. You will
learn more about prompts
in Chapter 2.
Figure 1-11 A C# number-doubling program in Notepad
You can use the editor of an integrated development environment
(IDE) to enter your program. An IDE is a software package that pro-
vides an editor, compiler, and other programming tools. For example,
Figure 1-12 shows a C# program in the Microsoft Visual Studio IDE,
an environment that contains tools useful for creating programs in
Visual Basic, C++, and C#.
Figure 1-12 A C# number-doubling program in Visual Studio
24
C H A P T E R 1 An Overview of Computers and Programming
Other documents randomly have
different content
devant d'eux en bon ordre et bannières déployées. On se trouvait
dans de vastes bruyères coupées de fossés. Les hommes d'armes
bourguignons y cherchèrent longtemps la route qu'ils devaient
suivre. Au centre, les fossés étaient absolument inabordables: à
gauche, on ne pouvait les franchir qu'à pied; mais vers la droite,
Jacques de Lalaing, le sire d'Aumont, et les deux sires de Vaudrey
parvinrent à faire passer leurs chevaux et les lancèrent au milieu des
Gantois, tandis que les hommes d'armes du sire de Croy, qui
revenaient du sac d'Overmeire, les attaquaient par derrière. Les
difficultés du terrain facilitèrent la retraite des Gantois. S'ils laissaient
quatre ou cinq cents de leurs compagnons sur le champ du combat,
leur mort intrépide égala du moins leur résistance à une victoire, car
l'armée du duc, affaiblie par ses pertes, effrayée des tintements du
tocsin qui résonnaient au loin, s'arrêta et retourna à Termonde livrer
au bourreau quelques prisonniers qu'elle emmenait avec elle (23 mai
1452).
Que se passait-il au même moment au sud de Gand? Qu'était
devenue l'expédition du comte d'Étampes, entreprise simultanément
avec celle du duc de Bourgogne? Avait-elle obtenu, grâce à cette
tactique habile, un succès plus décisif? L'ordre du récit nous conduit
à de nouveaux combats, et quels qu'en doivent être les résultats, il
est trop aisé de prévoir que nous verrons s'y associer d'autres
scènes de pillage et de dévastation.
Le comte d'Etampes s'était dirigé d'Audenarde vers Harlebeke pour
faire lever le siége du château d'Ingelmunster que bloquaient
quelques Gantois. Il y réussit aisément, et ce fut en chassant devant
lui toutes les troupes gantoises qui étendaient leurs excursions
jusqu'à Courtray, qu'il poursuivit sa marche vers Nevele.
Nevele était un gros bourg entouré de fossés. Les Gantois,
commandés par Jean de Vos y avaient élevé un fort retranchement,
et, comme si ces précautions ne leur eussent pas suffi, ils avaient
fait couper toutes les routes environnantes et avaient placé dans les
blés des pieux destinés à arrêter les chevaux. Le comte d'Etampes
s'inquiéta peu de ces préparatifs. Son armée était fort nombreuse,
puisque les chroniques flamandes l'évaluent à huit mille chevaux; il
avait d'ailleurs avec lui la plupart de ses intrépides chevaliers qui
avaient délivré Audenarde. Le bâtard Antoine de Bourgogne
commandait l'avant-garde; le sire de Saveuse éclairait la marche de
l'armée. Elle se porta immédiatement en avant pour assaillir les
Gantois, qui s'attendaient peu à cette attaque, et les hommes
d'armes bourguignons, protégés par les traits des archers,
s'emparèrent facilement des retranchements qu'ils rencontrèrent. A
peine les Gantois eurent-ils le temps de se replier au delà de Nevele,
se défendant toutefois si courageusement que la chevalerie
bourguignonne ne put les entamer.
Nous retrouvons à la prise de Nevele toutes les circonstances de la
prise de Lokeren. Le comte d'Etampes, qui était resté hors du bourg
de Nevele, avait donné l'ordre de poursuivre les Gantois. Les plus
braves chevaliers de l'armée et la plupart des hommes d'armes
s'empressèrent d'obéir et s'éloignèrent pour les atteindre. Ceux qui
ne les avaient pas suivis ne songeaient qu'à piller, lorsque des
renforts importants arrivèrent de Gand sous les ordres de Pierre Van
den Nieuwenhuus: au même moment, quatre ou cinq cents paysans,
avertis de ce qui se passait, se réunirent au son du tocsin et
marchèrent vers Nevele en poussant de grands cris. Le sire de
Hérimès, qui occupait le bourg, les entendit, et rassemblant
quelques archers, il se fit ouvrir les barrières et s'avança
imprudemment pour combattre. Les Gantois, un instant ébranlés par
le choc des Picards, les forcèrent bientôt à reculer jusqu'au pont, et
là toute résistance cessa. Le sire de Hérimès, que l'on citait comme
l'un des plus vaillants chevaliers de l'armée du duc, tomba sous leurs
coups; avec lui périrent des chevaliers de la Bourgogne, du
Dauphiné, de la Picardie, qui étaient venus chercher la mort sous la
massue ou sous les pieux ferrés de quelques obscurs laboureurs. Les
Gantois pénétraient déjà dans Nevele et frappaient tous les hommes
d'armes qui s'offraient à leurs regards. Le comte d'Etampes pâlit en
apprenant ce désastre. Il fit appeler Simon de Lalaing, à qui il avait
confié sa bannière, et lui demanda conseil. «Monseigneur, lui
répondit le sire de Lalaing, il convient sans plus tarder que tantôt et
incontinent cette ville soit reconquise sur ces vilains; car si on attend
à les assaillir, je fais doute que tantôt qu'il sera sçu par le pays, les
paysans s'élèveront de tous côtés et viendront secourir leurs gens.»
Le comte d'Etampes approuva cet avis et ordonna que chacun mît
pied à terre pour attaquer les Gantois. Le combat s'engagea avec
une nouvelle fureur: le désir de réparer une défaite encourageait les
uns; celui de conserver leur avantage soutenait les autres. Par un
hasard favorable aux Bourguignons, le bâtard de Bourgogne et ses
compagnons, renonçant à une poursuite infructueuse, revenaient
déjà vers Nevele. Ils tardèrent peu à reconnaître, au bruit de
l'assaut, que les Gantois avaient reconquis le bourg, et joignirent
leurs efforts à ceux que le comte d'Etampes faisait du côté opposé.
Enfin l'enceinte de Nevele fut forcée. Les Gantois que les vainqueurs
purent saisir furent impitoyablement mis à mort. Quelques-uns
s'étaient réfugiés dans une petite île: on les entoura, et pas un seul
n'échappa à la vengeance des hommes d'armes bourguignons.
C'était aussi à Nevele que, soixante et onze années auparavant,
Rasse d'Herzeele avait péri avec un grand nombre des siens en
combattant Louis de Male.
Cependant, dès que l'avant-garde eut rejoint le corps d'armée, le
comte d'Etampes fit mettre le feu au bourg de Nevele et ordonna la
retraite. Il en était temps. Le tocsin des villages voisins n'avait pas
cessé de retentir, et de toutes parts les laboureurs s'assemblaient,
les uns pour combattre, les autres pour fermer par des abatis
d'arbres la route qu'avait suivie l'armée du comte d'Etampes. Le péril
était plus grand que jamais, et sans la prudence des chefs de cette
expédition, elle eût enveloppé dans un désastre commun tous ceux
qui y avaient pris part. De nouveaux obstacles arrêtaient à chaque
pas la marche et accroissaient le désordre, lorsque le capitaine du
château de Poucke assaillit impétueusement l'arrière-garde avec sept
ou huit cents combattants. L'alarme gagna le corps principal: le
désordre d'une retraite précipitée succéda aux chances égales d'une
bataille. Ce fut à grand'peine que les chevaliers rallièrent leurs
hommes d'armes autour de l'étendard du comte d'Etampes. A
chaque pas, la mort éclaircissait leurs rangs, et cette brillante armée,
épuisée de fatigues et de privations, ne parvint à atteindre
Harlebeke que vers le milieu de la nuit (24 mai 1452).
La guerre était devenue si acharnée et si cruelle que, dans l'armée
des Gantois aussi bien que dans celle du duc, les prisonniers
offraient en vain les plus fortes rançons: ils n'évitaient la mort sur les
champs de bataille que pour périr le lendemain noyés, pendus ou
décapités. La fureur des combattants ne respectait pas davantage
les priviléges du rang le plus élevé ou des noms les plus illustres, et
plusieurs chevaliers bourguignons jugèrent prudent de chercher à
éloigner le comte de Charolais «d'icelle mortelle guerre, pour doubte
de male fortune et que dolereuse aventure n'avenist au père et au
fils ensamble, qui eust esté la totale destruction de tous les pays du
duc de Bourgogne.» Le duc Philippe partagea leur avis et chargea le
sire de Ternant de conduire son fils à Bruxelles, près de sa mère;
mais la duchesse de Bourgogne, instruite des motifs de ce voyage,
ne témoigna aucune joie de voir l'unique héritier de Philippe le Hardi
s'abriter dans le sein maternel comme dans un pacifique asile. Elle
garda le silence et se contenta d'inviter à un banquet «les chevaliers,
escuyers, dames et damoiselles.» Déjà la fête s'achevait, lorsque la
fière princesse portugaise, élevant la voix, s'adressa en ces mots au
comte de Charolais: «O mon fils, pour l'amour de vous, j'ay
assemblé ceste belle compaignie pour vous festoyer, car vous estes
la créature du monde, après monseigneur vostre père, que je ayme
le mieulx.... Or doncques, puisque monseigneur vostre père est en la
guerre à l'encontre de ses rebelles et désobéissans subjetz, pour son
honneur, haulteur et seigneurie garder, je vous prye que demain au
matin vous retournez devers lui, et gardez bien que en quelconque
lieu qu'il soit, pour doubte de mort ne autre chose en ce monde qui
vous puist advenir, vous n'eslongiez sa personne et soyés toujours
au plus près de luy.» Le comte de Charolais revint à Termonde; mais
le duc de Bourgogne, en le revoyant dans son camp, se sentit plus
disposé aux négociations, et peu de jours après le retour du comte
de Charolais, les marchands d'Espagne, d'Aragon, de Portugal,
d'Ecosse, de Venise, de Florence, de Milan, de Gênes et de Lucques,
résidant à Bruges, se rendirent à Gand pour s'efforcer de rétablir la
paix.
La cité de Gand restait puissante et redoutée. De quelque côté que
se portassent ses regards, l'horizon moins sombre semblait s'éclairer
de quelques rayons. Le roi de France se montrait disposé à abjurer
le système hostile de Philippe le Bel et de Philippe de Valois, tandis
qu'à Londres rien n'avait affaibli les sympathies séculaires qui
unissaient la patrie de Jacques d'Artevelde au royaume d'Edouard
III.
Le 24 mai 1452, les capitaines, les échevins et les doyens des
métiers adressaient à Charles VII une longue lettre pour lui faire
connaître leurs griefs et leurs plaintes. Ils y exposaient que le duc de
Bourgogne avait mandé des hommes d'armes pour les combattre et
qu'il s'efforçait de les livrer à la famine, protestant toutefois que bien
que la guerre fût «moult dure, griefve et déplaisante,» ils étaient
résolus à maintenir leurs droits, leurs priviléges, franchises,
coutumes et usages, dont le roi, comme leur souverain seigneur,
était «le gardien et conservateur.»
Deux jours après, des ambassadeurs anglais arrivaient à Gand,
chargés par Henri VI d'offrir un secours de sept mille hommes.
Enfin, peu d'heures avant que les représentants des marchands
étrangers, des nations, comme on avait coutume de les nommer,
eussent salué les bords de l'Escaut, six mille Gantois, sous les ordres
de Jean de Vos, quittaient Gand par la route de Nevele pour se
diriger vers Bruges. Ils avaient pour mission de rappeler à leurs
anciens alliés leur serment de sacrifier d'étroites rivalités aux intérêts
d'une patrie commune, de les soutenir s'ils tentaient quelque
mouvement favorable, de les menacer peut-être dans le cas où
l'influence du duc y étoufferait tous les efforts de leurs amis. En
effet, ils apprirent bientôt que Louis de la Gruuthuse et Pierre
Bladelin avaient fait fermer les portes, et d'un commun accord ils
s'arrêtèrent à Moerbrugge, assez près du Beverhoutsveld. Un de
leurs trompettes se présenta à la porte de Sainte-Catherine avec
plusieurs lettres adressées aux divers métiers de Bruges: «S'il vous
plaît, écrivaient-ils aux Brugeois, nous faire assistence pour nous
aidier à entretenir nos droits et franchises, lesquels nous en nulle
manière ne pensons délaissier ne souffrir estre amendris à l'aide de
Dieu et de nos bons amis, nous vous promettons que nous vous
ferons samblable assistence à l'entretenement de vos droits et
franchises, et que nous, pour plus grand sureté de ces choses,
jamais ne ferons paix sans vous; car vous et nous ne porions mieulx
entretenir iceulx nos droits et franchises, se non par bonne union.»
Ces lettres ne furent point remises. Louis de la Gruuthuse et Pierre
Bladelin, étant sortis par un guichet pour parlementer, réussirent à
persuader aux Gantois que les magistrats de Bruges étaient disposés
à appuyer leurs réclamations, et que le but de leur voyage était
atteint par la démarche des nations. Les Gantois se retirèrent vers
Oedelem et Knesselaere; ils acceptaient comme un succès complet
ces vagues et douteuses espérances.
Les marchands des nations avaient déjà été admis à Gand dans la
collace. Dans un discours rédigé avec habileté, ils représentèrent
vivement les désastres qui menaçaient une contrée célèbre entre
toutes celles du monde par les richesses qu'elles devaient à son
commerce. Ils ajoutaient que les Gantois agiraient sagement en
cessant de rappeler à tout propos leurs franchises et leurs priviléges
et qu'il serait agréable au duc de leur voir supprimer leurs
«chievetaineries.» Les Gantois eussent craint de paraître, par leur
silence, renoncer à leurs priviléges: quant à la mission de leurs
capitaines, ils déclaraient qu'elle n'avait d'autre but que de maintenir
au milieu des agitations de la guerre la sécurité et l'ordre intérieur, et
l'on eût tout au plus consenti à leur donner un autre nom.
Cependant la médiation des nations fut acceptée et quatre religieux
furent choisis pour seconder leurs efforts: c'étaient l'abbé de
Tronchiennes, le prieur des Chartreux, le prieur de Saint-Bavon et un
moine de la même abbaye, nommé Baudouin de Fosseux, dont la
sœur avait épousé Jean de Montmorency, grand chambellan de
France. Ils trouvèrent le duc à Termonde. Le prieur des Chartreux
parla le premier, puis l'un des marchands étrangers lut une cédule où
ils exposaient qu'ils se trouveraient, si la guerre ne se calmait point,
bientôt réduits à quitter la Flandre, «car, comme chascun peult
savoir, les marchands et les marchandises requièrent paix et pays de
paix, et nullement ne pevent soustenir la guerre.» Les conseillers du
duc délibérèrent et se plaignirent de ce que les Gantois étaient pires
que les Juifs, «car se les Juifs eussent véritablement sceu que nostre
benoit Sauveur Jésus-Christ eust esté Dieu, ils ne l'eussent point mis
à mort: mais les Gantois ne pouvoient et ne pevent ignorer que
monseigneur le duc ne fust et soit leur seigneur naturel.» Les
Gantois étaient si fiers, le duc si irrité qu'il était bien difficile de
concilier des prétentions tout opposées.
Les négociations se poursuivaient depuis quelques jours lorsque des
nouvelles importantes vinrent modifier profondément la situation des
choses. On avait appris en même temps à Gand et à Termonde que
Charles VII, cédant aux prières des députés flamands, voulait
intervenir comme médiateur dans les querelles du duc et de ses
sujets et l'on savait déjà que ses ambassadeurs étaient arrivés le 11
juin à Saint-Amand; c'étaient: Louis de Beaumont, sénéchal de
Poitou; Gui Bernard, archidiacre de Tours, et maître Jean Dauvet,
procureur général au parlement; mais il leur avait été ordonné de
placer à la tête de leur ambassade le comte de Saint-Pol, l'un des
plus illustres feudataires du royaume qui, en ce moment même,
combattait sous les drapeaux du duc de Bourgogne et semblait, par
l'étendue et la situation de ses domaines, investi d'un droit
d'arbitrage qui devait un jour lui devenir fatal.
Les instructions destinées aux ambassadeurs français leur avaient
été remises à Bourges, le 5 juin; elles comprenaient deux points
principaux, deux réclamations également importantes pour la
puissance de la monarchie. La première s'appuyait bien moins sur
l'équité que sur le sentiment national de la France, blessé par le
honteux traité d'Arras et prêt à saisir avec empressement la première
occasion favorable pour le déchirer. Il s'agissait de la restitution des
villes de la Somme, sans rachat, sous le simple prétexte que la
cession n'avait eu lieu que pour protéger les pays du duc contre les
excursions des Anglais, et qu'elle était devenue sans objet par la
conquête de la Normandie et l'existence des trêves. Le sire de Croy
avait dit vrai, lors des conférences d'Arras, que le duc de Bourgogne
renoncerait volontiers aux avantages qui lui avaient été faits si
Charles VII acceptait les conditions mises à la paix par les Anglais, et
il suffit de rappeler, pour s'expliquer cette déclaration, que le duc
Philippe craignait en traitant séparément d'exciter à la fois les
murmures de la Flandre et la colère de l'Angleterre; mais on n'avait
rédigé aucun acte de cette promesse, essentiellement vague et sans
doute limitée aux négociations de cette époque. Le second point,
c'était la médiation du roi dans les affaires de Flandre, l'exercice
complet et entier de son droit de souveraineté dans ces provinces
qui formaient le plus riche héritage de la maison de Bourgogne, et
les envoyés de Charles VII se trouvaient chargés de travailler en son
nom au rétablissement de la paix.
Pour atteindre ce but, les ambassadeurs français tiendront au duc et
aux Gantois un langage tout différent. Ils diront au duc que le roi,
arbitre légitime de toutes les dissensions de ce genre, peut, à
l'exemple de ses prédécesseurs, les terminer, soit par sa sentence,
soit en recourant, contre ceux qui ne s'y soumettraient point, à la
force des armes. Ils exposeront, au contraire, aux Gantois que le roi,
qui décide seul dans toute l'étendue du royaume de la paix ou de la
guerre, est disposé à les préserver de toute oppression comme ses
bons et loyaux sujet. Dans le même système, ils devaient ou
ajourner les négociations relatives à la Flandre pour assurer le
succès de celles qui se rapporteraient à la restitution de villes de la
Somme, ou bien, si elle était contestée, présenter à la Flandre
l'appui du roi contre le duc de Bourgogne.
A Gand on lut publiquement, dans la journée du 14 juin, les lettres
qui annonçaient l'intervention du roi de France, et dès le lendemain
le capitaine de Saint-Nicolas, Jean de Vos, prit le commandement
d'une expédition dirigée contre le Hainaut.
Le duc de Bourgogne n'était pas moins impatient de renouveler la
guerre. Si les Gantois sentaient leur zèle se ranimer par l'espoir de
l'appui de Charles VII, il était important à ses yeux que leur défaite
immédiate rendît cet appui inutile ou superflu: le 13 juin il congédia
les députés des nations, rejetant avec dédain la trêve de six mois
qu'ils avaient demandée et leur proposition de remplacer désormais
le nom que portaient les capitaines (hooftmans) par celui de
gouverneurs, recteurs, ou deffendeurs. L'armée bourguignonne avait
reçu d'importants renforts et était prête à envahir le pays de Waes.
Le duc le déclara lui-même aux députés des nations. Quelques
heures plus tard il eût pu, pour les en convaincre, leur montrer les
flammes qui s'élevaient à l'horizon au-dessus de ces heureuses
campagnes enrichies par les bienfaits d'une longue paix.
Le sire de Contay et trois cents hommes d'armes avaient passé
l'Escaut, près du bourg de Rupelmonde, dont les Bourguignons
avaient depuis longtemps incendié les habitations. Ces ruines leur
offrirent un abri où ils se fortifièrent avec quelques coulevrines. La
nuit s'écoula dans une grande inquiétude: deux mille Gantois
occupaient Tamise; ils étaient au nombre de quatre mille à Basele:
on craignait qu'ils ne se réunissent à Rupelmonde pour repousser le
sire de Contay et ses compagnons.
Cependant l'aurore se leva: les Gantois n'avaient fait aucun
mouvement, soit qu'ils ignorassent la tentative des Bourguignons,
soit qu'ils crussent leur troupe plus nombreuse, et d'autres chevaliers
ne tardèrent pas à rejoindre le sire de Contay. Le comte de Saint-Pol
et le sire de Chimay traversèrent les premiers le fleuve avec l'avant-
garde, composée de mille archers et de trois cents lances: toutes les
enseignes furent aussitôt déployées et guidèrent les combattants
vers Basele. Les Gantois, surpris et chassés de leurs retranchements
par les archers, se réfugiaient précipitamment dans l'église et dans
une maison fortifiée qui en était voisine. On les y assiégea. Les
archers décochaient leurs traits sur tous ceux qui se montraient aux
fenêtres, et la plupart des hommes d'armes, entraînés par leur
exemple, abandonnaient leurs rangs et accouraient en désordre pour
prendre part à l'assaut, lorsqu'une troupe nombreuse de Gantois qui
avait quitté Tamise les attaqua inopinément. Un cri d'effroi avait
retenti parmi les hommes d'armes bourguignons et une sanglante
mêlée s'engagea aussitôt autour de la bannière du comte de Saint-
Pol.
Le duc Philippe remarqua, de l'autre rive de l'Escaut, le péril qui
menaçait les siens. Il se jeta sans hésiter dans une petite nacelle
avec son fils, le duc de Clèves, et Corneille, bâtard de Bourgogne. A
mesure que ses hommes d'armes le suivaient sur la rive opposée, il
les rangeait lui-même en bon ordre et les envoyait là où le danger
était le plus pressant. Grâce aux secours qu'ils reçurent, le comte de
Saint-Pol et le sire de Chimay parvinrent à repousser les Gantois, qui
perdirent une partie de leurs chariots et de leur artillerie.
Ce succès permit à l'armée bourguignonne d'achever son
mouvement sans obstacle, et le lendemain vers le soir elle se
trouvait tout entière sur la rive gauche du fleuve.
Le 16 juin 1452, dès que le jour parut, les hommes d'armes qui
combattaient sous la bannière du duc de Bourgogne quittèrent leurs
tentes: Philippe avait ordonné qu'à l'exception d'un petit nombre de
chevaucheurs chargés de surveiller les mouvements de l'ennemi, ils
luttassent tous à pied. En ce moment, en y comprenant les sergents
qu'avait amenés le duc de Clèves, ils étaient trente ou quarante
mille: redoutable légion d'élite, que des chevaliers accourus de
toutes les provinces de France conduisaient à la destruction des
milices communales de Flandre. «Fière chose fust, dit Olivier de la
Marche, à voir telle assemblée et telle noblesse, dont seulement la
fierté de l'ordre, la resplendisseur des pompes et des armures, la
contenance des étendards et des enseignes estoient suffisans pour
ébahir et troubler le hardement et la folle emprise du plus hardi
peuple du monde.»
Une vaste plaine s'étend entre Rupelmonde et Basele; c'est là que le
duc attendait les Gantois. On apercevait près de lui le jeune comte
de Charolais qui, au milieu des hommes d'armes dociles à ses
ordres, se préparait à combattre pour la première fois. Déjà il savait
se faire craindre et obéir, et montrait bien «que le cœur lui disoit et
apprenoit qu'il estoit prince, né et élevé pour autres conduire et
gouverner.»
Les Gantois qui occupaient le pays de Waes se trouvaient sous les
ordres de Gauthier Leenknecht. Intrépide jusqu'à la témérité et déjà
fameux par la prise de Grammont, il avait un instant formé le projet
de percer les digues et d'engloutir dans les eaux le duc et toute son
armée, mais il en avait été empêché par l'arrivée de quelques
archers bourguignons; sa confiance dans le succès n'en avait
toutefois pas été ébranlée, et il croyait qu'à l'aide des renforts
conduits de Gand par le capitaine de Saint-Jean, Jacques Meussone,
il pourrait rejeter dans l'Escaut les Bourguignons, dont le nombre lui
était inconnu. En effet, dès que le sire de Masmines eut annoncé
que l'on signalait au loin la bannière où le lion de Notre-Dame
semble, même pendant son sommeil, chercher de sa griffe
entr'ouverte la lutte et le combat, le duc avait ordonné à son avant-
garde de se retirer; ce mouvement simulé devait tromper les Gantois
et les entraîner au milieu de leurs ennemis, tandis que le duc de
Clèves, le comte d'Etampes et le bâtard Corneille de Bourgogne
veillaient à ce qu'aucune attaque ne fût dirigée soit contre l'arrière-
garde, soit contre l'aile gauche qui s'étendait vers le village de
Tamise.
Le comte de Saint-Pol exécuta habilement les instructions qui lui
avaient été données. Les Gantois, se disputant l'honneur de le
poursuivre, se livraient à l'enthousiasme de la victoire, quand ils
entendirent, comme un arrêt de deuil et de mort, retentir tout à
coup autour d'eux cent trompettes ennemies dont les lugubres
fanfares s'effacèrent dans la détonation de toute l'artillerie du duc.
Aux balles de pierres et de fer qui sillonnaient un nuage de fumée
ardente se mêlaient les flèches acérées des archers: c'était le signal
que les hommes d'armes bourguignons attendaient pour se porter
en avant.
Les Gantois, en se voyant enveloppés par toute une armée, avaient
reconnu les embûches qui leur étaient préparées: ils ne cherchaient
plus qu'à s'inspirer de ces sentiments suprêmes d'abnégation et de
courage que le spectacle d'une mort inévitable ne rend que plus vifs
chez les âmes héroïques. Jacques de Luxembourg, s'étant élancé le
premier dans leurs rangs épais, y eut son cheval abattu sous lui, et
peu s'en fallut qu'il ne pérît. Jacques de Lalaing fut atteint à la jambe
d'un coup de faux, le sire de Chimay fut blessé au pied. Ce fut en
vain que les chevaliers bourguignons cherchèrent à conquérir la
grande bannière de Gand: un vieux bourgeois, à qui elle avait été
confiée, la défendait si vaillamment que jamais on ne put la lui
arracher. Les Gantois, pressés par le choc de la chevalerie ennemie,
reculaient en résistant à chaque pas, et leur dernière troupe, près de
succomber, ne s'arrêta que pour livrer un dernier combat où le
bâtard Corneille de Bourgogne tomba, frappé d'un coup de pique à
la gorge. C'était l'objet de l'affection la plus tendre du duc. Il fit
aussitôt pendre à un arbre Gauthier Leenknecht qu'on avait relevé
parmi les blessés, mais cette vengeance ne pouvait le consoler de la
perte de son fils; on disait que la mort de cent mille hommes des
communes de Flandre n'y eût point suffi. La duchesse de Bourgogne
se chargea elle-même du soin de lui faire célébrer de magnifiques
obsèques dans l'église de Sainte-Gudule de Bruxelles, et on
l'ensevelit dans le tombeau des descendants légitimes des princes de
Brabant et de Bourgogne, avec sa bannière, son étendard et son
pennon, ce qui n'appartenait qu'aux chevaliers morts les armes à la
main.
Le lendemain, on aperçut une flotte nombreuse qui remontait
l'Escaut, étalant au soleil, au milieu de ses voiles blanches, mille
écus aux éclatantes couleurs; elle portait des hommes d'armes
réunis en Hollande par les sires de Borssele, de Brederode et
d'autres puissants bannerets.
Lorsque le duc Philippe vit, immédiatement après sa victoire, cette
nouvelle armée se joindre à une armée déjà si puissante, il s'avança
jusqu'à Waesmunster, espérant peut-être y trouver des députés de
Gand chargés d'implorer sa clémence; mais les Gantois se
consolaient déjà de la défaite de Gauthier Leenknecht par les
heureux résultats de l'expédition de Jean de Vos qui avait repris
Grammont, dispersé la garnison d'Ath, brûlé Acre et Lessines et
semé la terreur jusqu'aux portes de Mons, en recueillant partout sur
son passage un immense butin; Jean de Vos, rentré à Gand, fut
proclamé upperhooftman ou premier capitaine de la ville.
A la même époque se forma, de l'appel d'un homme par connétablie,
ce corps si célèbre depuis sous les ordres du bâtard de Blanc-Estrain,
des compagnons de la Verte Tente, destinés à opposer aux Picards
une guerre non interrompue d'excursions inopinées et
d'escarmouches sanglantes: ils avaient juré, comme les vieux
Suèves, de ne connaître d'autre abri que le dôme des forêts et la
voûte du ciel.
Le 13 juin, le duc de Bourgogne, averti du débarquement du sire de
Contay sur la rive gauche de l'Escaut, avait fait écrire aux
ambassadeurs du roi qu'il lui était impossible de les recevoir à
Termonde et qu'il les invitait à se rendre à Bruxelles. Il eût désiré
qu'ils négociassent avec ses conseillers loin du théâtre de la guerre,
sans la troubler par leur intervention; mais les instructions formelles
de Charles VII s'y opposaient. Ils ne devaient traiter qu'avec le duc
lui-même, et lorsqu'on eut réussi à les retenir trois jours à Bruxelles,
il fallut bien se résoudre à leur permettre de se diriger vers le camp
de Waesmunster.
Un héraut français, parti le 15 juin de Tournay, était déjà arrivé à
Gand, porteur d'une lettre par laquelle les envoyés de Charles VII
annonçaient qu'ils avaient reçu du roi pleine autorité pour faire
cesser la guerre et juger tous les démêlés qui en avaient été la
cause. Un grand enthousiasme accueillit à Gand cette déclaration, et
les magistrats répondirent immédiatement aux ambassadeurs
français «qu'ils ne desiroient que l'amiableté du roy et estre de lui
préservez et entretenuz en justice, laquelle leur avoit longhement
esté empeschiée.»
Il est aisé de comprendre qu'au camp de Waesmunster la médiation
de Charles VII était jugée avec un sentiment tout opposé. Bien que
le sénéchal de Poitou et ses collègues exposassent leur mission «au
mieulx et le plus doucement qu'ils pussent,» le duc leur répondit
vivement, «sans délibération de conseil,» que les Gantois «estoient
les chefs de toute rébellion, qu'ils lui avoient fait les plus grands
outrages du monde et qu'il estoit besoing d'en faire telle punition
que ce fust exemple à jamais.» Enfin, il ajouta que si le roi
connaissait la véritable situation des choses, «il seroit bien content
de lui laisser faire sans lui parler de paix,» et il pria les
ambassadeurs «qu'ils s'en voulsissent déporter.» Le lendemain
(c'était le 21 juin 1452), le duc paraissait plus calme: il avait laissé à
son chancelier le soin de parler en son nom, et les ambassadeurs
firent connaître leur intention d'aller eux-mêmes à Gand «pour le
bien de la besongne.» C'était soulever une nouvelle tempête. Le
chancelier de Bourgogne, Nicolas Rolin, objecta qu'il ne pouvait y
avoir honneur, ni sûreté à s'y rendre. La discussion s'était terminée
sans résultats et les envoyés de Charles VII s'étaient retirés à
Termonde, quand ils y reçurent une nouvelle lettre des magistrats de
Gand qui les pressaient de hâter leur arrivée dans cette ville, «afin
qu'on les pust advertir tout au long des affaires et besoingnes, car
bon et playn advertissement sont le bien et fondation de la
conduicte d'une matière.» Cette lettre légitimait leurs instances. Ils
les maintinrent énergiquement dans une conférence avec les
conseillers bourguignons, qui se prolongea jusqu'au soir, et bien
qu'on leur opposât «plusieurs grands arguments pour cuider rompre
leur dite commission et empescher leur alée audit lieu de Gand,» ils
fixèrent au lendemain l'accomplissement de leur résolution, après
avoir décidé toutefois que le comte de Saint-Pol ne les
accompagnerait pas à Gand, puisqu'il se trouvait en ce moment, à
raison des fiefs qu'il possédait, tenu de combattre sous les drapeaux
du duc de Bourgogne. Les droits de l'autorité royale exigeaient à leur
avis qu'ils accueillissent les plaintes de l'opprimé et ils n'y voyaient,
disaient-ils, ni déshonneur, ni sujet de crainte: ce qu'ils redoutaient
bien davantage, c'était de ne pouvoir se faire écouter ni par un
prince obstiné dans ses projets, ni par une population inquiète et
accessible à toutes les passions tumultueuses.
Les échevins de Gand et un grand nombre de bourgeois s'étaient
rendus solennellement à une lieue de la ville au devant des
ambassadeurs du roi. La remise des lettres closes sur lesquelles
reposait leur mission eut lieu le lendemain, et dans les conférences
qui s'ouvrirent aussitôt après, ils obtinrent que l'on enverrait près du
duc l'abbé de Tronchiennes, Simon Boorluut et d'autres députés, afin
de tenter un dernier effort pour rétablir la paix, ajoutant que si l'on
ne pouvait y parvenir par voies amiables, le roi de France était prêt à
maintenir le droit des Gantois par autorité de justice.
Pour juger ce que présentait de sérieux, le 25 juin, ce projet d'un
débat contradictoire entre les envoyés du duc et ceux de la
commune insurgée, il faut que nous reportions nos regards sur les
événements qui se sont accomplis dans le pays de Waes depuis que
les ambassadeurs français ont quitté Termonde.
Le 23 juin, Philippe, mécontent et irrité, avait consenti malgré lui à
ce que les ambassadeurs français allassent étaler les fleurs de lis
royales parsemées sur les cottes d'armes de leurs hérauts au milieu
des bannières gantoises. Le même jour, il fit appeler le comte
d'Etampes et lui ordonna de s'avancer vers le pays des Quatre-
Métiers en mettant tout à feu et à sang. Le comte d'Etampes obéit:
la guerre devint de plus en plus cruelle, de plus en plus acharnée;
un grand nombre de chaumières avaient été livrées aux flammes et
plusieurs retranchements avaient été enlevés d'assaut quand le
comte d'Etampes, arrivé près de Kemseke, s'arrêta dans son
mouvement. La chaleur était si étouffante, racontent les
chroniqueurs bourguignons, qu'il se vit réduit à retourner à
Waesmunster: il est bien plus probable qu'il avait appris que six mille
Gantois occupaient depuis deux jours le village de Moerbeke et qu'il
avait jugé prudent d'ajourner le projet de les y attaquer.
En effet, le 24 juin, l'armée du comte d'Etampes, à laquelle le comte
de Charolais avait conduit de puissants renforts, reprit la route suivie
par l'expédition de la veille; elle se rangea en bon ordre entre
Stekene et l'abbaye de Baudeloo, et l'on envoya des chevaucheurs
en avant pour examiner la position des Gantois. Elle était très-forte,
et malgré l'avis du sire de Créquy, qui voulait reconnaître de plus
près les ennemis, les chevaliers, auxquels était confié le soin de la
personne de l'unique héritier de la maison de Bourgogne, résolurent
de rentrer de nouveau à Waesmunster.
Lorsque Philippe apprit que son fils était revenu dans son camp,
comme le comte d'Etampes, sans que le moindre succès eût
couronné ses armes, il résolut, quelque sanglant qu'en dût être le
prix, de conquérir sur les Gantois les retranchements de Moerbeke.
Les sires de Créquy, de Ternant, d'Humières furent chargés de
préparer le plan du combat. Le duc de Bourgogne l'approuva
aussitôt et fixa, à tous les hommes d'armes réunis à Waesmunster,
l'heure du départ et celle de l'assaut; cependant, lorsque le son des
trompettes appela l'armée sous les armes, un mouvement
d'hésitation se manifesta; des murmures se firent entendre; ce fut
presque une rébellion: les chevaliers eux-mêmes craignaient de
s'exposer aux dangers qu'ils prévoyaient. Philippe se vit réduit à
céder, mais sa colère éclata en présence des membres de son
conseil et on l'entendit donner l'ordre d'enlever l'étendard qui flottait
devant son hôtel.
Ceci se passait le jour même où la déclaration des magistrats relative
aux négociations était publiée à Gand: le lendemain, 26 juin, le duc
accordait une trêve de trois jours.
Si les chroniqueurs contemporains mentionnent à peine cette
suspension d'armes, il ne faut point s'en étonner. Le duc l'employa à
de nouveaux armements: à Gand, les discordes intérieures allaient
devenir un fléau de plus pour le peuple déjà épuisé par une longue
guerre.
Henri VI et Charles VII poursuivaient en Guyenne la grande lutte de
Jeanne d'Arc contre Talbot: leurs ambassadeurs, portant en Flandre
les mêmes sentiments de rivalité, se disputaient l'appui des
communes. Les uns, accourus les premiers, sans pompe, sans éclat,
et plutôt comme des espions, s'étaient adressés aux souvenirs des
temps les plus glorieux et des hommes les plus illustres: les autres
avaient essayé de réhabiliter cette suzeraineté trop souvent
invoquée par Philippe le Bel et Philippe de Valois, et, en effet, ils
avaient paru, entourés de respect et d'honneurs, aussi bien au milieu
des Gantois auxquels ils promettaient un protecteur, qu'à la cour du
duc qu'ils menaçaient d'un juge.
De l'un et de l'autre côté il n'y avait que des promesses. Les Anglais
se persuadèrent assez aisément que le meilleur moyen de faire
croire à leur sincérité était de les exécuter sans délai et sans bruit;
rien n'était plus habile pour faire échouer les négociations entamées
par les ambassadeurs français. Tandis que le sénéchal de Poitou,
l'archidiacre de Tours et maître Jean Dauvet retournaient à
Waesmunster, on vit arriver à Gand quelques archers anglais venus
probablement de Calais. Dès ce moment, il y eut un parti français,
ou pour mieux dire, un parti de la paix qui favorisait la médiation des
ambassadeurs de Charles VII, et un parti de la guerre
qu'encourageait l'impuissance de l'armée bourguignonne devant les
palissades précipitamment élevées dans les marais de Moerbeke.
Le 29 juin, maître Jean Dauvet était revenu à Gand pour y annoncer
qu'on n'avait pu obtenir du duc une trêve d'un mois comme les
Gantois l'avaient demandé aux ambassadeurs français. Il était en
même temps chargé de rendre compte des premières négociations:
les principes qui y avaient présidé étaient, d'une part, le maintien de
l'autorité du duc si longtemps méconnue, de l'autre, la conservation
des priviléges menacés d'une sentence de confiscation, et avant tout
le droit d'arbitrage des envoyés du roi en n'y attachant d'autre
sanction légale que l'amende, dans le cas où les Gantois seraient
reconnus coupables de quelque délit. Cette déclaration, soumise à
l'assemblée de la commune pour qu'elle y adhérât, fut vivement
combattue et bientôt rejetée: la collace n'accepta la médiation des
ambassadeurs qu'en repoussant leur arbitrage, et elle se réserva
non-seulement ses priviléges et le soin de se justifier des griefs du
duc, mais aussi le droit de ratifier toutes les conditions relatives au
rétablissement de la paix.
Une expédition s'était organisée sous l'influence de ce sentiment
hostile aux négociations. Les partisans des Anglais, se croyant
assurés de vaincre les Bourguignons parce qu'ils conduisaient avec
eux quelques archers de Henri VI, avaient formé le projet de
s'emparer de Hulst. Ils savaient qu'Antoine de Bourgogne, qu'on
appelait le bâtard de Bourgogne depuis la mort de son frère
Corneille s'y tenait avec Simon, Jacques et Sanche de Lalaing et une
partie de l'armée hollandaise: il avait même pillé et dévasté le pays
jusqu'à Axel. A l'approche des Gantois qui s'avançaient avec une
nombreuse artillerie, il recourut de nouveau à l'une de ces ruses que
nos communes ne surent jamais prévoir. Tandis qu'il multipliait sur
les remparts de Hulst de vains simulacres de défense, Jacques de
Lalaing et Georges de Rosimbos, cachés hors de la ville avec un
grand nombre d'archers, enveloppaient les Gantois, et presque au
même moment le capitaine d'Assenede, qui portait l'étendard de
Gand, le jeta à ses pieds en criant: Bourgogne! Cette attaque, cette
trahison non moins funeste et non moins imprévue, répandent la
confusion et le désordre parmi les milices communales. Jacques de
Lalaing s'y précipite: cent glaives se dirigent vers sa poitrine et trois
chevaux tombent sous lui; mais il triomphe, et les Gantois fuient
jusqu'aux portes de Gand, où Jean de Vos fait saisir et décapiter
quelques-uns de ceux qui n'ont été ni assez prudents pour traiter
avec dignité, ni assez intrépides pour combattre avec honneur.
La gloire de la Flandre eût reçu une tache indélébile dans cette
journée, si quelques bourgeois de Gand n'avaient continué à lutter
presque seuls contre la multitude de leurs ennemis, afin que leur
courage fît du moins oublier la honte de leurs compagnons. Leur
résistance se prolongea longtemps, et ceux d'entre eux qui
survécurent à un combat acharné refusèrent de recourir à la
clémence du duc pour se dérober à la hache du bourreau, aimant
mieux perdre la vie que de se montrer indignes de la conserver. «En
vérité, raconte Jacques Duclercq, je vous diray ung grand merveille,
et à peu sembleroit-elle croyable: c'est que les Gantois estoient tant
obstinés à faire guerre qu'ils respondirent qu'ils aimoient mieulx
mourir que de prier mercy au duc, et qu'ils mouroient à bonne
querelle et comme martyrs (29 juin 1452).»
Cependant les vainqueurs, craignant quelque autre attaque des
Gantois, avaient envoyé des messagers à Waesmunster afin de
réclamer des renforts. Hulst n'est éloigné que de quatre lieues de
Waesmunster. Le duc ordonna le même soir à toute son armée de se
réunir. En vain les ambassadeurs du roi lui représentèrent-ils qu'un
de leurs collègues était resté à Gand et qu'il ne tarderait peut-être
point à apporter des nouvelles qui rendraient désormais inutile
l'effusion du sang, le duc se contenta de répondre que les mauvaises
intentions des Gantois lui étaient assez connues. L'avant-garde, le
corps principal et l'arrière-garde se mirent successivement en
marche; les chariots suivaient, afin que ceux qui viendraient à se
briser ne formassent point un obstacle sur le chemin. Le duc, ayant
ainsi chevauché toute la nuit, s'arrêta à une demi-lieue de Hulst. Il y
fut rejoint par quelques hommes d'armes hollandais commandés par
le sire de Lannoy, et donna aussitôt à Jacques et à Simon de Lalaing
l'ordre d'aller examiner de quel côté il serait plus aisé d'escalader les
remparts d'Axel, mal défendus par de larges fossés dont un soleil
ardent avait épuisé les eaux.
Ces précautions étaient inutiles. Les Gantois, avertis de la marche de
l'armée bourguignonne, s'étaient retirés pendant la nuit. Le duc fit
mettre le feu aux trois mille maisons qui formaient le bourg d'Axel, et
se rendit à Wachtebeke où il passa deux jours, attendant les vivres
que les sires de Masmines et de la Viefville étaient allés chercher à
l'Ecluse.
Pendant ces deux jours, les hommes d'armes du duc se dispersèrent
pour parcourir les champs. Ils découvrirent un petit fort où quelques
Gantois s'étaient retranchés. Ils les prirent et les mirent à mort. Leur
principal but, toutefois, était de piller. Les laboureurs, dans leur fuite
précipitée, avaient abandonné leurs troupeaux qui paissaient dans
les prairies. Ils étaient, disent les chroniqueurs, si nombreux que l'on
vendait au camp du duc une belle vache du pays de Waes pour cinq
sous: pour quatre écus on en avait cent.
Devant le village de Wachtebeke s'étendent de vastes marais
qu'arrose un bras de la Durme. Les sires de Poix et de Contay y
avaient fait établir un passage pour que l'armée bourguignonne pût
les traverser; mais dès qu'elle se fut mise en marche, le sol humide
de la route céda et elle devint impraticable. Il fallut reculer, et les
hommes d'armes du duc, à demi noyés dans la fange et dans la
boue, rentrèrent à Wachtebeke. Bien que leur départ fût fixé au
lendemain, on avait profité de ces retards pour incendier quelques
villages. La chronique de Jacques de Lalaing en nomme un seul:
celui d'Artevelde.
Le 6 juillet, le duc quitta Wachtebeke qu'on livra aux flammes, et
passa la Durme près de Daknam. Le lendemain, il se rendit à
Wetteren, gros bourg situé sur l'Escaut, à deux lieues et demie de
Gand, et y plaça son camp. Les ambassadeurs du roi, qui étaient
restés à Termonde pendant ces combats, l'y suivirent et firent de
nouvelles instances pour qu'il suspendît la guerre par une trêve qui
permettrait de recommencer les négociations. Le moment de ces
remontrances était mal choisi: le duc refusa de les écouter, et le 10
juillet il ordonna au duc de Clèves de prendre son étendard et de
s'avancer jusqu'auprès de Gand. Il espérait engager les bourgeois à
sortir de leur ville et à lui livrer bataille. Il avait même fait connaître,
sans qu'on sonnât les trompettes, que chacun scellât son cheval et
se tînt prêt à combattre. Toison d'or accompagnait le duc de Clèves
et avait amené avec lui tous les rois d'armes, hérauts et poursuivants
de la cour du duc, afin qu'ils lui apprissent de suite l'attaque des
Gantois.
Cependant les Gantois instruits par les revers de Basele, trompèrent
ces espérances. Ils vinrent en grand nombre escarmoucher aux
portes de leur ville; mais lorsqu'ils se sentaient pressés de trop près,
ils reculaient et attiraient eux-mêmes les hommes d'armes du duc
assez loin pour qu'ils pussent les atteindre avec les arbalètes, les
coulevrines et les canons placés sur leurs remparts. Le combat se
prolongea pendant deux heures sans que les Gantois cessassent de
conserver l'avantage. Un grand nombre d'hommes d'armes du duc
avaient succombé, et tous leurs efforts n'avaient amené d'autre
résultat que l'incendie de quelques maisons des faubourgs.
Philippe n'avait point assez de forces pour songer à assiéger une
grande et populeuse cité comme celle de Gand, qui pouvait armer
chaque jour, disait-on, quarante mille défenseurs et en porter même
le nombre à cent mille, si le péril l'exigeait. Cette fois, du moins, il
avait compté inutilement sur l'inexpérience et l'imprudente témérité
de ses ennemis, et il ne lui restait plus qu'à opter entre une retraite
honteuse et une inaction qui épuiserait ses ressources sans moins
dissimuler son impuissance. Dans cette situation, il n'hésita pas à
subir la nécessité d'un trêve, et le 15 juillet, sans consulter ni son
chancelier ni les membres de son conseil, il annonça son intention à
Jean Vander Eecken, secrétaire des échevins des parchons, qui se
trouvait depuis plusieurs jours à Wetteren avec les ambassadeurs du
roi. Cette suspension d'armes devait durer six semaines depuis le 21
juillet jusqu'au 1er
septembre.
Le duc licencia aussitôt son armée. Il se contenta de laisser de fortes
garnisons à Courtray, à Audenarde, à Alost, à Termonde et à
Biervliet; mais il n'osa point en envoyer à Bruges, de peur de
mécontenter les habitants de cette ville, à qui il avait donné pour
capitaine un de leurs concitoyens, qui jouissait d'une grande autorité
parmi eux, messire Louis de la Gruuthuse. Les Gantois s'étaient déjà
empressés d'écrire au roi de France pour placer leurs droits sous la
protection de sa suzeraineté. Le duc lui-même lui adressa de
Termonde, le 29 juillet, une lettre écrite dans les termes les plus
humbles, pour le supplier d'entendre ses ambassadeurs, Guillaume
de Vaudrey et Pierre de Goux, avant d'accorder à ses adversaires
«aucuns mandements ou provisions à l'encontre de luy.»
Philippe avait désigné la ville de Lille pour les conférences relatives à
la paix. Louis de Beaumont et ses collègues s'y rendirent
immédiatement. La commune de Gand, qui en ce moment même
voyait s'associer à sa magistrature les noms influents des Rym, des
Sersanders, des Vanden Bossche, des Steelant, des Everwin, avait
choisi, pour la représenter, Simon Borluut, Oste de Gruutere, Jean
Vander Moere et d'autres bourgeois, auxquels les historiens
bourguignons n'hésitent pas à donner le titre encore si recherché et
si rare de chevaliers.
Les députés flamands avaient réclamé les conseils d'un avocat du
parlement de Paris, nommé maître Jean de Popincourt. Le mémoire
qu'ils présentèrent indique, par son titre, le but dans lequel il avait
été rédigé: «C'est le régiment et gouvernement qui longtemps a esté
au pays de Flandres contre les anciens droitz d'icelluy pays, et contre
raison et justice en grant grief de la chose publique et de la
marchandise sur laquelle le dit pays est principalement fondé.» On y
lisait successivement que les impôts prélevés par le duc dépassaient
ceux que ses prédécesseurs avaient recueillis pendant un siècle, que
les transactions commerciales avaient été soumises à des impôts
illégaux dont l'exclusion des marchends osterlings avait été le
résultat, que le commandement des forteresses de Flandre avait été
confié à des étrangers. On y rappelait le complot tramé par George
Debul pour l'extermination des bourgeois de Gand, puis les
préparatifs belliqueux du duc auxquels s'étaient jointes d'autres
mesures prises pour les affamer. Enfin sur chacun des points qui
avaient été l'objet des différends du prince et de la commune, on y
trouvait citées quelques-unes de ces nombreuses chartes de
priviléges octroyées à la ville de Gand depuis Philippe d'Alsace
jusqu'à Jean sans Peur. Toutes ces plaintes se résumaient dans ce
texte de la keure de Gand de 1192: Gandenses fideles debent esse
principi quamdiu juste et rationabiliter eos tractare voluerit.
La réponse du duc n'embrasse pas un moins grand nombre de
griefs. Si dans le système des Gantois le maintien de leurs priviléges
est la condition de leurs serments et la base de leurs devoirs, les
conseillers bourguignons n'y voient que le prix d'une obéissance
humble et complète. A les entendre, les chefs de la commune
insurgée «avoient intention de prendre et tenir le pays de Flandre,
de s'en dire et porter contes et de le départir entre eulx et leurs
complices,» et pour les punir, le duc pouvait à son gré ou enlever à
la ville de Gand ses priviléges, ou même la détruire et la raser usque
ad aratrum.
Le duc de Bourgogne avait, en quittant Wetteren, annoncé aux
ambassadeurs du roi qu'il les suivrait de près à Lille: il y arriva peu
de jours après eux. Sa présence sembla devoir imprimer
immédiatement une nouvelle marche aux négociations, car, dès le 21
août, les envoyés de Charles VII abordèrent l'exposé du second
point de leur mission, ce qu'ils n'avaient osé faire ni à Wetteren, ni à
Waesmunster. Ne sachant trop comment entrer en matière pour
présenter une réclamation si étrange et, il faut le dire, si peu
justifiée, ils commencèrent par rappeler qu'il y avait eu «aucunes
paroles et ouvertures à cause d'aucunes terres et seigneuries du roi»
entre le comte de Saint-Pol et les sires de Croy, à qui Charles VII
attribuait la promesse verbale, si malencontreusement omise dans le
traité d'Arras. Il fallait, à leurs avis, supposer que ces terres et
seigneuries qui n'avaient point été désignées, source fortuite et
éventuelle de contestations, étaient les villes de la Somme, et que le
duc, en protestant de son désir de complaire au roi en toutes
choses, avait annoncé le dessein de les lui restituer. A ce langage si
inattendu et si nouveau, Philippe ne put retenir sa surprise. «Je me
donne merveilles, dit-il au sénéchal de Poitou et à ses collègues, de
ce que vous me distes touchant la restitution des terres, veu que
jamais je n'en ai parlé à messires de Croy, et s'ils se sont advancés
d'en parler, je les désavoue, et ils en paieront la lamproye.» Antoine
et Jean de Croy assistaient à cette audience; ils se hâtèrent de
démentir ce qu'on leur avait attribué. Les ambassadeurs français,
s'étant retirés pour délibérer sur ce qu'ils avaient à répondre,
jugèrent qu'il ne fallait pas insister davantage sur les paroles et
ouvertures des sires de Croy, et ils cherchèrent seulement à établir
que la cession des villes de la Somme n'avait été qu'une cession
provisoire, destinée à protéger contre les Anglais les frontières des
Etats du duc de Bourgogne, et que cela avait été expressément
convenu, quoiqu'il n'en eût point été fait mention dans le traité
d'Arras. Bien que Philippe se montrât peu disposé à céder, son
langage s'était adouci, et il congédia les ambassadeurs en leur
déclarant «que la matière estoit grande et qu'il y eschéoyt bien
penser.»
Evidemment le duc de Bourgogne ne pouvait consentir à la
restitution de ces villes, dont le rachat avait été fixé à la somme
énorme de quatre cent mille écus d'or: si elles avaient cessé d'être
une barrière contre les Anglais chassés de la Normandie, elles
restaient, pour le duc Philippe, ce qu'elles étaient avant tout à ses
yeux, une ligne importante de défense contre les rois de France, qui
avaient si fréquemment envahi, sans obstacle, les plaines fertiles de
l'Artois et de la Flandre. La puissance du duc de Bourgogne reposait
sur le traité d'Arras; il ne pouvait, sans en abdiquer les fruits, en
déchirer le texte dans l'une des clauses qui lui étaient les plus
avantageuses. Cependant il n'ignorait pas que Charles VII,
triomphant à la fois du Dauphin réduit à s'humilier et des Anglais
expulsés de la Guyenne, réunissait à ses frontières du nord tous ses
chevaliers et tous ses hommes d'armes pour le combattre. Il
temporisait et attendait son salut de l'Angleterre. Une guerre civile,
fomentée par le duc d'York, avait été étouffée par la fortune
victorieuse de la maison de Lancastre, à laquelle la duchesse de
Bourgogne appartenait par sa mère, et le gouvernement était de
nouveau dirigé par le duc de Somerset, si favorable au duc Philippe
qu'il avait été accusé au parlement de l'année précédente de vouloir
lui livrer Calais. Il n'est guère permis de douter que des agents
bourguignons n'aient suivi à Londres le cours des événements, prêts
à en profiter dans l'intérêt de leur maître, et s'appuyant sans cesse
sur tout ce que les passions nationales conservaient d'hostile contre
les Français; l'histoire ne nous a conservé ni leurs noms, ni les traces
de leurs négociations; mais nous en connaissons le résultat: le choix
de Jean Talbot, le fameux comte de Shrewsbury, pour commander
une expédition qui allait aborder dans la Gironde.
C'était le 21 août que les ambassadeurs français avaient réclamé du
duc Philippe la restitution des villes de la Somme, «ayant charge de
s'adresser à sa personne et non à autre, privément et rondement,
sans entrer en grans argumens,» car il suffit d'être fort et redoutable
pour avoir le droit de parler haut et bref. L'invasion imminente des
Anglais, en appelant de nouveau dans les provinces du midi les
forces de Charles VII, qui s'était trop confié dans la trêve, modifia
tout à coup leur position. L'ambassadeur mandataire de la colère et
des vengeances du seigneur suzerain s'effaça: il ne resta que
l'homme timide et faible, entouré des séductions d'un vassal plus
riche que le roi lui-même.
Le 30 août, les envoyés du roi de France adressèrent aux échevins
de Gand une lettre où ils avouaient que jusqu'à ce jour ils n'avaient
rien obtenu du duc de Bourgogne, et toutefois, d'après leur propre
aveu, le moment approchait où la fin des trêves nécessiterait
l'adoption d'un «appointement.» Quel qu'il dût être, ils leur
défendaient, au nom du roi, «qui a bien le vouloir de donner remise
à leurs griefs,» de chercher à s'y opposer «en procédant par armes
ne par voie de fait.»
Les craintes que fit naître cette déclaration, si ambiguë dans ses
termes et si menaçante dans ce qu'elle laissait entrevoir, ne devaient
pas tarder à se confirmer. Le 3 septembre, vers le soir, les députés
flamands qui avaient pris part aux conférences de Lille rentrèrent
tristement à Gand. Leur mission avait été terminée par le rejet de
toutes leurs demandes, et dès le lendemain on publia à Lille, au
cloître de Saint-Pierre, la sentence arbitrale des ambassadeurs
français, toute favorable aux prétentions du duc. Elle ordonnait que
les portes par lesquelles les Gantois étaient sortis pour attaquer
Audenarde seraient fermées le jeudi de chaque semaine; que celle
par laquelle ils s'étaient dirigés vers Basele le serait perpétuellement;
qu'ils payeraient une amende de deux cent mille écus d'or; que
toutes leurs bannières leur seraient enlevées; que les chaperons
blancs seraient supprimés; qu'il n'y aurait plus d'assemblées
générales des métiers; que les magistrats de Gand n'exerceraient
aucune autorité supérieure sur les châtellenies voisines, et ne
pourraient prendre aucune décision sans l'assentiment du bailli du
duc; que ces mêmes magistrats se rendraient, en chemise et tête
nue, au devant du duc, suivis de deux mille bourgeois sans ceinture,
pour s'excuser en toute humilité de leur rébellion et en demander
pardon, grâce et miséricorde.
Quelques jours s'écoulèrent. Un héraut chargé par les ambassadeurs
français d'interpeller les Gantois sur leur adhésion à la sentence du 4
septembre, quitta Lille et se rendit à Gand. Dès qu'il fut descendu
dans une hôtellerie, il s'informa de quelle manière il pourrait remplir
son message. «Gardez-vous bien, s'écria l'hôte prenant pitié de lui,
gardez-vous bien de faire connaître quel motif vous amène, car si on
le savait, vous seriez perdu.» Et il cacha le héraut dans sa maison
afin qu'il pût attendre un moment plus favorable pour s'acquitter de
sa mission. Cependant l'agitation ne se calmait point. La collace,
convoquée le 8 septembre, avait rejeté tout d'une voix le traité de
Lille comme contraire aux priviléges de la commune, et il ne resta au
héraut qu'à tourner sa robe ornée de fleurs de lis et à feindre qu'il
était un marchand français revenant d'Anvers. Il y réussit, se fit
ouvrir les portes de la ville et frappa son cheval de l'éperon jusqu'à
ce qu'il fût rentré à Lille.
Il nous reste à raconter ce qu'était devenue la négociation relative
aux villes de la Somme. Le 9 septembre, c'est-à-dire, selon toute
apparence, le jour même du retour du messager français envoyé à
Gand, le duc Philippe, ne tenant aucun compte de la sentence
rendue en sa faveur par les envoyés de Charles VII, repoussa tout ce
qu'ils avaient allégué sur l'origine de la cession de 1435, en se
contentant de répondre que les causes en étaient assez connues,
mais «qu'il ne le vouloit point dire pour l'honneur du roy.» C'était
rappeler l'attentat de Montereau, l'alliance du duc Jean et des
Anglais, et l'humiliation du roi qui, pour ne pas subir la loi des
étrangers, l'avait acceptée d'un vassal. Cette réponse était un défi au
moment où le duc se félicitait de voir les Anglais menacer de
nouveau la Guyenne et peut-être même se préparer à reconquérir la
Normandie.
Du reste, Philippe ne méconnaissait point les bons services des
ambassadeurs français qui avaient condamné les Gantois. Comme
s'il prévoyait qu'ils pourraient être mal accueillis à leur retour à Paris,
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.
More than just a book-buying platform, we strive to be a bridge
connecting you with timeless cultural and intellectual values. With an
elegant, user-friendly interface and a smart search system, you can
quickly find the books that best suit your interests. Additionally,
our special promotions and home delivery services help you save time
and fully enjoy the joy of reading.
Join us on a journey of knowledge exploration, passion nurturing, and
personal growth every day!
ebookbell.com

Contenu connexe

PDF
Starting out with Visual C 2010 2nd Edition Edition Tony Gaddis
PDF
(eBook PDF) Starting Out with C++: Early Objects 9th Edition
PDF
Objectoriented Programming Using C Fourth Edition 4th Joyce Farrell
PDF
C Programming Program Design Including Data Structures 5th Edition D. S. Malik
PDF
Starting Out with C++: From Control Structures through Objects 8th Edition, (...
PDF
Download full ebook of s instant download pdf
PDF
Java programming from problem analysis to program design 5th ed Edition D S M...
PDF
The Ring programming language version 1.2 book - Part 1 of 84
Starting out with Visual C 2010 2nd Edition Edition Tony Gaddis
(eBook PDF) Starting Out with C++: Early Objects 9th Edition
Objectoriented Programming Using C Fourth Edition 4th Joyce Farrell
C Programming Program Design Including Data Structures 5th Edition D. S. Malik
Starting Out with C++: From Control Structures through Objects 8th Edition, (...
Download full ebook of s instant download pdf
Java programming from problem analysis to program design 5th ed Edition D S M...
The Ring programming language version 1.2 book - Part 1 of 84

Similaire à Programming Logic And Design Comprehensive 6th Edition 6th Edition Joyce Farrell (20)

PDF
Programming in C 2nd Edition Safari download pdf
PDF
Opencl In Action How To Accelerate Graphics And Computations Matthew Scarpino
PDF
Starting out with C Early objects 9th Global edition Edition Gaddis
PDF
The Ring programming language version 1.3 book - Part 1 of 88
PDF
Computer Simulation A Foundational Approach Using Python 1st Edition Yahya Es...
PDF
C How To Program Harvey Deitel Paul Deitel Jeffrey A Listfield Tem R Nieto Ch...
PDF
Your Wish Is My Command: Programming by Example - eBook PDF
PDF
Data Structures and Algorithms in C 2nd Edition Michael T. Goodrich
PDF
Test Bank for Java Software Solutions 7th Edition (International Edition). Jo...
PDF
Technology In Action Complete 9th Edition Evans Test Bank
PDF
The Ring programming language version 1.9 book - Part 3 of 210
PDF
Computer Architecture For Scientists Principles And Performance New Chien
PDF
C 6 0 Cookbook Solutions for C Developers 4th Edition Jay Hilyard
PDF
The Ring programming language version 1.10 book - Part 1 of 212
PDF
The Ring programming language version 1.10 book - Part 3 of 212
PDF
Theories of Programming Languages 1st Edition John C. Reynolds
PDF
Learning to program with Alice 2nd ed Edition Dann
PDF
Ktab asd
PDF
Download full ebook of Object-Oriented Python Irv Kalb instant download pdf
Programming in C 2nd Edition Safari download pdf
Opencl In Action How To Accelerate Graphics And Computations Matthew Scarpino
Starting out with C Early objects 9th Global edition Edition Gaddis
The Ring programming language version 1.3 book - Part 1 of 88
Computer Simulation A Foundational Approach Using Python 1st Edition Yahya Es...
C How To Program Harvey Deitel Paul Deitel Jeffrey A Listfield Tem R Nieto Ch...
Your Wish Is My Command: Programming by Example - eBook PDF
Data Structures and Algorithms in C 2nd Edition Michael T. Goodrich
Test Bank for Java Software Solutions 7th Edition (International Edition). Jo...
Technology In Action Complete 9th Edition Evans Test Bank
The Ring programming language version 1.9 book - Part 3 of 210
Computer Architecture For Scientists Principles And Performance New Chien
C 6 0 Cookbook Solutions for C Developers 4th Edition Jay Hilyard
The Ring programming language version 1.10 book - Part 1 of 212
The Ring programming language version 1.10 book - Part 3 of 212
Theories of Programming Languages 1st Edition John C. Reynolds
Learning to program with Alice 2nd ed Edition Dann
Ktab asd
Download full ebook of Object-Oriented Python Irv Kalb instant download pdf
Publicité

Dernier (20)

DOCX
ENDODONTIE CONSERVATRICE.docx faculté de médecine dentaire
PPTX
Hopital bonne sante.pptxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
PDF
Avis Digital Marketing Elite: Mon Retour d'Expérience Après 3 Mois d'Utilisation
PPTX
le subjonctif présent, Conjugaison français
PPTX
Le rendez-vous de l'été.pptx Film français
PPTX
SESSION4-SUPPORT-DE-COURS-FLEC-(Future leader en énergie au Cameroun)-CECOSDA...
PPTX
Présentation Projet Entreprise Minimaliste Moderne Sobre Blanc Noir.pptx
PPTX
Conception de documents et d'interfaces numériques.pptx
PDF
Consignes générales sécurité et environnement.pdf
PPT
Les moyens de transport-2023.ppt french language teaching ppt
PPTX
Fondamentaux du LMD.pptx pour les etudiants
PPTX
SESSION1-SUPPORT-DE-COURS-FLEC-(Future leader en énergie au Cameroun)-CECOSDA...
PDF
🎓 Le Secret des Profs Captivants - 💡 2. Hygiène vocale et santé professionnel...
PPTX
Bienvenido slides about the first steps in spanish.pptx
PPT
étude----- droit------ 2005---------.ppt
PPTX
Séminaire protection des personnes vulnérables.pptx
PPTX
Le rendez-vous de l'été.pptx Film français
PPT
Etalonnage de débitmètres.Champ d'application
PPT
calcul---électrique--et--chutes de tension.ppt
PPTX
SESSION3-SUPPORT-DE-COURS-FLEC-(Future leader en énergie au Cameroun)-CECOSDA...
ENDODONTIE CONSERVATRICE.docx faculté de médecine dentaire
Hopital bonne sante.pptxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Avis Digital Marketing Elite: Mon Retour d'Expérience Après 3 Mois d'Utilisation
le subjonctif présent, Conjugaison français
Le rendez-vous de l'été.pptx Film français
SESSION4-SUPPORT-DE-COURS-FLEC-(Future leader en énergie au Cameroun)-CECOSDA...
Présentation Projet Entreprise Minimaliste Moderne Sobre Blanc Noir.pptx
Conception de documents et d'interfaces numériques.pptx
Consignes générales sécurité et environnement.pdf
Les moyens de transport-2023.ppt french language teaching ppt
Fondamentaux du LMD.pptx pour les etudiants
SESSION1-SUPPORT-DE-COURS-FLEC-(Future leader en énergie au Cameroun)-CECOSDA...
🎓 Le Secret des Profs Captivants - 💡 2. Hygiène vocale et santé professionnel...
Bienvenido slides about the first steps in spanish.pptx
étude----- droit------ 2005---------.ppt
Séminaire protection des personnes vulnérables.pptx
Le rendez-vous de l'été.pptx Film français
Etalonnage de débitmètres.Champ d'application
calcul---électrique--et--chutes de tension.ppt
SESSION3-SUPPORT-DE-COURS-FLEC-(Future leader en énergie au Cameroun)-CECOSDA...
Publicité

Programming Logic And Design Comprehensive 6th Edition 6th Edition Joyce Farrell

  • 1. Programming Logic And Design Comprehensive 6th Edition 6th Edition Joyce Farrell download https://ebookbell.com/product/programming-logic-and-design- comprehensive-6th-edition-6th-edition-joyce-farrell-2422158 Explore and download more ebooks at ebookbell.com
  • 2. Here are some recommended products that we believe you will be interested in. You can click the link to download. Programming Logic And Design Comprehensive 6th Edition Joyce Farrell https://ebookbell.com/product/programming-logic-and-design- comprehensive-6th-edition-joyce-farrell-4586394 Programming Logic And Design Comprehensive 9th Edition 9th Edition Joyce Farrell https://ebookbell.com/product/programming-logic-and-design- comprehensive-9th-edition-9th-edition-joyce-farrell-37513870 Programming Logic And Design Comprehensive 7th Edition Joyce Farrell https://ebookbell.com/product/programming-logic-and-design- comprehensive-7th-edition-joyce-farrell-4054238 Programming Logic And Design Comprehensive 8th Edition Joyce Farrell https://ebookbell.com/product/programming-logic-and-design- comprehensive-8th-edition-joyce-farrell-4950652
  • 3. Programming Logic And Design Comprehensive 8th Joyce Farrell https://ebookbell.com/product/programming-logic-and-design- comprehensive-8th-joyce-farrell-5551838 Starting Out With Programming Logic And Design 6e 6th Tony Gaddis https://ebookbell.com/product/starting-out-with-programming-logic-and- design-6e-6th-tony-gaddis-54522858 C Programs To Accompany Programming Logic And Design 1st Edition Jo Ann Smith https://ebookbell.com/product/c-programs-to-accompany-programming- logic-and-design-1st-edition-jo-ann-smith-2371708 Just Enough Programming Logic And Design 1st Edition Joyce Farrell https://ebookbell.com/product/just-enough-programming-logic-and- design-1st-edition-joyce-farrell-2454550 Starting Out With Programming Logic And Design 3rd Edition Tony Gaddis https://ebookbell.com/product/starting-out-with-programming-logic-and- design-3rd-edition-tony-gaddis-4577402
  • 8. S I X T H E D I T I O N PR OGRAMMING LOGIC AND DESIGN COMPREHENSIVE JO YCE FARRELL Australia • Brazil • Japan • Korea • Mexico • Singapore • Spain • United Kingdom • United States
  • 9. This is an electronic version of the print textbook. Due to electronic rights restrictions, some third party content may be suppressed. Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. The publisher reserves the right to remove content from this title at any time if subsequent rights restrictions require it. For valuable information on pricing, previous editions, changes to current editions, and alternate formats, please visit www.cengage.com/highered to search by ISBN#, author, title, or keyword for materials in your areas of interest.
  • 10. © 2011 Course Technology, Cengage Learning ALL RIGHTS RESERVED. No part of this work covered by the copyright herein may be reproduced, transmitted, stored or used in any form or by any means—graphic, electronic, or mechanical, including but not limited to photocopying, recording, scanning, digitizing, taping, Web distribution, information networks, or information storage and retrieval systems, except as permitted under Section 107 or 108 of the 1976 United States Copyright Act—without the prior written permission of the publisher. Library of Congress Control Number: 2009938501 ISBN-13: 978-0-5387-4476-8 ISBN-10: 0-538-74476-6 Course Technology 20 Channel Center Street Boston, MA 02210 USA Some of the product names and company names used in this book have been used for identification purposes only and may be trademarks or registered trademarks of their respective manufacturers and sellers. Course Technology, a part of Cengage Learning, reserves the right to revise this publication and make changes from time to time in its content without notice. Cengage Learning is a leading provider of customized learning solutions with office locations around the globe, including Singapore, the United Kingdom, Australia, Mexico, Brazil, and Japan. Locate your local office at: www.cengage.com/global Cengage Learning products are represented in Canada by Nelson Education, Ltd. To learn more about Course Technology, visit www.cengage.com/coursetechnology Purchase any of our products at your local college store or at our preferred online store www.ichapters.com Programming Logic and Design, Comprehensive, Sixth Edition Joyce Farrell Executive Editor: Marie Lee Acquisitions Editor: Amy Jollymore Managing Editor: Tricia Coia Developmental Editor: Dan Seiter Content Project Manager: Jennifer Feltri Editorial Assistant: Zina Kresin Marketing Manager: Bryant Chrzan Art Director: Marissa Falco Text Designer: Shawn Girsberger Cover Designer: Cabbage Design Company Cover Image: iStockphoto Print Buyer: Julio Esperas Copy Editor: Michael Beckett Proofreader: Vicki Zimmer Indexer: Alexandra Nickerson Compositor: Integra Printed in Canada 1 2 3 4 5 6 7 14 13 12 11 10 For product information and technology assistance, contact us at Cengage Learning Customer & Sales Support, 1-800-354-9706 For permission to use material from this text or product, submit all requests online at cengage.com/permissions Further permissions questions can be emailed to permissionrequest@cengage.com
  • 11. Brief Contents Preface . . . . . . . . . . . . . . . . . xvi CHAPTER 1 An Overview of Computers and Programming . . 1 CHAPTER 2 Working with Data, Creating Modules, and Designing High-Quality Programs . . . . 41 CHAPTER 3 Understanding Structure . . . . . . . . . . 92 CHAPTER 4 Making Decisions . . . . . . . . . . . . 133 CHAPTER 5 Looping . . . . . . . . . . . . . . . . 184 CHAPTER 6 Arrays . . . . . . . . . . . . . . . . . 228 CHAPTER 7 File Handling and Applications . . . . . . 276 CHAPTER 8 Advanced Array Concepts, Indexed Files, and Linked Lists. . . . . . . . . . . . . 325 CHAPTER 9 Advanced Modularization Techniques . . . . 370 CHAPTER 10 Object-Oriented Programming . . . . . . . 426 CHAPTER 11 More Object-Oriented Programming Concepts . . . . . . . . . . . . . . . . 469 CHAPTER 12 Event-Driven GUI Programming, Multithreading, and Animation . . . . . . . 515 CHAPTER 13 System Modeling with the UML . . . . . . 550 CHAPTER 14 Using Relational Databases . . . . . . . . 585 APPENDIX A Understanding Numbering Systems and Computer Codes. . . . . . . . . . . 637 APPENDIX B Flowchart Symbols . . . . . . . . . . . 646 v
  • 12. APPENDIX C Structures . . . . . . . . . . . . . . . 647 APPENDIX D Solving Difficult Structuring Problems . . . 649 APPENDIX E Creating Print Charts . . . . . . . . . . 658 APPENDIX F Two Variations on the Basic Structures— case and do-while . . . . . . . . . . 660 Glossary . . . . . . . . . . . . . . . . 666 Index . . . . . . . . . . . . . . . . . 681 B R I E F C O N T E N T S vi
  • 13. Contents Preface . . . . . . . . . . . . . . . . . xvi CHAPTER 1 An Overview of Computers and Programming . . . . . . . . . . . . . 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 . . . . . . . . . . . .14 Maintaining the Program . . . . . . . . . . . . . . . . .14 Using Pseudocode Statements and Flowchart Symbols . . . .15 Writing Pseudocode . . . . . . . . . . . . . . . . . . .15 Drawing Flowcharts . . . . . . . . . . . . . . . . . . .17 Repeating Instructions . . . . . . . . . . . . . . . . . .18 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 Review Questions . . . . . . . . . . . . . . . . . . . . .32 Exercises . . . . . . . . . . . . . . . . . . . . . . . . .37 CHAPTER 2 Working with Data, Creating Modules, and Designing High-Quality Programs . . . . . . 41 Declaring and Using Variables and Constants. . . . . . . . .42 vii
  • 14. Working with Variables . . . . . . . . . . . . . . . . . .42 Naming Variables . . . . . . . . . . . . . . . . . . . .44 Understanding Unnamed, Literal Constants and their Data Types . . . . . . . . . . . . . . . . . .45 Understanding the Data Types of Variables . . . . . . . . .46 Declaring Named Constants. . . . . . . . . . . . . . . .47 Assigning Values to Variables . . . . . . . . . . . . . . . .48 Performing Arithmetic Operations . . . . . . . . . . . . .49 Understanding the Advantages of Modularization . . . . . . . 52 Modularization Provides Abstraction . . . . . . . . . . . .53 Modularization Allows Multiple Programmers to Work on a Problem. . . . . . . . . . . . . . . . . .54 Modularization Allows You to Reuse Your Work . . . . . . .54 Modularizing a Program . . . . . . . . . . . . . . . . . .55 Declaring Variables and Constants within Modules . . . . . . . . . . . . . . . . . . . . .59 Understanding the Most Common Configuration for Mainline Logic . . . . . . . . . . . . . . . . . . . .61 Creating Hierarchy Charts . . . . . . . . . . . . . . . . .66 Features of Good Program Design. . . . . . . . . . . . . .68 Using Program Comments . . . . . . . . . . . . . . . .69 Choosing Identifiers . . . . . . . . . . . . . . . . . . .71 Designing Clear Statements. . . . . . . . . . . . . . . .72 Writing Clear Prompts and Echoing Input . . . . . . . . . .74 Maintaining Good Programming Habits . . . . . . . . . . .76 Chapter Summary . . . . . . . . . . . . . . . . . . . . .77 Key Terms . . . . . . . . . . . . . . . . . . . . . . . .78 Review Questions . . . . . . . . . . . . . . . . . . . . .82 Exercises . . . . . . . . . . . . . . . . . . . . . . . . .86 CHAPTER 3 Understanding Structure . . . . . . . . . . 92 Understanding Unstructured Spaghetti Code . . . . . . . . .93 Understanding the Three Basic Structures . . . . . . . . . .95 Using a Priming Input to Structure a Program . . . . . . . 103 Understanding the Reasons for Structure . . . . . . . . . 110 Recognizing Structure . . . . . . . . . . . . . . . . . . 111 Structuring and Modularizing Unstructured Logic . . . . . . 115 Chapter Summary . . . . . . . . . . . . . . . . . . . . 121 Key Terms . . . . . . . . . . . . . . . . . . . . . . . 122 Review Questions . . . . . . . . . . . . . . . . . . . . 123 Exercises . . . . . . . . . . . . . . . . . . . . . . . . 127 C O N T E N T S viii
  • 15. CHAPTER 4 Making Decisions . . . . . . . . . . . . 133 Evaluating Boolean Expressions to Make Comparisons . . . 134 Using Relational Comparison Operators . . . . . . . . . . 137 Avoiding a Common Error with Relational Operators . . . . 141 Understanding AND Logic . . . . . . . . . . . . . . . . 141 Nesting AND Decisions for Efficiency . . . . . . . . . . 144 Using the AND Operator . . . . . . . . . . . . . . . . 146 Avoiding Common Errors in an AND Selection. . . . . . . 148 Understanding OR Logic . . . . . . . . . . . . . . . . . 150 Writing OR Decisions for Efficiency . . . . . . . . . . . 152 Using the OR Operator . . . . . . . . . . . . . . . . . 153 Avoiding Common Errors in an OR Selection . . . . . . . 155 Making Selections within Ranges . . . . . . . . . . . . . 159 Avoiding Common Errors When Using Range Checks . . . 162 Understanding Precedence When Combining AND and OR Operators . . . . . . . . . . . . . . . . . 166 Chapter Summary . . . . . . . . . . . . . . . . . . . . 169 Key Terms . . . . . . . . . . . . . . . . . . . . . . . 170 Review Questions . . . . . . . . . . . . . . . . . . . . 171 Exercises . . . . . . . . . . . . . . . . . . . . . . . . 177 CHAPTER 5 Looping . . . . . . . . . . . . . . . . 184 Understanding the Advantages of Looping . . . . . . . . . 185 Using a Loop Control Variable. . . . . . . . . . . . . . . 186 Using a Definite Loop with a Counter . . . . . . . . . . 187 Using an Indefinite Loop with a Sentinel Value . . . . . . 188 Understanding the Loop in a Program’s Mainline Logic. . . 190 Nested Loops . . . . . . . . . . . . . . . . . . . . . . 192 Avoiding Common Loop Mistakes . . . . . . . . . . . . . 196 Mistake: Neglecting to Initialize the Loop Control Variable . . . . . . . . . . . . . . . . . 197 Mistake: Neglecting to Alter the Loop Control Variable . . . . . . . . . . . . . . . . . 198 Mistake: Using the Wrong Comparison with the Loop Control Variable . . . . . . . . . . . . . . . . . 200 Mistake: Including Statements Inside the Loop that Belong Outside the Loop . . . . . . . . . . . . . 201 Using a for Loop . . . . . . . . . . . . . . . . . . . . 206 Common Loop Applications . . . . . . . . . . . . . . . . 208 Using a Loop to Accumulate Totals . . . . . . . . . . . 208 Using a Loop to Validate Data . . . . . . . . . . . . . . 211 Limiting a Reprompting Loop . . . . . . . . . . . . . . 213 ix C O N T E N T S
  • 16. Validating a Data Type . . . . . . . . . . . . . . . . . 215 Validating Reasonableness and Consistency of Data . . . . 216 Chapter Summary . . . . . . . . . . . . . . . . . . . . 217 Key Terms . . . . . . . . . . . . . . . . . . . . . . . 218 Review Questions . . . . . . . . . . . . . . . . . . . . 219 Exercises . . . . . . . . . . . . . . . . . . . . . . . . 223 CHAPTER 6 Arrays . . . . . . . . . . . . . . . . . 228 Understanding Arrays and How They Occupy Computer Memory . . . . . . . . . . . . . . . . . . . 229 How Arrays Occupy Computer Memory. . . . . . . . . . 229 Manipulating an Array to Replace Nested Decisions . . . . . 232 Using Constants with Arrays . . . . . . . . . . . . . . . 240 Using a Constant as the Size of an Array . . . . . . . . . 240 Using Constants as Array Element Values . . . . . . . . 241 Using a Constant as an Array Subscript . . . . . . . . . 241 Searching an Array . . . . . . . . . . . . . . . . . . . 242 Using Parallel Arrays . . . . . . . . . . . . . . . . . . . 246 Improving Search Efficiency. . . . . . . . . . . . . . . 251 Searching an Array for a Range Match . . . . . . . . . . . 254 Remaining within Array Bounds . . . . . . . . . . . . . . 258 Using a for Loop to Process Arrays . . . . . . . . . . . 261 Chapter Summary . . . . . . . . . . . . . . . . . . . . 262 Key Terms . . . . . . . . . . . . . . . . . . . . . . . 263 Review Questions . . . . . . . . . . . . . . . . . . . . 264 Exercises . . . . . . . . . . . . . . . . . . . . . . . . 268 CHAPTER 7 File Handling and Applications . . . . . . 276 Understanding Computer Files . . . . . . . . . . . . . . 277 Organizing Files . . . . . . . . . . . . . . . . . . . . 278 Understanding the Data Hierarchy . . . . . . . . . . . . . 279 Performing File Operations . . . . . . . . . . . . . . . . 280 Declaring a File . . . . . . . . . . . . . . . . . . . . 280 Opening a File . . . . . . . . . . . . . . . . . . . . . 281 Reading Data From a File . . . . . . . . . . . . . . . . 281 Writing Data to a File . . . . . . . . . . . . . . . . . . 283 Closing a File . . . . . . . . . . . . . . . . . . . . . 283 A Program that Performs File Operations. . . . . . . . . 283 Understanding Sequential Files and Control Break Logic . . . 286 Understanding Control Break Logic . . . . . . . . . . . 287 Merging Sequential Files . . . . . . . . . . . . . . . . . 293 Master and Transaction File Processing . . . . . . . . . . 303 x C O N T E N T S
  • 17. Random Access Files . . . . . . . . . . . . . . . . . . 311 Chapter Summary . . . . . . . . . . . . . . . . . . . . 313 Key Terms . . . . . . . . . . . . . . . . . . . . . . . 314 Review Questions . . . . . . . . . . . . . . . . . . . . 316 Exercises . . . . . . . . . . . . . . . . . . . . . . . . 320 CHAPTER 8 Advanced Array Concepts, Indexed Files, and Linked Lists. . . . . . . . . . . . . 325 Understanding the Need for Sorting Records . . . . . . . . 326 Understanding How to Swap Two Values . . . . . . . . . . 327 Using a Bubble Sort . . . . . . . . . . . . . . . . . . . 329 Sorting a List of Variable Size. . . . . . . . . . . . . . 337 Refining the Bubble Sort to Reduce Unnecessary Comparisons. . . . . . . . . . . . . . . . . . . . . 341 Refining the Bubble Sort to Eliminate Unnecessary Passes . . . . . . . . . . . . . . . . . . . . . . . 343 Other Sorts . . . . . . . . . . . . . . . . . . . . . . 345 Using Multidimensional Arrays . . . . . . . . . . . . . . 345 Using Indexed Files and Linked Lists. . . . . . . . . . . . 352 Using Indexed Files . . . . . . . . . . . . . . . . . . 352 Using Linked Lists . . . . . . . . . . . . . . . . . . . 354 Chapter Summary . . . . . . . . . . . . . . . . . . . . 357 Key Terms . . . . . . . . . . . . . . . . . . . . . . . 358 Review Questions . . . . . . . . . . . . . . . . . . . . 359 Exercises . . . . . . . . . . . . . . . . . . . . . . . . 364 CHAPTER 9 Advanced Modularization Techniques . . . . 370 Using Methods with No Parameters . . . . . . . . . . . . 371 Creating Methods that Require a Single Parameter . . . . . 374 Creating Methods that Require Multiple Parameters . . . . . 379 Creating Methods that Return a Value . . . . . . . . . . . 381 Using an IPO Chart . . . . . . . . . . . . . . . . . . . 387 Passing an Array to a Method . . . . . . . . . . . . . . . 388 Overloading Methods. . . . . . . . . . . . . . . . . . . 395 Avoiding Ambiguous Methods . . . . . . . . . . . . . . . 398 Using Predefined Methods . . . . . . . . . . . . . . . . 401 Method Design Issues: Implementation Hiding, Cohesion, and Coupling . . . . . . . . . . . . . . . . . . . . . 403 Understanding Implementation Hiding . . . . . . . . . . 403 Increasing Cohesion . . . . . . . . . . . . . . . . . . 404 Reducing Coupling . . . . . . . . . . . . . . . . . . . 405 Understanding Recursion . . . . . . . . . . . . . . . . . 407 xi C O N T E N T S
  • 18. Chapter Summary . . . . . . . . . . . . . . . . . . . . 411 Key Terms . . . . . . . . . . . . . . . . . . . . . . . 413 Review Questions . . . . . . . . . . . . . . . . . . . . 415 Exercises . . . . . . . . . . . . . . . . . . . . . . . . 419 CHAPTER 10 Object-Oriented Programming . . . . . . . 426 Principles of Object-Oriented Programming. . . . . . . . . 427 Classes and Objects . . . . . . . . . . . . . . . . . . 427 Polymorphism . . . . . . . . . . . . . . . . . . . . . 430 Inheritance . . . . . . . . . . . . . . . . . . . . . . 431 Encapsulation . . . . . . . . . . . . . . . . . . . . . 432 Defining Classes and Creating Class Diagrams . . . . . . . 433 Creating Class Diagrams . . . . . . . . . . . . . . . . 435 The Set Methods. . . . . . . . . . . . . . . . . . . . 438 The Get Methods. . . . . . . . . . . . . . . . . . . . 440 Work Methods . . . . . . . . . . . . . . . . . . . . . 440 Understanding Public and Private Access . . . . . . . . . 442 Organizing Classes . . . . . . . . . . . . . . . . . . . 446 Understanding Instance Methods . . . . . . . . . . . . . 447 Understanding Static Methods . . . . . . . . . . . . . . 453 Using Objects . . . . . . . . . . . . . . . . . . . . . . 455 Chapter Summary . . . . . . . . . . . . . . . . . . . . 459 Key Terms . . . . . . . . . . . . . . . . . . . . . . . 460 Review Questions . . . . . . . . . . . . . . . . . . . . 462 Exercises . . . . . . . . . . . . . . . . . . . . . . . . 466 CHAPTER 11 More Object-Oriented Programming Concepts . . . . . . . . . . . . . . . . 469 An Introduction to Constructors . . . . . . . . . . . . . . 470 Constructors with Parameters. . . . . . . . . . . . . . 473 Overloading Class Methods and Constructors. . . . . . . 473 Understanding Destructors . . . . . . . . . . . . . . . . 476 Understanding Composition. . . . . . . . . . . . . . . . 478 Understanding Inheritance . . . . . . . . . . . . . . . . 479 Understanding Inheritance Terminology . . . . . . . . . 481 Accessing Private Members of a Parent Class . . . . . . 484 Using Inheritance to Achieve Good Software Design . . . . 490 One Example of Using Predefined Classes: Creating GUI Objects . . . . . . . . . . . . . . . . . . 491 Understanding Exception Handling. . . . . . . . . . . . . 493 Drawbacks to Traditional Error-Handling Techniques . . . . 493 The Object-Oriented Exception Handling Model . . . . . . 495 xii C O N T E N T S
  • 19. Using Built-in Exceptions and Creating Your Own Exceptions. . . . . . . . . . . . . . . . . . . . . . 498 Reviewing the Advantages of Object-Oriented Programming . . . . . . . . . . . . . . . . . . . . . 499 Chapter Summary . . . . . . . . . . . . . . . . . . . . 500 Key Terms . . . . . . . . . . . . . . . . . . . . . . . 502 Review Questions . . . . . . . . . . . . . . . . . . . . 503 Exercises . . . . . . . . . . . . . . . . . . . . . . . . 508 CHAPTER 12 Event-Driven GUI Programming, Multithreading, and Animation . . . . . . . 515 Understanding Event-Driven Programming . . . . . . . . . 516 User-Initiated Actions and GUI Components. . . . . . . . . 519 Designing Graphical User Interfaces . . . . . . . . . . . . 523 The Interface Should Be Natural and Predictable . . . . . 523 The Interface Should Be Attractive, Easy to Read, and Nondistracting . . . . . . . . . . . . . . . . . . . . 524 To Some Extent, It’s Helpful If the User Can Customize Your Applications. . . . . . . . . . . . . . 524 The Program Should Be Forgiving . . . . . . . . . . . . 525 The GUI Is Only a Means to an End . . . . . . . . . . . 525 The Steps to Developing an Event-Driven Application . . . . 526 Creating Storyboards. . . . . . . . . . . . . . . . . . 527 Defining the Storyboard’s Objects in an Object Dictionary . . . . . . . . . . . . . . . . . 527 Defining Connections Between the User Screens . . . . . 528 Planning the Logic . . . . . . . . . . . . . . . . . . . 529 Understanding Multithreading . . . . . . . . . . . . . . . 535 Creating Animation. . . . . . . . . . . . . . . . . . . . 537 Chapter Summary . . . . . . . . . . . . . . . . . . . . 540 Key Terms . . . . . . . . . . . . . . . . . . . . . . . 541 Review Questions . . . . . . . . . . . . . . . . . . . . 542 Exercises . . . . . . . . . . . . . . . . . . . . . . . . 546 CHAPTER 13 System Modeling with the UML . . . . . . 550 Understanding the Need for System Modeling . . . . . . . 551 What is the UML? . . . . . . . . . . . . . . . . . . . . 552 Using Use Case Diagrams . . . . . . . . . . . . . . . . 554 Using Class and Object Diagrams . . . . . . . . . . . . . 560 Using Sequence and Communication Diagrams . . . . . . . 564 Using State Machine Diagrams . . . . . . . . . . . . . . 566 Using Activity Diagrams . . . . . . . . . . . . . . . . . 567 xiii C O N T E N T S
  • 20. Using Component, Deployment, and Profile Diagrams . . . . 570 Diagramming Exception Handling . . . . . . . . . . . . . 572 Deciding When to Use the UML and Which UML Diagrams to Use . . . . . . . . . . . . . . . . . 573 Chapter Summary . . . . . . . . . . . . . . . . . . . . 575 Key Terms . . . . . . . . . . . . . . . . . . . . . . . 576 Review Questions . . . . . . . . . . . . . . . . . . . . 578 Exercises . . . . . . . . . . . . . . . . . . . . . . . . 582 CHAPTER 14 Using Relational Databases . . . . . . . . 585 Understanding Relational Database Fundamentals. . . . . . 586 Creating Databases and Table Descriptions . . . . . . . . 588 Identifying Primary Keys . . . . . . . . . . . . . . . . . 591 Understanding Database Structure Notation . . . . . . . . 594 Adding, Deleting, Updating, and Sorting Records within Tables. . . . . . . . . . . . . . . . . . . . . . 595 Sorting the Records in a Table . . . . . . . . . . . . . 596 Creating Queries. . . . . . . . . . . . . . . . . . . . . 596 Understanding Relationships Between Tables . . . . . . . . 600 Understanding One-to-Many Relationships . . . . . . . . 600 Understanding Many-to-Many Relationships . . . . . . . . 601 Understanding One-to-One Relationships . . . . . . . . . 606 Recognizing Poor Table Design . . . . . . . . . . . . . . 607 Understanding Anomalies, Normal Forms, and Normalization . . . . . . . . . . . . . . . . . . . 609 First Normal Form . . . . . . . . . . . . . . . . . . . 610 Second Normal Form . . . . . . . . . . . . . . . . . . 612 Third Normal Form . . . . . . . . . . . . . . . . . . . 615 Database Performance and Security Issues . . . . . . . . 618 Providing Data Integrity. . . . . . . . . . . . . . . . . 618 Recovering Lost Data . . . . . . . . . . . . . . . . . 619 Avoiding Concurrent Update Problems . . . . . . . . . . 619 Providing Authentication and Permissions . . . . . . . . 620 Providing Encryption . . . . . . . . . . . . . . . . . . 620 Chapter Summary . . . . . . . . . . . . . . . . . . . . 621 Key Terms . . . . . . . . . . . . . . . . . . . . . . . 622 Review Questions . . . . . . . . . . . . . . . . . . . . 625 Exercises . . . . . . . . . . . . . . . . . . . . . . . . 630 xiv C O N T E N T S
  • 21. APPENDIX A Understanding Numbering Systems and Computer Codes. . . . . . . . . . . 637 APPENDIX B Flowchart Symbols . . . . . . . . . . . 646 APPENDIX C Structures . . . . . . . . . . . . . . . 647 APPENDIX D Solving Difficult Structuring Problems . . . 649 APPENDIX E Creating Print Charts . . . . . . . . . . 658 APPENDIX F Two Variations on the Basic Structures— case and do-while . . . . . . . . . . 660 Glossary . . . . . . . . . . . . . . . . 666 Index . . . . . . . . . . . . . . . . . 681 xv C O N T E N T S
  • 22. Preface Programming Logic and Design, Comprehensive, Sixth Edition provides the beginning programmer with a guide to developing structured program logic. This textbook assumes no programming language experience. The writing is nontechnical and emphasizes good programming practices. The examples are business examples; they do not assume mathematical background beyond high school business math. Additionally, the examples illustrate one or two major points; they do not contain so many features that students become lost following irrelevant and extraneous details. The examples in Programming Logic and Design have been created to provide students with a sound background in logic, no matter what programming languages they eventually use to write programs. This book can be used in a stand-alone logic course that students take as a prerequisite to a programming course, or as a companion book to an introductory programming text using any programming language. Organization and Coverage Programming Logic and Design, Comprehensive, Sixth Edition introduces students to programming concepts and enforces good style and logical thinking. General programming concepts are intro- duced in Chapter 1. Chapter 2 discusses using data and introduces two important concepts: modularization and creating high-quality programs. It is important to emphasize these topics early so that students start thinking in a modular way and concentrate on making their programs efficient, robust, easy to read, and easy to maintain. Chapter 3 covers the key concepts of structure, including what structure is, how to recognize it, and most importantly, the advan- tages to writing structured programs. This early overview gives students a solid foundation for thinking in a structured way before they have to manage the details of the structures. Chapters 4, 5, and 6 explore the intricacies of decision making, looping, and array manipulation. Chapter 7 provides details of file handling so students can create programs that handle a significant amount of data. xvi
  • 23. In Chapters 8 and 9, students learn more advanced techniques in array manipulation and modularization. Chapters 10 and 11 provide a thorough, yet accessible, introduction to concepts and terminology used in object-oriented programming. Students learn about classes, objects, instance and static class members, constructors, destructors, inheritance, and the advantages provided by object-oriented thinking. Chapter 12 explores additional object-oriented programming issues: event-driven GUI programming, multithreading, and animation. Chapter 13 discusses system design issues and details the features of the Unified Modeling Language. Chapter 14 is a thorough introduc- tion to the most important database concepts business programmers should understand. The first three appendices give students summaries of numbering systems, flowchart symbols, and structures. Additional appendices allow students to gain extra experience with structuring large unstructured programs, creating print charts, and understanding posttest loops and case structures. Programming Logic and Design combines text explanation with flowcharts and pseudocode examples to provide students with alternative means of expressing structured logic. Numerous detailed, full-program exercises at the end of each chapter illustrate the concepts explained within the chapter, and reinforce understanding and retention of the material presented. Programming Logic and Design distinguishes itself from other programming logic books in the following ways: It is written and designed to be non-language specific. The logic • used in this book can be applied to any programming language. The examples are everyday business examples; no special knowledge • of mathematics, accounting, or other disciplines is assumed. The concept of structure is covered earlier than in many other • texts. Students are exposed to structure naturally, so they will automatically create properly designed programs. Text explanation is interspersed with flowcharts and pseudocode • so students can become comfortable with both logic development tools and understand their interrelationship. Screen shots of running programs also are included, providing students with a clear and concrete image of the programs’ execution. Complex programs are built through the use of complete business • examples. Students see how an application is constructed from start to finish instead of studying only segments of programs. xvii P R E FA C E
  • 24. Features This edition of the text includes many features to help students become better programmers and understand the big picture in program development. Many new features have been added, and the popular features from the first five editions are still included. Features maintained from previous editions include: OBJECTIVES Each chapter begins with a list of objectives so the student knows the topics that will be presented in the chapter. In addition to providing a quick reference to topics covered, this feature provides a useful study aid. FLOWCHARTS This book has plenty of figures and illustrations, including flowcharts, which provide the reader with a visual learning experience, rather than one that involves simply studying text. You can see examples of flowcharts beginning in Chapter 1. PSEUDOCODE This book also includes numerous examples of pseudocode, which illustrate correct usage of the programming logic and design concepts being taught. NOTES These tips provide additional information—for example, another location in the book that expands on a topic, or a common error to watch out for. THE DON’T DO IT ICON It is sometimes illustrative to show an example of how NOT to do something—for example, having a dead code path in a program. However, students do not always read carefully and sometimes use logic similar to that shown in what is intended to be a “bad” example. When the instructor is critical, the frustrated student says, “But that’s how they did it in the book!” Therefore, although the text will continue to describe bad examples, and the captions for the related figures will mention that they are bad examples, the book also includes a “Don’t Do It” icon near the offending section of logic. This icon provides a visual jolt to the student, emphasizing that particular figures are NOT to be emulated. THE TWO TRUTHS AND A LIE QUIZ This quiz appears after each chapter section, with answers provided. The quiz contains three statements based on the preceding section of text—two true and one false. Over the years, students have requested answers to problems, but we have hesitated to distribute them in case instructors want to use problems as assignments or test questions. These true-false mini-quizzes provide students with immediate feedback as they read, without “giving away” answers to the multiple-choice questions and programming problems later in the chapter. xviii P R E FA C E
  • 25. GAME ZONE EXERCISES These exercises are included at the end of each chapter. Students can create games as an additional entertaining way to understand key concepts presented in the chapter. CHAPTER SUMMARIES Following each chapter is a summary that recaps the programming concepts and techniques covered in the chapter. This feature provides a concise means for students to review and check their understanding of the main points in each chapter. KEY TERMS Each chapter lists key terms and their definitions; the list appears in the order the terms are encountered in the chapter. Along with the chapter summary, the list of key terms provides a snapshot overview of a chapter’s main ideas. A glossary at the end of the book lists all the key terms in alphabetical order, along with working definitions. DEBUGGING EXERCISES Because examining programs critically and closely is a crucial programming skill, each chapter includes a “Find the Bugs” section in which program- ming examples are presented that contain syntax errors and logical errors for the student to find and correct. REVIEW QUESTIONS Twenty multiple-choice review questions appear at the end of every chapter to allow students to test their comprehension of the major ideas and techniques presented. EXERCISES Multiple end-of-chapter flowcharting and pseudocoding exercises are included so students have more opportunities to practice concepts as they learn them. These exercises increase in difficulty and are designed to allow students to explore logical programming concepts. Each exercise can be completed using flowcharts, pseudocode, or both. In addition, instructors can assign the exercises as programming prob- lems to be coded and executed in a particular programming language. ESSAY QUESTIONS Each chapter contains an “Up For Discussion” section in which questions present personal and ethical issues that programmers must consider. These ques- tions can be used for written assignments or as a starting point for classroom discussions. New to this Edition! VIDEO LESSONS Each chapter is accompanied by two or more video lessons that help explain an important chapter concept. A listing of the videos provided can be found on the inside back cover of this text. These videos are designed and narrated by the author and are available for free with a new book. (They can also be purchased separately at iChapters.com.) xix P R E FA C E
  • 26. If you have a new book, it will contain a URL and PIN code. Once you go to this URL and enter your PIN code, follow the prompts to locate the videos for this text. If you are a user of an online course cartridge, such as BlackBoard, WebCT, or Angel, you will also have access to these videos through that platform. INCREASED EMPHASIS ON MODULARITY From the second chapter, students are encouraged to write code in concise, easily manageable, and reusable modules. Instructors have found that modularization is a technique that should be encouraged early to instill good habits and a clearer understanding of structure. This edition explains modularization early, using global variables instead of local passed and returned values, and saves parameter passing for later when the student has become more adept. CLEARER EXPLANATIONS This edition has been rewritten to provide clearer, simpler explanations that are appropriate for the beginning programming student. As a result of the new, cleaner approach, the length of the book has been reduced. NEW APPENDICES FOR EASY REFERENCE New appendices have been added that cover numbering systems, flowchart symbols, and structures. DECREASED EMPHASIS ON CONTROL BREAKS Professional programmers should understand control break logic, but creating such logic is not as common a task as it was years ago. Therefore, the topic is still covered briefly as part of the file-handling chapter, but with reduced emphasis from previous editions of the book. Instructor Resources The following supplemental materials are available when this book is used in a classroom setting. All of the instructor resources available with this book are provided to the instructor on a single CD-ROM. ELECTRONIC INSTRUCTOR’S MANUAL The Instructor’s Manual that accompanies this textbook provides additional instructional material to assist in class preparation, including items such as Sample Syllabi, Chapter Outlines, Technical Notes, Lecture Notes, Quick Quizzes, Teaching Tips, Discussion Topics, and Key Terms. EXAMVIEW® This textbook is accompanied by ExamView, a powerful testing software package that allows instructors to create and admin- ister printed, computer (LAN-based), and Internet exams. ExamView includes hundreds of questions that correspond to the topics covered in this text, enabling students to generate detailed study guides that include page references for further review. The computer-based and Internet xx P R E FA C E
  • 27. testing components allow students to take exams at their computers, and save the instructor time by grading each exam automatically. POWERPOINT PRESENTATIONS This book comes with Microsoft PowerPoint© slides for each chapter. These are included as a teach- ing aid for classroom presentation, to make available to students on your network for chapter review, or to be printed for classroom distribution. Instructors can add their own slides for additional topics they introduce to the class. SOLUTIONS Suggested solutions to Review Questions and Exercises are provided on the Instructor Resources CD and may also be found on the Course Technology Web site at www.cengage.com/coursetech- nology. The solutions are password protected. DISTANCE LEARNING Course Technology offers WebCT© and Blackboard© courses for this text to provide the most complete and dynamic learning experience possible. When you add online content to one of your courses, you’re adding a lot: automated tests, topic reviews, quick quizzes, and additional case projects with solutions. For more information on how to bring distance learning to your course, contact your Course Technology sales representative. Software Options You have the option to bundle software with your text! Please contact your Course Technology sales representative for more information. MICROSOFT® OFFICE VISIO® PROFESSIONAL Visio is a diagramming program that helps users create flowcharts and diagrams easily while working through the text, enabling them to visualize concepts and learn more effectively. VISUAL LOGIC™ This simple but powerful tool teaches program- ming logic and design without traditional high-level programming language syntax. Visual Logic uses flowcharts to explain essential programming concepts, including variables, input, assignment, out- put, conditions, loops, procedures, graphics, arrays, and files. It also has the ability to interpret and execute flowcharts, providing students with immediate and accurate feedback about their solutions. By exe- cuting student solutions, Visual Logic combines the power of a high- level language with the ease and simplicity of flowcharts. Acknowledgments I would like to thank all of the people who helped to make this book a reality, especially Dan Seiter, Development Editor, whose hard work and attention to detail have made this a high-quality textbook. I have xxi P R E FA C E
  • 28. worked with Dan for many years now, and he is indispensable in pro- ducing accurate and approachable technical instruction. Thanks also to Tricia Coia, Managing Editor; Amy Jollymore, Acquisitions Editor; Jennifer Feltri, Content Project Manager; and Green Pen QA, Technical Editors. I am grateful to be able to work with so many fine people who are dedicated to producing high-quality instructional materials. I am grateful to the many reviewers who provided helpful and insightful comments during the development of this book, including Gilbert Armour, Virginia Western Community College; John Buerck, Saint Louis University; Karen Cummings, McLennan Community College; Clara Groeper, Illinois Central College; and Jeff Hedrington, Colorado Technical University. Thanks, too, to my husband, Geoff, and our daughters, Andrea and Audrey, for their support. This book, as were all its previous editions, is dedicated to them. –Joyce Farrell xxii P R E FA C E
  • 29. About the Inside Front Cover Check out our interviews with recent graduates who are now working in the IT field. One is featured on the inside front cover of this book. If you know people who recently landed a job in IT, we’d like to interview them too! Send your suggestions via e-mail to Amy Jollymore, Acquisitions Editor, at Amy.Jollymore@Cengage.com. xxiii P R E FA C E
  • 31. C H A P T E R 1 An Overview of Computers and Programming In this chapter, you will learn about: Computer systems  Simple program logic  The steps involved in the program development cycle  Pseudocode statements and flowchart symbols  Using a sentinel value to end a program  Programming and user environments  The evolution of programming models 
  • 32. Understanding Computer Systems 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 large mainframe computers, laptops, and even smaller comput- ers that are embedded into products such as cars and thermostats, but the types of operations performed by different-sized comput- ers are very similar. When you think of a computer, you often think of its physical components first, but for a computer to be useful it needs more than devices; a computer needs to be given instruc- tions. Just as your stereo equipment does not do much until you provide music, computer hardware needs instructions that control how and when data items are input, how they are processed, and the form in which they are output or stored. Software • is computer instructions that tell the hardware what to do. Software is programs: instructions written by programmers. You can buy prewritten programs that are stored on a disk or that you down- load from the Web. For example, businesses use word-processing and accounting programs, and casual computer users enjoy pro- grams 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 as application software or system software. Application software comprises all the programs you apply to a task— word-processing programs, spreadsheets, payroll and inventory programs, and even games. System software comprises the programs that you use to manage your computer, including operating systems such as Windows, Linux, or UNIX. This book focuses on the logic used to write application software pro- grams, 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 put into mem- ory, where they can be processed. Hardware devices that perform input operations include keyboards and mice. Data items include all the text, numbers, and other information that are processed by a computer. In business, much of the data used is facts and figures about such entities as products, customers, and personnel. However, data can also be items such as the choices a player makes in a game or the notes required by a music- playing program. 2 C H A P T E R 1 An Overview of Computers and Programming
  • 33. Many computer professionals distinguish between the terms data, which describes items that are input, and information, which describes data items that have been processed and sent to a device where people can read and interpret them. For example, your name, Social Security number, and hourly pay rate are data items when they are input to a program, but the same items are information after they have been processed and output on your paycheck. 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. Output • —After data items have been processed, the resulting infor- mation usually is sent to a printer, monitor, or some other output device so people can view, interpret, and use the results. Some people consider storage as a fourth major computer operation. Instead of sending output to a device such as a printer, monitor, or speaker where a person can interpret it, you sometimes store output on storage devices, such as a disk or flash media. 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 also write programs in different languages. Some programmers work exclusively in one language, whereas others know several program- ming languages and use the one that is best suited to the task at hand. Every programming language has rules governing its word usage and punctuation. These rules are called the language’s syntax. 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. When you write a program, you usually type its instructions using a keyboard. When you type program instructions, they are stored in computer memory, which is a computer’s temporary, internal The instruc- tions you write using a pro- gramming language are called program code; when you write instruc- tions, you are coding the program. 3 Understanding Computer Systems
  • 34. storage. Internal storage is volatile—its contents are lost when the computer is turned off or loses power. Usually, you want to be able to retrieve and perhaps modify the stored instructions later, so you also store them on a permanent storage device, such as a disk. Permanent storage devices are nonvolatile—that is, their contents are persistent and are retained even when power is lost. After a computer program is stored in memory, it must be trans- lated from your programming language statements to machine language that represents the millions of on/off circuits within the computer. Each programming language uses a piece of software, called a compiler or an interpreter, to translate your program code into machine language. Machine language is also called binary language, and is represented as a series of 0s and 1s. The compiler or interpreter that translates your code tells you if any programming language component has been used incorrectly. Syntax errors are relatively easy to locate and correct because the compiler or interpreter you use highlights every syntax error. If you write a computer program using a language such as C++ but spell one of its words incorrectly or reverse the proper order of two words, the software lets you know that it found a mistake by displaying an error message as soon as you try to translate the program. Although there are differences in how compilers and interpreters work, their basic function is the same—to translate your programming statements into code the computer can use. When you use a compiler, an entire program is translated before it can execute; when you use an interpreter, each instruc- tion is translated just prior to execution. Usually, you do not choose which type of translation to use—it depends on the programming language. However, there are some languages for which both compilers and interpreters are available. Only after program instructions are successfully translated to machine code can the computer carry out the program instructions. When instructions are carried out, a program runs, or executes. In a typical program, some input will be accepted, some processing will occur, and results will be output. Besides the popular full-blown programming languages such as Java and C++, many programmers use scripting languages (also called scripting programming languages or script languages) such as Python, Lua, Perl, and PHP. Scripts written in these languages usually can be typed directly from a keyboard and are stored as text rather than as binary execut- able files. Scripting language programs are interpreted line by line each time the program executes, instead of being stored in a compiled (binary) form. Random access memory, or RAM, is a form of inter- nal, volatile memory. It is hardware on which the programs that are cur- rently running and the data items that are currently being used are stored for quick access. The program statements you write in a programming language are known as source code. The translated machine language statements are known as object code. 4 C H A P T E R 1 An Overview of Computers and Programming
  • 35. TWO TRUTHS & A LIE Understanding Computer Systems In each Two Truths and a Lie section, two of the numbered statements are true, and one is false. Identify the false statement and explain why it is false. 1. Hardware is the equipment, or the devices, associated with a computer. Software is computer instructions. 2. The grammar rules of a computer programming language are its syntax. 3. You write programs using machine language, and translation software con- verts the statements to a programming language. The false statement is #3. You write programs using a programming language such as Visual Basic or Java, and a translation program (called a compiler or inter- preter) converts the statements to machine language, which is 0s and 1s. Understanding Simple Program Logic A program with syntax errors cannot execute. A program with no syntax errors can execute, but might contain logical errors, and produce incor- rect output as a result. For a program to work properly, you must give the instructions to the computer in a specific sequence, you must not leave any instructions out, and you must not add extraneous instructions. By doing this, you are developing the logic of the computer program. Suppose you instruct someone to make a cake as follows: Get a bowl Stir Add two eggs Add a gallon of gasoline Bake at 350 degrees for 45 minutes Add three cups of flour Even though you have used the English language syntax correctly, the cake-baking instructions are out of sequence, some instructions are missing, and some instructions belong to procedures other than baking a cake. If you follow these instructions, you are not going to make an edi- ble cake, and you most likely will end up with a disaster. Logical errors are much more difficult to locate than syntax errors—it is easier for you to determine whether “eggs” is spelled incorrectly in a recipe than it is for you to tell if there are too many eggs or if they are added too soon. The dangerous cake-baking instructions are shown with a Don’t Do It icon. You will see this icon when the book contains an unrecommended pro- gramming practice that is used as an example of what not to do. If you misspell a program- ming language word, you commit a syntax error, but if you use an otherwise correct word that does not make sense in the current con- text, programmers say you have committed a semantic error. Either way, the program will not execute. Don’t Do It Don't bake a cake like this! 5 Understanding Simple Program Logic
  • 36. Just as baking directions can be given correctly in Mandarin, Urdu, or Spanish, the same program logic can be expressed in any number of programming languages. Because this book is not concerned with any specific language, the programming examples could have been written in Visual Basic, C++, or Java. For convenience, this book uses instructions written in English! Most simple computer programs include steps that perform input, processing, and output. Suppose you want to write a computer program to double any number you provide. You can write such a program in a programming language such as Visual Basic or Java, but if you were to write it using English-like statements, it would look like this: input myNumber set myAnswer = myNumber * 2 output myAnswer The number-doubling process includes three instructions: The instruction to • input myNumber is an example of an input operation. When the computer interprets this instruction, it knows to look to an input device to obtain a number. When you work in a specific programming language, you write instructions that tell the computer which device to access for input. For exam- ple, when a user enters a number as data for a program, the user might click on the number with a mouse, type it from a keyboard, or speak it into a microphone. Logically, however, it doesn’t really matter which hardware device is used, as long as the computer knows to look for a number. When the number is retrieved from an input device, it is placed in the computer’s memory at the location named myNumber. The location myNumber is a variable. A variable is a named memory location whose value can vary—for example, the value of myNumber might be 3 when the program is used for the first time and 45 when it is used the next time. From a logical perspective, when you input a value, the hardware device is irrelevant. The same is true in your daily life. If you follow the instruction “Get eggs for the cake,” it does not really matter if you purchase them from a store or harvest them from your own chickens—you get the eggs either way. There might be different practical considerations to getting the eggs, just as there are for getting data from a large database as opposed to an inexperienced user. For now, this book is only concerned with the logic of the operation, not the minor details. The instruction • set myAnswer = myNumber * 2 is an example of a processing operation. Mathematical operations are not the only kind of processing operations, but they are very typical. As with input operations, the type of hardware used for processing After you learn French, you automatically know, or can easily figure out, many Spanish words. Similarly, after you learn one programming lan- guage, it is much easier to understand several other languages. You will learn about the odd elimination of the space between words like my and Number in Chapter 2. Programmers use an aster- isk to indicate multiplication. You will learn more about arithmetic statements in Chapter 2. 6 C H A P T E R 1 An Overview of Computers and Programming
  • 37. is irrelevant—after you write a program, it can be used on comput- ers of different brand names, sizes, and speeds. The instruction takes the value stored in memory at the myNumber location, mul- tiplies it by 2, and stores the result in another memory location named myAnswer. In the number-doubling program, the • output myAnswer instruc- tion is an example of an output operation. Within a particular program, this statement could cause the output to appear on the monitor (which might be a flat-panel plasma screen or a cathode- ray tube), or the output could go to a printer (which could be laser or ink-jet), or the output could be written to a disk or DVD. The logic of the output process is the same no matter what hardware device you use. When this instruction executes, the value stored in memory at the location named myAnswer is sent to an output device. Computer memory consists of millions of numbered locations where data can be stored. The memory location of myNumber has a specific numeric address—for example, 48604. Your program associates myNumber with that address. Every time you refer to myNumber within a program, the com- puter retrieves the value at the associated memory location. When you write programs, you seldom need to be concerned with the value of the memory address; instead, you simply use the easy-to-remember name you created. Computer programmers often refer to memory addresses using hexadeci- mal notation, or base 16. Using this system, they might use a value like 42FF01A to refer to a memory address. Despite the use of letters, such an address is still a hexadecimal number. Appendix A contains information on this numbering system. TWO TRUTHS & A LIE Understanding Simple Program Logic 1. A program with syntax errors can execute but might produce incorrect results. 2. Although the syntax of programming languages differs, the same program logic can be expressed in different languages. 3. Most simple computer programs include steps that perform input, process- ing, and output. The false statement is #1. A program with syntax errors cannot execute; a program with no syntax errors can execute, but might produce incorrect results. Watch the video A Simple Program. 7 Understanding Simple Program Logic
  • 38. Understanding the Program Development Cycle A programmer’s job involves writing instructions (such as those in the doubling program in the preceding section), but a professional programmer usually does not just sit down at a computer keyboard and start typing. Figure 1-1 illustrates the program development cycle, which can be broken down into at least seven steps: 1. Understand the problem. 2. Plan the logic. 3. Code the program. 4. Use software (a compiler or interpreter) to translate the program into machine language. 5. Test the program. 6. Put the program into production. 7. Maintain the program. Understand the problem Test the program Put the program into production Maintain the program Plan the logic Translate the code Write the code Figure 1-1 The program development cycle Understanding the Problem Professional computer programmers write programs to satisfy the needs of others, called users or end users. Examples could include a Human Resources department that needs a printed list of all employ- ees, a Billing department that wants a list of clients who are 30 or more days overdue on their payments, and an Order department that 8 C H A P T E R 1 An Overview of Computers and Programming
  • 39. needs a Web site to provide buyers with an online shopping cart in which to gather their orders. Because programmers are providing a service to these users, programmers must first understand what the users want. Although when a program runs, you usually think of the logic as a cycle of input-processing-output operations; when you plan a program, you think of the output first. After you understand what the desired result is, you can plan what to input and process to achieve it. Suppose the director of Human Resources says to a programmer, “Our department needs a list of all employees who have been here over five years, because we want to invite them to a special thank-you dinner.” On the surface, this seems like a simple request. An experi- enced programmer, however, will know that the request is incom- plete. For example, you might not know the answers to the following questions about which employees to include: Does the director want a list of full-time employees only, or a list • of full- and part-time employees together? Does she want people who have worked for the company on a • month-to-month contractual basis over the past five years, or only regular, permanent employees? Do the listed employees need to have worked for the organization • for five years as of today, as of the date of the dinner, or as of some other cutoff date? What about an employee who, for example, worked three years, • took a two-year leave of absence, and has been back for three years? The programmer cannot make any of these decisions; the user (in this case, the Human Resources director) must address these questions. More decisions still might be required. For example: What data should be included for each listed employee? Should • the list contain both first and last names? Social Security numbers? Phone numbers? Addresses? Should the list be in alphabetical order? Employee ID number • order? Length-of-service order? Some other order? Should the employees be grouped by any criteria, such as depart- • ment number or years of service? Several pieces of documentation are often provided to help the pro- grammer understand the problem. Documentation consists of all the supporting paperwork for a program; it might include items such as original requests for the program from users, sample output, and descriptions of the data items available for input. The term end user distin- guishes those who actually use and ben- efit from a software prod- uct from others in an organization who might purchase, install, or have other contact with the software. 9 Understanding the Program Development Cycle
  • 40. Really understanding the problem may be one of the most difficult aspects of programming. On any job, the description of what the user needs may be vague—worse yet, users may not really know what they want, and users who think they know frequently change their minds after seeing sample output. A good programmer is often part coun- selor, part detective! Planning the Logic The heart of the programming process lies in planning the program’s logic. During this phase of the process, the programmer plans the steps of the program, deciding what steps to include and how to order them. You can plan the solution to a problem in many ways. The two most common planning tools are flowcharts and pseudocode. Both tools involve writing the steps of the program in English, much as you would plan a trip on paper before getting into the car or plan a party theme before shopping for food and favors. The programmer shouldn’t worry about the syntax of any particu- lar language at this point, but should focus on figuring out what sequence of events will lead from the available input to the desired output. Planning the logic includes thinking carefully about all the possible data values a program might encounter and how you want the program to handle each scenario. The process of walking through a program’s logic on paper before you actually write the program is called desk-checking. You will learn more about planning the logic throughout this book; in fact, the book focuses on this crucial step almost exclusively. Coding the Program After the logic is developed, only then can the programmer write the program. Hundreds of programming languages are available. Programmers choose particular languages because some have built-in capabilities that make them more efficient than others at handling certain types of operations. Despite their differences, programming languages are quite alike in their basic capabilities—each can handle input operations, arithmetic processing, output operations, and other standard functions. The logic developed to solve a programming problem can be executed using any number of languages. Only after choosing a language must the programmer be concerned with proper punctuation and the correct spelling of commands—in other words, using the correct syntax. Some very experienced programmers can successfully combine logic planning and program coding in one step. This may work for Watch the video The Program Development Cycle, Part 1. You may hear programmers refer to planning a program as “developing an algorithm.” An algorithm is the sequence of steps neces- sary to solve any problem. You will learn more about flowcharts and pseudo- code later in this chapter. In addition to flowcharts and pseudocode, programmers use a variety of other tools to help in program development. One such tool is an IPO chart, which delineates input, processing, and output tasks. Some object-oriented program- mers also use TOE charts, which list tasks, objects, and events. 10 C H A P T E R 1 An Overview of Computers and Programming
  • 41. planning and writing a very simple program, just as you can plan and write a postcard to a friend using one step. A good term paper or a Hollywood screenplay, however, needs planning before writing—and so do most programs. Which step is harder: planning the logic or coding the program? Right now, it may seem to you that writing in a programming lan- guage is a very difficult task, considering all the spelling and syntax rules you must learn. However, the planning step is actually more difficult. Which is more difficult: thinking up the twists and turns to the plot of a best-selling mystery novel, or writing a translation of an existing novel from English to Spanish? And who do you think gets paid more, the writer who creates the plot or the translator? (Try asking friends to name any famous translator!) Using Software to Translate the Program into Machine Language Even though there are many programming languages, each computer knows only one language: its machine language, which consists of 1s and 0s. Computers understand machine language because they are made up of thousands of tiny electrical switches, each of which can be set in either the on or off state, which is represented by a 1 or 0, respectively. Languages like Java or Visual Basic are available for programmers because someone has written a translator program (a compiler or interpreter) that changes the programmer’s English-like high-level programming language into the low-level machine language that the computer understands. If you write a programming language statement incorrectly (for example, by misspelling a word, using a word that doesn’t exist in the language, or using “illegal” grammar), the translator program doesn’t know how to proceed and issues an error message identifying a syntax error, which is a misuse of a language’s grammar rules. Although making errors is never desirable, syntax errors are not a major concern to programmers, because the compiler or interpreter catches every syntax error and displays a mes- sage that notifies you of the problem. The computer will not execute a program that contains even one syntax error. Typically, a programmer develops a program’s logic, writes the code, and compiles the program, receiving a list of syntax errors. The pro- grammer then corrects the syntax errors and compiles the program again. Correcting the first set of errors frequently reveals new errors that originally were not apparent to the compiler. For example, if you could use an English compiler and submit the sentence “The dg chase When you learn the syn- tax of a pro- gramming language, the commands you learn will work on any machine on which the language soft- ware has been installed. However, your com- mands are translated to machine language, which differs depending on your computer make and model. Watch the video The Program Development Cycle, Part 2. 11 Understanding the Program Development Cycle
  • 42. the cat,” the compiler at first might point out only one syntax error. The second word, “dg,” is illegal because it is not part of the English language. Only after you corrected the word to “dog” would the com- piler find another syntax error on the third word, “chase,” because it is the wrong verb form for the subject “dog.” This doesn’t mean “chase” is necessarily the wrong word. Maybe “dog” is wrong; perhaps the subject should be “dogs,” in which case “chase” is right. Compilers don’t always know exactly what you mean, nor do they know what the proper correction should be, but they do know when something is wrong with your syntax. When writing a program, a programmer might need to recompile the code several times. An executable program is created only when the code is free of syntax errors. When you run an executable program, it typically also might require input data. Figure 1-2 shows a diagram of this entire process. Write and correct the program code Compile the program Executable program Data that the program uses List of syntax error messages Program output If there are no syntax errors If there are syntax errors Figure 1-2 Creating an executable program Testing the Program A program that is free of syntax errors is not necessarily free of logi- cal errors. A logical error results when you use a syntactically correct statement but use the wrong one for the current context. For exam- ple, the English sentence “The dog chases the cat,” although syntacti- cally perfect, is not logically correct if the dog chases a ball or the cat is the aggressor. After a pro- gram has been trans- lated into machine lan- guage, the machine lan- guage program is saved and can be run any num- ber of times without repeating the translation step. You only need to retranslate your code if you make changes to your source code statements. 12 C H A P T E R 1 An Overview of Computers and Programming
  • 43. Once a program is free of syntax errors, the programmer can test it—that is, execute it with some sample data to see whether the results are logically correct. Recall the number-doubling program: input myNumber set myAnswer = myNumber * 2 output myAnswer If you execute the program, provide the value 2 as input to the pro- gram, and the answer 4 is displayed, you have executed one successful test run of the program. However, if the answer 40 is displayed, maybe the program contains a logical error. Maybe the second line of code was mistyped with an extra zero, so that the program reads: input myNumber set myAnswer = myNumber * 20 output myAnswer Placing 20 instead of 2 in the multiplication statement caused a logical error. Notice that nothing is syntactically wrong with this second program—it is just as reasonable to multiply a number by 20 as by 2—but if the programmer intends only to double myNumber, then a logical error has occurred. Programs should be tested with many sets of data. For example, if you write the program to double a number, then enter 2 and get an output value of 4, that doesn’t necessarily mean you have a correct program. Perhaps you have typed this program by mistake: input myNumber set myAnswer = myNumber + 2 output myAnswer An input of 2 results in an answer of 4, but that doesn’t mean your program doubles numbers—it actually only adds 2 to them. If you test your program with additional data and get the wrong answer—for example, if you enter 7 and get an answer of 9—you know there is a problem with your code. Selecting test data is somewhat of an art in itself, and it should be done carefully. If the Human Resources department wants a list of the names of five-year employees, it would be a mistake to test the program with a small sample file of only long-term employees. If no newer employees are part of the data being used for testing, you do not really know if the program would have eliminated them The process of finding and correcting program errors is called debugging. Don’t Do It The programmer typed "20" instead of "2". Don’t Do It The programmer typed "+" instead of " *". 13 Understanding the Program Development Cycle
  • 44. from the five-year list. Many companies do not know that their software has a problem until an unusual circumstance occurs—for example, the first time an employee has more than nine depen- dents, the first time a customer orders more than 999 items at a time, or when (as well-documented in the popular press) a new century begins. Putting the Program into Production Once the program is tested adequately, it is ready for the organi- zation to use. Putting the program into production might mean simply running the program once, if it was written to satisfy a user’s request for a special list. However, the process might take months if the program will be run on a regular basis, or if it is one of a large system of programs being developed. Perhaps data-entry people must be trained to prepare the input for the new program; users must be trained to understand the output; or existing data in the company must be changed to an entirely new format to accommodate this program. Conversion, the entire set of actions an organization must take to switch over to using a new pro- gram or set of programs, can sometimes take months or years to accomplish. Maintaining the Program After programs are put into production, making necessary changes is called maintenance. Maintenance can be required for many reasons: new tax rates are legislated, the format of an input file is altered, or the end user requires additional information not included in the original output specifications, to name a few. Frequently, your first programming job will require maintaining previously written programs. When you maintain the programs others have written, you will appreciate the effort the original pro- grammer put into writing clear code, using reasonable variable names, and documenting his or her work. When you make changes to existing programs, you repeat the development cycle. That is, you must understand the changes, then plan, code, translate, and test them before putting them into production. If a substantial number of program changes are required, the original program might be retired, and the program development cycle might be started for a new program. Chapter 4 contains more information on testing programs. Watch the video The Program Development Cycle, Part 3. 14 C H A P T E R 1 An Overview of Computers and Programming
  • 45. TWO TRUTHS & A LIE Understanding the Program Development Cycle 1. Understanding the problem that must be solved can be one of the most dif- ficult aspects of programming. 2. The two most commonly used logic-planning tools are flowcharts and pseudocode. 3. Flowcharting a program is a very different process if you use an older programming language instead of a newer one. The false statement is #3. Despite their differences, programming languages are quite alike in their basic capabilities—each can handle input operations, arithmetic processing, output operations, and other standard functions. The logic developed to solve a programming problem can be executed using any number of languages. Using Pseudocode Statements and Flowchart Symbols When programmers plan the logic for a solution to a programming problem, they often use one of two tools: pseudocode (pronounced “sue-doe-code”) or flowcharts. Pseudocode is an English-like repre- sentation of the logical steps it takes to solve a problem. A flowchart is a pictorial representation of the same thing. Pseudo is a prefix that means “false,” and to code a program means to put it in a programming language; therefore, pseudocode simply means “false code,” or sentences that appear to have been written in a computer programming language but do not necessarily follow all the syntax rules of any specific language. Writing Pseudocode You have already seen examples of statements that represent pseudo- code earlier in this chapter, and there is nothing mysterious about them. The following five statements constitute a pseudocode repre- sentation of a number-doubling problem: start input myNumber set myAnswer = myNumber * 2 output myAnswer stop 15 Using Pseudocode Statements and Flowchart Symbols
  • 46. Using pseudocode involves writing down all the steps you will use in a program. Usually, programmers preface their pseudocode with a beginning statement like start and end it with a terminating state- ment like stop. The statements between start and stop look like English and are indented slightly so that start and stop stand out. Most programmers do not bother with punctuation such as periods at the end of pseudocode statements, although it would not be wrong to use them if you prefer that style. Similarly, there is no need to capi- talize the first word in a sentence, although you might choose to do so. This book follows the conventions of using lowercase letters for verbs that begin pseudocode statements and omitting periods at the end of statements. Pseudocode is fairly flexible because it is a planning tool, and not the final product. Therefore, for example, you might prefer any of the following: Instead of • start and stop, some pseudocode developers would use the terms begin and end. Instead of writing • input myNumber, some developers would write get myNumber or read myNumber. Instead of writing • set myAnswer = myNumber * 2, some develop- ers would write calculate myAnswer = myNumber times 2 or compute myAnswer as myNumber doubled. Instead of writing • output myAnswer, many pseudocode devel- opers would write display myAnswer, print myAnswer, or write myAnswer. The point is, the pseudocode statements are instructions to retrieve an original number from an input device and store it in memory where it can be used in a calculation, and then to get the calculated answer from memory and send it to an output device so a person can see it. When you eventually convert your pseudocode to a specific programming language, you do not have such flexibility because spe- cific syntax will be required. For example, if you use the C# program- ming language and write the statement to output the answer, you will code the following: Console.Write (myAnswer); The exact use of words, capitalization, and punctuation are important in the C# statement, but not in the pseudocode statement. 16 C H A P T E R 1 An Overview of Computers and Programming
  • 47. Drawing Flowcharts Some professional programmers prefer writing pseudocode to drawing flowcharts, because using pseudocode is more similar to writing the final statements in the programming language. Others prefer drawing flowcharts to represent the logical flow, because flow- charts allow programmers to visualize more easily how the program statements will connect. Especially for beginning programmers, flow- charts are an excellent tool to help them visualize how the statements in a program are interrelated. When you create a flowchart, you draw geometric shapes that contain the individual statements and that are connected with arrows. You use a parallelogram to represent an input symbol, which indicates an input operation. You write an input statement in English inside the parallelogram, as shown in Figure 1-3. Arithmetic operation statements are examples of processing. In a flowchart, you use a rectangle as the processing symbol that contains a processing statement, as shown in Figure 1-4. To represent an output state- ment, you use the same symbol as for input statements—the output symbol is a parallelogram, as shown in Figure 1-5. Some software programs that use flowcharts (such as Visual Logic) use a left-slanting parallelogram to represent output. As long as the flowchart creator and the flowchart reader are communicating, the actual shape used is irrelevant. This book will follow the most standard convention of always using the right-slanting parallelogram for both input and output. To show the correct sequence of these statements, you use arrows, or flowlines, to connect the steps. Whenever possible, most of a flow- chart should read from top to bottom or from left to right on a page. That’s the way we read English, so when flowcharts follow this con- vention, they are easier for us to understand. You can draw a flowchart by hand or use software, such as Microsoft Word and Microsoft PowerPoint, that contains flowcharting tools. You can use sev- eral other software pro- grams, such as Visio and Visual Logic, specifically to create flowcharts. Because the parallelogram is used for both input and output, it is often called the input/output symbol or I/O symbol. Appendix B contains a summary of all the flow- chart symbols you will see in this book. input myNumber Figure 1-3 Input symbol set myAnswer = myNumber * 2 Figure 1-4 Processing symbol output myAnswer Figure 1-5 Output symbol 17 Using Pseudocode Statements and Flowchart Symbols
  • 48. To be complete, a flowchart should include two more elements: terminal symbols, or start/stop symbols, at each end. Often, you place a word like start or begin in the first terminal symbol and a word like end or stop in the other. The standard terminal symbol is shaped like a racetrack; many programmers refer to this shape as a lozenge, because it resembles the shape of the medication you might use to soothe a sore throat. Figure 1-6 shows a complete flowchart for the program that doubles a number, and the pseudocode for the same problem. You can see from the figure that the flowchart and pseudocode statements are the same—only the presentation format differs. start Flowchart Pseudocode stop input myNumber output myAnswer set myAnswer = myNumber * 2 start input myNumber set myAnswer = myNumber * 2 output myAnswer stop Figure 1-6 Flowchart and pseudocode of program that doubles a number Repeating Instructions After the flowchart or pseudocode has been developed, the programmer only needs to: (1) buy a computer, (2) buy a language compiler, (3) learn a programming language, (4) code the pro- gram, (5) attempt to compile it, (6) fix the syntax errors, (7) com- pile it again, (8) test it with several sets of data, and (9) put it into production. “Whoa!” you are probably saying to yourself. “This is simply not worth it! All that work to create a flowchart or pseudocode, and then all those other steps? For five dollars, I can buy a pocket calculator that will Programmers seldom create both pseudo- code and a flowchart for the same problem. You usually use one or the other. In a large program, you might even prefer to use pseudocode for some parts and draw a flowchart for others. 18 C H A P T E R 1 An Overview of Computers and Programming
  • 49. double any number for me instantly!” You are absolutely right. If this were a real computer program, and all it did was double the value of a number, it would not be worth the effort. Writing a computer program would be worthwhile only if you had many—let’s say 10,000—numbers to double in a limited amount of time—let’s say the next two minutes. Unfortunately, the number-doubling program represented in Figure 1-6 does not double 10,000 numbers; it doubles only one. You could execute the program 10,000 times, of course, but that would require you to sit at the computer and tell it to run the program over and over again. You would be better off with a program that could process 10,000 numbers, one after the other. One solution is to write the program shown in Figure 1-7 and execute the same steps 10,000 times. Of course, writing this program would be very time consuming; you might as well buy the calculator. Figure 1-7 Inefficient pseudocode for program that doubles 10,000 numbers start input myNumber set myAnswer = myNumber * 2 output myAnswer input myNumber set myAnswer = myNumber * 2 output myAnswer input myNumber set myAnswer = myNumber * 2 output myAnswer …and so on for 9,997 more times A better solution is to have the computer execute the same set of three instructions over and over again, as shown in Figure 1-8. The repetition of a series of steps is called a loop. With this approach, the computer gets a number, doubles it, displays the answer, and then starts over again with the first instruction. The same spot in memory, called myNumber, is reused for the second number and for any subse- quent numbers. The spot in memory named myAnswer is reused each time to store the result of the multiplication operation. The logic illus- trated in the flowchart in Figure 1-8 contains a major problem—the sequence of instructions never ends. This programming situation is known as an infinite loop—a repeating flow of logic with no end. You will learn one way to handle this problem later in this chapter; you will learn a superior way in Chapter 3. When you tell a friend how to get to your house, you might write a series of instructions or you might draw a map. Pseudocode is similar to written, step-by-step instructions; a flowchart, like a map, is a visual representation of the same thing. Don’t Do It You would never want to write such a repetitious list of instructions. 19 Using Pseudocode Statements and Flowchart Symbols
  • 50. start input myNumber output myAnswer set myAnswer = myNumber * 2 Don’t Do It This logic saves steps, but it has a fatal flaw – it never ends. Figure 1-8 Flowchart of infinite number-doubling program TWO TRUTHS & A LIE Using Pseudocode Statements and Flowchart Symbols 1. When you draw a flowchart, you use a parallelogram to represent an input operation. 2. When you draw a flowchart, you use a parallelogram to represent a process- ing operation. 3. When you draw a flowchart, you use a parallelogram to represent an output operation. The false statement is #2. When you draw a fl owchart, you use a rectangle to represent a processing operation. Using a Sentinel Value to End a Program The logic in the flowchart for doubling numbers, shown in Figure 1-8, has a major flaw—the program contains an infinite loop. If, for exam- ple, the input numbers are being entered at the keyboard, the program will keep accepting numbers and outputting doubles forever. Of course, the user could refuse to type any more numbers. But the computer is very patient, and if you refuse to give it any more numbers, it will sit and wait forever. When you finally type a number, the program will double it, output the result, and wait for another. The program cannot 20 C H A P T E R 1 An Overview of Computers and Programming
  • 51. progress any further while it is waiting for input; meanwhile, the pro- gram is occupying computer memory and tying up operating system resources. Refusing to enter any more numbers is not a practical solu- tion. Another way to end the program is simply to turn off the com- puter. But again, that’s neither the best way nor an elegant solution. A superior way to end the program is to set a predetermined value for myNumber that means “Stop the program!” For example, the program- mer and the user could agree that the user will never need to know the double of 0, so the user could enter a 0 to stop. The program could then test any incoming value contained in myNumber and, if it is a 0, stop the program. Testing a value is also called making a decision. You represent a decision in a flowchart by drawing a decision symbol, which is shaped like a diamond. The diamond usually contains a question, the answer to which is one of two mutually exclusive options—often yes or no. All good computer questions have only two mutually exclusive answers, such as yes and no or true and false. For example, “What day of the year is your birthday?” is not a good computer question because there are 366 possible answers. However, “Is your birthday June 24?” is a good computer question because, for everyone in the world, the answer is either yes or no. The question to stop the doubling program should be “Is the value of myNumber just entered equal to 0?” or “myNumber = 0?” for short. The complete flowchart will now look like the one shown in Figure 1-9. stop myNumber = 0? Yes No start input myNumber output myAnswer set myAnswer = myNumber times 2 Don’t Do It This logic is not structured; you will learn about structure in Chapter 3. Figure 1-9 Flowchart of number-doubling program with sentinel value of 0 A yes-or-no decision is called a binary deci- sion, because there are two possible outcomes. 21 Using a Sentinel Value to End a Program
  • 52. One drawback to using 0 to stop a program, of course, is that it won’t work if the user does need to find the double of 0. In that case, some other data-entry value that the user will never need, such as 999 or –1, could be selected to signal that the program should end. A preselected value that stops the execution of a program is often called a dummy value because it does not represent real data, but just a signal to stop. Sometimes, such a value is called a sentinel value because it repre- sents an entry or exit point, like a sentinel who guards a fortress. Not all programs rely on user data entry from a keyboard; many read data from an input device, such as a disk. When organizations store data on a disk or other storage device, they do not commonly use a dummy value to signal the end of the file. For one thing, an input record might have hundreds of fields, and if you store a dummy record in every file, you are wasting a large quantity of storage on “nondata.” Additionally, it is often difficult to choose sentinel values for fields in a company’s data files. Any balanceDue, even a zero or a negative number, can be a legitimate value, and any customerName, even “ZZ”, could be someone’s name. Fortunately, programming languages can recognize the end of data in a file automatically, through a code that is stored at the end of the data. Many programming languages use the term eof (for “end of file”) to refer to this marker that automatically acts as a sentinel. This book, therefore, uses eof to indicate the end of data whenever using a dummy value is impractical or inconvenient. In the flowchart shown in Figure 1-10, the eof question is shaded. stop eof? Yes No start input myNumber output myAnswer set myAnswer = myNumber times 2 Don’t Do It This logic is not structured; you will learn about structure in Chapter 3. Figure 1-10 Flowchart using eof 22 C H A P T E R 1 An Overview of Computers and Programming
  • 53. TWO TRUTHS & A LIE Using a Sentinel Value to End a Program 1. A program that contains an infinite loop is one that never ends. 2. A preselected value that stops the execution of a program is often called a dummy value or a sentinel value. 3. Many programming languages use the term fe (for “file end”) to refer to a marker that automatically acts as a sentinel. The false statement is #3. The term eof (for “end of fi le”) is the common term for a fi le sentinel. Understanding Programming and User Environments Many approaches can be used to write and execute a computer pro- gram. When you plan a program’s logic, you can use a flowchart or pseudocode, or a combination of the two. When you code the pro- gram, you can type statements into a variety of text editors. When your program executes, it might accept input from a keyboard, mouse, microphone, or any other input device, and when you provide a program’s output, you might use text, images, or sound. This section describes the most common environments you will encounter as a new programmer. Understanding Programming Environments When you plan the logic for a computer program, you can use paper and pencil to create a flowchart, or you might use software that allows you to manipulate flowchart shapes. If you choose to write pseudocode, you can do so by hand or by using a word-processing program. To enter the program into a computer so you can trans- late and execute it, you usually use a keyboard to type program statements into an editor. You can type a program into one of the following: A plain text editor • A text editor that is part of an integrated development • environment 23 Understanding Programming and User Environments
  • 54. A text editor is a program that you use to create simple text files. It is similar to a word processor, but without as many features. You can use a text editor such as Notepad that is included with Microsoft Windows. Figure 1-11 shows a C# program in Notepad that accepts a number and doubles it. An advantage to using a simple text editor to type and save a program is that the completed program does not require much disk space for storage. For example, the file shown in Figure 1-11 occupies only 314 bytes of storage. This line contains a prompt that tells the user what to enter. You will learn more about prompts in Chapter 2. Figure 1-11 A C# number-doubling program in Notepad You can use the editor of an integrated development environment (IDE) to enter your program. An IDE is a software package that pro- vides an editor, compiler, and other programming tools. For example, Figure 1-12 shows a C# program in the Microsoft Visual Studio IDE, an environment that contains tools useful for creating programs in Visual Basic, C++, and C#. Figure 1-12 A C# number-doubling program in Visual Studio 24 C H A P T E R 1 An Overview of Computers and Programming
  • 55. Other documents randomly have different content
  • 56. devant d'eux en bon ordre et bannières déployées. On se trouvait dans de vastes bruyères coupées de fossés. Les hommes d'armes bourguignons y cherchèrent longtemps la route qu'ils devaient suivre. Au centre, les fossés étaient absolument inabordables: à gauche, on ne pouvait les franchir qu'à pied; mais vers la droite, Jacques de Lalaing, le sire d'Aumont, et les deux sires de Vaudrey parvinrent à faire passer leurs chevaux et les lancèrent au milieu des Gantois, tandis que les hommes d'armes du sire de Croy, qui revenaient du sac d'Overmeire, les attaquaient par derrière. Les difficultés du terrain facilitèrent la retraite des Gantois. S'ils laissaient quatre ou cinq cents de leurs compagnons sur le champ du combat, leur mort intrépide égala du moins leur résistance à une victoire, car l'armée du duc, affaiblie par ses pertes, effrayée des tintements du tocsin qui résonnaient au loin, s'arrêta et retourna à Termonde livrer au bourreau quelques prisonniers qu'elle emmenait avec elle (23 mai 1452). Que se passait-il au même moment au sud de Gand? Qu'était devenue l'expédition du comte d'Étampes, entreprise simultanément avec celle du duc de Bourgogne? Avait-elle obtenu, grâce à cette tactique habile, un succès plus décisif? L'ordre du récit nous conduit à de nouveaux combats, et quels qu'en doivent être les résultats, il est trop aisé de prévoir que nous verrons s'y associer d'autres scènes de pillage et de dévastation. Le comte d'Etampes s'était dirigé d'Audenarde vers Harlebeke pour faire lever le siége du château d'Ingelmunster que bloquaient quelques Gantois. Il y réussit aisément, et ce fut en chassant devant lui toutes les troupes gantoises qui étendaient leurs excursions jusqu'à Courtray, qu'il poursuivit sa marche vers Nevele. Nevele était un gros bourg entouré de fossés. Les Gantois, commandés par Jean de Vos y avaient élevé un fort retranchement, et, comme si ces précautions ne leur eussent pas suffi, ils avaient fait couper toutes les routes environnantes et avaient placé dans les blés des pieux destinés à arrêter les chevaux. Le comte d'Etampes s'inquiéta peu de ces préparatifs. Son armée était fort nombreuse,
  • 57. puisque les chroniques flamandes l'évaluent à huit mille chevaux; il avait d'ailleurs avec lui la plupart de ses intrépides chevaliers qui avaient délivré Audenarde. Le bâtard Antoine de Bourgogne commandait l'avant-garde; le sire de Saveuse éclairait la marche de l'armée. Elle se porta immédiatement en avant pour assaillir les Gantois, qui s'attendaient peu à cette attaque, et les hommes d'armes bourguignons, protégés par les traits des archers, s'emparèrent facilement des retranchements qu'ils rencontrèrent. A peine les Gantois eurent-ils le temps de se replier au delà de Nevele, se défendant toutefois si courageusement que la chevalerie bourguignonne ne put les entamer. Nous retrouvons à la prise de Nevele toutes les circonstances de la prise de Lokeren. Le comte d'Etampes, qui était resté hors du bourg de Nevele, avait donné l'ordre de poursuivre les Gantois. Les plus braves chevaliers de l'armée et la plupart des hommes d'armes s'empressèrent d'obéir et s'éloignèrent pour les atteindre. Ceux qui ne les avaient pas suivis ne songeaient qu'à piller, lorsque des renforts importants arrivèrent de Gand sous les ordres de Pierre Van den Nieuwenhuus: au même moment, quatre ou cinq cents paysans, avertis de ce qui se passait, se réunirent au son du tocsin et marchèrent vers Nevele en poussant de grands cris. Le sire de Hérimès, qui occupait le bourg, les entendit, et rassemblant quelques archers, il se fit ouvrir les barrières et s'avança imprudemment pour combattre. Les Gantois, un instant ébranlés par le choc des Picards, les forcèrent bientôt à reculer jusqu'au pont, et là toute résistance cessa. Le sire de Hérimès, que l'on citait comme l'un des plus vaillants chevaliers de l'armée du duc, tomba sous leurs coups; avec lui périrent des chevaliers de la Bourgogne, du Dauphiné, de la Picardie, qui étaient venus chercher la mort sous la massue ou sous les pieux ferrés de quelques obscurs laboureurs. Les Gantois pénétraient déjà dans Nevele et frappaient tous les hommes d'armes qui s'offraient à leurs regards. Le comte d'Etampes pâlit en apprenant ce désastre. Il fit appeler Simon de Lalaing, à qui il avait confié sa bannière, et lui demanda conseil. «Monseigneur, lui répondit le sire de Lalaing, il convient sans plus tarder que tantôt et
  • 58. incontinent cette ville soit reconquise sur ces vilains; car si on attend à les assaillir, je fais doute que tantôt qu'il sera sçu par le pays, les paysans s'élèveront de tous côtés et viendront secourir leurs gens.» Le comte d'Etampes approuva cet avis et ordonna que chacun mît pied à terre pour attaquer les Gantois. Le combat s'engagea avec une nouvelle fureur: le désir de réparer une défaite encourageait les uns; celui de conserver leur avantage soutenait les autres. Par un hasard favorable aux Bourguignons, le bâtard de Bourgogne et ses compagnons, renonçant à une poursuite infructueuse, revenaient déjà vers Nevele. Ils tardèrent peu à reconnaître, au bruit de l'assaut, que les Gantois avaient reconquis le bourg, et joignirent leurs efforts à ceux que le comte d'Etampes faisait du côté opposé. Enfin l'enceinte de Nevele fut forcée. Les Gantois que les vainqueurs purent saisir furent impitoyablement mis à mort. Quelques-uns s'étaient réfugiés dans une petite île: on les entoura, et pas un seul n'échappa à la vengeance des hommes d'armes bourguignons. C'était aussi à Nevele que, soixante et onze années auparavant, Rasse d'Herzeele avait péri avec un grand nombre des siens en combattant Louis de Male. Cependant, dès que l'avant-garde eut rejoint le corps d'armée, le comte d'Etampes fit mettre le feu au bourg de Nevele et ordonna la retraite. Il en était temps. Le tocsin des villages voisins n'avait pas cessé de retentir, et de toutes parts les laboureurs s'assemblaient, les uns pour combattre, les autres pour fermer par des abatis d'arbres la route qu'avait suivie l'armée du comte d'Etampes. Le péril était plus grand que jamais, et sans la prudence des chefs de cette expédition, elle eût enveloppé dans un désastre commun tous ceux qui y avaient pris part. De nouveaux obstacles arrêtaient à chaque pas la marche et accroissaient le désordre, lorsque le capitaine du château de Poucke assaillit impétueusement l'arrière-garde avec sept ou huit cents combattants. L'alarme gagna le corps principal: le désordre d'une retraite précipitée succéda aux chances égales d'une bataille. Ce fut à grand'peine que les chevaliers rallièrent leurs hommes d'armes autour de l'étendard du comte d'Etampes. A chaque pas, la mort éclaircissait leurs rangs, et cette brillante armée,
  • 59. épuisée de fatigues et de privations, ne parvint à atteindre Harlebeke que vers le milieu de la nuit (24 mai 1452). La guerre était devenue si acharnée et si cruelle que, dans l'armée des Gantois aussi bien que dans celle du duc, les prisonniers offraient en vain les plus fortes rançons: ils n'évitaient la mort sur les champs de bataille que pour périr le lendemain noyés, pendus ou décapités. La fureur des combattants ne respectait pas davantage les priviléges du rang le plus élevé ou des noms les plus illustres, et plusieurs chevaliers bourguignons jugèrent prudent de chercher à éloigner le comte de Charolais «d'icelle mortelle guerre, pour doubte de male fortune et que dolereuse aventure n'avenist au père et au fils ensamble, qui eust esté la totale destruction de tous les pays du duc de Bourgogne.» Le duc Philippe partagea leur avis et chargea le sire de Ternant de conduire son fils à Bruxelles, près de sa mère; mais la duchesse de Bourgogne, instruite des motifs de ce voyage, ne témoigna aucune joie de voir l'unique héritier de Philippe le Hardi s'abriter dans le sein maternel comme dans un pacifique asile. Elle garda le silence et se contenta d'inviter à un banquet «les chevaliers, escuyers, dames et damoiselles.» Déjà la fête s'achevait, lorsque la fière princesse portugaise, élevant la voix, s'adressa en ces mots au comte de Charolais: «O mon fils, pour l'amour de vous, j'ay assemblé ceste belle compaignie pour vous festoyer, car vous estes la créature du monde, après monseigneur vostre père, que je ayme le mieulx.... Or doncques, puisque monseigneur vostre père est en la guerre à l'encontre de ses rebelles et désobéissans subjetz, pour son honneur, haulteur et seigneurie garder, je vous prye que demain au matin vous retournez devers lui, et gardez bien que en quelconque lieu qu'il soit, pour doubte de mort ne autre chose en ce monde qui vous puist advenir, vous n'eslongiez sa personne et soyés toujours au plus près de luy.» Le comte de Charolais revint à Termonde; mais le duc de Bourgogne, en le revoyant dans son camp, se sentit plus disposé aux négociations, et peu de jours après le retour du comte de Charolais, les marchands d'Espagne, d'Aragon, de Portugal, d'Ecosse, de Venise, de Florence, de Milan, de Gênes et de Lucques,
  • 60. résidant à Bruges, se rendirent à Gand pour s'efforcer de rétablir la paix. La cité de Gand restait puissante et redoutée. De quelque côté que se portassent ses regards, l'horizon moins sombre semblait s'éclairer de quelques rayons. Le roi de France se montrait disposé à abjurer le système hostile de Philippe le Bel et de Philippe de Valois, tandis qu'à Londres rien n'avait affaibli les sympathies séculaires qui unissaient la patrie de Jacques d'Artevelde au royaume d'Edouard III. Le 24 mai 1452, les capitaines, les échevins et les doyens des métiers adressaient à Charles VII une longue lettre pour lui faire connaître leurs griefs et leurs plaintes. Ils y exposaient que le duc de Bourgogne avait mandé des hommes d'armes pour les combattre et qu'il s'efforçait de les livrer à la famine, protestant toutefois que bien que la guerre fût «moult dure, griefve et déplaisante,» ils étaient résolus à maintenir leurs droits, leurs priviléges, franchises, coutumes et usages, dont le roi, comme leur souverain seigneur, était «le gardien et conservateur.» Deux jours après, des ambassadeurs anglais arrivaient à Gand, chargés par Henri VI d'offrir un secours de sept mille hommes. Enfin, peu d'heures avant que les représentants des marchands étrangers, des nations, comme on avait coutume de les nommer, eussent salué les bords de l'Escaut, six mille Gantois, sous les ordres de Jean de Vos, quittaient Gand par la route de Nevele pour se diriger vers Bruges. Ils avaient pour mission de rappeler à leurs anciens alliés leur serment de sacrifier d'étroites rivalités aux intérêts d'une patrie commune, de les soutenir s'ils tentaient quelque mouvement favorable, de les menacer peut-être dans le cas où l'influence du duc y étoufferait tous les efforts de leurs amis. En effet, ils apprirent bientôt que Louis de la Gruuthuse et Pierre Bladelin avaient fait fermer les portes, et d'un commun accord ils s'arrêtèrent à Moerbrugge, assez près du Beverhoutsveld. Un de leurs trompettes se présenta à la porte de Sainte-Catherine avec
  • 61. plusieurs lettres adressées aux divers métiers de Bruges: «S'il vous plaît, écrivaient-ils aux Brugeois, nous faire assistence pour nous aidier à entretenir nos droits et franchises, lesquels nous en nulle manière ne pensons délaissier ne souffrir estre amendris à l'aide de Dieu et de nos bons amis, nous vous promettons que nous vous ferons samblable assistence à l'entretenement de vos droits et franchises, et que nous, pour plus grand sureté de ces choses, jamais ne ferons paix sans vous; car vous et nous ne porions mieulx entretenir iceulx nos droits et franchises, se non par bonne union.» Ces lettres ne furent point remises. Louis de la Gruuthuse et Pierre Bladelin, étant sortis par un guichet pour parlementer, réussirent à persuader aux Gantois que les magistrats de Bruges étaient disposés à appuyer leurs réclamations, et que le but de leur voyage était atteint par la démarche des nations. Les Gantois se retirèrent vers Oedelem et Knesselaere; ils acceptaient comme un succès complet ces vagues et douteuses espérances. Les marchands des nations avaient déjà été admis à Gand dans la collace. Dans un discours rédigé avec habileté, ils représentèrent vivement les désastres qui menaçaient une contrée célèbre entre toutes celles du monde par les richesses qu'elles devaient à son commerce. Ils ajoutaient que les Gantois agiraient sagement en cessant de rappeler à tout propos leurs franchises et leurs priviléges et qu'il serait agréable au duc de leur voir supprimer leurs «chievetaineries.» Les Gantois eussent craint de paraître, par leur silence, renoncer à leurs priviléges: quant à la mission de leurs capitaines, ils déclaraient qu'elle n'avait d'autre but que de maintenir au milieu des agitations de la guerre la sécurité et l'ordre intérieur, et l'on eût tout au plus consenti à leur donner un autre nom. Cependant la médiation des nations fut acceptée et quatre religieux furent choisis pour seconder leurs efforts: c'étaient l'abbé de Tronchiennes, le prieur des Chartreux, le prieur de Saint-Bavon et un moine de la même abbaye, nommé Baudouin de Fosseux, dont la sœur avait épousé Jean de Montmorency, grand chambellan de France. Ils trouvèrent le duc à Termonde. Le prieur des Chartreux parla le premier, puis l'un des marchands étrangers lut une cédule où
  • 62. ils exposaient qu'ils se trouveraient, si la guerre ne se calmait point, bientôt réduits à quitter la Flandre, «car, comme chascun peult savoir, les marchands et les marchandises requièrent paix et pays de paix, et nullement ne pevent soustenir la guerre.» Les conseillers du duc délibérèrent et se plaignirent de ce que les Gantois étaient pires que les Juifs, «car se les Juifs eussent véritablement sceu que nostre benoit Sauveur Jésus-Christ eust esté Dieu, ils ne l'eussent point mis à mort: mais les Gantois ne pouvoient et ne pevent ignorer que monseigneur le duc ne fust et soit leur seigneur naturel.» Les Gantois étaient si fiers, le duc si irrité qu'il était bien difficile de concilier des prétentions tout opposées. Les négociations se poursuivaient depuis quelques jours lorsque des nouvelles importantes vinrent modifier profondément la situation des choses. On avait appris en même temps à Gand et à Termonde que Charles VII, cédant aux prières des députés flamands, voulait intervenir comme médiateur dans les querelles du duc et de ses sujets et l'on savait déjà que ses ambassadeurs étaient arrivés le 11 juin à Saint-Amand; c'étaient: Louis de Beaumont, sénéchal de Poitou; Gui Bernard, archidiacre de Tours, et maître Jean Dauvet, procureur général au parlement; mais il leur avait été ordonné de placer à la tête de leur ambassade le comte de Saint-Pol, l'un des plus illustres feudataires du royaume qui, en ce moment même, combattait sous les drapeaux du duc de Bourgogne et semblait, par l'étendue et la situation de ses domaines, investi d'un droit d'arbitrage qui devait un jour lui devenir fatal. Les instructions destinées aux ambassadeurs français leur avaient été remises à Bourges, le 5 juin; elles comprenaient deux points principaux, deux réclamations également importantes pour la puissance de la monarchie. La première s'appuyait bien moins sur l'équité que sur le sentiment national de la France, blessé par le honteux traité d'Arras et prêt à saisir avec empressement la première occasion favorable pour le déchirer. Il s'agissait de la restitution des villes de la Somme, sans rachat, sous le simple prétexte que la cession n'avait eu lieu que pour protéger les pays du duc contre les
  • 63. excursions des Anglais, et qu'elle était devenue sans objet par la conquête de la Normandie et l'existence des trêves. Le sire de Croy avait dit vrai, lors des conférences d'Arras, que le duc de Bourgogne renoncerait volontiers aux avantages qui lui avaient été faits si Charles VII acceptait les conditions mises à la paix par les Anglais, et il suffit de rappeler, pour s'expliquer cette déclaration, que le duc Philippe craignait en traitant séparément d'exciter à la fois les murmures de la Flandre et la colère de l'Angleterre; mais on n'avait rédigé aucun acte de cette promesse, essentiellement vague et sans doute limitée aux négociations de cette époque. Le second point, c'était la médiation du roi dans les affaires de Flandre, l'exercice complet et entier de son droit de souveraineté dans ces provinces qui formaient le plus riche héritage de la maison de Bourgogne, et les envoyés de Charles VII se trouvaient chargés de travailler en son nom au rétablissement de la paix. Pour atteindre ce but, les ambassadeurs français tiendront au duc et aux Gantois un langage tout différent. Ils diront au duc que le roi, arbitre légitime de toutes les dissensions de ce genre, peut, à l'exemple de ses prédécesseurs, les terminer, soit par sa sentence, soit en recourant, contre ceux qui ne s'y soumettraient point, à la force des armes. Ils exposeront, au contraire, aux Gantois que le roi, qui décide seul dans toute l'étendue du royaume de la paix ou de la guerre, est disposé à les préserver de toute oppression comme ses bons et loyaux sujet. Dans le même système, ils devaient ou ajourner les négociations relatives à la Flandre pour assurer le succès de celles qui se rapporteraient à la restitution de villes de la Somme, ou bien, si elle était contestée, présenter à la Flandre l'appui du roi contre le duc de Bourgogne. A Gand on lut publiquement, dans la journée du 14 juin, les lettres qui annonçaient l'intervention du roi de France, et dès le lendemain le capitaine de Saint-Nicolas, Jean de Vos, prit le commandement d'une expédition dirigée contre le Hainaut. Le duc de Bourgogne n'était pas moins impatient de renouveler la guerre. Si les Gantois sentaient leur zèle se ranimer par l'espoir de
  • 64. l'appui de Charles VII, il était important à ses yeux que leur défaite immédiate rendît cet appui inutile ou superflu: le 13 juin il congédia les députés des nations, rejetant avec dédain la trêve de six mois qu'ils avaient demandée et leur proposition de remplacer désormais le nom que portaient les capitaines (hooftmans) par celui de gouverneurs, recteurs, ou deffendeurs. L'armée bourguignonne avait reçu d'importants renforts et était prête à envahir le pays de Waes. Le duc le déclara lui-même aux députés des nations. Quelques heures plus tard il eût pu, pour les en convaincre, leur montrer les flammes qui s'élevaient à l'horizon au-dessus de ces heureuses campagnes enrichies par les bienfaits d'une longue paix. Le sire de Contay et trois cents hommes d'armes avaient passé l'Escaut, près du bourg de Rupelmonde, dont les Bourguignons avaient depuis longtemps incendié les habitations. Ces ruines leur offrirent un abri où ils se fortifièrent avec quelques coulevrines. La nuit s'écoula dans une grande inquiétude: deux mille Gantois occupaient Tamise; ils étaient au nombre de quatre mille à Basele: on craignait qu'ils ne se réunissent à Rupelmonde pour repousser le sire de Contay et ses compagnons. Cependant l'aurore se leva: les Gantois n'avaient fait aucun mouvement, soit qu'ils ignorassent la tentative des Bourguignons, soit qu'ils crussent leur troupe plus nombreuse, et d'autres chevaliers ne tardèrent pas à rejoindre le sire de Contay. Le comte de Saint-Pol et le sire de Chimay traversèrent les premiers le fleuve avec l'avant- garde, composée de mille archers et de trois cents lances: toutes les enseignes furent aussitôt déployées et guidèrent les combattants vers Basele. Les Gantois, surpris et chassés de leurs retranchements par les archers, se réfugiaient précipitamment dans l'église et dans une maison fortifiée qui en était voisine. On les y assiégea. Les archers décochaient leurs traits sur tous ceux qui se montraient aux fenêtres, et la plupart des hommes d'armes, entraînés par leur exemple, abandonnaient leurs rangs et accouraient en désordre pour prendre part à l'assaut, lorsqu'une troupe nombreuse de Gantois qui avait quitté Tamise les attaqua inopinément. Un cri d'effroi avait
  • 65. retenti parmi les hommes d'armes bourguignons et une sanglante mêlée s'engagea aussitôt autour de la bannière du comte de Saint- Pol. Le duc Philippe remarqua, de l'autre rive de l'Escaut, le péril qui menaçait les siens. Il se jeta sans hésiter dans une petite nacelle avec son fils, le duc de Clèves, et Corneille, bâtard de Bourgogne. A mesure que ses hommes d'armes le suivaient sur la rive opposée, il les rangeait lui-même en bon ordre et les envoyait là où le danger était le plus pressant. Grâce aux secours qu'ils reçurent, le comte de Saint-Pol et le sire de Chimay parvinrent à repousser les Gantois, qui perdirent une partie de leurs chariots et de leur artillerie. Ce succès permit à l'armée bourguignonne d'achever son mouvement sans obstacle, et le lendemain vers le soir elle se trouvait tout entière sur la rive gauche du fleuve. Le 16 juin 1452, dès que le jour parut, les hommes d'armes qui combattaient sous la bannière du duc de Bourgogne quittèrent leurs tentes: Philippe avait ordonné qu'à l'exception d'un petit nombre de chevaucheurs chargés de surveiller les mouvements de l'ennemi, ils luttassent tous à pied. En ce moment, en y comprenant les sergents qu'avait amenés le duc de Clèves, ils étaient trente ou quarante mille: redoutable légion d'élite, que des chevaliers accourus de toutes les provinces de France conduisaient à la destruction des milices communales de Flandre. «Fière chose fust, dit Olivier de la Marche, à voir telle assemblée et telle noblesse, dont seulement la fierté de l'ordre, la resplendisseur des pompes et des armures, la contenance des étendards et des enseignes estoient suffisans pour ébahir et troubler le hardement et la folle emprise du plus hardi peuple du monde.» Une vaste plaine s'étend entre Rupelmonde et Basele; c'est là que le duc attendait les Gantois. On apercevait près de lui le jeune comte de Charolais qui, au milieu des hommes d'armes dociles à ses ordres, se préparait à combattre pour la première fois. Déjà il savait se faire craindre et obéir, et montrait bien «que le cœur lui disoit et
  • 66. apprenoit qu'il estoit prince, né et élevé pour autres conduire et gouverner.» Les Gantois qui occupaient le pays de Waes se trouvaient sous les ordres de Gauthier Leenknecht. Intrépide jusqu'à la témérité et déjà fameux par la prise de Grammont, il avait un instant formé le projet de percer les digues et d'engloutir dans les eaux le duc et toute son armée, mais il en avait été empêché par l'arrivée de quelques archers bourguignons; sa confiance dans le succès n'en avait toutefois pas été ébranlée, et il croyait qu'à l'aide des renforts conduits de Gand par le capitaine de Saint-Jean, Jacques Meussone, il pourrait rejeter dans l'Escaut les Bourguignons, dont le nombre lui était inconnu. En effet, dès que le sire de Masmines eut annoncé que l'on signalait au loin la bannière où le lion de Notre-Dame semble, même pendant son sommeil, chercher de sa griffe entr'ouverte la lutte et le combat, le duc avait ordonné à son avant- garde de se retirer; ce mouvement simulé devait tromper les Gantois et les entraîner au milieu de leurs ennemis, tandis que le duc de Clèves, le comte d'Etampes et le bâtard Corneille de Bourgogne veillaient à ce qu'aucune attaque ne fût dirigée soit contre l'arrière- garde, soit contre l'aile gauche qui s'étendait vers le village de Tamise. Le comte de Saint-Pol exécuta habilement les instructions qui lui avaient été données. Les Gantois, se disputant l'honneur de le poursuivre, se livraient à l'enthousiasme de la victoire, quand ils entendirent, comme un arrêt de deuil et de mort, retentir tout à coup autour d'eux cent trompettes ennemies dont les lugubres fanfares s'effacèrent dans la détonation de toute l'artillerie du duc. Aux balles de pierres et de fer qui sillonnaient un nuage de fumée ardente se mêlaient les flèches acérées des archers: c'était le signal que les hommes d'armes bourguignons attendaient pour se porter en avant. Les Gantois, en se voyant enveloppés par toute une armée, avaient reconnu les embûches qui leur étaient préparées: ils ne cherchaient plus qu'à s'inspirer de ces sentiments suprêmes d'abnégation et de
  • 67. courage que le spectacle d'une mort inévitable ne rend que plus vifs chez les âmes héroïques. Jacques de Luxembourg, s'étant élancé le premier dans leurs rangs épais, y eut son cheval abattu sous lui, et peu s'en fallut qu'il ne pérît. Jacques de Lalaing fut atteint à la jambe d'un coup de faux, le sire de Chimay fut blessé au pied. Ce fut en vain que les chevaliers bourguignons cherchèrent à conquérir la grande bannière de Gand: un vieux bourgeois, à qui elle avait été confiée, la défendait si vaillamment que jamais on ne put la lui arracher. Les Gantois, pressés par le choc de la chevalerie ennemie, reculaient en résistant à chaque pas, et leur dernière troupe, près de succomber, ne s'arrêta que pour livrer un dernier combat où le bâtard Corneille de Bourgogne tomba, frappé d'un coup de pique à la gorge. C'était l'objet de l'affection la plus tendre du duc. Il fit aussitôt pendre à un arbre Gauthier Leenknecht qu'on avait relevé parmi les blessés, mais cette vengeance ne pouvait le consoler de la perte de son fils; on disait que la mort de cent mille hommes des communes de Flandre n'y eût point suffi. La duchesse de Bourgogne se chargea elle-même du soin de lui faire célébrer de magnifiques obsèques dans l'église de Sainte-Gudule de Bruxelles, et on l'ensevelit dans le tombeau des descendants légitimes des princes de Brabant et de Bourgogne, avec sa bannière, son étendard et son pennon, ce qui n'appartenait qu'aux chevaliers morts les armes à la main. Le lendemain, on aperçut une flotte nombreuse qui remontait l'Escaut, étalant au soleil, au milieu de ses voiles blanches, mille écus aux éclatantes couleurs; elle portait des hommes d'armes réunis en Hollande par les sires de Borssele, de Brederode et d'autres puissants bannerets. Lorsque le duc Philippe vit, immédiatement après sa victoire, cette nouvelle armée se joindre à une armée déjà si puissante, il s'avança jusqu'à Waesmunster, espérant peut-être y trouver des députés de Gand chargés d'implorer sa clémence; mais les Gantois se consolaient déjà de la défaite de Gauthier Leenknecht par les heureux résultats de l'expédition de Jean de Vos qui avait repris
  • 68. Grammont, dispersé la garnison d'Ath, brûlé Acre et Lessines et semé la terreur jusqu'aux portes de Mons, en recueillant partout sur son passage un immense butin; Jean de Vos, rentré à Gand, fut proclamé upperhooftman ou premier capitaine de la ville. A la même époque se forma, de l'appel d'un homme par connétablie, ce corps si célèbre depuis sous les ordres du bâtard de Blanc-Estrain, des compagnons de la Verte Tente, destinés à opposer aux Picards une guerre non interrompue d'excursions inopinées et d'escarmouches sanglantes: ils avaient juré, comme les vieux Suèves, de ne connaître d'autre abri que le dôme des forêts et la voûte du ciel. Le 13 juin, le duc de Bourgogne, averti du débarquement du sire de Contay sur la rive gauche de l'Escaut, avait fait écrire aux ambassadeurs du roi qu'il lui était impossible de les recevoir à Termonde et qu'il les invitait à se rendre à Bruxelles. Il eût désiré qu'ils négociassent avec ses conseillers loin du théâtre de la guerre, sans la troubler par leur intervention; mais les instructions formelles de Charles VII s'y opposaient. Ils ne devaient traiter qu'avec le duc lui-même, et lorsqu'on eut réussi à les retenir trois jours à Bruxelles, il fallut bien se résoudre à leur permettre de se diriger vers le camp de Waesmunster. Un héraut français, parti le 15 juin de Tournay, était déjà arrivé à Gand, porteur d'une lettre par laquelle les envoyés de Charles VII annonçaient qu'ils avaient reçu du roi pleine autorité pour faire cesser la guerre et juger tous les démêlés qui en avaient été la cause. Un grand enthousiasme accueillit à Gand cette déclaration, et les magistrats répondirent immédiatement aux ambassadeurs français «qu'ils ne desiroient que l'amiableté du roy et estre de lui préservez et entretenuz en justice, laquelle leur avoit longhement esté empeschiée.» Il est aisé de comprendre qu'au camp de Waesmunster la médiation de Charles VII était jugée avec un sentiment tout opposé. Bien que le sénéchal de Poitou et ses collègues exposassent leur mission «au
  • 69. mieulx et le plus doucement qu'ils pussent,» le duc leur répondit vivement, «sans délibération de conseil,» que les Gantois «estoient les chefs de toute rébellion, qu'ils lui avoient fait les plus grands outrages du monde et qu'il estoit besoing d'en faire telle punition que ce fust exemple à jamais.» Enfin, il ajouta que si le roi connaissait la véritable situation des choses, «il seroit bien content de lui laisser faire sans lui parler de paix,» et il pria les ambassadeurs «qu'ils s'en voulsissent déporter.» Le lendemain (c'était le 21 juin 1452), le duc paraissait plus calme: il avait laissé à son chancelier le soin de parler en son nom, et les ambassadeurs firent connaître leur intention d'aller eux-mêmes à Gand «pour le bien de la besongne.» C'était soulever une nouvelle tempête. Le chancelier de Bourgogne, Nicolas Rolin, objecta qu'il ne pouvait y avoir honneur, ni sûreté à s'y rendre. La discussion s'était terminée sans résultats et les envoyés de Charles VII s'étaient retirés à Termonde, quand ils y reçurent une nouvelle lettre des magistrats de Gand qui les pressaient de hâter leur arrivée dans cette ville, «afin qu'on les pust advertir tout au long des affaires et besoingnes, car bon et playn advertissement sont le bien et fondation de la conduicte d'une matière.» Cette lettre légitimait leurs instances. Ils les maintinrent énergiquement dans une conférence avec les conseillers bourguignons, qui se prolongea jusqu'au soir, et bien qu'on leur opposât «plusieurs grands arguments pour cuider rompre leur dite commission et empescher leur alée audit lieu de Gand,» ils fixèrent au lendemain l'accomplissement de leur résolution, après avoir décidé toutefois que le comte de Saint-Pol ne les accompagnerait pas à Gand, puisqu'il se trouvait en ce moment, à raison des fiefs qu'il possédait, tenu de combattre sous les drapeaux du duc de Bourgogne. Les droits de l'autorité royale exigeaient à leur avis qu'ils accueillissent les plaintes de l'opprimé et ils n'y voyaient, disaient-ils, ni déshonneur, ni sujet de crainte: ce qu'ils redoutaient bien davantage, c'était de ne pouvoir se faire écouter ni par un prince obstiné dans ses projets, ni par une population inquiète et accessible à toutes les passions tumultueuses.
  • 70. Les échevins de Gand et un grand nombre de bourgeois s'étaient rendus solennellement à une lieue de la ville au devant des ambassadeurs du roi. La remise des lettres closes sur lesquelles reposait leur mission eut lieu le lendemain, et dans les conférences qui s'ouvrirent aussitôt après, ils obtinrent que l'on enverrait près du duc l'abbé de Tronchiennes, Simon Boorluut et d'autres députés, afin de tenter un dernier effort pour rétablir la paix, ajoutant que si l'on ne pouvait y parvenir par voies amiables, le roi de France était prêt à maintenir le droit des Gantois par autorité de justice. Pour juger ce que présentait de sérieux, le 25 juin, ce projet d'un débat contradictoire entre les envoyés du duc et ceux de la commune insurgée, il faut que nous reportions nos regards sur les événements qui se sont accomplis dans le pays de Waes depuis que les ambassadeurs français ont quitté Termonde. Le 23 juin, Philippe, mécontent et irrité, avait consenti malgré lui à ce que les ambassadeurs français allassent étaler les fleurs de lis royales parsemées sur les cottes d'armes de leurs hérauts au milieu des bannières gantoises. Le même jour, il fit appeler le comte d'Etampes et lui ordonna de s'avancer vers le pays des Quatre- Métiers en mettant tout à feu et à sang. Le comte d'Etampes obéit: la guerre devint de plus en plus cruelle, de plus en plus acharnée; un grand nombre de chaumières avaient été livrées aux flammes et plusieurs retranchements avaient été enlevés d'assaut quand le comte d'Etampes, arrivé près de Kemseke, s'arrêta dans son mouvement. La chaleur était si étouffante, racontent les chroniqueurs bourguignons, qu'il se vit réduit à retourner à Waesmunster: il est bien plus probable qu'il avait appris que six mille Gantois occupaient depuis deux jours le village de Moerbeke et qu'il avait jugé prudent d'ajourner le projet de les y attaquer. En effet, le 24 juin, l'armée du comte d'Etampes, à laquelle le comte de Charolais avait conduit de puissants renforts, reprit la route suivie par l'expédition de la veille; elle se rangea en bon ordre entre Stekene et l'abbaye de Baudeloo, et l'on envoya des chevaucheurs en avant pour examiner la position des Gantois. Elle était très-forte,
  • 71. et malgré l'avis du sire de Créquy, qui voulait reconnaître de plus près les ennemis, les chevaliers, auxquels était confié le soin de la personne de l'unique héritier de la maison de Bourgogne, résolurent de rentrer de nouveau à Waesmunster. Lorsque Philippe apprit que son fils était revenu dans son camp, comme le comte d'Etampes, sans que le moindre succès eût couronné ses armes, il résolut, quelque sanglant qu'en dût être le prix, de conquérir sur les Gantois les retranchements de Moerbeke. Les sires de Créquy, de Ternant, d'Humières furent chargés de préparer le plan du combat. Le duc de Bourgogne l'approuva aussitôt et fixa, à tous les hommes d'armes réunis à Waesmunster, l'heure du départ et celle de l'assaut; cependant, lorsque le son des trompettes appela l'armée sous les armes, un mouvement d'hésitation se manifesta; des murmures se firent entendre; ce fut presque une rébellion: les chevaliers eux-mêmes craignaient de s'exposer aux dangers qu'ils prévoyaient. Philippe se vit réduit à céder, mais sa colère éclata en présence des membres de son conseil et on l'entendit donner l'ordre d'enlever l'étendard qui flottait devant son hôtel. Ceci se passait le jour même où la déclaration des magistrats relative aux négociations était publiée à Gand: le lendemain, 26 juin, le duc accordait une trêve de trois jours. Si les chroniqueurs contemporains mentionnent à peine cette suspension d'armes, il ne faut point s'en étonner. Le duc l'employa à de nouveaux armements: à Gand, les discordes intérieures allaient devenir un fléau de plus pour le peuple déjà épuisé par une longue guerre. Henri VI et Charles VII poursuivaient en Guyenne la grande lutte de Jeanne d'Arc contre Talbot: leurs ambassadeurs, portant en Flandre les mêmes sentiments de rivalité, se disputaient l'appui des communes. Les uns, accourus les premiers, sans pompe, sans éclat, et plutôt comme des espions, s'étaient adressés aux souvenirs des temps les plus glorieux et des hommes les plus illustres: les autres
  • 72. avaient essayé de réhabiliter cette suzeraineté trop souvent invoquée par Philippe le Bel et Philippe de Valois, et, en effet, ils avaient paru, entourés de respect et d'honneurs, aussi bien au milieu des Gantois auxquels ils promettaient un protecteur, qu'à la cour du duc qu'ils menaçaient d'un juge. De l'un et de l'autre côté il n'y avait que des promesses. Les Anglais se persuadèrent assez aisément que le meilleur moyen de faire croire à leur sincérité était de les exécuter sans délai et sans bruit; rien n'était plus habile pour faire échouer les négociations entamées par les ambassadeurs français. Tandis que le sénéchal de Poitou, l'archidiacre de Tours et maître Jean Dauvet retournaient à Waesmunster, on vit arriver à Gand quelques archers anglais venus probablement de Calais. Dès ce moment, il y eut un parti français, ou pour mieux dire, un parti de la paix qui favorisait la médiation des ambassadeurs de Charles VII, et un parti de la guerre qu'encourageait l'impuissance de l'armée bourguignonne devant les palissades précipitamment élevées dans les marais de Moerbeke. Le 29 juin, maître Jean Dauvet était revenu à Gand pour y annoncer qu'on n'avait pu obtenir du duc une trêve d'un mois comme les Gantois l'avaient demandé aux ambassadeurs français. Il était en même temps chargé de rendre compte des premières négociations: les principes qui y avaient présidé étaient, d'une part, le maintien de l'autorité du duc si longtemps méconnue, de l'autre, la conservation des priviléges menacés d'une sentence de confiscation, et avant tout le droit d'arbitrage des envoyés du roi en n'y attachant d'autre sanction légale que l'amende, dans le cas où les Gantois seraient reconnus coupables de quelque délit. Cette déclaration, soumise à l'assemblée de la commune pour qu'elle y adhérât, fut vivement combattue et bientôt rejetée: la collace n'accepta la médiation des ambassadeurs qu'en repoussant leur arbitrage, et elle se réserva non-seulement ses priviléges et le soin de se justifier des griefs du duc, mais aussi le droit de ratifier toutes les conditions relatives au rétablissement de la paix.
  • 73. Une expédition s'était organisée sous l'influence de ce sentiment hostile aux négociations. Les partisans des Anglais, se croyant assurés de vaincre les Bourguignons parce qu'ils conduisaient avec eux quelques archers de Henri VI, avaient formé le projet de s'emparer de Hulst. Ils savaient qu'Antoine de Bourgogne, qu'on appelait le bâtard de Bourgogne depuis la mort de son frère Corneille s'y tenait avec Simon, Jacques et Sanche de Lalaing et une partie de l'armée hollandaise: il avait même pillé et dévasté le pays jusqu'à Axel. A l'approche des Gantois qui s'avançaient avec une nombreuse artillerie, il recourut de nouveau à l'une de ces ruses que nos communes ne surent jamais prévoir. Tandis qu'il multipliait sur les remparts de Hulst de vains simulacres de défense, Jacques de Lalaing et Georges de Rosimbos, cachés hors de la ville avec un grand nombre d'archers, enveloppaient les Gantois, et presque au même moment le capitaine d'Assenede, qui portait l'étendard de Gand, le jeta à ses pieds en criant: Bourgogne! Cette attaque, cette trahison non moins funeste et non moins imprévue, répandent la confusion et le désordre parmi les milices communales. Jacques de Lalaing s'y précipite: cent glaives se dirigent vers sa poitrine et trois chevaux tombent sous lui; mais il triomphe, et les Gantois fuient jusqu'aux portes de Gand, où Jean de Vos fait saisir et décapiter quelques-uns de ceux qui n'ont été ni assez prudents pour traiter avec dignité, ni assez intrépides pour combattre avec honneur. La gloire de la Flandre eût reçu une tache indélébile dans cette journée, si quelques bourgeois de Gand n'avaient continué à lutter presque seuls contre la multitude de leurs ennemis, afin que leur courage fît du moins oublier la honte de leurs compagnons. Leur résistance se prolongea longtemps, et ceux d'entre eux qui survécurent à un combat acharné refusèrent de recourir à la clémence du duc pour se dérober à la hache du bourreau, aimant mieux perdre la vie que de se montrer indignes de la conserver. «En vérité, raconte Jacques Duclercq, je vous diray ung grand merveille, et à peu sembleroit-elle croyable: c'est que les Gantois estoient tant obstinés à faire guerre qu'ils respondirent qu'ils aimoient mieulx
  • 74. mourir que de prier mercy au duc, et qu'ils mouroient à bonne querelle et comme martyrs (29 juin 1452).» Cependant les vainqueurs, craignant quelque autre attaque des Gantois, avaient envoyé des messagers à Waesmunster afin de réclamer des renforts. Hulst n'est éloigné que de quatre lieues de Waesmunster. Le duc ordonna le même soir à toute son armée de se réunir. En vain les ambassadeurs du roi lui représentèrent-ils qu'un de leurs collègues était resté à Gand et qu'il ne tarderait peut-être point à apporter des nouvelles qui rendraient désormais inutile l'effusion du sang, le duc se contenta de répondre que les mauvaises intentions des Gantois lui étaient assez connues. L'avant-garde, le corps principal et l'arrière-garde se mirent successivement en marche; les chariots suivaient, afin que ceux qui viendraient à se briser ne formassent point un obstacle sur le chemin. Le duc, ayant ainsi chevauché toute la nuit, s'arrêta à une demi-lieue de Hulst. Il y fut rejoint par quelques hommes d'armes hollandais commandés par le sire de Lannoy, et donna aussitôt à Jacques et à Simon de Lalaing l'ordre d'aller examiner de quel côté il serait plus aisé d'escalader les remparts d'Axel, mal défendus par de larges fossés dont un soleil ardent avait épuisé les eaux. Ces précautions étaient inutiles. Les Gantois, avertis de la marche de l'armée bourguignonne, s'étaient retirés pendant la nuit. Le duc fit mettre le feu aux trois mille maisons qui formaient le bourg d'Axel, et se rendit à Wachtebeke où il passa deux jours, attendant les vivres que les sires de Masmines et de la Viefville étaient allés chercher à l'Ecluse. Pendant ces deux jours, les hommes d'armes du duc se dispersèrent pour parcourir les champs. Ils découvrirent un petit fort où quelques Gantois s'étaient retranchés. Ils les prirent et les mirent à mort. Leur principal but, toutefois, était de piller. Les laboureurs, dans leur fuite précipitée, avaient abandonné leurs troupeaux qui paissaient dans les prairies. Ils étaient, disent les chroniqueurs, si nombreux que l'on vendait au camp du duc une belle vache du pays de Waes pour cinq sous: pour quatre écus on en avait cent.
  • 75. Devant le village de Wachtebeke s'étendent de vastes marais qu'arrose un bras de la Durme. Les sires de Poix et de Contay y avaient fait établir un passage pour que l'armée bourguignonne pût les traverser; mais dès qu'elle se fut mise en marche, le sol humide de la route céda et elle devint impraticable. Il fallut reculer, et les hommes d'armes du duc, à demi noyés dans la fange et dans la boue, rentrèrent à Wachtebeke. Bien que leur départ fût fixé au lendemain, on avait profité de ces retards pour incendier quelques villages. La chronique de Jacques de Lalaing en nomme un seul: celui d'Artevelde. Le 6 juillet, le duc quitta Wachtebeke qu'on livra aux flammes, et passa la Durme près de Daknam. Le lendemain, il se rendit à Wetteren, gros bourg situé sur l'Escaut, à deux lieues et demie de Gand, et y plaça son camp. Les ambassadeurs du roi, qui étaient restés à Termonde pendant ces combats, l'y suivirent et firent de nouvelles instances pour qu'il suspendît la guerre par une trêve qui permettrait de recommencer les négociations. Le moment de ces remontrances était mal choisi: le duc refusa de les écouter, et le 10 juillet il ordonna au duc de Clèves de prendre son étendard et de s'avancer jusqu'auprès de Gand. Il espérait engager les bourgeois à sortir de leur ville et à lui livrer bataille. Il avait même fait connaître, sans qu'on sonnât les trompettes, que chacun scellât son cheval et se tînt prêt à combattre. Toison d'or accompagnait le duc de Clèves et avait amené avec lui tous les rois d'armes, hérauts et poursuivants de la cour du duc, afin qu'ils lui apprissent de suite l'attaque des Gantois. Cependant les Gantois instruits par les revers de Basele, trompèrent ces espérances. Ils vinrent en grand nombre escarmoucher aux portes de leur ville; mais lorsqu'ils se sentaient pressés de trop près, ils reculaient et attiraient eux-mêmes les hommes d'armes du duc assez loin pour qu'ils pussent les atteindre avec les arbalètes, les coulevrines et les canons placés sur leurs remparts. Le combat se prolongea pendant deux heures sans que les Gantois cessassent de conserver l'avantage. Un grand nombre d'hommes d'armes du duc
  • 76. avaient succombé, et tous leurs efforts n'avaient amené d'autre résultat que l'incendie de quelques maisons des faubourgs. Philippe n'avait point assez de forces pour songer à assiéger une grande et populeuse cité comme celle de Gand, qui pouvait armer chaque jour, disait-on, quarante mille défenseurs et en porter même le nombre à cent mille, si le péril l'exigeait. Cette fois, du moins, il avait compté inutilement sur l'inexpérience et l'imprudente témérité de ses ennemis, et il ne lui restait plus qu'à opter entre une retraite honteuse et une inaction qui épuiserait ses ressources sans moins dissimuler son impuissance. Dans cette situation, il n'hésita pas à subir la nécessité d'un trêve, et le 15 juillet, sans consulter ni son chancelier ni les membres de son conseil, il annonça son intention à Jean Vander Eecken, secrétaire des échevins des parchons, qui se trouvait depuis plusieurs jours à Wetteren avec les ambassadeurs du roi. Cette suspension d'armes devait durer six semaines depuis le 21 juillet jusqu'au 1er septembre. Le duc licencia aussitôt son armée. Il se contenta de laisser de fortes garnisons à Courtray, à Audenarde, à Alost, à Termonde et à Biervliet; mais il n'osa point en envoyer à Bruges, de peur de mécontenter les habitants de cette ville, à qui il avait donné pour capitaine un de leurs concitoyens, qui jouissait d'une grande autorité parmi eux, messire Louis de la Gruuthuse. Les Gantois s'étaient déjà empressés d'écrire au roi de France pour placer leurs droits sous la protection de sa suzeraineté. Le duc lui-même lui adressa de Termonde, le 29 juillet, une lettre écrite dans les termes les plus humbles, pour le supplier d'entendre ses ambassadeurs, Guillaume de Vaudrey et Pierre de Goux, avant d'accorder à ses adversaires «aucuns mandements ou provisions à l'encontre de luy.» Philippe avait désigné la ville de Lille pour les conférences relatives à la paix. Louis de Beaumont et ses collègues s'y rendirent immédiatement. La commune de Gand, qui en ce moment même voyait s'associer à sa magistrature les noms influents des Rym, des Sersanders, des Vanden Bossche, des Steelant, des Everwin, avait choisi, pour la représenter, Simon Borluut, Oste de Gruutere, Jean
  • 77. Vander Moere et d'autres bourgeois, auxquels les historiens bourguignons n'hésitent pas à donner le titre encore si recherché et si rare de chevaliers. Les députés flamands avaient réclamé les conseils d'un avocat du parlement de Paris, nommé maître Jean de Popincourt. Le mémoire qu'ils présentèrent indique, par son titre, le but dans lequel il avait été rédigé: «C'est le régiment et gouvernement qui longtemps a esté au pays de Flandres contre les anciens droitz d'icelluy pays, et contre raison et justice en grant grief de la chose publique et de la marchandise sur laquelle le dit pays est principalement fondé.» On y lisait successivement que les impôts prélevés par le duc dépassaient ceux que ses prédécesseurs avaient recueillis pendant un siècle, que les transactions commerciales avaient été soumises à des impôts illégaux dont l'exclusion des marchends osterlings avait été le résultat, que le commandement des forteresses de Flandre avait été confié à des étrangers. On y rappelait le complot tramé par George Debul pour l'extermination des bourgeois de Gand, puis les préparatifs belliqueux du duc auxquels s'étaient jointes d'autres mesures prises pour les affamer. Enfin sur chacun des points qui avaient été l'objet des différends du prince et de la commune, on y trouvait citées quelques-unes de ces nombreuses chartes de priviléges octroyées à la ville de Gand depuis Philippe d'Alsace jusqu'à Jean sans Peur. Toutes ces plaintes se résumaient dans ce texte de la keure de Gand de 1192: Gandenses fideles debent esse principi quamdiu juste et rationabiliter eos tractare voluerit. La réponse du duc n'embrasse pas un moins grand nombre de griefs. Si dans le système des Gantois le maintien de leurs priviléges est la condition de leurs serments et la base de leurs devoirs, les conseillers bourguignons n'y voient que le prix d'une obéissance humble et complète. A les entendre, les chefs de la commune insurgée «avoient intention de prendre et tenir le pays de Flandre, de s'en dire et porter contes et de le départir entre eulx et leurs complices,» et pour les punir, le duc pouvait à son gré ou enlever à
  • 78. la ville de Gand ses priviléges, ou même la détruire et la raser usque ad aratrum. Le duc de Bourgogne avait, en quittant Wetteren, annoncé aux ambassadeurs du roi qu'il les suivrait de près à Lille: il y arriva peu de jours après eux. Sa présence sembla devoir imprimer immédiatement une nouvelle marche aux négociations, car, dès le 21 août, les envoyés de Charles VII abordèrent l'exposé du second point de leur mission, ce qu'ils n'avaient osé faire ni à Wetteren, ni à Waesmunster. Ne sachant trop comment entrer en matière pour présenter une réclamation si étrange et, il faut le dire, si peu justifiée, ils commencèrent par rappeler qu'il y avait eu «aucunes paroles et ouvertures à cause d'aucunes terres et seigneuries du roi» entre le comte de Saint-Pol et les sires de Croy, à qui Charles VII attribuait la promesse verbale, si malencontreusement omise dans le traité d'Arras. Il fallait, à leurs avis, supposer que ces terres et seigneuries qui n'avaient point été désignées, source fortuite et éventuelle de contestations, étaient les villes de la Somme, et que le duc, en protestant de son désir de complaire au roi en toutes choses, avait annoncé le dessein de les lui restituer. A ce langage si inattendu et si nouveau, Philippe ne put retenir sa surprise. «Je me donne merveilles, dit-il au sénéchal de Poitou et à ses collègues, de ce que vous me distes touchant la restitution des terres, veu que jamais je n'en ai parlé à messires de Croy, et s'ils se sont advancés d'en parler, je les désavoue, et ils en paieront la lamproye.» Antoine et Jean de Croy assistaient à cette audience; ils se hâtèrent de démentir ce qu'on leur avait attribué. Les ambassadeurs français, s'étant retirés pour délibérer sur ce qu'ils avaient à répondre, jugèrent qu'il ne fallait pas insister davantage sur les paroles et ouvertures des sires de Croy, et ils cherchèrent seulement à établir que la cession des villes de la Somme n'avait été qu'une cession provisoire, destinée à protéger contre les Anglais les frontières des Etats du duc de Bourgogne, et que cela avait été expressément convenu, quoiqu'il n'en eût point été fait mention dans le traité d'Arras. Bien que Philippe se montrât peu disposé à céder, son langage s'était adouci, et il congédia les ambassadeurs en leur
  • 79. déclarant «que la matière estoit grande et qu'il y eschéoyt bien penser.» Evidemment le duc de Bourgogne ne pouvait consentir à la restitution de ces villes, dont le rachat avait été fixé à la somme énorme de quatre cent mille écus d'or: si elles avaient cessé d'être une barrière contre les Anglais chassés de la Normandie, elles restaient, pour le duc Philippe, ce qu'elles étaient avant tout à ses yeux, une ligne importante de défense contre les rois de France, qui avaient si fréquemment envahi, sans obstacle, les plaines fertiles de l'Artois et de la Flandre. La puissance du duc de Bourgogne reposait sur le traité d'Arras; il ne pouvait, sans en abdiquer les fruits, en déchirer le texte dans l'une des clauses qui lui étaient les plus avantageuses. Cependant il n'ignorait pas que Charles VII, triomphant à la fois du Dauphin réduit à s'humilier et des Anglais expulsés de la Guyenne, réunissait à ses frontières du nord tous ses chevaliers et tous ses hommes d'armes pour le combattre. Il temporisait et attendait son salut de l'Angleterre. Une guerre civile, fomentée par le duc d'York, avait été étouffée par la fortune victorieuse de la maison de Lancastre, à laquelle la duchesse de Bourgogne appartenait par sa mère, et le gouvernement était de nouveau dirigé par le duc de Somerset, si favorable au duc Philippe qu'il avait été accusé au parlement de l'année précédente de vouloir lui livrer Calais. Il n'est guère permis de douter que des agents bourguignons n'aient suivi à Londres le cours des événements, prêts à en profiter dans l'intérêt de leur maître, et s'appuyant sans cesse sur tout ce que les passions nationales conservaient d'hostile contre les Français; l'histoire ne nous a conservé ni leurs noms, ni les traces de leurs négociations; mais nous en connaissons le résultat: le choix de Jean Talbot, le fameux comte de Shrewsbury, pour commander une expédition qui allait aborder dans la Gironde. C'était le 21 août que les ambassadeurs français avaient réclamé du duc Philippe la restitution des villes de la Somme, «ayant charge de s'adresser à sa personne et non à autre, privément et rondement, sans entrer en grans argumens,» car il suffit d'être fort et redoutable
  • 80. pour avoir le droit de parler haut et bref. L'invasion imminente des Anglais, en appelant de nouveau dans les provinces du midi les forces de Charles VII, qui s'était trop confié dans la trêve, modifia tout à coup leur position. L'ambassadeur mandataire de la colère et des vengeances du seigneur suzerain s'effaça: il ne resta que l'homme timide et faible, entouré des séductions d'un vassal plus riche que le roi lui-même. Le 30 août, les envoyés du roi de France adressèrent aux échevins de Gand une lettre où ils avouaient que jusqu'à ce jour ils n'avaient rien obtenu du duc de Bourgogne, et toutefois, d'après leur propre aveu, le moment approchait où la fin des trêves nécessiterait l'adoption d'un «appointement.» Quel qu'il dût être, ils leur défendaient, au nom du roi, «qui a bien le vouloir de donner remise à leurs griefs,» de chercher à s'y opposer «en procédant par armes ne par voie de fait.» Les craintes que fit naître cette déclaration, si ambiguë dans ses termes et si menaçante dans ce qu'elle laissait entrevoir, ne devaient pas tarder à se confirmer. Le 3 septembre, vers le soir, les députés flamands qui avaient pris part aux conférences de Lille rentrèrent tristement à Gand. Leur mission avait été terminée par le rejet de toutes leurs demandes, et dès le lendemain on publia à Lille, au cloître de Saint-Pierre, la sentence arbitrale des ambassadeurs français, toute favorable aux prétentions du duc. Elle ordonnait que les portes par lesquelles les Gantois étaient sortis pour attaquer Audenarde seraient fermées le jeudi de chaque semaine; que celle par laquelle ils s'étaient dirigés vers Basele le serait perpétuellement; qu'ils payeraient une amende de deux cent mille écus d'or; que toutes leurs bannières leur seraient enlevées; que les chaperons blancs seraient supprimés; qu'il n'y aurait plus d'assemblées générales des métiers; que les magistrats de Gand n'exerceraient aucune autorité supérieure sur les châtellenies voisines, et ne pourraient prendre aucune décision sans l'assentiment du bailli du duc; que ces mêmes magistrats se rendraient, en chemise et tête nue, au devant du duc, suivis de deux mille bourgeois sans ceinture,
  • 81. pour s'excuser en toute humilité de leur rébellion et en demander pardon, grâce et miséricorde. Quelques jours s'écoulèrent. Un héraut chargé par les ambassadeurs français d'interpeller les Gantois sur leur adhésion à la sentence du 4 septembre, quitta Lille et se rendit à Gand. Dès qu'il fut descendu dans une hôtellerie, il s'informa de quelle manière il pourrait remplir son message. «Gardez-vous bien, s'écria l'hôte prenant pitié de lui, gardez-vous bien de faire connaître quel motif vous amène, car si on le savait, vous seriez perdu.» Et il cacha le héraut dans sa maison afin qu'il pût attendre un moment plus favorable pour s'acquitter de sa mission. Cependant l'agitation ne se calmait point. La collace, convoquée le 8 septembre, avait rejeté tout d'une voix le traité de Lille comme contraire aux priviléges de la commune, et il ne resta au héraut qu'à tourner sa robe ornée de fleurs de lis et à feindre qu'il était un marchand français revenant d'Anvers. Il y réussit, se fit ouvrir les portes de la ville et frappa son cheval de l'éperon jusqu'à ce qu'il fût rentré à Lille. Il nous reste à raconter ce qu'était devenue la négociation relative aux villes de la Somme. Le 9 septembre, c'est-à-dire, selon toute apparence, le jour même du retour du messager français envoyé à Gand, le duc Philippe, ne tenant aucun compte de la sentence rendue en sa faveur par les envoyés de Charles VII, repoussa tout ce qu'ils avaient allégué sur l'origine de la cession de 1435, en se contentant de répondre que les causes en étaient assez connues, mais «qu'il ne le vouloit point dire pour l'honneur du roy.» C'était rappeler l'attentat de Montereau, l'alliance du duc Jean et des Anglais, et l'humiliation du roi qui, pour ne pas subir la loi des étrangers, l'avait acceptée d'un vassal. Cette réponse était un défi au moment où le duc se félicitait de voir les Anglais menacer de nouveau la Guyenne et peut-être même se préparer à reconquérir la Normandie. Du reste, Philippe ne méconnaissait point les bons services des ambassadeurs français qui avaient condamné les Gantois. Comme s'il prévoyait qu'ils pourraient être mal accueillis à leur retour à Paris,
  • 82. Welcome to our website – the perfect destination for book lovers and knowledge seekers. We believe that every book holds a new world, offering opportunities for learning, discovery, and personal growth. That’s why we are dedicated to bringing you a diverse collection of books, ranging from classic literature and specialized publications to self-development guides and children's books. More than just a book-buying platform, we strive to be a bridge connecting you with timeless cultural and intellectual values. With an elegant, user-friendly interface and a smart search system, you can quickly find the books that best suit your interests. Additionally, our special promotions and home delivery services help you save time and fully enjoy the joy of reading. Join us on a journey of knowledge exploration, passion nurturing, and personal growth every day! ebookbell.com