100% found this document useful (8 votes)
322 views

Download C Programming From Problem Analysis to Program Design 2nd Edition Barbara Doyle ebook All Chapters PDF

Program

Uploaded by

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

Download C Programming From Problem Analysis to Program Design 2nd Edition Barbara Doyle ebook All Chapters PDF

Program

Uploaded by

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

Get ebook downloads in full 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

DOWNLOAD EBOOK

Explore and download more ebook at https://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/

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/

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/

Advances in Imaging and Electron Physics 141 1st


Edition Peter Hawkes (Eds.)

https://ebookname.com/product/advances-in-imaging-and-electron-
physics-141-1st-edition-peter-hawkes-eds/
Divided by Borders Mexican Migrants and Their Children
1st Edition Joanna Dreby

https://ebookname.com/product/divided-by-borders-mexican-
migrants-and-their-children-1st-edition-joanna-dreby/

Oxford Reading Tree Level 3 More Songbirds Phonics Stop


Chatting Bill Julia Donaldson

https://ebookname.com/product/oxford-reading-tree-level-3-more-
songbirds-phonics-stop-chatting-bill-julia-donaldson/

Kase on Technical Analysis Workbook Video Course


Trading and Forecasting 1st Edition Cynthia Kase

https://ebookname.com/product/kase-on-technical-analysis-
workbook-video-course-trading-and-forecasting-1st-edition-
cynthia-kase/

Bench to Bedside Microbiology for Clinicians First


Edition Khardori

https://ebookname.com/product/bench-to-bedside-microbiology-for-
clinicians-first-edition-khardori/

Risky Transactions Trust Kinship and Ethnicity 1st


Edition Frank K. Salter (Editor)

https://ebookname.com/product/risky-transactions-trust-kinship-
and-ethnicity-1st-edition-frank-k-salter-editor/
Elementary Number Theory and Its Applications 5th
edition Instructor s Solutions Manual Kenneth H. Rosen

https://ebookname.com/product/elementary-number-theory-and-its-
applications-5th-edition-instructor-s-solutions-manual-kenneth-h-
rosen/
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.
Preface xxv

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.
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 numer-
ous 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 tech-
niques, 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 and Visual C# Standard Edition, using both Windows 2000
and Windows XP.
Microsoft® Visual C# ® can be packaged with this text. Please contact your Course Technology
Sales Representative for more information.

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

Figure 4-10 Call by reference versus value

Numerous visual diagrams throughout the text illustrate


difficult concepts.

switchƒ(expression)
{
ƒƒƒƒcaseƒvalue1:ƒƒstatement(s);
ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒbreak;
ƒƒƒƒcaseƒvalue2:ƒƒstatement(s);
ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒbreak;
ƒƒƒƒƒƒƒƒƒƒƒƒƒƒ.ƒ.ƒ.
ƒƒƒƒcaseƒvalueN:ƒƒstatement(s);
ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒbreak;
ƒƒƒ[default:ƒƒƒƒƒƒstatement(s);
ƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒƒbreak;]
}

Syntax boxes show the general form for different types


of statements.

Copyright 2008 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
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.

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.

Copyright 2008 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
QUICK REVIEW
1. An array may contain any number of variables of the same type. One common identi-
fier names the entire structure.
2. The individual variables in the array are called the elements of the array.
3. To access an array element, use an index enclosed in square brackets.The index (or
subscript) references the location of the variable relative to the beginning location.The
first index is always zero.

Quick Reviews offer a summary of the concepts covered in


the chapter.

PROGRAMMING EXERCISES
1. Write a program that generates 100 random numbers between 0 and 1000. Display
the number of even values generated as well as the smallest, largest, and the range of
values. Output should be displayed in a Windows message box.
2. Prompt the user for the length of three line segments as integers. If the three lines
could form a triangle, print the integers and a message indicating they form a triangle.
Recall that the sum of the lengths of any two sides must be greater than the length of
the third side in order to form a triangle. For example, 20, 5, and 10 cannot be the
lengths of the sides of a triangle because 5 + 10 is not greater than 20. For line seg-
ments that do not form a triangle, print the integers and an appropriate message indi-
cating no triangle can be created. Use a state-controlled loop to allow users to enter as
many different combinations as they like.
3. Write a program to calculate the average of all scores entered between 0 and 100. Use
a sentinel-controlled loop variable to terminate the loop. After values are entered and
the average calculated, test the average to determine whether an A, B, C, D, or F
should be recorded.The scoring rubric is as follows:
A—90-100; B—80-89; C—70-79; D—60-69; F < 60.

