100% found this document useful (4 votes)
105 views

C Programming From Problem Analysis to Program Design 2nd Edition Barbara Doyle download pdf

Doyle

Uploaded by

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

C Programming From Problem Analysis to Program Design 2nd Edition Barbara Doyle download pdf

Doyle

Uploaded by

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

Download Full ebookname - Read Now at ebookname.

com

C Programming From Problem Analysis to Program


Design 2nd Edition Barbara Doyle

https://ebookname.com/product/c-programming-from-problem-
analysis-to-program-design-2nd-edition-barbara-doyle/

OR CLICK BUTTON

DOWLOAD EBOOK

Discover More Ebook - Explore Now at ebookname.com


Instant digital products (PDF, ePub, MOBI) available
Download now and explore formats that suit you...

C Programming From Problem Analysis to Program Design 5th


Edition Barbara Doyle

https://ebookname.com/product/c-programming-from-problem-analysis-to-
program-design-5th-edition-barbara-doyle/

ebookname.com

C Programming From Problem Analysis to Program Design 6th


Edition D. S. Malik

https://ebookname.com/product/c-programming-from-problem-analysis-to-
program-design-6th-edition-d-s-malik/

ebookname.com

C Programming Program Design Including Data Structures


Fourth edition D. S. Malik

https://ebookname.com/product/c-programming-program-design-including-
data-structures-fourth-edition-d-s-malik/

ebookname.com

Neuropsychological Assessment 5th Edition Muriel Deutsch


Lezak & Diane B. Howieson & Erin D. Bigler & Daniel Tranel

https://ebookname.com/product/neuropsychological-assessment-5th-
edition-muriel-deutsch-lezak-diane-b-howieson-erin-d-bigler-daniel-
tranel/
ebookname.com
Interpartner Dynamics in Strategic Alliances 1st Edition
T. K. Das

https://ebookname.com/product/interpartner-dynamics-in-strategic-
alliances-1st-edition-t-k-das/

ebookname.com

Company to Company A Task Based Approach to Business


Emails Letters and Faxes Student s Book 4th Edition Andrew
Littlejohn
https://ebookname.com/product/company-to-company-a-task-based-
approach-to-business-emails-letters-and-faxes-student-s-book-4th-
edition-andrew-littlejohn/
ebookname.com

Comparative Homeland Security Global Lessons Wiley Series


on Homeland Defense and Security 1st Edition Nadav Morag

https://ebookname.com/product/comparative-homeland-security-global-
lessons-wiley-series-on-homeland-defense-and-security-1st-edition-
nadav-morag/
ebookname.com

Animals A Visual Encyclopedia 2nd Edition Dk

https://ebookname.com/product/animals-a-visual-encyclopedia-2nd-
edition-dk/

ebookname.com

Teaching Mathematics to English Language Learners Teaching


English Language Learners Across the Curriculum 1st
Edition Gladi Kersaint
https://ebookname.com/product/teaching-mathematics-to-english-
language-learners-teaching-english-language-learners-across-the-
curriculum-1st-edition-gladi-kersaint/
ebookname.com
Principles of Marketing 12th Edition Philip Kotler

https://ebookname.com/product/principles-of-marketing-12th-edition-
philip-kotler/

ebookname.com
C# Programming:
From Problem Analysis
to Program Design,
Second Edition

Copyright 2008 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Copyright 2008 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
C# Programming:
From Problem Analysis
to Program Design,
Second Edition

Barbara Doyle

Australia • Canada • Mexico • Singapore • Spain • United Kingdom • United States

Copyright 2008 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
C# Programming: From Problem Analysis to Program Design, Second Edition
by Barbara Doyle

Senior Product Manager: Marketing Manager: Compositor:


Alyssa Pratt Bryant Chrzan GEX Publishing Services

Acquisitions Editor: Cover Designer: Senior Print Buyer:


Amy Jollymore Lisa Kuhn Justin Palmeiro

Content Product Manager: Editorial Assistant:


Pam Elizian Patrick Frank

COPYRIGHT © 2008 Course Technology, ALL RIGHTS RESERVED. No part of this Disclaimer
a division of Thomson Learning, Inc. work covered by the copyright hereon Course Technology reserves the right
Thomson Learning™ is a trademark may be reproduced or used in any to revise this publication and make
used herein under license. form or by any means—graphic, elec- changes from time to time in its con-
tronic, or mechanical, including photo- tent without notice. The programs in
Printed in the United States of America copying, recording, taping, Web this book are for instructional purposes
distribution, or information storage only. They have been tested with care
1 2 3 4 5 6 7 8 9 TC 11 10 09 08 07 and retrieval systems—without the but are not guaranteed for any partic-
written permission of the publisher. ular intent beyond educational pur-
For more information, contact Course poses. The author and the publisher do
Technology, 25 Thomson Place, Boston, For permission to use material from not offer any warranties or representa-
Massachusetts, 02210. this text or product, contact us by tions, nor do they accept any liabilities
Or find us on the World Wide Web at: Tel (800) 730-2214 with respect to the programs.
www.course.com Fax (800) 730-2215
www.thomsonrights.com 10-digit ISBN: 1-4239-0146-0

13-digit ISBN: 978-1-4239-0146-4

Copyright 2008 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Brief

Contents
PREFACE xix

1. Introduction to Computing and Programming 1


2. Your First C# Program 41

3. Data Types and Expressions 83

4. Methods and Behaviors 135

5. Making Decisions 209

6. Repeating Instructions 265

7. Arrays and Collections 329


8. Introduction to Windows Programming 401

9. Programming Based on Events 479

10. Advanced Object-Oriented Programming Features 577

11. Debugging and Handling Exceptions 649

12. Working with Files 705

13. Database Access using ADO.NET 757

14. Web-Based Applications 835

Copyright 2008 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
vi C# Programming: From Problem Analysis to Program Design

APPENDIX A Compiling and Running an Application


from the Command Line 925

APPENDIX B Visual Studio Configuration 935

APPENDIX C Code Editor Tools 945

APPENDIX D Character Sets 957

APPENDIX E Operator Precedence 959


APPENDIX F C# Keywords 960

APPENDIX G Coding Standards 961

GLOSSARY 965
INDEX 979

Copyright 2008 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Table of

Contents
PREFACE xix

1. Introduction to Computing and Programming 1


History of Computers 2
Physical Components of a Computer System 5
Hardware 5
Processor 6
Storage 7
Input and Output Devices 9
Data Representation 9
Bits 9
Bytes 9
Binary Numbering System 10
Character Sets 12
Kilobyte, Megabyte, Gigabyte,Terabyte, Petabyte… 13
System and Application Software 13
System Software 14
Application Software 15
Software Development Process 15
Steps in the Program Development Process 16
Programming Methodologies 23
Structured Procedural Programming 23
Object-Oriented Programming 25
Evolution of C# and .NET 28
Programming Languages 28
.NET 29
Why C#? 32
Resources 33
Quick Review 34
Exercises 36

Copyright 2008 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
viii C# Programming: From Problem Analysis to Program Design

2. Your First C# Program 41


Types of Applications Developed with C# 42
Web Applications 42
Windows Applications 43
Console Applications 44
Exploring the First C# Program 45
Elements of a C# Program 46
Comments 46
Using Directive 47
Namespace 49
Class Definition 50
Main( ) Method 50
Method Body—Statements 51
Installing the .NET Framework 55
Creating a Place to Store Your Work 56
Typing Your Program Statements 57
Compiling, Building, and Running an Application 58
Compilation and Execution Process 58
Compiling the Source Code Using Visual Studio IDE 59
Debugging an Application 66
Syntax Errors 66
Run-time Errors 68
Creating an Application 68
Programming Example: ProgrammingMessage 69
Resources 74
Quick Review 75
Exercises 76
Programming Exercises 80

3. Data Types and Expressions 83


Memory Locations for Data 84
Identifiers 84
Variables 87
Literal Values 88
Types, Classes, and Objects 89

Copyright 2008 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Table of Contents ix

Types 89
Classes 89
Objects 90
Predefined Data Types 91
Value Types 92
Integral Data Types 93
Floating-Point Types 95
Decimal Types 97
Boolean Variables 98
Declaring Strings 98
Making Data Constant 99
Assignment Statements 100
Basic Arithmetic Operations 103
Increment and Decrement Operations 105
Compound Operations 108
Order of Operations 110
Mixed Expressions 112
Casts 114
Formatting Output 114
Programming Example: CarpetCalculator 118
Resources 126
Quick Review 126
Exercises 127
Programming Exercises 132

