Instant Ebooks Textbook C Programming From Problem Analysis To Program Design 4th Edition Barbara Doyle Download All Chapters
Instant Ebooks Textbook C Programming From Problem Analysis To Program Design 4th Edition Barbara Doyle Download All Chapters
com
https://ebookgate.com/product/c-programming-from-
problem-analysis-to-program-design-4th-edition-
barbara-doyle/
https://ebookgate.com/product/java-programming-from-problem-
analysis-to-program-design-4th-edition-d-s-malik/
https://ebookgate.com/product/c-programming-from-problem-
analysis-to-program-design-5th-5th-edition-d-s-malik/
https://ebookgate.com/product/c-programming-program-design-
including-data-structures-5ed-edition-malik-d-s/
https://ebookgate.com/product/c-programming-program-design-
including-data-structures-7th-edition-d-s-malik/
C Programming Program Design Including Data Structures
6th Edition D. S. Malik
https://ebookgate.com/product/c-programming-program-design-
including-data-structures-6th-edition-d-s-malik/
https://ebookgate.com/product/fixed-income-analysis-4th-edition-
edition-barbara-s-petitt/
https://ebookgate.com/product/programming-in-objective-c-4th-
edition-stephen-kochan/
https://ebookgate.com/product/c-programming-data-structures-4th-
edition-e-balagurusamy/
https://ebookgate.com/product/reading-the-middle-ages-
from-c-900-to-c-1500-3-ed-edition-barbara-h-rosenwein/
C# PROGRAMMING:
FROM PROBLEM ANALYSIS TO PROGRAM DESIGN
FOURTH EDITION
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
This is an electronic version of the print textbook. Due to electronic rights restrictions,
some third party content may be suppressed. Editorial review has deemed that any suppressed
content does not materially affect the overall learning experience. The publisher reserves the right
to remove content from this title at any time if subsequent rights restrictions require it. For
valuable information on pricing, previous editions, changes to current editions, and alternate
formats, please visit www.cengage.com/highered to search by ISBN#, author, title, or keyword for
materials in your areas of interest.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
C# PROGRAMMING:
FROM PROBLEM ANALYSIS TO PROGRAM DESIGN
FOURTH EDITION
BARBARA DOYLE
Australia l Brazil l Japan l Korea l Mexico l Singapore l Spain l United Kingdom l United States
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
C# Programming: From Problem Analysis © 2014 Cengage Learning
to Program Design, Fourth Edition
ALL RIGHTS RESERVED. No part of this work covered by the copyright
Barbara Doyle herein may be reproduced, transmitted, stored or used in any form or
by any means graphic, electronic, or mechanical, including but not
Executive Editor: Kathleen McMahon
limited to photocopying, recording, scanning, digitizing, taping, Web
Senior Product Manager: Alyssa Pratt distribution, information networks, or information storage and
Editorial Assistant: Sarah Ryan retrieval systems, except as permitted under Section 107 or 108 of the
1976 United States Copyright Act, without the prior written permission
Content Project Manager: Jennifer Feltri-George
of the publisher.
Art Director: Cheryl Pearl, GEX
Manufacturing Planner: Julio Esperas
Cover Designer: GEX Publishing Services For product information and technology assistance, contact us at
Cover Photo: ©iurii /Shutterstock Cengage Learning Customer & Sales Support,
www.cengage.com/support
Copyeditor: Andrea Schein
Indexer: Sharon Hilgenberg For permission to use material from this text or product,
submit all requests online at cengage.com/permissions
Compositor: Integra
Further permissions questions can be e-mailed to
[email protected]
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.
Any fictional data related to persons or companies or URLs used
throughout this book is intended for instructional purposes only. At the
time this book was printed, any such data was fictional and not
belonging to any real persons or companies.
Cengage Learning reserves the right to revise this publication and
make changes from time to time in its content without notice.
The programs in this book are for instructional purposes only. They
have been tested with care, but are not guaranteed for any
particular intent beyond educational purposes. The author and the
publisher do not offer any warranties or representations, nor do they
accept any liabilities with respect to the programs.
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 Cengage Learning visit
www.cengage.com.
Purchase any of our products at your local college store or at our
preferred online store: www.cengagebrain.com
PREFACE xxi
7. Arrays 383
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
vi | C# Programming: From Problem Analysis to Program Design, Fourth Edition
GLOSSARY 1117
INDEX 1131
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
TABLE OF C ONTENTS
Preface xxi
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
viii | C# Programming: From Problem Analysis to Program Design, Fourth Edition
Main( ) Method 33
Method Body Statements 34
Compiling, Building, and Running an Application 38
Typing Your Program Statements 38
Compilation and Execution Process 39
Compiling the Source Code Using Visual Studio IDE 39
Debugging an Application 45
Syntax Errors 45
Run-time Errors 47
Creating an Application 47
Coding Standards 52
Pseudocode 52
Resources 53
Quick Review 53
Exercises 56
Programming Exercises 61
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Table of Contents | ix
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Table of Contents | xi
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
xii | C# Programming: From Problem Analysis to Program Design, Fourth Edition
ARRAYS 383
7 Array Basics 384
Array Declaration 385
Array Initializers 388
Array Access 390
Sentinel-Controlled Access 394
Using Foreach with Arrays 395
Array Class 396
Arrays as Method Parameters 401
Pass by Reference 401
Array Assignment 405
Params Parameters 406
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Table of Contents | xiii
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
xiv | C# Programming: From Problem Analysis to Program Design, Fourth Edition
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Table of Contents | xvii
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
xviii | C# Programming: From Problem Analysis to Program Design, Fourth Edition
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Table of Contents | xix
ASP.NET 986
Visual Studio for Web Development 986
ASP.NET Programming Models 987
Web Forms Page 988
Creating an ASP.NET Web Forms Site 988
Master Pages 993
Cascading Style Sheet (CSS) 997
ASP.NET Empty Web Site 1001
Controls 1004
HTML Controls 1004
HTML Server Controls 1008
Web Forms Standard Server Controls 1012
Available Web Forms Controls 1012
Web Forms Controls of the Common Form Type 1014
Adding Common Form-Type Controls 1018
Validation, Custom, and Composite Controls 1021
Validation Controls 1021
Calendar Control 1026
GridView Control 1033
AccessDataSource 1039
Using Visual Tools to Connect 1040
Setting the Visibility Property 1045
Other Controls 1047
Web Services 1050
Web Services Protocols 1050
Windows Communication Foundation (WCF) 1052
Smart Device Applications (Optional) 1052
Windows 7.x Phone 1053
Silverlight 1054
Creating a Smart Device Application for Windows 7.x Phones 1054
Windows 8 Phone Apps 1061
Creating a Windows 8 Phone App 1063
XML 1064
Code-Behind File 1065
XAML Code 1067
Running the App 1068
Deploying to an Emulator 1068
Deploying to a Device 1071
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
xx | C# Programming: From Problem Analysis to Program Design, Fourth Edition
GLOSSARY 1117
INDEX 1131
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
P REFACE
Why C#?
C# has gained tremendous popularity in the industry. 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 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 graphical 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 accommodate Internet and
Windows applications. C# is an elegant and simple object-oriented language that allows
programmers to build a breadth of applications. For these reasons, C# was chosen as the
language for this book.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
xxii | C# Programming: From Problem Analysis to Program Design, Fourth Edition
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
development techniques that can be used to build a number of advanced types of
applications including Windows, data-driven applications using a database, and Web and
mobile applications for smart devices. Generics, delegates, ArrayLists, dynamic data types,
abstract classes, interfaces, and many advanced object-oriented concepts are introduced.
Readers retrieve data from files and store data both to sequential and binary files. Solutions
involving multidimensional arrays and other advanced collection classes are demonstrated.
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 interactively capturing and responding to user input on Windows
and Web forms. Class libraries, Windows Forms applications, and Windows Presentation
Foundation client applications are created. Two full chapters are devoted to programming
based on events and then those topics are integrated throughout the remainder of the
book. Readers are introduced to ASP.NET for Web applications and ADO.NET for
working with databases.
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. A number of
visual development tools are illustrated to connect to data sources. Other interesting
topics include retrieving data using Language-Integrated Query (LINQ), developing
stand-alone .dll components (class libraries), and programming applications for mobile
devices such as tablets and smart phones. All of these advanced features are discussed
after the reader has gained a thorough understanding of the basic components found in
programming languages.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Preface | xxiii
Approach
A problem-solving methodology based on object-oriented software development is
introduced 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 specifications, designing a solution, implementing the design, and verifying or
validating the solution 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 introduced,
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, readers practice
and solidify the concepts presented by completing the end of the chapter exercises. Readers
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 as NOTES on the concepts being presented. Code snippets and numbered examples
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 Coding Standards section, which provides a summary of acceptable
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
xxiv | C# Programming: From Problem Analysis to Program Design, Fourth Edition
conventions or guidelines pertaining to the chapter’s topics that focus on style issues.
A list of Web sites for readers to explore is included in a special Resources section at
the end of each chapter. A summary of the major points covered in that chapter and
review exercises in both objective and subjective formats are included. Every chapter
contains 10 programming exercises that give readers an opportunity to experience
programming.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Preface | xxv
Readers learn to create their own classes in Chapter 4. This chapter introduces the
components of a class including the data, property, and method members. Special methods,
including constructors, are written.
Chapters 5 and 6 introduce control structures that alter the sequential flow of execution.
Selection control constructs are introduced in Chapter 5. One-way, multiway, switch, and
ternary operators used to make decisions are illustrated. Looping is introduced in Chapter 6.
The rich set of iteration operators including while, for, do while, and foreach are
explored. Recursive solutions are also explored.
Chapter 7 discusses arrays. This chapter describes how to declare and perform compile-time
initialization of array elements. The Array class and its many members are introduced.
Methods of the string and ArrayList classes are included in Chapter 8. Multidimensional
arrays and other collection classes, including stacks, queues, and hash tables are also
introduced in Chapter 8.
Chapters 9 and 10 present a different way of programming, which is based on interactively
responding to events. A number of classes in the FCL that are used to create Windows
applications are introduced. Elements of good design are discussed in Chapter 9. Delegates
are also explored in Chapter 9. Visual Studio’s drag-and-drop approach to rapid application
development is introduced and used in these chapters. The Windows Presentation Foundation
(WPF) is also introduced in Chapter 10 as an alternative approach to Windows Forms for
creating Windows applications.
Advanced object-oriented programming features are the focus of Chapter 11. Readers are
introduced to component-based development and learn how to create their own class library
files. Inheritance, interfaces, abstract classes, sealed classes, generic types, partial classes, and
polymorphic programming are discussed in detail. Advanced features such as overriding,
overloading, and the use of virtual methods are also included in Chapter 11. Static versus
dynamic typing is also investigated in Chapter 11.
Chapter 12 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
run-time 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 discussing .NET
exception classes, custom exceptions are designed.
Chapter 13 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 14
introduces a number of new namespaces collectively called ADO.NET, which consists of a
managed set of library classes that enables interaction 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 Language-Integrated Query (LINQ) is also introduced in
Chapter 14.
The focus of Chapter 15 is on Web applications. Readers explore how the design of Web-
based applications differs from Windows applications. They discover the differences between
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
xxvi | C# Programming: From Problem Analysis to Program Design, Fourth Edition
static and dynamic Web pages and how HTML and Web server controls differ. Master pages
and Cascading Style Sheets are introduced. Also included in Chapter 15 is an introduction to
mobile applications that can be viewed with small smart devices such as the Windows Phone.
Chapter 15 illustrates how validation controls can be used to check users’ input values and
shows how the ADO.NET classes, introduced in Chapter 14, can also be used with Web
applications to access database records.
Appendix A presents suggestions for customizing the appearance and behavior of the
Integrated Development Environment (IDE). Appendix B discusses the Code Editor
features of Visual Studio. Code snippets and refactoring are described. These new features
improve programmer productivity by reducing the number of keystrokes required to enter
program statements. This appendix also illustrates developing applications visually using class
diagrams. Appendix C lists the Unicode and ASCII (American Standard Code for Information
Interchange) character sets. Appendix D shows the precedence of the C# operators and
Appendix E lists the C# keywords.
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.
l Multi-color interior design shows accurate C# code and related comments.
l Learning objectives offer an outline of the concepts discussed in detail in the chapter.
l Hundreds of visual diagrams throughout the text illustrate difficult concepts.
l Syntax boxes show the general form for different types of statements.
l 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.
l Notes highlight important facts about the concepts introduced in the chapter.
l Numerous tables are included that describe and summarize information compactly for
easy viewing.
l A Coding Standards section provides a summary of acceptable conventions or guidelines
pertaining to the chapter’s topic. These coding/programming guidelines help ensure
consistency and reduce the number of bugs and errors entered into programming projects.
l Internet sites listed including tutorials that can be used to enhance concepts are
presented in the Resources section.
l 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.
l Quick Reviews offer a summary of the concepts covered in the chapter.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Preface | xxvii
l Exercises further reinforce learning and ensure that students have, in fact, absorbed the
material. Both objective and subjective types of questions are included at the end of
each chapter.
l Programming Exercises challenge students to write C# programs with a specified
outcome.
l The glossary at the end of the book lists nearly four-hundred key terms in alphabetical
order along with definitions for easy reference. Throughout this text the terms set in
bold indicate that they are defined in the glossary.
From beginning to end, the concepts are introduced at a pace that is conducive to learning.
The writing style of this book is simple and straightforward, and it parallels the teaching style of
a classroom. The concepts introduced are described using examples and small programs.
The chapters have two types of programs. The first type includes small programs that are part
of the numbered examples and are used to explain key concepts. This book also features
numerous case studies called Programming Examples. These Programming Examples are
placed at the end of the chapters to pull together many of the concepts presented
throughout the chapter. The programs are designed to be methodical and workable. Each
Programming Example starts with a Problem Analysis and is then followed by the Algorithm
Design. Every step of the algorithm is then coded in C#. In addition to teaching problem-
solving techniques, these detailed programs show the user how to implement concepts in an
actual C# program. Students are encouraged to study the Programming Examples very
carefully in order to learn C# effectively.
All source code and solutions have been written, compiled, and tested by quality assurance
with Visual Studio Professional 2012.
Microsoft Visual C# can be packaged with this text. Please contact your Course
Technology Sales Representative for more information.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
FEATURES OF THE BOOK
Numerous visual
diagrams
throughout the
text illustrate
difficult concepts.
Updated screen
shots of what
readers see in
Visual Studio are
also included
throughout the
book.
Multi-color
interior design
shows accurate
C# code and
related
comments.
Throughout the
book, keywords
are shown in blue
and comments
appear in green.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Syntax boxes
show the general
form for different
types of
statements.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Notes provide short quick
tips highlighting important
concepts and features that
might be overlooked.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
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.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Programming
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
implementation.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Coding/programming
style guidelines and
suggestions are
featured at the end
of each chapter.
A special Resources
section at the end of
each chapter offers a
number of Web sites
for the reader to
explore.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Exercises further
reinforce learning
and ensure that
students have, in
fact, absorbed the
material. Both
objective and
subjective types of
activities are
included at the end
of each chapter.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Programming
Exercises challenge
students to write C#
programs with a
specified outcome.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
xxxvi | C# Programming: From Problem Analysis to Program Design, Fourth Edition
Instructor Resources
The following teaching tools are available for download at our Instructor Companion Site.
Simply search for this text at login.cengage.com. An instructor login is required.
Electronic Instructor’s Manual. The Instructor’s Manual that accompanies this textbook
includes additional instructional material to assist in class preparation, including suggestions for
lecture topics.
ExamView. This textbook is accompanied by ExamView, a powerful testing software
package that allows instructors to create and administer 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. These computer-based and Internet-testing components allow
students to take exams at their computers, and save the instructor time because each exam is
graded automatically.
PowerPoint Presentations. This book comes with Microsoft PowerPoint slides for each
chapter. These are included as a teaching aid for classroom presentations, either to make
available to students on the network for chapter review, or to be printed for classroom
distribution. Instructors can add their own slides for additional topics that they introduce to
the class.
Source Code for Examples. The complete Visual Studio project files for the examples
included within each chapter are available for instructors and are also posted for students on
www.cengagebrain.com. Individual source code files are stored with a .cs extension inside the
project subdirectory.
Programming Exercises Solution Files. The complete Visual Studio project files for the
solutions to all programming exercises included at the end of the chapters are provided. The
individual source code files are stored with a .cs extension inside the project subdirectory.
Acknowledgments
I would like to express my gratitude for the opportunity to complete the fourth edition of this
book. Like the other editions, it was a huge undertaking for me. Special thanks go out to
Alyssa Pratt, Senior Product Manager at Cengage Learning, for her positive comments,
guidance, and support. She was a pleasure to work with again on this new edition. I am
grateful to the Quality Assurance team members who verified that each of the examples and
exercise solutions worked properly. Also thanks to the Content Manager and Copy Editor,
Jennifer Feltri-George and Andrea Schein, who provided great suggestions as we progressed
with the project.
I am very grateful to the following reviewers for their uplifting comments and suggestions for
improvements:
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Preface | xxxvii
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Neale Cousland / Shutterstock.com
CHAPTER
1
I NTRODUCTION TO
COMPUTING AND
P ROGRAMMING
I N T H I S C H A P T E R , YO U W I L L :
Computers have penetrated every aspect of our society and have greatly simplified many
tasks. Can you picture yourself typing a paper on an electric typewriter? Would you use an
eraser to make your corrections? Would you start from scratch to increase or decrease
your margins or line spacing? Can you imagine living in an age without electronic
messaging or e-mail capability? What would you do without an automatic teller machine
(ATM) in your neighborhood?
Computers have become such an integral part of our lives that many of their functions are
taken for granted. Yet, only a few years ago, mobile apps, text messaging and cloud
computing were unknown. Social media technologies like internet forums, weblogs,
wikis, podcasts and social networks like Facebook were unknown. In 2012 social media
became one of the most powerful sources for news updates through platforms like Twitter
and Facebook. Advances in computing are occurring every day, and the programs that are
loaded on your computer have become very complex. The technology of wireless
communication is advancing quickly. Expectations are that tablet sales will grow by 200
percent through 2016. Over 100 million units will be sold in 2012. For most consumers,
tablets are not replacements for their conventional computers, but are added devices
they’ll purchase. Mobile applications for smartphones, pocket and tablet PCs, and other
handheld wireless computers are increasingly in demand. To reach this level of
complexity, software development has gone through a number of eras, and today
technical advances accumulate faster and faster. What new types of computer services
and programs will be integral to our daily lives in the future? This book focuses on
creating software programs. Before beginning the journey into software development, a
historical perspective on computing is included to help you see the potential for
advancements that awaits you.
History of Computers
Computing dates back some 5000 years. Many consider the abacus to be the first computer.
Used by merchants of the past and present for trading transactions, the abacus is a calculating
device that uses a system of sliding beads on a rack for addition and subtraction.
In 1642, another calculating device, called the Pascaline, was created. The Pascaline had
eight movable dials on wheels that could calculate sums up to eight figures long. Both the
abacus and Pascaline could perform only addition and subtraction. It was not until the
1830s that the first general-purpose computer, the Analytical Engine, was available.
Charles Babbage and his assistant, Lady Augusta Ada Bryon, Countess of Lovelace,
designed the Analytical Engine. Although it was very primitive by today’s standards, it
was the prototype for what is known today as a general-purpose computer. The Analytical
Engine included input devices, memory storage, a control unit that allowed processing
instructions in any sequence, and output devices.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
History of Computers | 3
In the 1980s, the U.S. Defense Department named the Ada programming language in honor 1
of Lady Lovelace. She has been called the world’s first programmer. Controversy surrounds
her title. Lady Byron was probably the fourth or fifth person to write programs. She did
programming as a student of Charles Babbage and reworked some of his calculations.
Many computer historians believe the present day to be in the fifth generation of modern
computing. Each era is characterized by an important advancement. In the mid-1940s, the
Second World War, with its need for strategic types of calculations, spurred on the first
generation of general-purpose machines. These large, first-generation computers were
distinguished by the use of vacuum tubes. They were difficult to program and limited in
functionality. The operating instructions were made to order for each specific task.
The invention of the transistor in 1956 led to second-generation computers, which were
smaller, faster, more reliable, and more energy efficient than their predecessors. The
software industry was born during the second generation of computers with the
introduction of FORTRAN and COBOL.
The third generation, 1964–1971, saw computers become smaller, as transistors were
squeezed onto small silicon discs (single chips), which were called semiconductors.
Operating systems, as they are known today, which allowed machines to run many
different programs at once, were also first seen in third-generation systems.
As time passed, chips kept getting smaller and capable of storing more transistors, making
computers more powerful and less expensive. The Intel 4004 chip, developed in 1971,
placed the most important components of a computer (central processing unit, memory,
and input and output controls) on a minuscule chip about half the size of a dime. Many
household items such as microwave ovens, television sets, and automobiles benefited from
the fourth generation of computing.
During the fourth generation, computer manufacturers tried to bring computing to
general consumers. In 1981, IBM introduced its personal computer (PC). The 1980s
saw an expansion in computer use as clones of the IBM PC made the personal computer
even more affordable. We also saw the development of Graphical User Interfaces (GUIs)
and the mouse as a handheld input device. The number of personal computers in use more
than doubled from two million in 1981 to 5.5 million in 1982. Ten years later, 65 million
PCs were in use.
According to the October 2010 U.S. Census Bureau’s Current Population Survey, released
in July 2012, over 76% of households in the United States had computers.
Defining a fifth generation of systems is somewhat difficult because the generation is still
young. Computers can now accept spoken word instructions, imitate human reasoning
through artificial intelligence, and communicate with devices instantaneously around the
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
4 | Chapter 1: Introduction to Computing and Programming
globe by transmitting digital media. Mobile apps are growing. By applying problem-
solving steps, expert systems assist doctors in making diagnoses. Healthcare professionals
are now using handheld devices in patients’ rooms to retrieve and update patient records.
Using handheld devices, drivers of delivery trucks are accessing global positioning systems
(GPS) to verify locations of customers for pickups and deliveries. Sitting at a traffic light,
you can check your e-mail, make airline reservations, remotely monitor and manage
household appliances, and access your checking and savings accounts. Using wireless
networks, students can access a professor’s notes when they enter the classroom.
Major advances in software are anticipated as integrated development environments
(IDEs) such as Visual Studio make it easier to develop applications for the Internet
rapidly. Because of the programmability of the computer, the imagination of software
developers is set free to conjure the computing functions of the future.
The real power of the computer does not lie in the hardware, which comprises the
physical components that make up the system. The functionality lies in the software
available to make use of the hardware. The hardware processes complex patterns of 0s and
1s. The software actually transposes these 0s and 1s into text, images, and documents that
people can read. The next section begins the discussion on software.
System Software
System software is loaded when you power on the computer. When thinking of system
software, most people think of operating systems. Operating systems such as Windows 8,
Android, iOS, Windows 7, and Linux are types of programs that oversee and coordinate the
resources on the machine. Included are file system utilities, small programs that take care of
locating files and keeping up with the details of a file’s name, size, and date of creation.
System software programs perform a variety of other functions: setting up directories;
moving, copying, and deleting files; transferring data from secondary storage to primary
memory; formatting media; and displaying data on screens. Operating systems include
communication programs for connecting to the Internet or connecting to output devices
such as printers. They include user interface subsystems for managing the look and feel of
the system.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
System and Application Software | 5
Operating systems are one type of system software. They are utility programs that make it 1
easier for you to use the hardware.
Another type of system software includes compilers, interpreters, and assemblers. As you
begin learning software development, you will write instructions for the computer using a
programming language. Modern programming languages are designed to be easy to
read and write. They are called high-level languages because they are written in
English-like statements. The programming language you will be using is C#
(pronounced see sharp). Other high-level computer programming languages include
Visual Basic, FORTRAN, Pascal, C, C++, and Java.
Before the computer can execute the instructions written in a programming language such
as C#, the instructions must be translated into machine-readable format. A compiler
makes this conversion. Figure 1-1 shows what a machine language instruction looks like.
Just as the English language has rules for sentence construction, programming languages
such as C# have a set of rules, called syntax, that must be followed. Before translating
code into machine-readable form, a compiler checks for rule violations. Compilers do not
convert any statements into machine language until all syntax errors are removed. Code
can be interpreted as well as compiled. Intepreters translate one statement of code into
machine-readable form and then they execute that line. They then translate the next
instruction, execute it, and so on. Unlike compilers, which look at entire pieces of code,
interpreters check for rule violations line by line. If the line does not contain an error, it
is converted to machine language. Interpreters are normally slower than compilers. Many
languages offer both compilers and interpreters, including C, BASIC, Python, and Lisp.
Assemblers convert the assembly programming language, which is a low-level
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
6 | Chapter 1: Introduction to Computing and Programming
programming language, into machine code. Low-level programming languages are closer
to hardware. They are not as easy to read or write as high-level programming languages.
Application Software
Application software consists of programs developed to perform a specific task. The
games you might play or the search engines you use on the Internet are types of
application software. Word processors, such as Microsoft Word, are examples of
application software. Word was written to help users create professional looking
documents by including a number of editing and formatting options. Spreadsheets, such
as Microsoft Excel, are types of application software designed to make numerical
calculations and generate charts. Database management systems, such as SQL Server,
Oracle, or Microsoft Access, were designed to organize large amounts of data, so that
reports could easily be generated. Software that generates payroll checks is considered
application software, as is software that helps you register for a class. E-commerce Web
sites with database-driven shopping carts, such as eBay, are forms of application software.
Application software is used by the banking industry to manage your checking and saving
accounts. Programmers use programming languages such as C# to write application
software to carry out specific tasks or to solve specific problems. The programs that you
write from this book will be application software.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Software Development Process | 7
Sometimes one of the most difficult parts of the process is getting clear specifications
from the user. Unless you know what the problem is, there is no way you can solve it. Make
sure you understand the problem definition.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
8 | Chapter 1: Introduction to Computing and Programming
Specialty-sports
$31.95
$41.95 $49.95
$59.95
During this first phase, in addition to making sure you understand the problem definition,
you must also review the program inputs. You should ask the following types of questions:
l What kind of data will be available for input?
l What types of values (e.g., whole numbers, alphabetic characters, and
numbers with a decimal point) will be in each of the identified data items?
l What is the domain (range of the values) for each input item?
l Will the user of the program be inputting values?
l If the problem solution is to be used with multiple data sets, are there any
data items that stay the same, or remain constant, with each set?
Before you move to designing a solution, you should have a thorough understanding of
the problem. It might be helpful to verbalize the problem definition. It might help to see
sample input for each of the data items. Figure 1-4 illustrates how the input data items
would be determined during analysis for the car rental agency problem shown in Figure 1-3.
Figure 1-4 shows the identifier, or name of the data item, the type, and the domain of
values for each item.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Software Development Process | 9
Instead of having the user enter the full words of Economy, Intermediate, Full size, or
Speciality Sports, the characters E, I, F, and S could be mapped to those categories. 1
char
(single coded E, I, F, or S
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
10 | Chapter 1: Introduction to Computing and Programming
Figure 1-5 is a class diagram divided into three sections with the top portion
identifying the name of the class. The middle portion of a class diagram
always lists the data characteristics. Data representing the type of vehicle to
rent and the number of days for the rental are important to a rental car
agency. The bottom portion of the class diagram shown in Figure 1-5 shows
what actions are to be performed with the data items. ComputeCharges( )
is used to determine the cost of the rental using the type of vehicle and the
number of rental days. You will learn more about class diagrams later in this
chapter. Procedural designs, which are appropriate for simpler problem
definitions, use structure charts to show the hierarchy of modules, and
flowcharts or pseudocode listings to detail the steps for each of the modules.
Algorithms for the behaviors (object oriented) or processes (procedural)
should be developed for both of these methodologies. An algorithm is a
clear, unambiguous, step-by-step process for solving a problem. These
steps must be expressed so completely and so precisely that all details are
included. The instructions in the algorithm should be both simple to
perform and capable of being carried out in a finite amount of time.
Following the steps blindly should result in the same results every time.
An algorithm for ComputeCharges( ) multiplies the number of rental
days by the rate associated with the type of vehicle rented to produce the
rental charge. After the algorithm is developed, the design should be
checked for correctness. One way to do this is to use sample data and
desk check your algorithms by mimicking the computer; in other words,
walking through the computer’s steps. Follow each step precisely, one step
at a time. If the problem involves calculations, use a calculator, and follow
your design statements exactly. It is important when you desk check not
to add any additional steps, unless you go back and revise the algorithm.
During this phase, it might also be helpful to plan and design the look of
the desired output by developing a prototype. A prototype is a mock-up
of screens depicting the look of the final output.
3. Code the solution. After you have completed the design and verified
that the algorithm is correct, you translate the design into source code.
Copyright 2013 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Another random document with
no related content on Scribd:
The Project Gutenberg eBook of Sink or swim?
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.
Language: English
SINK OR SWIM?
A Novel.
BY THE AUTHOR OF
“RECOMMENDED TO MERCY,”
ETC.
IN THREE VOLUMES.
VOL. III.
LONDON:
TINSLEY BROTHERS, 18 CATHERINE ST. STRAND.
1868.
LONDON:
ROBSON AND SON, GREAT NORTHERN PRINTING WORKS,
PANCRAS ROAD, N.W.
CONTENTS OF VOL. III.
CHAP. PAGE
I. “He comes too near,” etc. 1
II. A Lover found and lost 21
III. What was Honor doing? 36
IV. Mrs. Beacham writes a Letter 46
V. Honor turns rebellious 54
VI. What, sell Rough Diamond! 62
VII. Mea culpa 77
VIII. John Beacham makes a Discovery 87
IX. John proves his Right 104
X. “As well as can be expected” 111
XI. From lively to severe 119
XII. Mrs. Beacham refuses to forget 131
XIII. Arthur cheers up 136
XIV. Arthur finds himself done 146
XV. Misfortunes never come singly 154
XVI. Out at Sea 164
XVII. Honor makes a new Acquaintance 188
XVIII. John discovers his Loss 202
XIX. Another Escape 208
XX. Poor Sophy! 216
XXI. Suspense 227
XXII. John gives way 237
XXIII. Honor receives a Letter 243
XXIV. The Uses of Adversity 259
XXV. Conclusion 274
SINK OR SWIM?
CHAPTER I.
Once in the large comfortable wherry which had been hired for the
occasion, Arthur found very little opportunity, beyond that of paying the
most devoted attention to her personal comfort, of making himself
agreeable to his lady-love. That there was one subject, at least, besides
herself of real and almost absorbing interest to Arthur Vavasour soon
became evident to Honor; and that subject was the approaching Derby race.
Since her instalment in Stanwick-street, Honor had heard more talk of that
all-important annual event than—horse-breeder’s wife though she was—she
had listened to through all the many months of her married life; and
naturally enough, seeing that the “favourite” was her father’s property, and
that Arthur Vavasour appeared deeply interested in the triumph of Rough
Diamond, the success of that distinguished animal became one of the most
anxious wishes of Mrs. John Beacham’s heart.
“O, I do so hope he’ll win!” she exclaimed enthusiastically; “he is such a
wonderfully beautiful creature. And he has a brother who, they think, will
be more perfect still;—no, not a brother quite, a half-brother, I think he is;
and I used to watch him every day led out to exercise, looking so wild and
lovely. He is only a year old, and his name is Faust; and they say he is quite
sure to be a Derby horse.”
Poor Honor! In her eagerness on the subject, and her intense love of the
animal whose varied charms and excellences were to be seen in such
perfection in her husband’s home, she had been inadvertently “talking
shop” for the amusement of the spurious fine ladies, whose supercilious
glances at each other were not, even by such a novice as Honor Beacham,
to be mistaken. In a moment—for the poison of such glances is as rapid as
it is insidious—two evil spirits, the spirits of anger and of a keen desire to
be avenged, took possession of our heroine. She saw herself despised, and
—so true is it that we cannot scarcely commit the smallest sin without
doing an injury as well to our neighbours as to ourselves—she resolved, to
the utter extinction of the very inferior beauties near her, to make the most
of the wondrous gift of loveliness which she was conscious of possessing.
Hitherto she had “borne her faculties meekly;” the consciousness that she
was, by marriage, without the pale of the “upper ten thousand” had,
together with an innate modesty which was one of her rarest charms, kept
her silent and somewhat subdued when in what is called “company.” It had
required the looks of contempt which she had seen passing between the
well-got-up sisters to rouse the spirit of display in Honor Beacham’s heart;
but, once aroused, the intoxication of success encouraged her to proceed,
and the demon of Coquetry was found hard indeed to crush.
The row, slow and dreamy, up-stream to Teddington-lock, would, even
had there been no unlawful and much-prized lover—of whom, explain it as
you will, Honor was more than half afraid—by her side, have been simply
delightful. The river was so purely clear that the water-weeds beneath its
pellucid surface showed brightly, freshly green; and then the long low islets,
with the graceful willow-boughs, vivid with the hues of early spring,
dipping their last-opened buds into the laving stream, and the banks,
verdant and fair, and cattle-sprinkled—all combined to make a Breughal-
like picture of spring verdure and beauty.
Notwithstanding a certain amount of horsey conversation, flirting, covert
as well as open, was the order of the afternoon. Both Mrs. Foley and her
sister were adepts at that truly feminine and easily-acquired
accomplishment. To look the thing they meant not, to understand or not
understand the ingenious double entendre, to give the little hope that
hinders from despair, and only the little hope, lest the excited lover should
presume, were arts in which ces dames, the unprofessional demi-monde of
gay middle life, were thoroughly skilled. It required more audacity than
Honor would have previously believed that she possessed to cope with
rivals such as these, but, champagne aidant, she got through the female
duty well; and the dinner which succeeded the aquatic excursion owed not a
little of its success to the lively spirits lending added charms to the powerful
influence of beauty.
The hour of ten had struck by the town clocks, and the many wine-
bottles on the table of No. 3 room were near to emptying, before it occurred
to any of the party therein assembled that the night was fine and warm and
starlight, and that in the gardens of the hotel a fresher, purer air could be
imbibed than that which reminded them somewhat too forcibly of the good
things they had been imbibing.
At a conjugal hint from the Colonel, his watchful and obedient wife
suggested that the moon had risen, and was looking lovely over the river. A
turn on the terrace would be delightful, she thought; and as her proposal
met with no opposition, they made themselves an impromptu drawing-room
under the starry canopy of heaven.
“What a lovely night! how glad I am to have seen this! The moonlight
never looked to me so soft and beautiful before!”
“Never? I am glad of that,” Arthur said, his face very near to Honor’s as
they leant over the stone balustrade and gazed out upon the tranquil scene.
“I may hope then that, for a little while at least, the memory of this night
will linger with you. It is a day that I at least shall find it very hard to forget.
You smile and shake your head. Perhaps you take me for one who knows
nothing of his own mind,—one whom a fresh face can stir into new and
soon-to-be-changed feelings. But, Honor, listen to me—listen while we
have these few moments we can call our own. I tell you that the love I feel
for you is one that will defy all time and space and change. You have never
been loved, my beautiful one, with such a love as this. You would tell me,
were you not an angel, and too pure and good for such a world as this, that
your husband—”
“Hush, hush! please don’t; I cannot bear to hear you speak of him, Mr.
Vavasour,—well, well, Arthur—I know I have been very weak and wicked;
but for my own folly you would never have—have told me that you loved
me; and indeed I did not mean—I—”
He seized both her little hands in his strong grasp, and held them there as
in a vice.
“Honor,” he whispered,—and his voice trembled with concentrated
passion,—“are you going to tell me that I have been a blundering fool, and
that I have mistaken every look and word and smile that led me on to love
you? If so,—but no, I cannot, will not think it possible. Long ago, my
darling,”—and his voice softened into entreaty,—“long ago, when first I
held this precious hand in mine, you might, with cold words and scanty
smiles, have taught me”—and he smiled bitterly—“my place. But that you
did not do, Honor: you know you did not. What your motive was in leading
me on to hope that I was something—a very little—more to you than a
mere acquaintance, you best can say. If it were well meant on your part, all I
can say is that it was cruel kindness; for it will be a hard fall down again to
the place from which your gentle words and smiles had raised me. But once
more, Honor, for the love of Heaven, tell me that you have not trifled with
me. Do not make me lose my faith in every woman. Tell me before we part
to-night that if we were doomed never to meet again you would sorrow a
little, just a very little, for my loss. Tell me that sometimes, when you are
alone, you think of me; tell me”—and he ventured unreproved to steal his
arm round her waist—“tell me that you love me just a very little, Honor, in
return for the heart’s whole devotion that I feel for you.”
Her bosom heaved, and her heart beat very quickly, under the strong firm
pressure of his hand; but for all that—and perhaps some of my readers may
understand the anomaly—the strongest feeling in Honor Beacham’s mind at
that important crisis was one of relief that she was not alone with her
adorer. And yet in one sense she loved him. His touch, his lingering gaze
into the depths of her blue eyes, exercised—and never more so than at that
moment—a strange magnetic influence over her nerves. She could ill have
borne a decree that banished Arthur Vavasour from her society, and yet she
felt that he was to play no actual part in the misty future of her life—the life
which she never doubted she was to spend with John; the life that might be
a tolerably happy one when Mrs. Beacham was gathered—not to her
forefathers, but to the place allotted to her by her dead husband’s side.
Honor, to do her justice, never imagined an existence apart from her
husband. She was not happy at home; the life there was unsuited to her, and
John, she believed, did not love her well enough to care whether his mother
tormented her or not. In London, on the contrary, she did enjoy herself,
wildly, feverishly, but with a zest and an impulse that had nothing in it that
was natural or lasting. When the day came, she longed for the hour which
should bring Arthur Vavasour to her side; but with the longing came a kind
of nervous dread—a fear of his impatience, an alarm as of a hunted animal
at the thought of finding herself within his power—all which symptoms
might have told a more experienced woman that in her love for Arthur
Vavasour there was an alloy which, had he imagined its existence, would
have deprived the longing for possession of more than half its value.
It is often a misfortune to all parties concerned that the same symptoms
are indicative of various and opposite complaints. A blush is as often a sign
of innocence as of guilt; and a beating heart beneath a visibly agitated
bosom may be a token of other emotions besides the tender one of love.
When Arthur felt the throbbing pulse bounding beneath the pressure of
his hand, he never doubted that, had he been tête-à-tête with that most
peerless creature, she would have gladly sighed her love out on his breast,
listening in tender ecstasy to his vows of eternal constancy. Nearer and
nearer, happy in this blessed conviction, to his heart he held her, secured
from observation in a shadowy corner, and safe under the protection of the
remainder of the party, who lingered just out of earshot on the terrace.
Honor, afraid of offending her high-born lover, and sincerely hoping that
never—never under less safe and satisfactory circumstances might a similar
scene be enacted, contrived to stammer out the foolish, false, and guilty
assurance,—an assurance that filled the young lover’s heart with the wildest
hopes—the assurance, namely, that her heart was his, and that in his love
she found her dearest, sweetest happiness!
CHAPTER II.