Programming Exercises challenge students to write C# programs


with a specified outcome.

Copyright 2008 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
EXERCISES
1. The value contained within the square brackets that is used to indicate the length of
the array must be a(n):
a. class
b. double
c. string
d. integer
e. none of the above
2. Which of the following would be the best declaration for an array to store the high
temperature for each day of one full week?
a. int temp1, temp2, temp3, temp4, temp5, temp6, temp7;
b. int temp [7] = new int [7];
c. temp int [ ] = new temp[7];
d. int [ ] temp = new temp [7];
e. int [ ] temp = new temp [8];
3. Assume an array called num is declared to store four elements.Which of the following
statements correctly assigns the value 100 to each of the elements?
a. for(x = 0; x < 3; ++x) num [x] = 100
b. for(x = 0; x < 4; ++x) num [x] = 100;
c. for(x = 1; x < 4; ++x) num [x] = 100;
d. for(x = 1; x < 5; ++x) num [x] = 100;
e. none of the above

Exercises further reinforce learning and ensure that students have,


in fact, absorbed the material.

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

TEACHING TOOLS
The following supplemental materials are available when this book is used in a classroom set-
ting.All of the teaching tools available with this book are provided to the instructor on a sin-
gle CD-ROM.
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 ref-
erences for further review.These computer-based and Internet testing components allow stu-
dents 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 avail-
able to students on the network for chapter review, or to be printed for classroom distribu-
tion. Instructors can add their own slides for additional topics that they introduce to the class.
Distance Learning. Course Technology is proud to present online courses in WebCT and
Blackboard to provide the most complete and dynamic learning experience possible.When
you add online content to one of your courses, you’re providing a gateway to the 21st cen-
tury’s most important information resource.We hope you will make the most of your course,
both online and offline. For more information on how to bring distance learning to your
course, contact your local Course Technology sales representative.
Examples Source Code. The complete Visual Studio project files for the examples
included within each chapter are available at www.course.com, and are also available on the
Teaching Tools CD-ROM. The 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 chapter are available at
www.course.com , and are also available on the Teaching Tools CD-ROM.The individual
source code files are stored with a .cs extension inside the project subdirectory.

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

ACKNOWLEDGEMENTS
I would like to express my gratitude for the opportunity to complete the second edition of
this book. Like the first edition, it was a huge undertaking for me. Special thanks go out to
Alyssa Pratt, Senior Product Manager at Thomson, for her positive comments, guidance, and
support. She was a pleasure to work with throughout the project. I am grateful to Nicole
Ashton and the other Quality Assurance team members who verified that each of the exam-
ples and exercise solutions worked properly. Also thanks to the Content Manager, Pam Eliz-
ian. Pam joined the project late, but worked many nights and weekends to keep the project
on time.
Thanks go out to a number of my students for their involvement in the project, in particular
Corey Kelly for reading the manuscript and solving the programming exercises at the end of
chapters.
I am very grateful to the following reviewers for their uplifting comments and suggestions
for improvements:
Matthew Alimagham: Spartanburg Technical College
Steve Conger: Seattle Central Community College
Paul Rosenberg: DePaul University
I hope that the reviewers will see that many of their suggestions were implemented. The
textbook is much improved through their contributions.
I would also like to thank my family for their understanding while I was writing.Thanks to
my parents, Howard and Alma King, who even though they are hundreds of miles away, have
always been sources of encouragement and inspiration to me. And finally, a super special
thanks goes to David for the pats on the back and the confidence and faith he showed in me
that I could complete this project.

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.
1 Introduction to
Computing and
Programming

In this chapter, you will:


° Learn about the history of computers

° Explore the physical components of a computer system

° Learn to differentiate between system and application


Examine how computers represent data

° software
° Learn the steps of software development

° Become aware of how C# and .NET evolved and fit


Explore different programming methodologies

° together
° Learn why C# is being used today for software
development

Copyright 2008 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
2 Chapter 1 Introduction to Computing and Programming

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 mail? 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, word processing, e-mail, and ATMs were
unknown. 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. Mobile applications for Web-enabled phones, pocket and tablet PCs,
iPods, and personal digital assistants (PDAs) 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 pro-
grams. 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, which is pictured in
Figure 1-1, 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.