4. Methods and Behaviors 135


Anatomy of a Method 136
Modifiers 138
Return Type 141
Method Name 142
Parameters 142
Method Body 143
Calling Class Methods 144
Predefined Methods 146
Writing Your Own Class Methods 159

Copyright 2008 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
x C# Programming: From Problem Analysis to Program Design

Void Methods 160


Value-Returning Method 161
The Object Concept 167
Private Member Data 168
Writing Your Own Instance Methods 169
Constructor 169
Accessor 171
Mutators 172
Property 173
Calling Instance Methods 174
Calling the Constructor 174
Calling Accessor and Mutator Methods 176
Types of Parameters 182
Programming Example: RealEstateInvestment 188
Quick Review 197
Exercises 199
Programming Exercises 206

5. Making Decisions 209


Boolean Expressions 210
Boolean Results 210
Conditional Expressions 211
Equality, Relational, and Logical Tests 212
Short-Circuit Evaluation 219
Boolean Data Type 220
If...else Selection Statements 221
One-Way if Statement 221
Two-Way if Statement 226
Nested if…else Statement 231
Switch Selection Statements 236
Ternary Operator ? : 241
Order of Operations 242
Programming Example: SpeedingTicket 244
Quick Review 253
Exercises 255
Programming Exercises 262

Copyright 2008 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Table of Contents xi

6. Repeating Instructions 265


Why Use a Loop? 266
Using the While Statement 266
Counter-Controlled Loop 268
Sentinel-Controlled Loop 272
State-Controlled Loops 281
Using the For Statement Loop 284
Using the Foreach Statement 291
Using the Do...while Structure 292
Nested Loops 295
Recursive Calls 300
Unconditional Transfer of Control 302
Continue Statement 303
Deciding Which Loop to Use 305
Programming Example: LoanApplication 306
Quick Review 318
Exercises 319
Programming Exercises 325

7. Arrays and Collections 329


Array Basics 330
Array Declaration 331
Array Initializers 334
Array Access 336
Sentinel-Controlled Access 340
Using Foreach with Arrays 341
Array Class 342
Arrays as Method Parameters 347
Pass by Reference 347
Array Assignment 351
Params Parameters 352
Arrays in Classes 354
Array of User-Defined Objects 356
Arrays as Return Types 356
Two-Dimensional Arrays 363

Copyright 2008 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
xii C# Programming: From Problem Analysis to Program Design

Rectangular Array 363


Jagged Array 367
Multidimensional Arrays 367
ArrayList Class 372
String Class 375
Other Collection Classes 379
Programming Example: Manatee Application 380
Quick Review 390
Exercises 391
Programming Exercises 398

8. Introduction to Windows Programming 401


Contrasting Windows and Console Applications 402
Graphical User Interfaces 404
Elements of Good Design 408
Consistency 408
Alignment 409
Avoid Clutter 409
Color 409
Target Audience 409
Using C# and Visual Studio to Create Windows-Based Applications 410
Windows Forms 413
Windows Forms Properties 413
Inspecting the Code Generated by Visual Studio 419
Windows Forms Events 423
Controls 425
Placing, Moving, Resizing, and Deleting Control Objects 428
Methods and Properties of the Control Class 429
Derived Classes of the System.Windows.Form.Control Class 431
Programming Example:TempAgency Application 448
Quick Review 471
Exercises 472
Programming Exercises 477

Copyright 2008 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Table of Contents xiii

9. Programming Based on Events 479


Delegates 480
Defining Delegates 480
Creating Delegate Instances 481
Using Delegates 482
Relationship of Delegates to Events 484
Event Handling in C# 485
Event-Handler Methods 486
ListBox Control Objects 486
Creating a Form to Hold ListBox Controls 486
ListBox Event Handlers 489
Multiple Selections with a ListBox Object 490
ComboBox Control Objects 500
Adding ComboBox Objects 501
Handling ComboBox Events 502
Registering a KeyPress Event 502
Programming Event Handlers 503
MenuStrip Control Objects 505
Adding Menus 505
Adding Predefined Standard Windows Dialog Boxes 510
CheckBox and RadioButton Objects 518
CheckBox Objects 518
Adding CheckBox Objects 518
Registering CheckBox Object Events 519
Wiring One Event Handler to Multiple Objects 520
GroupBox Objects 522
RadioButton Objects 522
Adding RadioButton Objects 522
Registering RadioButton Object Events 524
TabControl Objects 533
Programming Example: DinerGui Application 536
Quick Review 567
Exercises 569
Programming Exercises 575

Copyright 2008 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
xiv C# Programming: From Problem Analysis to Program Design

10. Advanced Object-Oriented Programming Features 577


Object-Oriented Language Features 578
Component-Based Development 579
Inheritance 580
Inheriting from the Object Class 580
Inheriting from Other .NET FCL Classes 581
Creating Base Classes for Inheritance 582
Overriding Methods 585
Creating Derived Classes 586
Making Stand-Alone Components 595
Creating a Client Application to Use the DLL 601
Using ILDASM to View the Assembly 605
Abstract Classes 607
Abstract Methods 607
Partial Classes 609
Creating Partial Classes 609
Interfaces 609
Defining an Interface 610
Implementing the Interface 611
.NET Framework Interfaces 614
Polymorphism 615
Polymorphic Programming in .NET 616
Generics 617
Generic Classes 618
Generic Methods 622
Programming Example: StudentGov Application 624
Quick Review 640
Exercises 642
Programming Exercises 647

11. Debugging and Handling Exceptions 649


Errors 650
Run-Time Errors 651
Debugging in C# 652

Copyright 2008 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Table of Contents xv

Exceptions 658
Raising an Exception 661
Bugs, Errors, and Exceptions 662
Exception-Handling Techniques 664
Try…Catch…Finally Blocks 665
Exception Object 668
Exception Classes 670
Derived Classes of the Base Exception Class 670
ApplicationException Class 671
SystemException Class 671
Filtering Multiple Exceptions 673
Custom Exceptions 677
Throwing an Exception 679
Input Output (IO) Exceptions 681
Programming Example: ICW WaterDepth Application 682
Quick Review 697
Exercises 698
Programming Exercises 703

12. Working with Files 705


System.IO Namespace 706
File and Directory Classes 707
File Class 708
Directory Class 712
FileInfo and DirectoryInfo Classes 713
File Streams 715
Writing Text Files 718
Reading Text Files 723
Adding a Using Statement 727
BinaryReader and BinaryWriter Classes 729
Other Stream Classes 736
FileDialog Class 736
Programming Example: ICW WaterDepth File App 739

Copyright 2008 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
xvi C# Programming: From Problem Analysis to Program Design

Quick Review 748


Exercises 750
Programming Exercises 754

13. Database Access Using ADO.NET 757


Database Access 758
Database Management Systems 758
ADO.NET 759
Data Providers 760
Connecting to the Database 763
Retrieving Data from the Database 764
SQL Queries 765
Processing the Data 769
Updating Database Data 776
Using Datasets to Process Database Records 777
Data Source Configuration Tools 784
Add New Data Source 785
Dataset Object 794
DataGridView Control 796
Adding Update Functionality 803
DataSet Designer 804
Connecting Multiple Tables 813
Displaying Data Using Details View 819
Microsoft Access 821
Quick Review 826
Exercises 828
Programming Exercises 832

14. Web-Based Applications 835


Web-Based Applications 836
Web Programming Model 836
Static Pages 837
Dynamic Pages 839

Copyright 2008 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Table of Contents xvii

ASP.NET 841
Visual Web Developer 842
IIS 842
Web Forms Page 847
Creating a Web Page 847
Controls 854
HTML Controls 855
HTML Server Controls 860
Web Forms Server Controls 864
Available Web Forms Controls 864
Web Forms Controls of the Common Form Type 866
Adding Common Form-Type Controls 869
Validation, Custom, and Composite Controls 873
Validation Controls 873
Calender Control 876
DataGrid and GridView Controls 882
AccessDataSource 888
Using Visual Tools to Connect 889
Setting the Visibility Property 893
Other Controls 895
Web Services 898
Web Services Protocols 898
Building a Web Service 900
Using or Consuming Web Services 904
Smart Device Applications (Optional) 909
The .NET Compact Framework 909
Creating a Smart Device Application 909
Quick Review 916
Exercises 918
Programming Exercises 922