Figure 1-1 The abacus, the earliest computing device

Copyright 2008 Cengage Learning, Inc. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part.
Another Random Document on
Scribd Without Any Related Topics
Fig. 384.—Diagram of Berberis.

Fig. 385.—Berberis: carpel with 2


stamens.

Order 8. Berberidaceæ (Barberries).—The regular, ☿,


hypogynous flowers are dimerous or trimerous and have regularly
alternating whorls of free sepals, petals, and stamens and 1
unilocular carpel; the corolla and stamens have each 2 whorls, the
calyx at least 2. The anthers open, as in Lauraceæ, by (2) valves,
but are always introrse (Fig. 384). The pistil has a large, disc-like,
almost sessile stigma (Fig. 385), and in the ovary several erect
ovules are placed close to the base of the ventral suture. The fruit is
most frequently a berry. Seeds endospermous.—Shrubs or herbs
with scattered, most frequently compound leaves (without stipules),
and racemose inflorescences.—They show a relationship to the Lauraceæ
in the number of the parts of the flower and the dehiscence of the anthers.
Berberis is a shrub; it has sepals 3 + 3, petals 3 + 3, stamens 3 +
3 (Fig. 384). The petals (honey-leaves) bear internally at the base 2
darkish-yellow nectaries. The filaments are sensitive at the base,
and suddenly bend inwards if touched at that spot (Fig. 385). The
racemes often have a terminal, 5-merous flower; they are borne on dwarf-
branches. The leaves on the long-branches develope into thorns, but the buds in
their axils, in the same year as themselves, develope as the short-branches with
simple foliage-leaves, articulated at the base, from which fact some authorities
have considered that the leaf is compound with a single, terminal leaflet.—
Mahonia has imparipinnate leaves. The flower has 3 whorls of
sepals. Otherwise as in Berberis.—Epimedium; herbs with spurred petals;
the flowers dimerous; 4–5 whorls of sepals, 2 of petals and stamens. Fruit a
capsule. Leontice, fruit dry. The anthers of Podophyllum dehisce longitudinally.—
Nandina. Aceranthus.
100 species; North temp., especially Asia: fossils in Tertiary. Berberis vulgaris is
a native of Europe. This and other species, together with Mahonia aquifolium (N.
Am.), Epimedium alpinum, etc., are cultivated as ornamental plants. Several have
a yellow colouring matter in the root and stem. Officinal: the rhizome of
Podophyllum peltatum (from N. Am.) yields podophyllin.
Order 9. Menispermaceæ. This order has derived its name from the more or
less crescent-like fruits and seeds. Diœcious. The flowers are 2–3-merous, most
frequently as in Berberis (S3 + 3, P3 + 3, A3 + 3), with the difference that there are
3 free carpels, each with 1 ovule; in some genera, however, the number is
different. Stamens often united into a bundle (as in Myristica); anthers dehiscing
longitudinally; fruit a drupe.—The plants (with herbaceous or woody stems)
belonging to this order are nearly all twining or climbing plants, and have
scattered, palmate or peltate, sometimes lobed leaves without stipules. Structure
of stem anomalous. Cocculus, Menispermum, Cissampelos, Anamirta.
150 species; Tropical; very rich in bitter and poisonous properties. Officinal:
Calumba-root from Jateorhiza columba (E. Africa). The following are cultivated as
ornamental plants:—Menispermum canadense (N. Am.) and M. dahuricum (Asia).
The fruits of Anamirta cocculus (E. Ind.) are very poisonous (“Grains-of-Paradise”;
the poisonous matter is picrotoxine).
Order 10. Lardizabalaceæ. This order, by the free, apocarpous carpels,
belongs to a more primitive type, and by the united stamens to a more developed
one. Akebia; Holbœllia; principally climbing or twining shrubs. About 7 species in
S.E. Asia and S. Am.

Order 11. Lauraceæ (True Laurels). Trees or shrubs; the leaves,


always without stipules, are simple, most frequently scattered,
lanceolate or elliptical, entire, penninerved, finely reticulate (except
Cinnamomum with 3–5-veined leaf), leathery and evergreen (except,
e.g. Cinnamomum); they are frequently studded with clear glands
containing volatile oil. The flowers are borne in panicles and are
small and of a greenish or whitish colour. They are regular,
perigynous, with most frequently a bowl or cup-shaped receptacle
(Fig. 386), usually ☿, and trimerous (rarely dimerous) through all
(most frequently 6–7) whorls; viz. most frequently, perianth 2 whorls,
stamens 3–4 and carpels 1 (P3 + 3, A3 + 3 + 3 + 3, G3) in regular
alternation (Fig. 387). Each of the 2 or 4 loculi of the anthers open by
an upwardly directed valve (Fig. 386); of the stamens, the 2
outermost whorls are generally introrse, the others extrorse, or 1–3
whorls are developed as staminodes (Fig. 387 g). The gynœceum
has 1 loculus with 1 style and 1 pendulous ovule (Fig. 386), and may
be considered as formed of 3 carpels. The fruit is a berry (Fig. 388)
or drupe, which often is surrounded at its base by the persistent
receptacle (as an acorn by its cupule), which becomes fleshy and
sometimes coloured during the ripening of the fruit. The embryo has
2 thick cotyledons, but no endosperm (Fig. 388).
Fig. 386.—Flower of the
Cinnamon-tree (Cinnamomum
zeylanicum) (longitudinal
section).

Fig. 387.—Typical diagram of the


Lauraceæ: g staminodes.
Fig. 388.—Laurus nobilis:
longitudinal section of fruit.
The Lauraceæ present affinities with the Polygonaceæ, in which there is found
perigyny, as well as a similar number of parts in the flower and a similar
gynœceum, but with erect and orthotropous ovule. From their general characters
they should be classed among the Polycarpicæ, but stand, however, isolated by
the syncarpous gynœceum, if it is in reality formed by 3 carpels and not by 1 only.
Hernandia, which has epigynous monœcious flowers, deviates most.—Cassytha is
a Cuscuta-like, herbaceous, slightly green parasite with twining, almost leafless
stems. The flower however agrees with the diagram in Fig. 387. Some Lauraceæ
have curved veins or palminerved and lobed leaves (often together with entire
ones) e.g. Sassafras.
Fig. 389.—Myristica: fruit.]

Fig. 390.—Seed with aril entire


and in longitudinal section.
There are 1000 species; especially in the forests of tropical S. America and
Asia, of which they form the principal part. Only Laurus nobilis is found in Europe,
and there is little doubt that its proper home is in Western Asia. They are rare in
Africa.—On account of the volatile oil found in all parts of the plant, they are used
as spices, e.g. the false Cinnamon-tree (Dicypellium caryophyllatum, in the
Brazils). The officinal ones are—the Cinnamon-tree (Cinnamomum zeylanicum
from Ceylon, E. India, Eastern Asia), which is also cultivated; the Camphor-tree
(Cinnamomum camphora, Eastern Asia). The Laurel-tree (Laurus nobilis,
Mediterranean), the berries and leaves of which give laurel oil, is medicinal.—
Scented wood for furniture, etc., is obtained from Sassafras officinalis (from N.
Am.). The wood from its roots is officinal. Pichurim “beans” are the large
cotyledons of Nectandra pichury, whilst the famous “Greenheart” wood of
Demarara is the wood of Nectandra rodiæi. The pulp and seeds contain a fatty oil.
The pear-like fruit of Persea gratissima (Mexico, also cultivated) is very delicious.
Lindera benzoin is a garden shrub; Laurus nobilis likewise.
Order 12. Myristicaceæ (Nutmegs). In this order there is only 1 genus,
Myristica. Trees or shrubs. The leaves agree closely with those of the Lauraceæ,
with which this order has many points in common. The majority of the species are
aromatic, having in their vegetative parts pellucid glands with volatile oils. The
flowers are regular, diœcious, trimerous, and have a single gamophyllous (cupular
or campanulate) 3-toothed, fleshy perianth. In the ♂ -flowers the anthers vary in
number (3–15), and they are extrorse and borne on a centrally-placed column; in
the ♀ -flower the gynœceum is unilocular, unicarpellary, with 1 ovule. The fruit
(Fig. 389) has the form of a pear; it is a fleshy, yellow capsule, which opens along
the ventral and dorsal sutures, exposing the large seed. This seed has a large,
red, irregularly branched aril—the so-called “mace”; the “nutmeg,” on the other
hand, is the seed itself with the inner thin portion of the testa, which has pushed its
way irregularly into the endosperm, and causes the marbled appearance of the cut
seed (Fig. 390); the external, dark brown, hard, and brittle part of the seed-shell is
however removed. Mace and nutmeg contain volatile and fatty oils in abundance.
—80 species. Tropical. The majority are used on account of their aromatic seeds
and aril, the most important being M. fragrans (moschata), from the Moluccas. This
is cultivated in special plantations, not only in its native home, but in other tropical
countries also. Nutmegs were known as commodities in Europe in very ancient
times (e.g. by the Romans), but it was not until the year 1500 that the tree itself
was known. The seed is officinal.