APPENDIX A Compiling and Running an Application


from the Command Line 925
Command-Line Execution 925
Compiling the Source Code from the DOS Command Prompt 926
Setting the Path to the Compiler (csc) 928

Copyright 2008 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
xviii C# Programming: From Problem Analysis to Program Design

Compiling Program Statements from the Visual Studio Command Prompt 931
Executing the Application from the Command Prompt 932
Compiler Options 933
Other Platforms 933

APPENDIX B Visual Studio Configuration 935


Customizing the Development Environment 935
Environment 936
Projects and Solutions 938
Text Editor 939
Debugging 942
Other Options Settings 943

APPENDIX C Code Editor Tools 945


Code Snippets 945
Refactoring 947
Extract Method 947
Rename 949
Other Refactoring Options 951
Working with Class Diagrams 952
Class Details View 953
Using the Class Diagram to Add Members 954
Using the Class Diagram to Instantiate Objects 955

APPENDIX D Character Sets 957

APPENDIX E Operator Precedence 959

APPENDIX F C# Keywords 960

APPENDIX G Coding Standards 961


Naming Conventions 962
Spacing Conventions 963
Declaration Conventions 963
Commenting Conventions 964
Control Statement Conventions 964

GLOSSARY 965

INDEX 979
Copyright 2008 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Preface
C # Programming: From Problem Analysis to Program Design requires no previous introduction
to programming and only a mathematical background of high school algebra.The book
uses C# as the programming language for software development; however, the basic pro-
gramming concepts presented can be applied to a number of other languages. Instead of
focusing on the syntax of the C# language, this book uses the C# language to present gen-
eral programming concepts. It is the belief of the author that once you develop a thorough
understanding of one programming language, you can effectively apply those concepts to
other programming languages.

Why C#?
C# is a true object-oriented language that includes a rich set of instruction statements. C#
was the language used for development of much of .NET, the new Microsoft programming
paradigm that includes a collection of more than 2,000 predefined classes that make up the
Framework Class Library (FCL). Thus, C# has access to a large collection of predefined
classes similar to those available to Java. C# provides tools that make it easy to create graphi-
cal user interfaces—similar to the tools Visual Basic programmers have employed for years.
C# also provides the pure data crunching horsepower to which C/C++ programmers have
become accustomed. But unlike other languages, C# was designed from scratch to accom-
modate Internet and Windows applications. For these reasons, C# was chosen as the lan-
guage for this book.

Going Beyond the Traditional CS1 Course


This book was written for the Computer Science 1 (CS1) student and includes all of the
basic programming constructs normally covered in the traditional CS1 foundation course for
the Computer Science curriculum. But this book goes beyond what is traditionally found in
most CS1 textbooks and, because of the inclusion of a number of advanced applications, this
textbook could also be used in an intermediate course for students who have already been
exposed to some programming concepts.

Advanced Topics
After building a solid programming foundation, this book presents rapid application develop-
ment techniques that can be used to build a number of advanced types of applications.
Generics and partial classes,which are new to .NET 2.0 are introduced. Illustrating the drag
and drop construction approach used with Visual Studio, Windows and Web applications are
created. Readers are introduced to the event-driven programming model, which is based on

Copyright 2008 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
xx C# Programming: From Problem Analysis to Program Design

interactively capturing and responding to user input on Windows and Web forms. In the past,
CS1 courses and even CS2 courses did not include this model.
As a book for first-time programmers, this book is unusual in introducing applications that
retrieve and update data in databases such as those created using Microsoft Access or SQL
Server. Other interesting topics include creating and using XML Web Services, program-
ming applications for mobile devices—such as personal digital assistants (PDAs), and devel-
oping stand-alone .dll components (class libraries). All of these advanced features are
discussed after you have gained a thorough understanding of the basic components found
in programming languages.

CHANGES IN THE SECOND EDITION


C#: From Problem Analysis to Program Design, Second Edition, has been considerably
revised and updated to reflect the latest release of Visual C# and .NET 2.0 and 3.0. All
screenshots were updated to the Visual Studio 2005 IDE.The new edition provides more
coverage of file processing, exception handling, debugging, and data base access. Heavier
emphasis is focused on using the IDE’s drag and drop techniques to create data bound
applications. The new Visual Web Developer’s built-in Web server was used to create
ASP.NET 2.0 applications. In addition to these changes the second edition includes several
new topics.The following summarizes the changes in the second edition.
1. A number of new Web site resources were added as references. Chapter 3 identifies
and describes the new C# conceptual keywords. More examples of formatting data
using format specifiers were included.
2. Chapter 6 includes a new section on recursion.
3. Visual Studio 2005 separates the source code into three files when you create a simple
Windows application.The new .designer.cs file is examined in Chapter 8. Chapter 8
also introduces partial classes and several new properties of the Control class.The
SnapLine Layout mode, which makes it easier to align controls when they are initially
added to the form is illustrated.
4. Chapter 9 includes several new Windows forms controls including the new MenuStrip
and ToolTip objects.
5. Chapter 10 discusses how to create partial classes. It also provides an extensive sec-
tion on generics, which is one of the most powerful new feature added to C# 2.0.
6. Chapter 11 is a new chapter focused on debugging and handling exceptions.The
Debugger available in the IDE is illustrated in terms of adding breakpoints and single-
stepping through an application. In addition to discussing .NET exception classes,
custom exceptions are designed.
7. Chapter 12 is also new.The focus is on the major classes used to work with file and
directory systems. Examples are included illustrating how to write programs that
access stored data and programs that store results in a file.

Copyright 2008 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Preface xxi

8. Chapter 13 is a new chapter. It focuses on building data bound applications using


ADO.NET. Program statements are included, but the emphasis is on illustrating the
visual tools that can be used to create ADO.NET 2.0 applications that display and
update table data.This greatly simplifies accessing data.
9. With Visual Studio 2005, it is no longer necessary to install a separate Web server
(such as IIS) in order to build web applications.This simplifies development of web
applications and will enable you to incorporate this type of development more easily
into their curriculum. Chapter 14 discusses the use of the new Visual Web Developer’s
built-in web server to create ASP.NET Web applications.
10. Two new Appendices were added.Appendix C describes new code editor tools intro-
duced with Visual Studio 2005. Code snippets, refactoring, and enhancements to the
IntelliSense features are described in this appendix.Appendix C also illustrates how Visual
Studio can be used to create Class Diagrams and how code can be modified visually
using the diagrams.Appendix G provides guidelines and best practices Coding Standards.
It includes a list of naming and spacing conventions, suggestions for using comments and
different control statements, and provides overall suggestions for style issues.

APPROACH
A problem solving methodology based on object-oriented software development is intro-
duced early and used throughout the book. Programming Examples are presented at the end
of each chapter, and each example follows a consistent approach: analyzing the problem spec-
ifications, designing a solution, implementing the design, and verifying or validating the solu-
tion structures.
The author believes that the best way to learn to program is to experience programming.
This assumption drives the material presented in this textbook. As new concepts are intro-
duced, they are described using figures and illustrations. Examples are shown and discussed
as they relate to the concept being presented. With a hands-on approach to learning, you
practice and solidify the concepts presented by completing the end of the chapter exercises.
You are also encouraged throughout the book to explore and make use of the more than
2,000 classes that make up the Framework Class Library (FCL).
Every chapter begins with a list of objectives and a short overview of the previous chapter.
Text in each chapter is supplemented with figures and tables to help visual learners grasp the
concepts being presented. Each chapter is sprinkled with useful tips and hints on the con-
cepts being presented, and code snippets are embedded as new concepts are introduced in
each chapter. In addition, each chapter contains complete working programs illustrating an
application using C#. Every chapter ends with a summary of the major points covered in
that chapter and review exercises in both objective and subjective formats. Every chapter con-
tains ten programming exercises that give you an opportunity to experience programming.

Copyright 2008 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
xxii C# Programming: From Problem Analysis to Program Design

Using this Book for Two Different Courses