Family 10. Rhœadinæ.


The plants belonging to this family are almost exclusively
herbaceous, with scattered, exstipulate leaves. The flowers are
eucyclic di- or tetramerous, with the calyx and corolla deciduous,
hypogynous, ☿, regular, the gynœceum with 2–several carpels
(generally 2, transversely placed) (Figs. 391, 392, 393, 397). The
ovary is unilocular with parietal placentæ, but in Cruciferæ and a few
others it becomes bilocular by the development of a false,
membranous wall between the placentæ. The stigmas in the majority
of cases are commissural, i.e. they stand above the placentæ, and
not above the dorsal line of the carpels. The fruit is nearly always a
capsule, which opens by the middle portions of the carpels detaching
themselves as valves, bearing no seed, whilst the placentæ persist
as the seed-bearing frame. Endosperm is found in Papaveraceæ
and Fumariaceæ, but is absent in Cruciferæ and Capparidaceæ.—
This family through the Papaveraceæ is related to the Polycarpicæ (the
Nymphæaceæ), through the Capparidaceæ to the Resedaceæ in the next family.
Exceptions to the above are: Eschscholtzia, Subularia (Fig. 403) and a few
Capparidaceæ, in which perigynous flowers are found. A few Papaveraceæ and
Fumariaceæ have trimerous flowers. In Fumaria and certain Cruciferæ, the fruit is
a nut. The Fumariaceæ have zygomorphic flowers. Trees and shrubs are almost
entirely confined to the Capparidaceæ, in which order stipules also are found.
Order 1. Papaveraceæ (Poppies). Herbaceous plants with stiff
hairs and latex; flowers regular (Fig. 391) with generally 2 (-3) sepals
(which fall off as the flower opens), 2 + 2 petals (imbricate and
crumpled in the bud) without spur, numerous stamens in several
alternating whorls (generally a multiple of 2); carpels 2–several,
united into a unilocular gynœceum. Trimerous flowers also occur.
Capsule with very numerous seeds on the parietal placentæ; embryo
small, with large, oleaginous endosperm (Fig. 392).—The leaves
have no stipules and are generally pinnately lobed.
Fig. 391.—A Diagram of the flower of Glaucium and
the dichasium (which becomes transformed into a
scorpioid cyme). B Papaver argemone, transverse
section of the ovary with indication of the position of the
stigmas.
Fig. 392.—Papaver somniferum: A
capsule; st the stigma; v valves; h pores; B
seed in longitudinal section; alb endosperm;
emb embryo.
Papaver (Poppy) has large, solitary, terminal flowers; petals firmly
and irregularly folded in æstivation; gynœceum formed by many (4–
15) carpels; stigmas velvety, sessile and stellate (the rays stand
above the placentæ) (Fig. 391 B). The edges of the carpels project
deeply into the ovary, but do not meet in the centre, so that it
remains unilocular. The capsule opens by pores placed close
beneath the stigma, and formed of small valves alternating with the
placentæ and the rays of the stigma (Fig. 391). P. dubium, P.
argemone, P. rhœas.—Chelidonium (Greater Celandine) has yellow
latex, flowers in umbellate cymes (the terminal, central flower
opening first) and only 2 carpels; the fruit resembles the siliqua of the
Cruciferæ in having two barren valves, which are detached from the
base upwards, and a seed-bearing frame, but there is no partition
wall formed between the placentæ. Ch. majus.—The majority of the
other genera have, like Chelidonium, 2 carpels (lateral and alternating with the
sepals: Fig. 391 A) and siliqua-like fruit, thus: Eschscholtzia (perigynous) with a
linear, stigma-bearing prolongation extending as far above the placentæ as above
the dorsal suture of the carpels; Glaucium (Horn-Poppy); G. luteum, whose
extremely long, thin capsule differs from that of Chelidonium by the formation,
during ripening, of a thick, spongy (false) replum, which persists when the valves
are detached; Sanguinaria with red latex, the 2 petals divided into 8–12 small
petals (perhaps by dédoublement); Macleya and Bocconia (1-seeded capsule)
with 2 sepals and no petals.—Trimerous flowers are found in Argemone and
Platystemon (with a curious fruit, carpels free, and transversely divided and
constricted into joints which separate as nut-like portions).—Meconopsis.—
Hypecoum (Fig. 393 C) has tri-lobed and three cleft petals, 4 free stamens with 4-
locular anthers and a jointed siliqua; it presents a transitional form to the
Fumariaceæ, with which order it is sometimes included.
Pollination. Papaver and Chelidonium have no honey, and are without doubt
only visited by insects for the sake of the pollen. The anthers and stigmas mature
about the same time.—There are 80 species; especially from warm climates.
Officinal: Papaver somniferum (Opium-Poppy); the latex of its unripe capsules is
obtained by incisions, and dried (opium); it contains many alkaloids: morphine,
papaverine, narcotine, thebaine, etc. The oleaginous seeds are also used in the
manufacture of oil. Its home is in the East, where it is extensively cultivated. The
petals of the Corn-poppy (P. rhœas) are also officinal. Several species are
cultivated as ornamental plants.
Order 2. Fumariacæ (Fumitories). This order differs from the
closely allied Papaveraceæ in the absence of latex, a poorer flower,
generally transversely zygomorphic (Fig. 393 B), in which case one
or both of the outer lateral petals are gibbous, or prolonged into a
spur; the stamens are especially anomalous. Sepals 2, caducous;
petals 2 + 2; stamens 2, tripartite; each lateral anther is bilocular
(Figs. 393 A, B; 395); gynœceum bicarpellate. The fruit is a nut or
siliqua-like capsule. Endosperm.—Herbs with scattered, repeatedly
pinnately-divided leaves without stipules, generally quite glabrous
and glaucous; the flowers are arranged in racemes with subtending
bracts, but the bracteoles are sometimes suppressed.
Dicentra (syn. Dielytra) and Adlumia have a doubly symmetrical
flower, with a spur or gibbous swelling at the base of each of the
laterally-placed petals (Figs. 393 A, 394). Corydalis has a
zygomorphic flower, only one of the lateral petals having a spur, and
consequently there is only one nectary at the base of the bundle of
stamens, which stands right in front of the spur (Fig. 393 B, 395,
396). The fruit is a many-seeded siliqua-like capsule. A peculiarity of the
flower is that the plane of symmetry passes transversely through the flowers,
whilst in nearly all other zygomorphic flowers it lies in the median line. Moreover,
the flower is turned, so that the plane of symmetry ultimately becomes nearly
vertical, and the spur is directed backwards.—Many species have subterranean
tubers; in these the embryo germinates with one cotyledon, which is lanceolate
and resembles a foliage-leaf. The tuber is in some the swollen hypocotyl (C. cava),
in others a swollen root (C. fabacea, etc.), which grows down through the precisely
similar swollen root of the mother-plant. The sub-genus Ceratocapnos has
dimorphic fruits (nuts and capsules) in the same raceme. Fumaria differs from
Corydalis only by its almost drupaceous, one-seeded nut (Fig. 395).

Fig. 393.—Diagram of Dicentra (A), Corydalis (B), and Hypecoum (C).]


Fig. 394.—Dicentra spectabilis: A flower (2/5); B the same, after
removal of half of one outer petal; the cap, formed by the inner
petals, is moved away from the anthers and stigma; the insect does
this with the lower side of its abdomen, and thus rubs the stigma on
the hairs of its ventral surface; the dotted line at e indicates the
direction of the proboscis; C andrœcium and gynœceum; D stigma.
The structure of the flower. Hypecoum among the Papaveraceæ is the
connecting link with the Fumariaceæ. The diagram (Fig. 393 C) corresponds both
in number and in the relative position of its members with that of most of the other
Papaveraceæ (Fig. 391), except that there are only four stamens (with extrorse
anthers). In Dicentra (Fig. 393 A), the two central (uppermost) stamens are absent,
but each of the two lateral ones are divided into three filaments, of which the
central one bears a four-locular anther, and each of the others a two-locular (half)
anther. Corydalis and Fumaria stand alone in the symmetry of the flower, differing
from Dicentra in having only one of the lateral petals (Fig. 393 B, sp) prolonged
into a spur, while in Dicentra both the petals are spurred. This structure has been
interpreted in various ways. According to Asa Gray the median stamens are
absent in the last-named genera, and the lateral ones are split in a similar manner
to the petals of Hypecoum. Another, and no doubt the most reasonable theory
(adduced by De Candolle), is: that two median stamens are split, the two parts
move laterally, each to their respective sides and become united with the two
lateral stamens; this affords a natural explanation of the two half-anthers, and
establishes a close relationship to the Cruciferæ. A third interpretation, held by
Eichler and others, is as follows: the median stamens are always wanting; when
they appear to be present, as in Hypecoum, it is due to the fact that the side
portions of the lateral stamens approach each other (as interpetiolar stipules) and
coalesce into an apparently single stamen.