Although this book is primarily intended for a beginning programming course, it will also
work well in an intermediate course. For courses introducing students to programming,
Chapters 1 through 7 should be covered in detail. Depending on how quickly students are
able to grasp the material, the course could end in any of the chapters following Chapter 7.
For example, ending with Chapter 8, Introduction to Windows Programming, would give
students an opportunity to get excited about continuing their work in programming in
upcoming semesters.
For an intermediate course, Chapter 1 could be skipped and students could merely scan
Chapters 2, 3, 5 and 6. Scanning these chapters, students could compare and contrast the
details of the C# language with programming languages they know. For the intermediate
course, Chapters 4 and 7 should be covered, because topics covered in these chapters—
Methods and Behaviors, and Arrays and Collections—are often more difficult for the student
to grasp. The remainder of the book beginning in Chapter 8 would be included for the
intermediate course.

Overview of the Chapters


Chapter 1 briefly reviews the history of computers and programming languages including
the evolution of C# and .NET.This chapter introduces data and describes how it is repre-
sented.The primary types of hardware components are described and differing types of soft-
ware are discussed. This chapter explains the difference between structured and
object-oriented programming and includes the software development methodology used
throughout the remainder of the book.
Chapter 2 describes the different types of applications that can be developed using C#. It dis-
cusses the basic elements found in a C# program. It illustrates how to compile, run, and debug
an application. After completing Chapter 2, you are ready to write programs. The focus in
Chapter 3 is data types and expressions.You gain an understanding of how types, classes, and
objects are related.You also learn how to perform arithmetic procedures on the data, how to
display formatted data, and how expressions are evaluated using the rules of precedence.
Chapter 4 extends the manipulation of the data through introducing methods and behaviors
of the data. You learn to write statements that call methods and to write your own instance
and class methods.You learn how to pass arguments to methods that return values and to
those that do not. Chapters 5 and 6 introduce control structures that alter the sequential flow
of execution. Selection control constructs are introduced in Chapter 5. Looping is introduced
in Chapter 6. Chapter 7 discusses arrays and collections. Methods of the String and ArrayList
class are also included in this chapter. Both single and multi-dimensional arrays are introduced.

Copyright 2008 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Preface xxiii

Chapters 8 and 9 present a different way of programming, which is based on interactively


responding to events.You are introduced to a number of classes in the FCL that are used to
create Windows applications. Elements of good design are discussed in Chapter 8. Delegates
are explored in Chapter 9.Visual Studio’s drag and drop approach to rapid application devel-
opment is introduced and used in these chapters.
Advanced object-oriented programming features are the focus of Chapter 10.You are intro-
duced to component-based development and learn how to create your own class library files.
Inheritance, interfaces, abstract classes, generic types, partial classes, and polymorphic pro-
gramming are discussed in detail. Advanced features such as overriding, overloading, and the
use of virtual methods are also included in Chapter 10.
Chapter 11 discusses debugging and exception handling techniques.The chapter introduces
one of the tools available in Visual Studio, the Debugger, which can be used to observe the
runtime environment, take an up-close look at the code, and locate logic errors.
The try…catch…finally block is discussed for handling exceptions. In addition to dis-
cussing .NET exception classes, custom exceptions are designed.
Chapter 12 presents the basics of creating, opening, closing, reading, and writing files. The
major classes used to work with file and directory systems are introduced. Chapter 13 intro-
duces a number of new namespaces collectively called ADO.NET, which consists of a man-
aged set of library classes that allow you to interact with databases.The chapter illustrates how
ADO.NET classes are used to retrieve and update data in databases.The visual programming
tools and wizards available with Visual Studio, which simplify accessing data, are covered in this
chapter.
The focus of Chapter 14 is on Web applications.You explore how the design of Web-based
applications differs from Windows applications.You discover the differences between static and
dynamic Web pages and how HTML and Web server controls differ. In Chapter 14, you learn
what a Web service is and how to write one.Also included in Chapter 14 is an introduction to
mobile applications that can be viewed with small personal devices such as a personal digital
assistant (PDA). Chapter 14 illustrates how validation controls can be used to check users’
input values and shows how the ADO.NET classes, introduced in Chapter 13, can also be used
with Web applications to access database records.
Appendix A describes how you can compile and execute a C# program from the command
line. It includes details on how this can be done from within Visual Studio or by using the
special Microsoft SDK. Instructions for how to download Microsoft’s Framework Software
Development Kit, a free download that includes everything needed to run C# programs
from the command line is included.
Appendix B assumes development will be done using the Integrated Development Envi-
ronment (IDE) of Visual Studio.To increase productivity, this appendix presents suggestions for
customizing the appearance and behavior of the IDE. Appendix C discusses two new Code
Editor features of Visual Studio, code snippets and refactoring. These new features improve

Copyright 2008 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
xxiv C# Programming: From Problem Analysis to Program Design

programmer productivity by reducing the number of keystrokes required to enter program


statements.This appendix also illustrates developing applications visually using Class Diagrams.
Appendix D lists the Unicode and ASCII (American Standard Code for Information
Interchange) character sets. Appendix E shows the precedence of the C# operators and
Appendix F lists the C# keywords.
Appendix G provides a set of Coding Standards. Suggestions are made regarding naming
conventions. Recommendations for spacing, commenting, and use of control statements
are included in this appendix.

FEATURES
Every chapter in this book includes the following features.These features are both conducive
to learning in the classroom and enable you to learn the material at your own pace.
■ Four-color interior design shows accurate C# code and related comments.
■ Learning objectives offer an outline of the concepts discussed in detail in the chapter.
■ Hundreds of visual diagrams throughout the text illustrate difficult concepts.
■ Syntax boxes show the general form for different types of statements.
■ Numbered examples illustrate the key concepts with their relevant code, and the code
is often followed by a sample run.An explanation follows that describes the functions
of the most difficult lines of code.
■ Notes highlight important facts about the concepts introduced in the chapter.
■ Numerous tables are included which describe and summarize information compactly
for easy viewing.
■ Programming Examples are complete programs featured at the end of the chapter.The
examples contain the distinct stages of preparing a problem specification, analyzing the
problem, designing the solution, and coding the solution.
■ Quick Reviews offer a summary of the concepts covered in the chapter.
■ Exercises further reinforce learning and ensure that students have, in fact, absorbed the
material.
■ Programming Exercises challenge students to write C# programs with a specified
outcome.
■ Glossary at the end of the book lists all the key terms in alphabetical order along with
definitions, for easy reference.

Copyright 2008 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Random documents with unrelated
content Scribd suggests to you:
As the brawny seaman who had Osceola by the arm,
reminded him of the order for silence, Osceola merely
chuckled. But he continued to do so until they were far
below the waterline in the very bowels of the ship.

Eventually they came to a long passage running fore


and aft. Electric bulbs in the ceiling brightly lighted the
corridor on either side of which doors opened into tiny
cabins, evidently the quarters for stewards and the
ship’s petty officers. Half way down a steel-barred gate
blocked this passageway from floor to ceiling. Before it
lounged an armed sentry.

The man straightened to attention as the party 223


approached. Brinkerhoff presented a paper which he
read carefully.

“Very good, sir,” he pocketed the order and saluted. “All


cells are full, sir, except the first on the right. Better
stick them in there.”

He unlocked the gate while the Lieutenant pushed Bill


and Osceola into an empty cell. Without a word the
officer slammed shut the door. The gate clanged and
they were left together in their prison.

The cell boasted no illumination of its own. What light


and ventilation there was came through the door, which,
like the gate in the passage, was constructed of crossed
bars of steel. It was no more than a cubby-hole. There
were two narrow bunks, one above the other on one
side; across from these, a washbowl and toilet. There
was no other furniture. Both the cell and the corridor
were terribly hot and stuffy.

“Well, this isn’t so bad, I’ve had worse quarters,” Bill 224
remarked philosophically. “When the Baron took over
this ship and needed a special brig for his prisoners, he
slapped that gate into the passageway and put others in
place of the doors to these cabins. The sidewalls are of
wood. If we had some tools, it wouldn’t be such a job to
get out of here.”

“Humph! but we haven’t any! And if we had, and could


cut our way through into the next cabin, outside the
gate, where would we go from there?”

They were speaking in whispers, for the sentry outside


the gate was only a yard or so from their door.

“Well, we’ve been in worse fixes. This will take some


thinking out,” answered Bill.

“Worse fixes?” Osceola’s shoulders moved impatiently. “I


doubt it.” He sat down on the edge of a bunk. “Just
because these bozos have been more or less polite,
don’t get the idea they aren’t dangerous customers.
That Baron means to put our lights out. You got him
worried when you sprung that Maine story on him, and
I purposely got him just as angry as I could.”