Fig. 395.—Fumaria
officinalis: A the flower in
longitudinal section; B the
andrœcium and gynœceum;
nectary to the right.
Fig. 396.—Corydalis cava: a a flower (lateral view);
b the anthers lying round the stigma; c the anthers
shortly before the opening of the flower; d the head of
the stigma; e relative position of the parts of the flower
during the visit of an insect.
130 species; mostly from the northern temperatures.
Pollination. Fumaria, with its inconspicuous flowers, has to a great extent to
resort to self-pollination. Corydalis, on the other hand, is dependent on cross-
pollination; C. cava is even absolutely sterile with its own pollen. Corydalis is
pollinated by insects with long probosces (humble-bees, bees), which are able to
reach the honey secreted in the spur; as they alight on the flowers they press the
exterior petals on one side (Fig. 396 e), so that the stigma, surrounded by the
anthers, projects forward; the proboscis is introduced in the direction of the arrow
in the figure, and during this act the under-surface of the insect is covered with
pollen, which is transferred by similar movements to the stigma of another (older)
flower.—Ornamental plants; Dicentra (spectabilis and eximia), Adlumia, Corydalis.

Order 3. Cruciferæ (Crucifers). The flowers are regular, ☿;


sepals 4, free (2 + 2), deciduous; petals 4, free, deciduous,
unguiculate, placed diagonally in one whorl, and alternating with the
sepals; stamens 6; the 2 outer are short, the 4 inner (in reality the
two median split to the base) longer, placed in pairs (tetradynamia of
Linnæus); gynœceum syncarpous formed by 2 (as in the previous
order, lateral) carpels, with 2 parietal placentæ, but divided into two
loculi by a spurious membranous dissepiment (replum) (Fig. 397).
Style single, with a capitate, usually two-lobed stigma, generally
commisural, that is, placed above the parietal placentæ (Fig. 397),
but it may also be placed above the dorsal suture, or remain
undivided. Ovules curved. The fruit is generally a bivalvular siliqua
(Fig. 398 B, C), the valves separating from below upwards, and
leaving the placentæ attached to the replum; other forms of fruits are
described below. The oily seeds have no endosperm (endosperm is
present in the two previous orders); the embryo is curved (Figs. 398
E, F; 399, 400).—In general they are herbaceous plants, without
latex, with scattered, penninerved leaves, without stipules; the
inflorescence is very characteristic, namely, a raceme with the
flowers aggregated together at the time of flowering into a corymb,
and destitute of both bracts and bracteoles.

Fig. 397.—Diagram of a
Cruciferous flower.
Fig. 398.—Brassica oleracea: A raceme; B, C siliqua; D
seed; E embryo; F transverse section of seed.
Fig. 399.—Transverse section of
seed and embryo of Cheiranthus
cheiri.

Fig. 400.—Transverse section