“What was your big idea?” 225

“Why, I figured that when he thought it over later, it


would lead him to believe we really did have something
up our sleeves—some certain means of rescue or
escape. A big bully like he is would reason that we’d
never have the nerve to bait him otherwise.”

“You think it may help to postpone the—er—evil day?”

“I am hoping so. If I size that guy up right, he’ll make


watchful waiting his cue for a few days anyway. He’ll
want to see if anything really happens before he puts
his own head into a noose.”

“And when nothing happens, we’ll be put on the spot


for that same reason!”

“Tomorrow’s always another day, Bill. Say, you’re not up


to your usual form this morning. I’ll bet you got no
sleep last night. You’d better turn in now and take a
siesta.”

“I’ll do that soon, Osceola. But I’m interested in our 226


fellow prisoners. You know, we’re lucky—our one
consolation is that there wasn’t room in this dump to
separate us.”

“You bet.” Osceola yawned and standing up, stripped


down to a pair of shorts. “I’ve got the dope on those
lads,” he said, as he climbed into the upper berth. “I
heard Geibel telling the Chief Engineer that he’d jailed
all the suspects on the wireless business. We’re down
here with a bunch of multi-millionaires. Does that make
you feel any better?”

“It certainly does!”

“How come?” whispered the chief from his bunk.

“Why, don’t you see? With all the gaff we gave the
Baron, he’ll suspect we’re in cahoots with one or more
of them—and keep them down here, where they can’t
help us.”

Osceola grunted. “You’ve sure got it in for the poor


money kings—what have you got against ’em?”
“Gosh, you’re thick!” snorted his friend. “So long as they 227
fill the cells we’ll be together. It’s a heap easier for us to
get out of one cell, together, than it would be to get out
of two, separately!”

“Boy, you’re talking in circles. We now arrive at the fact,


once more, that we have no tools with which to get out!
Take my advice and snatch a nap. You need it worse
than I do, and this little Indian is going shut-eye right
now!”

228
Chapter XVII
CHARLIE’S NOTE

For the next couple of days, Bill and Osceola sweated in


their hot-box of a cell. What with the heat, the lack of
proper ventilation, and the uncertainty of their fate,
both lads sank into a state of mind that bordered on
despondency.

The monotony of their existence was broken but three


times a day, when meals were brought to the prisoners’
cells by a steward. The man was invariably accompanied
by the armed sentry, who acted as turnkey.

There appeared to be no possible means of escape. Day 229


and night the electric lights in the passage beyond the
steel bars burned brightly. The sentry outside the gate
was relieved by another seaman every four hours, with
the change of watch. With nothing to read, nothing to
do, the lads spent most of their time lying in the bunks
or taking turns pacing the narrow confines of their cell.

Sunday night, shortly after ten o’clock the tremble of


the ship’s engines stopped. The lads guessed that the
Amtonia had reached her destination at last. Half an
hour later they heard the sentry speaking to someone in
the passage just beyond the gate. Although the
conversation was carried on in German, Bill was able to
get the gist of it.

“What’s the matter, Hans?” inquired the sentry. “Aren’t


you going ashore with the rest of the boys?”

“Not me,” replied Hans. “I’ve got to start swabbing out


bathrooms at four o’clock.”

“Well, I’m going,” the sentry declared, “just as soon as


Otto relieves me at midnight. It isn’t often we have the
chance to stretch our legs ashore and have a good
time.”

“If your idea of a good time is to swill American 230


homebrew in a speakeasy, it’s not mine,” the other
retorted. “I’m from Munich, I am. Good brown
Lionsbrew for me. I can’t stomach the stuff they sell you
on this side. Anyway, I’ve been on my feet all day long.
My legs get all the stretching they want aboard this
ship. I’m tired—good night!”

The lads heard the door of the cabin next to them slam
shut as Hans went to his well-earned rest.

“That,” laughed Bill, “is the first bit of comedy I’ve heard
since we landed aboard this blooming pirate. That
Heinie’s a sensible man. We might as well turn in, too.
Tomorrow, I suppose, they’ll take us ashore and stand
us up against a stone fence. I for one don’t want to
think any more about it than I have to.”

“Keep on talking—don’t stop!” said Osceola in a low


voice. “Either Hans or someone else next door is
scraping on his side of the wall. I’ll try to find out what
it’s all about.”
Bill nodded and immediately launched into a long 231
account of the Army and Navy football game in which
he had played the previous fall. Meanwhile Osceola
climbed into the lower bunk, and lying flat, pressed his
ear against the wooden partition which separated their
cell from the bath-steward’s cabin.

The slight scraping continued and presently the sharp-


eyed Seminole saw the point of a knife appear through
a board. The slit slowly widened, and a folded piece of
paper was pushed halfway through. Osceola grabbed it
and scanned the writing that covered both sides. He
passed it to Bill, who accomplished the difficult feat of
reading it while continuing his story of the football
game. The handwriting, though tiny, was unformed and
he guessed at once that the message was from Charlie.
It ran:

232
“Dear Bill—Hans is my bath stewward. He is O.K.
Have promissed Dad will make him rich for life if he
helps you and the cheif. He will cut through the
boards to your cell. Hang your blankits down over
the edge of your upper bearth so as to deden
sound. He will push through another knife so you
can do some cuting. I think the other one better
talk or sing or something so the centry can’t here
you cuting. If you get away take Hans to. His name
will be mud after this on board the Amtonia.

“Yours truley,
“Charles Evans.”

Bill smiled broadly as he pocketed the boyish,


misspelled note. Then, still keeping up his endless
monologue anent football, he hung the blankets,
forming a curtain which completely shut in the lower
bunk. Osceola was already at work with a knife that
Hans had passed through the opening.

Bill continued to talk for the next twenty minutes, but


then he pulled aside one corner of the blanket. The
bunk was like a bake oven. Osceola was sweating from
every pore.

“My turn now. Come out, and don’t forget to talk.”

Osceola handed the knife to Bill, grabbed his clothes 233


and slipped out of the bunk.

Immediately Bill climbed in and divested himself of the


underclothes he wore. Because of the heat, neither of
the lads had been clothed in more than their undershirts
and shorts since their incarceration. As the blanket
dropped back into place, he heard Osceola begin a
recital of some hunting trip he had taken down in the
Florida everglades. He was surprised to find how the
double blankets deadened the sound of his friend’s
voice.

It was pitch dark in the bunk. He was just beginning to


wonder exactly where he should get to work when a
light appeared through two parallel slits in the wall-
boards. These, he saw, were about three feet long and
perhaps a foot and a half apart. From the cabin beyond
the voice of Hans came in a sibilant whisper.

“If the Herr Lieutenant will be good enough to start 234


cutting across the boards from the bottom of one slit to
the bottom of the other? I shall work on the top end. It
is not necessary to tell the Lieutenant not to press too
hard with his knife. The sound of splintering wood can
be heard in the passage. There is no need to disturb the
sentry—just yet.”

Bill heard the steward chuckle. Then, except for the


very slight sound of the knives as they cut across the
grain of the wood, no other came to his ears save the
low mumble of Osceola’s voice beyond the blankets.

It was hard work and tedious, slicing across the grain of


the boards. The heat made Bill dizzy, and he stopped
frequently to wipe away the sweat that streamed down
into his eyes. After what seemed an endless age, Hans
spoke again.

“I have cut through to the farther slit, sir. Will the Herr
Lieutenant be good enough now to place the palm of
his hand against the piece that is to come out? There
must be no cracking of the wood when we remove it.”

“Okay,” whispered Bill.

Less than five minutes later, he completed his job. Hans 235
took the panel they had cut from the wall and switched
off the light in his cabin.

“Stand by,” said Bill. “We’ll be with you just as soon as I


can get a drink and put on my clothes.”

“Very good, sir,” returned the man, and Bill climbed out
of the bunk.

He went at once to the washbasin where he rinsed out


his mouth and drank a few swallows of the tepid water.
A quick sluice and a rubdown followed. Then he got
quickly into his white linen uniform. Osceola, who was
already dressed, spent the time in taking down the
blankets, folding them and tossing them onto the upper
berth. Far down the passageway they heard a bell tinkle
eight times.

“Midnight,” said Bill, in a low tone. “Yes, there’s Otto,


relieving our weary sentry at last. We’ll give him five
minutes to vamoose, then we’ll get out of here.”

That seemed the longest five minutes of their lives. 236