of seed of Sisymbrium alliaria.
Many are biennial, forming in the first year a close leaf-rosette. By cultivation
the tap-root can readily be induced to swell out into the form of a tuber (Turnips,
Swedes, etc.). Stipules are found indicated by small glands on the very young
leaves; in Cochlearia armoracia they are fairly large triangular scales. Stellate
hairs often occur. Floral-leaves are occasionally developed. Terminal flowers are
never found in the inflorescences. Iberis and Teesdalia have zygomorphic flowers.
Subularia (Fig. 403) is perigynous. The 2 external sepals (Fig. 397) stand in the
median plane; it may therefore be supposed that there are two bracteoles outside
these which, however, are suppressed, and can only in a few instances be traced
in the young flower; the two lateral sepals are often gibbous at the base, and serve
as reservoirs for the nectar secreted by the glands placed above them; they
correspond in position to the external petals of the Fumariaceæ. The 4 petals
which follow next arise simultaneously, and alternate with the 4 sepals; if it could
be shown that these are merely 2 median petals, which have been deeply cleft and
the two parts separated from each other and displaced to the diagonal position,
there would be a perfect correspondence with the Fumariaceous flower; then the
petals would be followed in regular alternation by the 2 lateral small stamens, the 2
median long stamens, which it has been proved are split into 4 and placed in
couples, and the 2 laterally-placed carpels,—in all 6 dimerous whorls. But the
formation of the corolla by the splitting of 2 petals does not agree with the
development of the flower or bear comparison, and hence the only fact in favour of
this theory is the otherwise prevailing correspondence with the Fumariaceæ. Yet it
may be observed that in special cases each pair of long stamens clearly enough
arises from one protuberance and even later on may be considerably united or
entirely undivided (e.g. Vella); in other instances they are quite distinct from the
beginning, and it is possible that this latter condition has become constant in the
corolla. Lepidium ruderale and others have no corolla. Senebiera didyma has only
2 median stamens. Megacarpæa has several stamens, no doubt by
dédoublement, as in Capparidaceæ.—The number of carpels may also be
abnormally increased; Tetrapoma barbareifolium has normally 4 carpels with an
equal number of placentæ and repla. It is supposed to be a variety of Nasturtium
palustre.—The 2–4–8–10 greenish glands, which are found at the base of the
stamens, are nectaries, morphologically emergences, and not rudimentary
stamens. The forms of fruits are of great systematic significance, see the genera.
In some species dimorphic fruits are present, e.g. Cardamine chenopodiifolia
which has both ordinary Cardamine-siliquas and 1-seeded siliculas.
The curved embryo appears in five forms, which have systematic importance: 1.
To the Pleurorhizæ belong those genera whose radicle (with the hypocotyl) lies
bent upwards along the edge of the flat cotyledons (Fig. 399); to this group belong
Cardamine, Nasturtium, Cheiranthus, Matthiola, Cochlearia, Draba, Iberis, Thlaspi,
etc.; diagrammatic transverse section: ◯ =.—2. To Notorhizæ belong those
whose radicle lies in an upward direction along the back of one of the flat
cotyledons (Figs. 400, 413); e.g. Hesperis, Sisymbrium, Lepidium, Capsella,
Camelina: ◯ ‖.—3. Orthoploceæ differ from the Notorhizeæ in having the
cotyledons folded (not flat) (Fig. 398 E, F); to this belong Brassica, Sinapis,
Raphanus, Crambe, etc.: ◯ >>.—4. Spirolobeæ: the radicle lies as in the
Notorhizæ, but the cotyledons are so rolled together that a transverse section of
the seed cuts them twice; Bunias: ◯ ‖‖.—5. Diplecolobeæ: the cotyledons are
folded forward and backward so that a transverse section cuts them several times;
Subularia, Senebiera: ◯‖‖‖.

On germination the cotyledons appear above the ground as green


leaves; in the Orthoploceæ they are bilobed, in the Lepidium-species
divided.
1. Silicula, broad replum (Siliculosæ latiseptæ), valves flat or
slightly vaulted, and the replum extends through the greatest width of
the silicula (Fig. 404). The seeds are situated in two rows.
◯ =: Cochlearia (Horse-radish): the siliqua is nearly spheroid;
glabrous herbs, generally with fleshy, stalked leaves, and white
flowers.—Draba has an oblong, lanceolate, somewhat compressed
silicula; herbs with small rosettes of leaves, most frequently with
stellate and long-stalked racemes.—Alyssum and Berteroa are
whitish, on account of the stellate hairs; they have a more
compressed and round or elliptical silicula. Vesicaria; Aubrietia.
Lunaria (Honesty, Fig. 401): very broad and flat silicula with long
stalk (the receptacle as in Capparidaceæ).
◯ ‖: Camelina (Gold-of-pleasure) has a spheroid, pear-shaped
siliqua with a small rim passing right round (Fig. 402). Subularia
(Awlwort), an aquatic plant with perigynous flower (Fig. 403) and
folded cotyledons.
2. Silicula, narrow replum (Siliculosæ angustiseptæ), i.e. the
replum is much shorter than the arched, more or less boat-shaped
valves (Figs. 405, 406, 407).

You might also like