They kept their eyes glued on the luminous dials of their
wrist-watches.

“Time’s up!” said Bill at last.

“To the second,” was the Seminole’s sole comment. One


after the other they got into the lower berth and
squeezed through the opening in the wall.

“What’s the plan now, Hans?” Bill whispered in the


darkness.

“With permission, sir, I will go into the passage and talk


to Otto, who is on watch now. I will leave the cabin
door ajar, sir, and as soon as his back is turned, it will
be well if the gentlemen come out and—”

“Scrag him,” Bill supplied.

“That’s it, sir. Here are four pieces of rope and a gag.
That ought to be enough to keep Otto quiet. Will the
gentlemen please take me with them,” he asked
somewhat diffidently, “when they leave the ship?”

“You bet we will!” said Osceola. “Only don’t be so 237


darned polite. You make me nervous. Cut along now,
we’ll attend to Otto just as soon as you get him facing
the right way.”
“Very good, sir. Thank you, sir.”

Hans opened the door and went out, leaving it slightly


ajar. From the shadows beside it, the lads saw him
approach the sentry, who lounged on a stool by the
gate.

“Too hot in there to sleep,” remarked Hans. “I’m going


above to catch a breath of air.”

“Wish I could!” The sentry placed his rifle against the


wall. “This ship is an oven below-decks. Practically the
whole port watch has gone ashore. Just my bad luck to
be stuck down here.”

“Look at the size of that rat!” exclaimed the steward,


pointing down the prison corridor.

“Where?” Otto swung round toward the barred gate.

Hans immediately caught up the rifle and pressed the


muzzle against the man’s side. “One peep out of you,”
he muttered, “and I’ll give you a bellyful!”

Otto stared at him dazedly. Before he could decide 238


whether or not to make a move, Bill thrust the gag in
his mouth, while Osceola caught his wrists and lashed
them fast behind his back.

It took only a moment longer to tie up his ankles. Otto


was laid on the floor, and with Hans in the lead and
carrying the rifle, the three hurried down the passage
away from the gate.

239
Chapter XVIII
THE FLYING FISH PLAYS ITS
PART

Hans led them up through the galleys and pantries into


the First Class Dining Saloon without encountering a
single soul. They went boldly up the main staircase to
the promenade deck, which seemed deserted. A small
figure hiding in the shadows ran up to them, and Charlie
gripped his friends’ hands.

“Never mind the thanks,” he whispered. “We’ve got to


work fast. There’s an armed seaman at the gangway
head. We must quiet him first. Then we’ll take the ship’s
boat that’s moored below.”

“Okay, boy.”

Without another word, Bill walked up to the gangway


sentry, who immediately brought his rifle to the present.

“There’s rust on that barrel,” growled Bill and held out 240
his hand. “I can see it even in this light.”

“But—but I think,” stammered the sentry, “that my


officer is mistaken!” He passed over the gun without
suspicion.
Immediately afterward, he found himself in the same
dilemma Otto had encountered ten minutes earlier. Tied
up and gagged with a handkerchief, he was deposited
behind a pile of deck chairs.

His captors wasted no further time. They ran down the


gangway and piled aboard the skiff moored to the
grating. Hans got out the single pair of oars, Osceola
unloosed the painter, and Bill, who seated himself
beside Charlie in the stern, steered their small craft
away from the ship. There were men on the Amtonia’s
bridge but they received no hail to return.

Bill looked about. Although there was no moon, the 241


brilliant starlight gave ample light for him to size up his
surroundings. He found that they were floating in a
large cove or harbor almost landlocked. The body of
water was eggshaped; perhaps a mile long by half that
distance in width. The shores were rocky, with black
patches of sandy beach. Beyond grew a dense forest,
except at one end of the bay, where twinkling lights
marked a small settlement. The outlet to the ocean was
narrow, and guarded by high cliffs. It was a perfect
retreat for the Baron and his pirates.

Charlie piped up in his boyish treble. “The Amtonia’s


absolutely hidden by those heads from any ship passing
up or down the coast. The harbor entrance makes a
right-angled turn half way to the sea. I heard Lieutenant
Brinkerhoff say that a warship passed the mouth, going
west, about eleven-thirty. The lookout on the head
signalled in. Brinkerhoff was laughing about it, I guess it
made him feel good.”

“Well, his break is ours now,” declared Bill. “And there’s


another one for us!”
He pointed to where the Flying Fish lay moored, with 242
her wings spread, a few hundred yards away.

“It’ll be hot as Tophet in her hull tonight! Row on, Hans.


We’re going over there to pay a visit. By the way, does
anyone know exactly where we are?”

“Yes, sir,” replied the man, “this harbor is on the coast of


Maine. Washington County, I think, sir—not very far
from Englishman’s Bay.”

“Good enough! What are those lights yonder?”

“You might call that our private Navy Yard, sir. It’s the
Baron’s shore base. He keeps a crew on duty there,
while the ships are at sea. There are storehouses, a
machine shop, the men’s quarters and a store. It’s ten
miles back to the railroad. He owns all the shore
acreage hereabouts. A high wire fence shuts in the
property from all outsiders. There are one or two big
estates up and down the coast, but the nearest house is
a good three miles away.”

“How are the roads?” 243

“There’s no road along the coast, sir. The one from the
base runs back to the little town on the railroad. It’s in
very bad condition, sir. There is no other way out.”

“Thank you, Hans. You’re a treasure-house of local


knowledge.”

“Thank you, sir. May I make a suggestion?”

“Fire away.”
“My brother, August, is deck watch aboard the Flying
Fish, sir. Usually, in port, only one man is kept aboard
her. August does not like this life. Like me, he was
shanghaied into it. Once with this outfit, there is no
getting away, unless by a miracle, like tonight, sir.
August speaks no English. May I ask him to join us?”

“By all means, Hans. It will save a lot of trouble. Offer


him what Mrs. Evans said she would give you. I will see
that it is paid.”

“Very good, sir. Thank you, sir.”

They were close to the converted submarine now. On 244


the narrow deck, abaft the motors a man was seated on
a camp chair, smoking. He stood up as the boat
approached.

Hans hailed him and for several minutes the two


brothers hurled harsh gutturals at each other. Bill
guessed them to be speaking a low Bavarian dialect of
German. He failed to understand a single word of what
they said.

“He wants me to thank you—he will come,” Hans


asserted presently.

“What a polite family you are—” chuckled Bill. “Let’s get


aboard.”

Fifteen minutes later those officers and men who had


remained on deck aboard the anchored pirate ship were
astonished to see the Flying Fish taxi down the harbor
and take the air. A few seconds later her tail lights
disappeared into the dark beyond the headlands.
Aboard the Amtonia orders were shouted, bells clanged,
and presently the whining howl of her siren awoke the
echoes of the night.

Half an hour passed. Bill, at the wheel of the Flying 245


Fish, leaned forward, his eyes focussed on a pinpoint of
light far below and about ten miles ahead of the
speeding airplane.

“There she is on a bet,” he said to Osceola, who was in


the other pilot’s seat.

“You mean the warship Charlie told us about? What


makes you so sure?”

“I’ve got a hunch, that’s all. Anyway, nothing but a


fishing boat or one of the little steamers that put in at
the small seaports along this part of the coast would be
so close to shore. That’s a big ship out there. I think I’m
right about her.”

Bill’s hunch was correct, as the two in the cockpit


presently saw.

“It’s the Stamford, or her twin!” he declared. “Uncle


Sam sure is on the job!”

Catching up with the cruiser, he circled her three times.


Then the Flying Fish darted ahead, landed and came to
rest half a mile beyond. By the time the warship hove to
beside them, Bill had a sea anchor out and was waiting
on the heaving deck. He held a megaphone in his hand.
Beside him, staring at the big cruiser, stood Osceola,
Charlie, Hans and August.

“What craft is that?” came a hail from the warship’s 246


bridge.
“The convertible submarine-seaplane, Flying Fish,
Midshipman William Bolton in command,” Bill yelled
back. “She was part of von Hiemskirk’s pirate outfit. She
belongs to Uncle Sam now. We captured her less than
an hour ago. Are you the Stamford?”

“You’ve guessed it!” spoke a jubilant voice. “Commander


Brown speaking,” it went on, “are you the chaps who
sent out that wireless?”

“Yes, sir.”

“Congratulations, Mr. Bolton. Where is the Amtonia?”

“At anchor in a small harbor a few miles up the coast,


sir. One of her propellers was shot off in the scrap the
other day. She hasn’t got steam up, or didn’t have,
when we left—so I guess she’s still there.”

“Good! Take off at once and lead us to her.”

“Aye, aye, sir. There’s plenty of water but the channel to 247
the harbor is a narrow one between twin heads. You’ll
have to be careful.”

“Thank you, Mr. Bolton. Any other suggestions?”

“Yes, sir. Please wireless to the state constabulary to


guard the road from Twin Head Harbor to Clayton.
That’s the only way von Hiemskirk and his crew can
escape by land.”

“We’ll attend to it at once,” said the Commander. “Cut


along now. We’ll follow you, so don’t get too far ahead.”

“Aye, sir,” said Bill, and sent Hans forward to haul in the
sea anchor.
The first pale rays of summer dawn were brightening
sea and land when the Stamford navigated the entrance
between Twin Heads and pushed her wicked snout into
the harbor. At the same instant, Bill landed the Flying
Fish on the calm water.

Through the cockpit windows Bill saw that the Amtonia


was raising her anchors.

“Von Hiemskirk was all set to run for it,” he said to the 248
chief.

“But he wasn’t quite quick enough,” grinned Osceola.


“Next stop, Atlanta, for that bunch. There’s mighty little
pirating to be done in a federal prison!”

“They’re hauling down the Jolly Roger!” cried Bill. “Well,


that cuts it. Somebody will be sending a boat over here
after awhile. Let’s see if we can rustle some chow in the
meantime. I’m starved!”

The boat came alongside shortly after the five aboard


the Flying Fish had finished doing justice to a very
substantial breakfast. And all five were on deck when
the ensign in charge came over the side.

“Mr. Bolton?” inquired the young officer, as Bill stepped


forward.

“Himself,” smiled Bill.

“I’m Pierce, of the Stamford.” The two shook hands.

“Commander Brown’s compliments,” he continued after 249


Bill had introduced the quartet, “he wishes you to come
aboard the Amtonia. We wirelessed the news, of course,
and have just received a message of thanks addressed
to you, signed by the President. You are to go to
Washington, just as soon as this business here is
cleaned up. In fact, the President wants to meet the five
of you.”

“I bet Bill will get the Congressional Medal!” shrilled


Charlie.

“I shouldn’t be surprised,” smiled Pierce. “Gosh!” he


exploded, “this is a big thing you fellows have put over!”

“But Bill was the brains of it,” said Osceola.

“Without everybody’s help,” said Bill, “we never should


have pulled it off.”

“Cut the argument,” laughed Ensign Pierce. “The skipper


is waiting, and so are several hundred delighted
passengers.”

“That’s just it,” protested Bill, “I’d rather be shot than


face that mob!”

“Not me!” said Charlie. “Gee, it’ll be swell! Because I 250


was the youngest on board, everybody took pleasure in
jumping on me. Now I can tell them all where to shove
off! Let’s go!”

THE END

Those who read and enjoyed this book and the one
preceding it, (Bill Bolton—Flying Midshipman) will want
to read the next of this series, Bill Bolton and The
Hidden Danger.
Transcriber’s Notes

Copyright notice provided as in the original—this e-text


is public domain in the country of publication.
Silently corrected palpable typos; left non-standard (or
amusing) spellings and dialect unchanged.
In the text versions, delimited italics text in
_underscores_ (the HTML version reproduces the font
form of the printed book.)
*** END OF THE PROJECT GUTENBERG EBOOK BILL BOLTON AND
THE FLYING FISH ***

Updated editions will replace the previous one—the old editions will
be renamed.

Creating the works from print editions not protected by U.S.


copyright law means that no one owns a United States copyright in
these works, so the Foundation (and you!) can copy and distribute it
in the United States without permission and without paying
copyright royalties. Special rules, set forth in the General Terms of
Use part of this license, apply to copying and distributing Project
Gutenberg™ electronic works to protect the PROJECT GUTENBERG™
concept and trademark. Project Gutenberg is a registered trademark,
and may not be used if you charge for an eBook, except by following
the terms of the trademark license, including paying royalties for use
of the Project Gutenberg trademark. If you do not charge anything
for copies of this eBook, complying with the trademark license is
very easy. You may use this eBook for nearly any purpose such as
creation of derivative works, reports, performances and research.
Project Gutenberg eBooks may be modified and printed and given
away—you may do practically ANYTHING in the United States with
eBooks not protected by U.S. copyright law. Redistribution is subject
to the trademark license, especially commercial redistribution.

START: FULL LICENSE


THE FULL PROJECT GUTENBERG
LICENSE
PLEASE READ THIS BEFORE YOU DISTRIBUTE OR USE THIS WORK

To protect the Project Gutenberg™ mission of promoting the free


distribution of electronic works, by using or distributing this work (or
any other work associated in any way with the phrase “Project
Gutenberg”), you agree to comply with all the terms of the Full
Project Gutenberg™ License available with this file or online at
www.gutenberg.org/license.

Section 1. General Terms of Use and


Redistributing Project Gutenberg™
electronic works
1.A. By reading or using any part of this Project Gutenberg™
electronic work, you indicate that you have read, understand, agree
to and accept all the terms of this license and intellectual property
(trademark/copyright) agreement. If you do not agree to abide by all
the terms of this agreement, you must cease using and return or
destroy all copies of Project Gutenberg™ electronic works in your
possession. If you paid a fee for obtaining a copy of or access to a
Project Gutenberg™ electronic work and you do not agree to be
bound by the terms of this agreement, you may obtain a refund
from the person or entity to whom you paid the fee as set forth in
paragraph 1.E.8.

1.B. “Project Gutenberg” is a registered trademark. It may only be


used on or associated in any way with an electronic work by people
who agree to be bound by the terms of this agreement. There are a
few things that you can do with most Project Gutenberg™ electronic
works even without complying with the full terms of this agreement.
See paragraph 1.C below. There are a lot of things you can do with
Project Gutenberg™ electronic works if you follow the terms of this
agreement and help preserve free future access to Project
Gutenberg™ electronic works. See paragraph 1.E below.
1.C. The Project Gutenberg Literary Archive Foundation (“the
Foundation” or PGLAF), owns a compilation copyright in the
collection of Project Gutenberg™ electronic works. Nearly all the
individual works in the collection are in the public domain in the
United States. If an individual work is unprotected by copyright law
in the United States and you are located in the United States, we do
not claim a right to prevent you from copying, distributing,
performing, displaying or creating derivative works based on the
work as long as all references to Project Gutenberg are removed. Of
course, we hope that you will support the Project Gutenberg™
mission of promoting free access to electronic works by freely
sharing Project Gutenberg™ works in compliance with the terms of
this agreement for keeping the Project Gutenberg™ name associated
with the work. You can easily comply with the terms of this
agreement by keeping this work in the same format with its attached
full Project Gutenberg™ License when you share it without charge
with others.

1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside the
United States, check the laws of your country in addition to the
terms of this agreement before downloading, copying, displaying,
performing, distributing or creating derivative works based on this
work or any other Project Gutenberg™ work. The Foundation makes
no representations concerning the copyright status of any work in
any country other than the United States.

1.E. Unless you have removed all references to Project Gutenberg:

1.E.1. The following sentence, with active links to, or other


immediate access to, the full Project Gutenberg™ License must
appear prominently whenever any copy of a Project Gutenberg™
work (any work on which the phrase “Project Gutenberg” appears,
or with which the phrase “Project Gutenberg” is associated) is
accessed, displayed, performed, viewed, copied or distributed:
This eBook is for the use of anyone anywhere in
the United States and most other parts of the world
at no cost and with almost no restrictions
whatsoever. You may copy it, give it away or re-use
it under the terms of the Project Gutenberg License
included with this eBook or online at
www.gutenberg.org. If you are not located in the
United States, you will have to check the laws of
the country where you are located before using this
eBook.

1.E.2. If an individual Project Gutenberg™ electronic work is derived


from texts not protected by U.S. copyright law (does not contain a
notice indicating that it is posted with permission of the copyright
holder), the work can be copied and distributed to anyone in the
United States without paying any fees or charges. If you are
redistributing or providing access to a work with the phrase “Project
Gutenberg” associated with or appearing on the work, you must
comply either with the requirements of paragraphs 1.E.1 through
1.E.7 or obtain permission for the use of the work and the Project
Gutenberg™ trademark as set forth in paragraphs 1.E.8 or 1.E.9.

1.E.3. If an individual Project Gutenberg™ electronic work is posted


with the permission of the copyright holder, your use and distribution
must comply with both paragraphs 1.E.1 through 1.E.7 and any
additional terms imposed by the copyright holder. Additional terms
will be linked to the Project Gutenberg™ License for all works posted
with the permission of the copyright holder found at the beginning
of this work.

1.E.4. Do not unlink or detach or remove the full Project


Gutenberg™ License terms from this work, or any files containing a
part of this work or any other work associated with Project
Gutenberg™.
1.E.5. Do not copy, display, perform, distribute or redistribute this
electronic work, or any part of this electronic work, without
prominently displaying the sentence set forth in paragraph 1.E.1
with active links or immediate access to the full terms of the Project
Gutenberg™ License.

1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if you
provide access to or distribute copies of a Project Gutenberg™ work
in a format other than “Plain Vanilla ASCII” or other format used in
the official version posted on the official Project Gutenberg™ website
(www.gutenberg.org), you must, at no additional cost, fee or
expense to the user, provide a copy, a means of exporting a copy, or
a means of obtaining a copy upon request, of the work in its original
“Plain Vanilla ASCII” or other form. Any alternate format must
include the full Project Gutenberg™ License as specified in
paragraph 1.E.1.

1.E.7. Do not charge a fee for access to, viewing, displaying,


performing, copying or distributing any Project Gutenberg™ works
unless you comply with paragraph 1.E.8 or 1.E.9.

1.E.8. You may charge a reasonable fee for copies of or providing


access to or distributing Project Gutenberg™ electronic works
provided that:

• You pay a royalty fee of 20% of the gross profits you


derive from the use of Project Gutenberg™ works
calculated using the method you already use to
calculate your applicable taxes. The fee is owed to the
owner of the Project Gutenberg™ trademark, but he has
agreed to donate royalties under this paragraph to the
Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each
date on which you prepare (or are legally required to
prepare) your periodic tax returns. Royalty payments
should be clearly marked as such and sent to the
Project Gutenberg Literary Archive Foundation at the
address specified in Section 4, “Information about
donations to the Project Gutenberg Literary Archive
Foundation.”

• You provide a full refund of any money paid by a user


who notifies you in writing (or by e-mail) within 30 days
of receipt that s/he does not agree to the terms of the
full Project Gutenberg™ License. You must require such
a user to return or destroy all copies of the works
possessed in a physical medium and discontinue all use
of and all access to other copies of Project Gutenberg™
works.

• You provide, in accordance with paragraph 1.F.3, a full


refund of any money paid for a work or a replacement
copy, if a defect in the electronic work is discovered and
reported to you within 90 days of receipt of the work.

• You comply with all other terms of this agreement for


free distribution of Project Gutenberg™ works.

1.E.9. If you wish to charge a fee or distribute a Project Gutenberg™


electronic work or group of works on different terms than are set
forth in this agreement, you must obtain permission in writing from
the Project Gutenberg Literary Archive Foundation, the manager of
the Project Gutenberg™ trademark. Contact the Foundation as set
forth in Section 3 below.

1.F.

1.F.1. Project Gutenberg volunteers and employees expend


considerable effort to identify, do copyright research on, transcribe
and proofread works not protected by U.S. copyright law in creating
the Project Gutenberg™ collection. Despite these efforts, Project
Gutenberg™ electronic works, and the medium on which they may
be stored, may contain “Defects,” such as, but not limited to,
incomplete, inaccurate or corrupt data, transcription errors, a
copyright or other intellectual property infringement, a defective or
damaged disk or other medium, a computer virus, or computer
codes that damage or cannot be read by your equipment.

1.F.2. LIMITED WARRANTY, DISCLAIMER OF DAMAGES - Except for


the “Right of Replacement or Refund” described in paragraph 1.F.3,
the Project Gutenberg Literary Archive Foundation, the owner of the
Project Gutenberg™ trademark, and any other party distributing a
Project Gutenberg™ electronic work under this agreement, disclaim
all liability to you for damages, costs and expenses, including legal
fees. YOU AGREE THAT YOU HAVE NO REMEDIES FOR
NEGLIGENCE, STRICT LIABILITY, BREACH OF WARRANTY OR
BREACH OF CONTRACT EXCEPT THOSE PROVIDED IN PARAGRAPH
1.F.3. YOU AGREE THAT THE FOUNDATION, THE TRADEMARK
OWNER, AND ANY DISTRIBUTOR UNDER THIS AGREEMENT WILL
NOT BE LIABLE TO YOU FOR ACTUAL, DIRECT, INDIRECT,
CONSEQUENTIAL, PUNITIVE OR INCIDENTAL DAMAGES EVEN IF
YOU GIVE NOTICE OF THE POSSIBILITY OF SUCH DAMAGE.

1.F.3. LIMITED RIGHT OF REPLACEMENT OR REFUND - If you


discover a defect in this electronic work within 90 days of receiving
it, you can receive a refund of the money (if any) you paid for it by
sending a written explanation to the person you received the work
from. If you received the work on a physical medium, you must
return the medium with your written explanation. The person or
entity that provided you with the defective work may elect to provide
a replacement copy in lieu of a refund. If you received the work
electronically, the person or entity providing it to you may choose to
give you a second opportunity to receive the work electronically in
lieu of a refund. If the second copy is also defective, you may
demand a refund in writing without further opportunities to fix the
problem.
1.F.4. Except for the limited right of replacement or refund set forth
in paragraph 1.F.3, this work is provided to you ‘AS-IS’, WITH NO
OTHER WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.

1.F.5. Some states do not allow disclaimers of certain implied


warranties or the exclusion or limitation of certain types of damages.
If any disclaimer or limitation set forth in this agreement violates the
law of the state applicable to this agreement, the agreement shall be
interpreted to make the maximum disclaimer or limitation permitted
by the applicable state law. The invalidity or unenforceability of any
provision of this agreement shall not void the remaining provisions.

1.F.6. INDEMNITY - You agree to indemnify and hold the Foundation,


the trademark owner, any agent or employee of the Foundation,
anyone providing copies of Project Gutenberg™ electronic works in
accordance with this agreement, and any volunteers associated with
the production, promotion and distribution of Project Gutenberg™
electronic works, harmless from all liability, costs and expenses,
including legal fees, that arise directly or indirectly from any of the
following which you do or cause to occur: (a) distribution of this or
any Project Gutenberg™ work, (b) alteration, modification, or
additions or deletions to any Project Gutenberg™ work, and (c) any
Defect you cause.

Section 2. Information about the Mission


of Project Gutenberg™
Project Gutenberg™ is synonymous with the free distribution of
electronic works in formats readable by the widest variety of
computers including obsolete, old, middle-aged and new computers.
It exists because of the efforts of hundreds of volunteers and
donations from people in all walks of life.
Volunteers and financial support to provide volunteers with the
assistance they need are critical to reaching Project Gutenberg™’s
goals and ensuring that the Project Gutenberg™ collection will
remain freely available for generations to come. In 2001, the Project
Gutenberg Literary Archive Foundation was created to provide a
secure and permanent future for Project Gutenberg™ and future
generations. To learn more about the Project Gutenberg Literary
Archive Foundation and how your efforts and donations can help,
see Sections 3 and 4 and the Foundation information page at
www.gutenberg.org.

Section 3. Information about the Project


Gutenberg Literary Archive Foundation
The Project Gutenberg Literary Archive Foundation is a non-profit
501(c)(3) educational corporation organized under the laws of the
state of Mississippi and granted tax exempt status by the Internal
Revenue Service. The Foundation’s EIN or federal tax identification
number is 64-6221541. Contributions to the Project Gutenberg
Literary Archive Foundation are tax deductible to the full extent
permitted by U.S. federal laws and your state’s laws.

The Foundation’s business office is located at 809 North 1500 West,


Salt Lake City, UT 84116, (801) 596-1887. Email contact links and up
to date contact information can be found at the Foundation’s website
and official page at www.gutenberg.org/contact

Section 4. Information about Donations to


the Project Gutenberg Literary Archive
Foundation
Project Gutenberg™ depends upon and cannot survive without
widespread public support and donations to carry out its mission of
increasing the number of public domain and licensed works that can
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

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

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookname.com

You might also like