Download as pdf or txt
Download as pdf or txt
You are on page 1of 41

Starting out with Visual C# 4th Edition

by Tony Gaddis (eBook PDF)


Visit to download the full and correct content document:
https://ebooksecure.com/download/starting-out-with-visual-c-4th-edition-by-tony-gaddi
s-ebook-pdf/
Contents vii

Chapter 3 Processing Data   117


3.1 Reading Input with TextBox Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
3.2 A First Look at Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
Tutorial 3-1: The Birth Date String Application . . . . . . . . . . . . . . . . . . . . . . . . . 126
3.3 Numeric Data Types and Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
3.4 Performing Calculations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
3.5 Inputting and Outputting Numeric Values . . . . . . . . . . . . . . . . . . . . . . . . . 141
Tutorial 3-2: Calculating Fuel Economy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
3.6 Formatting Numbers with the ToString Method . . . . . . . . . . . . . . . . . . . . 149
Tutorial 3-3: Creating the Sale Price Calculator Application with
Currency Formatting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
3.7 Simple Exception Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
Tutorial 3-4: Creating the Test Average Application with
Exception Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
3.8 Using Named Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
3.9 Declaring Variables as Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
Tutorial 3-5: Creating the Change Counter Application . . . . . . . . . . . . . . . . . . . 169
3.10 Using the Math Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
3.11 More GUI Details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
3.12 Using the Debugger to Locate Logic Errors . . . . . . . . . . . . . . . . . . . . . . . . . 184
tutorial 3-6 Single-stepping through an Application’s Code
at Runtime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
Key Terms 190 • Review Questions 190 • Programming Problems 195

Chapter 4 Making Decisions   199


4.1 Decision Structures and the if Statement . . . . . . . . . . . . . . . . . . . . . . . . . . 199
Tutorial 4-1: Completing the Test Score Average Application . . . . . . . . . . . . . . . 204
4.2 The if-else Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
Tutorial 4-2: Completing the Payroll with Overtime Application . . . . . . . . . . . . 210
4.3 Nested Decision Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
Tutorial 4-3: Completing the Loan Qualifier Application . . . . . . . . . . . . . . . . . . 216
4.4 Logical Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
4.5 bool Variables and Flags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
4.6 Comparing Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
4.7 Preventing Data Conversion Exceptions with the TryParse
Methods ������������������������������������������������������������������������������������������������������� 234
Tutorial 4-4: Calculating Fuel Economy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
4.8 Input Validation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
4.9 Radio Buttons and Check Boxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
Tutorial 4-5: Creating the Color Theme Application . . . . . . . . . . . . . . . . . . . . . . 248
4.10 The switch Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
4.11 Introduction to List Boxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253
Tutorial 4-6: Creating the Time Zone Application . . . . . . . . . . . . . . . . . . . . . . . 255
Key Terms 259 • Review Questions 259 • Programming Problems 263
viii Contents

Chapter 5 Loops, Files, and Random Numbers   269


5.1 More about ListBoxes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
5.2 The while Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
Tutorial 5-1: Using a Loop to Calculate an Account Balance . . . . . . . . . . . . . . . 275
Tutorial 5-2: Enhancing the Ending Balance Application . . . . . . . . . . . . . . . . . . 278
5.3 The ++ and −− operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282
5.4 The for Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283
Tutorial 5-3: Using the for Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288
5.5 The do-while Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291
5.6 Using Files for Data Storage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293
Tutorial 5-4: Writing Data to a Text File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299
Tutorial 5-5: Appending Data to the Friend.txt File . . . . . . . . . . . . . . . . . . . . . . 304
Tutorial 5-6: Using a Loop to Read to the End of a File . . . . . . . . . . . . . . . . . . . 312
Tutorial 5-7: Calculating a Running Total . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316
5.7 The OpenFileDialog and SaveFileDialog Controls . . . . . . . . . . . . . . . . . . . . 319
5.8 Random Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324
Tutorial 5-8: Simulating Coin Tosses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326
5.9 The Load Event . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 330
Tutorial 5-9: Creating a Load Event Handler . . . . . . . . . . . . . . . . . . . . . . . . . . . 331
Key Terms 334 • Review Questions 334 • Programming Problems 337

Chapter 6 Modularizing Your Code with Methods   341


6.1 Introduction to Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341
6.2 void Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 343
Tutorial 6-1: Creating and Calling Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . 347
6.3 Passing Arguments to Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 351
Tutorial 6-2: Passing an Argument to a Method . . . . . . . . . . . . . . . . . . . . . . . . . 354
6.4 Passing Arguments by Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 362
Tutorial 6-3: Using an Output Parameter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365
6.5 Value-Returning Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369
Tutorial 6-4: Writing a Value-Returning Method . . . . . . . . . . . . . . . . . . . . . . . . 374
Tutorial 6-5: Modularizing Input Validation with a Boolean Method . . . . . . . . . 377
6.6 Debugging Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382
TUTORIAL 6-6: Practicing the Step Into Command . . . . . . . . . . . . . . . . . . . . . . . . . 383
TUTORIAL 6-7: Practicing the Step Over Command . . . . . . . . . . . . . . . . . . . . . . . . 384
TUTORIAL 6-8: Practicing the Step Out Command . . . . . . . . . . . . . . . . . . . . . . . . . 385
Key Terms 387 • Review Questions 387 • Programming Problems 390

Chapter 7 Arrays and Lists   395


7.1 Value Types and Reference Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395
7.2 Array Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 398
Tutorial 7-1: Using an Array to Hold a List of Random Lottery Numbers . . . . . 405
7.3 Working with Files and Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 410
7.4 Passing Arrays as Arguments to Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . 413
7.5 Some Useful Array Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 420
Tutorial 7-2: Processing an Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 430
7.6 Advanced Algorithms for Sorting and Searching Arrays . . . . . . . . . . . . . . . 435
Contents ix

7.7 Two-Dimensional Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 442


Tutorial 7-3: Completing the Seating Chart Application . . . . . . . . . . . . . . . . . . . 445
7.8 Jagged Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 451
7.9 The List Collection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 452
Tutorial 7-4: Completing the Test Score List Application . . . . . . . . . . . . . . . . . . 458
Key Terms 464 • Review Questions 464 • Programming Problems 468

Chapter 8 More About Processing Data   471


8.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 471
8.2 String and Character Processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 471
Tutorial 8-1: Completing the Password Validation Application . . . . . . . . . . . . . 477
Tutorial 8-2: Completing the Telephone Format Application . . . . . . . . . . . . . . . 490
Tutorial 8-3: Completing the Telephone Unformat Application . . . . . . . . . . . . . 494
Tutorial 8-4: Completing the CSV Reader Application . . . . . . . . . . . . . . . . . . . . 500
8.3 Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 505
Tutorial 8-5: Completing the Phonebook Application . . . . . . . . . . . . . . . . . . . . . 515
8.4 Enumerated Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 520
Tutorial 8-6: Completing the Color Spectrum Application . . . . . . . . . . . . . . . . . 523
8.5 The ImageList Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 528
Tutorial 8-7: Completing the Random Card Application . . . . . . . . . . . . . . . . . . 530
Key Terms 533 • Review Questions 533 • Programming Problems 537

Chapter 9 Classes and Multiform Projects   541


9.1 Introduction to Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 541
Tutorial 9-1: Creating and Using the Coin Class . . . . . . . . . . . . . . . . . . . . . . . . . 548
9.2 Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 553
Tutorial 9-2: Creating and Using the CellPhone Class . . . . . . . . . . . . . . . . . . . . 556
9.3 Parameterized Constructors and Overloading . . . . . . . . . . . . . . . . . . . . . . . 563
Tutorial 9-3: Creating and Using the BankAccount Class . . . . . . . . . . . . . . . . . . 563
9.4 Storing Class Type Objects in Arrays and Lists . . . . . . . . . . . . . . . . . . . . . . 569
Tutorial 9-4: Completing the Cell Phone Inventory Application . . . . . . . . . . . . . 571
9.5 Finding the Classes and Their Responsibilities in a Problem . . . . . . . . . . . . 575
9.6 Creating Multiple Forms in a Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 584
Tutorial 9-5: Creating an Application with Two Forms . . . . . . . . . . . . . . . . . . . 588
TUTORIAL 9-6: Accessing a Control on a Different Form . . . . . . . . . . . . . . . . . . . . 593
Key Terms 598 • Review Questions 598 • Programming Problems 602

Chapter 10 Inheritance and Polymorphism   605


10.1 Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 605
Tutorial 10-1: Creating and Testing the SavingsAccount and
CDAccount Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 615
10.2 Polymorphism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 623
Tutorial 10-2: Completing the Polymorphism Application . . . . . . . . . . . . . . . . . 628
10.3 Abstract Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 633
Tutorial 10-3: Completing the Computer Science Student Application . . . . . . . . 635
Key Terms 640 • Review Questions 640 • Programming Problems 643
x Contents

Chapter 11 Databases  645
11.1 Introduction to Database Management Systems . . . . . . . . . . . . . . . . . . . . . 645
11.2 Tables, Rows, and Columns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 647
11.3 Creating a Database in Visual Studio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 650
Tutorial 11-1: Starting the Phone Book Application and Creating
the Phonelist.mdf Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 651
11.4 The DataGridView Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 659
Tutorial 11-2: Completing the Phone Book Application . . . . . . . . . . . . . . . . . . . 659
11.5 Connecting to an Existing Database and Using Details View Controls . . . . 666
Tutorial 11-3: Creating the Products Application and Using a Details View . . . . 668
11.6 More About Data-Bound Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 676
Tutorial 11-4: Creating the Product Lookup Application . . . . . . . . . . . . . . . . . . 679
Tutorial 11-5: Creating the Multiform Products Application . . . . . . . . . . . . . . . 682
11.7 Selecting Data with the SQL Select Statement . . . . . . . . . . . . . . . . . . . . . . 688
Tutorial 11-6: Creating the Product Queries Application . . . . . . . . . . . . . . . . . . 694
Tutorial 11-7: Creating the Product Queries Application . . . . . . . . . . . . . . . . . . 703
Tutorial 11-8: Creating the Product Search Application . . . . . . . . . . . . . . . . . . . 707
Key Terms 713 • Review Questions 713 • Programming Problems 717

Appendix A C# Primitive Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . 719


Appendix B Additional User Interface Controls . . . . . . . . . . . . . . . . . . . 721
Appendix C ASCII/Unicode Characters . . . . . . . . . . . . . . . . . . . . . . . . . . . 741
Appendix D Answers to Checkpoint Questions . . . . . . . . . . . . . . . . . . . . 743
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 763
Preface

W elcome to Starting Out with Visual C#, Fourth Edition. This book is intended
for an introductory programming course and is ideal for students with no
prior experience. Students who are new to programming will appreciate the clear, down-
to-earth explanations and the detailed walk-throughs that are provided by the hands-on
tutorials. More experienced students will appreciate the depth of detail as they learn
about the .NET Framework, databases, and other topics.
As with all the books in the Starting Out With series, the hallmark of this text is its clear,
friendly, and easy-to-understand writing. In addition, it is rich in example programs that are
concise and practical. The programs in this book include short examples that highlight specific
programming topics, as well as more involved examples that focus on problem solving. Each
chapter provides numerous hands-on tutorials that guide the student through each step of the
development of an application. In addition to detailed, step-by-step instructions, the tutorials
also provide the application’s completed code and screen captures of the completed forms.

New to This Edition


• Completely updated for Visual Studio 2015—This book was revised and tested
using Visual Studio 2015 Community Edition.
• New Coverage of Debugging—A new section on using the Visual Studio debugger
to locate logic errors has been added to Chapter 3. The section includes a hands-on
tutorial that demonstrates how to set a breakpoint and single-step through an appli-
cation’s code. A new section has also been added to Chapter 6, demonstrating how
to use the debugger to step into, step over, and step out of methods.
• Accessing Controls on a Different Form—Chapter 9 has a new section, with a
hands-on tutorial, that demonstrates how code on one form can access a control
that exists on a different form.
• Auto-Properties—Chapter 9 has a new section on auto-properties. An auto-­property
is a property that simply sets and gets a value, and can be declared without explicitly
declaring backing fields, and without writing the code that sets and gets the
­property’s value.
• Read-Only Auto-Properties—Chapter 9 also has a new section on read-only a­ uto-
properties, which can be used to read the properties’ value, but not set the value.

A GUI-Based Approach
Beginning students are more motivated to learn programming when their applications
have some sort of graphical element, such as a graphical user interface (GUI). Students
using this book will learn to create GUI-based, event-driven, Visual C# applications. The
Visual Studio environment is used to create forms that are rich with user interface con-
trols and graphical images.

Learn to Use Objects Early, Learn to Write Classes Later


This book explains what an object is very early and shows the student how to create
objects from classes that are provided by the .NET Framework. It then introduces the
student to the fundamentals of input and output, control structures, methods, arrays and
lists, and file operations. Then, the student learns to write his or her own classes and
explores the topics of inheritance and polymorphism.
xi
xii Preface

Brief Overview of Each Chapter


Chapter 1: Introduction to Computers and Programming. This chapter begins
by giving a very concrete and easy-to-understand explanation of how computers work,
how data is stored and manipulated, and why we write programs in high-level languages.
In this chapter, the student learns what an object is and sees several examples by studying
the objects that make up a program’s GUI. The chapter discusses steps in the program-
ming development cycle. It also gives an introduction to the Visual Studio environment.
Chapter 2: Introduction to Visual C#. In this chapter, the student learns to create
forms with labels, buttons, and picture boxes and learns to modify control properties.
The student is introduced to C# code and learns the organizational structure of names-
paces, classes, and methods. The student learns to write simple event-driven applications
that respond to button clicks or provide interaction through clickable images. The impor-
tance of commenting code is also discussed.
Chapter 3: Processing Data. This chapter introduces variables and data types. It
discusses the use of local variables and variables declared as fields within a form class.
The student learns to create applications that read input from TextBox controls, perform
mathematical operations, and produce formatted output. The student learns about the
exceptions that can occur when the user enters invalid data into a TextBox and learns to
write simple exception-handling code to deal with those problems. Named constants are
introduced as a way of representing unchanging values and creating self-documenting,
maintainable code. The student also learns more intricacies of creating graphical user
interfaces. The chapter concludes with a discussion and tutorial on using the Visual ­Studio
debugger to locate logic errors by single-stepping through an application’s code.
Chapter 4: Making Decisions. In this chapter, the student learns about relational
operators and Boolean expressions and is shown how to control the flow of a program
with decision structures. The if, if-else, and if-else-if statements are covered. Nested deci-
sion structures, logical operators, and the switch statement are also discussed. The student
learns to use the TryParse family of methods to validate input and prevent exceptions.
Radio buttons, check boxes, and list boxes are introduced as ways to let the user select
items in a GUI.
Chapter 5: Loops, Files, and Random Numbers. This chapter shows the student
how to use loops to create repetition structures. The while loop, the for loop, and the do-
while loop are presented. Counters, accumulators, and running totals are also discussed.
This chapter also introduces sequential file input and output and using text files. The
student learns various programming techniques for writing data to text files and reading
the contents of test files. The chapter concludes with a discussion of pseudorandom num-
bers, their applications, and how to generate them.
Chapter 6: Modularizing Your Code with Methods. In this chapter, the student
first learns how to write and call void methods as well as value-returning methods. The
chapter shows the benefits of using methods to modularize programs and discusses the
top-down design approach. Then, the student learns to pass arguments to methods. Pass-
ing by value, by reference, and output parameters are discussed. The chapter concludes
with a discussion and tutorial on debugging methods with the Visual Studio step-into,
step-over, and step-out, commands.
Chapter 7: Arrays and Lists. Arrays and lists are reference-type objects in C# so this
chapter begins by discussing the difference between value type and reference type objects
in the C# language. Then, the student learns to create and work with single-dimensional
and two-dimensional arrays. The student learns to pass arrays as arguments to methods,
transfer data between arrays and files, work with partially filled arrays, and create jagged
arrays. Many examples of array processing are provided, including examples of finding
Preface xiii

the sum, average, highest, and lowest values in an array. Finally, the student learns to
­create List objects and store data in them.
Chapter 8: More About Processing Data. This chapter presents several diverse
topics. Now that the student has studied the fundamentals of Visual C# programming, he
or she can use the topics presented in this chapter to perform more advanced operations.
First, various string and character processing techniques are introduced. Then, the student
learns to use structures to encapsulate several variables into a single item. The student
next learns to create and use enumerated types. Last, the student learns about the Image-
List control, a data structure for storing and retrieving images.
Chapter 9: Classes and Multiform Projects. Up to this point, the student has
extensively used objects that are instances of .NET Framework classes. In this chapter, the
student learns to write classes to create his or her own objects with fields, methods, and
constructors. The student learns how to implement various types of properties within a
class, including auto-properties and read-only auto-properties. Creating arrays of objects
and storing objects in a List are also discussed. A primer on finding the classes in a prob-
lem as well as their responsibilities is provided. Finally, the chapter shows the student
how to create multiple form classes in a project, instantiate those classes, and display
them. A tutorial is given where the student creates a multiform application in which the
code in one form accesses controls on another form.
Chapter 10: Inheritance and Polymorphism. The study of classes continues in
this chapter with the subjects of inheritance and polymorphism. The topics covered
include base classes, derived classes, how constructors functions work in inheritance,
method ­o verriding, and polymorphism. Abstract classes and abstract methods are
also discussed.
Chapter 11: Databases. This chapter introduces the student to basic database con-
cepts. The student first learns about tables, rows, and columns and how to create an SQL
Server database in Visual Studio. The student then learns how to connect a database to a
Visual C# application and display a table in a DataGridView control, a Details view, and
other data-bound controls. Finally, the student learns how to write SQL Select statements
to retrieve data from a table.
Appendix A: C# Primitive Data Types. This appendix gives an overview of the
primitive data types available in C#.
Appendix B: Additional User Interface Controls. This appendix shows how to
create a variety of controls such as ToolTips, combo boxes, scroll bars, TabControls,
WebBrowser controls, ErrorProvider components, and menu systems.
Appendix C: ASCII/Unicode Characters. This appendix lists the ASCII (American
Standard Code for Information Interchange) character set, which is also the Latin Subset
of Unicode.
Appendix D: Answers to Checkpoint Questions. This appendix provides the
answers to the Checkpoint questions that appear throughout each chapter in the book.

Organization of the Text


The text teaches Visual C# step by step. Each chapter covers a major set of programming
topics, introduces controls and GUI elements, and builds knowledge as the student pro-
gresses through the book. Although the chapters can be easily taught in their existing
sequence, there is some flexibility. Figure P-1 shows the chapter dependencies. As shown
in the figure, Chapters 1–7 present the fundamentals of Visual C# programming and
should be covered in sequence. Then, you can move directly to Chapter 8, Chapter 9, or
Chapter 11. Chapter 10 should be covered after Chapter 9.
xiv Preface

Figure P-1 Chapter dependencies

Chapters 1 - 7 (Cover in Order)


Programming and
Visual C# Fundamentals

Depend On

Chapter 8 Chapter 9
Chapter 11
More about Classes and
Databases
Processing Data Multiform Projects

Depends On

Chapter 10
Inheritance and
Polymorphism

Features of the Text


Concept Statements. Each major section of the text starts with a concept statement.
This statement concisely summarizes the main point of the section.
Tutorials. Each chapter has several hands-on tutorials that guide the student through the
development of an application. Each tutorial provides detailed, step-by-step instructions,
as well as the application’s completed code and screen captures of the completed forms.
Example Programs. Each chapter has an abundant number of code examples designed
to highlight the current topic.
Notes. Notes appear at several places throughout the text. They are short explanations
of interesting or often misunderstood points relevant to the topic at hand.
Tips. Tips advise the student on the best techniques for approaching different program-
ming or animation problems.
Warnings. Warnings caution students about programming techniques or practices that
can lead to malfunctioning programs or lost data.
Checkpoints. Checkpoints are questions placed at intervals throughout each chapter.
They are designed to query the student’s knowledge quickly after learning a new topic.
The answers to the Checkpoint questions can be found in Appendix D.
Review Questions. Each chapter presents a thorough and diverse set of Review
­Questions. They include Multiple Choice, True/False, Algorithm Workbench, and Short
Answer.
Programming Problems. Each chapter offers a pool of Programming Problems
designed to solidify the student’s knowledge of the topics currently being studied.
VideoNotes. Each tutorial in the book has an accompanying online VideoNote that can
be accessed on the book’s companion Web site www.pearsonhighered.com/gaddis.
VideoNote
­Students can follow along with the author as he or she works through each tutorial in the
videos. Also, one programming problem at the end of each chapter has an accompanying
VideoNote that shows the student how to create the solution.
Preface xv

Supplements
Student The following supplementary material is available with the book:
• Source code and files required for the chapter tutorials are available at www.­
pearsonhighered.com/cs-resources
• A complete set of online VideoNotes that take the student through each tutorial in
the book. Also, one programming problem from each chapter has an accompanying
VideoNote that helps the student create a solution. You may access the VideoNotes
by going to www.pearsonhighered.com/cs-resources.
Instructor The following supplements are available to qualified instructors:
• Answers to all Review Questions in the text
• Solutions for all Programming Problems in the text
• Completed versions of all tutorials
• PowerPoint presentation slides for every chapter
• Test bank
For information on how to access these supplements, visit the Pearson Education Instruc-
tor Resource Center at www.pearsonhighered.com/irc.

Acknowledgments
There were many helping hands in the development and publication of this text. I would
like to thank the following faculty reviewers for their helpful suggestions and expertise
during the production of this edition:
Matthew Alimagham
Spartanburg Community College
Carolyn Borne
Louisiana State University
Arthur E. Carter
Radford University
Sallie B. Dodson
Radford University
Elizabeth Freije
Indiana University—Purdue University, Indianapolis
Bettye J. Parham
Daytona State College
Wendy L. Payne
Gulf Coast State College
Jason Sharp
Tarleton State University
John Van Assen
York Technical College
Reginald White
Black Hawk College
Dawn R. Wick
Southwestern Community College
xvi Preface

I would also like to thank my family and friends for their love and support in all my pro-
jects. I am extremely fortunate to have Matt Goldstein as my editor. His support and
encouragement make it a pleasure to write chapters and meet deadlines. I am also fortu-
nate to have Demetrius Hall and Bram Van Kempen as Marketing Managers. Their hard
work is truly inspiring, and they do a great job of getting this book out to the academic
community. The production team, led by Camille Trentacoste, worked tirelessly to make
this book a reality. Thanks to you all!

About the Author


Tony Gaddis is the principal author of the Starting Out With series of textbooks. Tony
has nearly 20 years experience teaching computer science courses at Haywood Commu-
nity College in North Carolina. He is a highly acclaimed instructor who was previously
selected as the North Carolina Community College Teacher of the Year and has received
the Teaching Excellence Award from the National Institute for Staff and Organizational
Development.
The Starting Out With series includes introductory books using the C++ programming
language, the Java™ programming language, Microsoft® Visual Basic®, Microsoft®
C#®, Python, Programming Logic and Design, MIT App Inventor, and Alice, all ­published
by Pearson Education.
Attention Students
Installing Visual Studio
To complete the tutorials and programming problems in this book, you need to install
Visual Studio 2015, or a later version, on your computer. We recommend that you
download Visual Studio Community 2015 from the following website, and install it on
your system:
www.visualstudio.com
Visual Studio Community 2015 is a free, full-featured development environment, and is a
perfect companion for this textbook.

NO TE: If you are working in your school’s computer lab, there is a good chance
that Microsoft Visual Studio has already been installed. If this is the case, your
­instructor will show you how to start Visual Studio.

Installing the Student Sample Program Files


The Student Sample Program files that accompany this book are available for download
from the book’s companion Web site at:
www.pearsonhighered.com/cs-resources
These files are required for many of the book’s tutorials. Simply download the Student
Sample Program files to a location on your hard drive where you can easily access them.

xvii
This page intentionally left blank
Introduction to Computers
1
CHAPTER

and Programming

TOPICS

1.1 Introduction 1.6 Objects


1.2 Hardware and Software 1.7 The Program Development Process
1.3 How Computers Store Data 1.8 Getting Started with the Visual
1.4 How a Program Works Studio Environment
1.5 Graphical User Interfaces

1.1 Introduction
Think about some of the different ways that people use computers. In school, students use
computers for tasks such as writing papers, searching for articles, sending e-mail, and
participating in online classes. At work, people use computers to analyze data, make pres-
entations, conduct business transactions, communicate with customers and coworkers,
control machines in manufacturing facilities, and do many other things. At home, people
use computers for tasks such as paying bills, shopping online, staying connected with
friends and family, and playing computer games. And don’t forget that smart phones,
iPods®, car navigation systems, and many other devices are computers as well. The uses
of computers are almost limitless in our everyday lives.
Computers can do such a wide variety of things because they can be programmed, which
means that computers are designed not to do just one job, but to do any job that their
programs tell them to do. A program is a set of instructions that a computer follows to
perform a task. For example, Figure 1-1 shows screens from two commonly used M
­ icrosoft
programs: Word and PowerPoint. Word is a word processing program that allows you to
create, edit, and print documents. PowerPoint allows you to create graphical slides and
use them as part of a presentation.
Programs are commonly referred to as software. Software is essential to a computer
because without software, a computer can do nothing. All the software that makes our
computers useful is created by individuals known as programmers, or software develop-
ers. A programmer, or software developer, is a person with the training and skills neces-
sary to design, create, and test computer programs. Computer programming is an exciting
and rewarding career. Today, programmers work in business, medicine, government, law
enforcement, agriculture, academics, entertainment, and almost every other field.
1
2 Chapter 1 Introduction to Computers and Programming

Figure 1-1 A word processing program and a presentation program

This book introduces you to the fundamental concepts of computer programming using
the C# programming language. Before we begin exploring those concepts, you need to
understand a few basic things about computers and how they work. This chapter provides
a solid foundation of knowledge that you will continually rely on as you study computer
science. First, we discuss the physical components that computers are commonly made of.
Then, we look at how computers store data and execute programs. Next, we introduce
you to two fundamental elements of modern software design: graphical user interfaces and
objects. Finally, we give a quick introduction to the software used to write C# programs.

1.2 Hardware and Software

CONCEPT: The physical devices that a computer is made of are referred to as the
computer’s hardware. The programs that run on a computer are referred
to as software.

Hardware
Hardware refers to all the physical devices, or components, of which a computer is made. A
computer is not one single device but is a system of devices that all work together. Like the
different instruments in a symphony orchestra, each device in a computer plays its own part.
If you have ever shopped for a computer, you have probably seen sales literature listing
components such as microprocessors, memory, disk drives, video displays, graphics cards,
and so forth. Unless you already know a lot about computers or at least have a friend who
does, understanding what these different components do can be confusing. As shown in
Figure 1-2, a typical computer system consists of the following major components:
• The central processing unit (CPU)
• Main memory
• Secondary storage devices
• Input devices
• Output devices
Let’s take a closer look at each of these components.
1.2 Hardware and Software 3

Figure 1-2 Typical components of a computer system

Central Processing
Unit

Output
Devices

Input
Devices

Main Memory
(RAM)

Secondary
Storage Devices

The CPU
When a computer is performing the tasks that a program tells it to do, we say that the
computer is running or executing the program. The central processing unit, or CPU, is the
part of a computer that actually runs programs. The CPU is the most important compo-
nent in a computer because without it, the computer could not run software.
In the earliest computers, CPUs were huge devices made of electrical and mechanical com-
ponents such as vacuum tubes and switches. Figure 1-3 shows such a device. The two

Figure 1-3 The ENIAC computer


4 Chapter 1 Introduction to Computers and Programming

women in the photo are working with the historic ENIAC computer. The ENIAC, consid-
ered by many to be the world’s first programmable electronic computer, was built in 1945
to calculate artillery ballistic tables for the U.S. Army. This machine, which was primarily
one big CPU, was 8 feet tall and 100 feet long and weighed 30 tons.
Today, CPUs are small chips known as microprocessors. Figure 1-4 shows a photo of a
lab technician holding a modern-day microprocessor. In addition to being much smaller
than the old electromechanical CPUs in early computers, microprocessors are also much
more powerful.

Figure 1-4 A lab technician holds a modern microprocessor

Main Memory
You can think of main memory as the computer’s work area. This is where the computer
stores a program while the program is running, as well as the data that the program is
working with. For example, suppose you are using a word processing program to write an
essay for one of your classes. While you do this, both the word processing program and
the essay are stored in main memory.
Main memory is commonly known as random access memory, or RAM. It is called this
because the CPU is able to quickly access data stored at any random location in RAM.
RAM is usually a volatile type of memory that is used only for temporary storage while a
program is running. When the computer is turned off, the contents of RAM are erased.
Inside your computer, RAM is stored in chips, similar to the ones shown in Figure 1-5.

Secondary Storage Devices


Secondary storage is a type of memory that can hold data for long periods of time, even
when there is no power to the computer. Programs are normally stored in secondary
memory and loaded into main memory as needed. Important data, such as word process-
ing documents, payroll data, and inventory records, is saved to secondary storage as well.
The most common type of secondary storage device is the disk drive. A traditional disk
drive stores data by magnetically encoding it onto a spinning circular disk. Solid-state
drives, which store data in solid-state memory, are increasingly becoming popular. A
solid-state drive has no moving parts and operates faster than a traditional disk drive.
1.2 Hardware and Software 5

Figure 1-5 Memory chips

Most computers have some sort of secondary storage device, either a traditional disk drive
or a solid-state drive, mounted inside their case. External storage devices are also availa-
ble, which connect to one of the computer’s communication ports, or plug into a memory
slot. External storage devices can be used to create backup copies of important data or to
move data to another computer. For example, USB (Universal Serial Bus) drives and SD
(Secure Digital) memory cards are small devices that appear in the system as disk drives.
They are inexpensive, reliable, and small enough to be carried in your pocket.
Optical devices such as the compact disc (CD) and the digital versatile disc (DVD) are also
popular for data storage. Data is not recorded magnetically on an optical disc but is
encoded as a series of pits on the disc surface. CD and DVD drives use a laser to detect the
pits and thus read the encoded data. Optical discs hold large amounts of data, and because
recordable CD and DVD drives are now commonplace, they are good mediums for creat-
ing backup copies of data.

Input Devices
Input is any data the computer collects from people and from other devices. The compo-
nent that collects the data and sends it to the computer is called an input device. Common
input devices are the keyboard, mouse, touchscreen, scanner, microphone, and digital
camera. Disk drives and optical drives can also be considered input devices because pro-
grams and data are retrieved from them and loaded into the computer’s memory.

Output Devices
Output is any data the computer produces for people or for other devices. It might be a
sales report, a list of names, or a graphic image. The data is sent to an output device,
which formats and presents it. Common output devices are screens and printers. Storage
devices can also be considered output devices because the system sends data to them in
order to be saved.

Software
If a computer is to function, software is not optional. Everything that a computer does,
from the time you turn the power switch on until you shut the system down, is under the
control of software. There are two general categories of software: system software and
application software. Most computer programs clearly fit into one of these two categories.
Let’s take a closer look at each.
6 Chapter 1 Introduction to Computers and Programming

System Software
The programs that control and manage the basic operations of a computer are generally
referred to as system software. System software typically includes the following types
of programs:
Operating Systems
An operating system is the most fundamental set of programs on a computer. The
operating system controls the internal operations of the computer’s hardware, manages
all the devices connected to the computer, allows data to be saved to and retrieved
from storage devices, and allows other programs to run on the computer.
Utility Programs
A utility program performs a specialized task that enhances the computer’s operation
or safeguards data. Examples of utility programs are virus scanners, file-compression
programs, and data-backup programs.
Software Development Tools
The software tools that programmers use to create, modify, and test software are
referred to as software development tools. Assemblers, compilers, and interpreters,
which are discussed later in this chapter, are examples of programs that fall into
this category.

Application Software
Programs that make a computer useful for everyday tasks are known as application soft-
ware. These are the programs that people normally spend most of their time running on
their computers. Figure 1-1, at the beginning of this chapter, shows screens from two com-
monly used applications—Microsoft Word, a word processing program, and ­Microsoft
Powerpoint, a presentation program. Some other examples of application software are
spreadsheet programs, e-mail programs, Web browsers, and game programs.

Checkpoint

1.1 What is a program?


1.2 What is hardware?
1.3 List the five major components of a computer system.
1.4 What part of the computer actually runs programs?
1.5 What part of the computer serves as a work area to store a program and its data
while the program is running?
1.6 What part of the computer holds data for long periods of time, even when there is
no power to the computer?
1.7 What part of the computer collects data from people and from other devices?
1.8 What part of the computer formats and presents data for people or other devices?
1.9 What fundamental set of programs control the internal operations of the
­computer’s hardware?
1.10 What do you call a program that performs a specialized task, such as a virus ­scanner,
a file-compression program, or a data-backup program?
1.11 Word processing programs, spreadsheet programs, e-mail programs, Web browsers,
and game programs belong to what category of software?
Another random document with
no related content on Scribd:
Otoconcha is peculiar. The fresh-water Mollusca, besides the Isidora
characteristic of the sub-region, are partly related to New Caledonia
through the occurrence of Melanopsis, partly to Tasmania through
Potamopyrgus, while the peculiar Latia is possibly akin to
Gundlachia (Tasmania). The land operculates number only 5 genera
and 14 species in all, excluding a doubtful Diplommatina.[374]
Land and Fresh-water Mollusca of the Neozealanian Province
Schizoglossa 1
Paryphanta 5
Rhytida 6
Rhenea 2
Helicarion 1
Otoconcha 1
Microcystis 1
Trochonanina 1
Phacussa 3
Thalassohelix 5
Gerontia 2
Allodiscus 10
Pyrrha 1
Therasia 7
Phenacohelix 3
Suteria 1
Flammulina 13
Laoma 23
Endodonta 10
Charopa 28
Placostylus 1
Carthaea 1
Tornatellina 1
Janella 3
Latia 2
Ancylus 2
Limnaea 5
Amphipeplea 2
Planorbis 1
Isidora 7
Melanopsis 2
Potamopyrgus 4
Paxillus 1
Lagochilus 7
Omphalotropis 1
Realia 4
Hydrocena 1
Unio 9
Sphaerium 1
Pisidium 2
Lord Howe’s I. is remarkable as containing a Placostylus, which
thus links the island with this province. The remainder of the fauna is
Polynesian, with the exception of a species (common to the Fijis) of
Parmella, a slug akin to Helicarion, Parmacochlea, and Cystopelta.
(3) The Polynesian Sub-region includes all the island groups of
the central and southern Pacific (except those classified in the
Papuan and Australian sub-regions), from the Pelews and Carolines
in the west to the Marquesas and Paumotus in the east, and from
the Tonga group in the south to the Sandwich Is. in the north. It may
be subdivided into (a) the Polynesian province proper, and (b) the
Hawaiian province, which includes the Sandwich Is. only.

Fig. 216.—Characteristic
Polynesian Mollusca: A,
Achatinella vulpina Fér.,
Sandwich Is.; B, Partula
planilabrum Pease, Society
Is.
(a) The general features of the Polynesian province are very
similar throughout, although the Mollusca of each island group are in
the main peculiar. The species are mostly small and obscure. Helix
scarcely occurs, its place being taken by small Zonitidae
(Microcystis, Charopa, Trochomorpha, etc.), and by groups of so-
called Patula (Endodonta, Pitys, etc.), the exact position of which is
not yet settled. Libera, remarkable for its method of ovipositing (p.
128), is peculiar to the Society and Hervey Is.; Partula is almost
universal, attaining its maximum (40 sp.) in the Society Is.;
Tornatellina, Pupa, and Vertigo occur throughout.
The land operculates consist chiefly of Omphalotropis, Pupina,
Realia, and Helicina. Diplommatina and Palaina are abundant on the
Pelews, and a Moussonia occurs in the Samoa Is. Ostodes, a small
form of Cyclophorus, is found in some of the southern groups. The
fresh-water operculates are Melania, Neritina (including Clithon, a
sub-genus furnished with spines), and Navicella; there are no
Unionidae, while fresh-water Pulmonata are very scarce.
(b) The land Mollusca of the Hawaiian province are distinguished
by the possession of four entirely peculiar genera—Achatinella,
Leptachatina, Carelia, and Auriculella. More than 300 of the two
former genera have been described, every mountain valley of some
of the islands having its own peculiar species. The destruction of the
indigenous herbage by goats is rapidly extinguishing many forms.
Partula, and the small land operculates, so characteristic of the other
groups, are, with the exception of Helicina, entirely wanting. The
occurrence of one of the Merope group of Helix (Solomon Is.) is
remarkable, and there is a rich development of Succinea. “Patula,”
Microcystis, Tornatellina, and the other small Polynesian land
Pulmonata are well represented. The presence of Isidora, absent
from the central Pacific groups, is remarkable, and Erinna is a
peculiar genus belonging to the Limnaeidae.
CHAPTER XI
GEOGRAPHICAL DISTRIBUTION OF LAND MOLLUSCA (continued)—THE
ETHIOPIAN, NEARCTIC, AND NEOTROPICAL REGIONS

D. The Ethiopian Region


The Ethiopian region includes the whole of Africa south of the
Great Desert, and Southern Arabia, together with the outlying
islands, excepting those of the Atlantidean province (p. 297).
Regarded as a whole, the Ethiopian is poorest in land Mollusca of
all the tropical regions. And yet its characteristics are very
remarkable. The entire Achatina group is peculiar, and takes,
especially in W. Africa, some curious forms (Columna, Perideris,
Pseudachatina). Carnivorous Mollusca (Ennea, Gibbus, etc.) are
highly developed, especially in the south and east, the largest known
helicoid form (Aerope) being from Natal. In the possession of these
types of the Agnatha, Africa is more closely related to the
Australasian than to the Oriental region. The true Cyclostoma are
entirely peculiar to the region, but are absent from West Africa.
Fresh-water Mollusca are abundant and characteristic, especially
in and near the Great Lakes. Lanistes, Cleopatra, and Meladomus,
among the operculates, together with Mutela and Aetheria
(Unionidae), Galatea and Fischeria (Cyrenidae), are peculiar.
In its negative, as well as its positive features, the Ethiopian
region is markedly isolated. Helicidae and Naninidae are equally
deficient, the former, indeed, attaining some numerical
predominance in the extreme south, but the species are nearly all
insignificant in size and colouring. It is only in Madagascar that Helix
asserts itself. Arion, Limax, Hyalinia, Clausilia, and a number of other
genera abundant along the Mediterranean, are either altogether
absent, or are very scantily represented. Land operculates, so
characteristic of other tropical countries, are almost entirely wanting.
If we disregard the Malagasy sub-region, there are scarcely forty
species of land operculates on the whole African continent.
The Ethiopian region may be divided into three sub-regions: (1)
the Central African; (2) the South African; (3) the Malagasy.
(1) The Central African Sub-region is bounded on the north by
the Great Desert, on the east and west by the ocean, and on the
south by a line roughly drawn between the mouth of the Orange
River and Delagoa Bay; it also includes S. Arabia. No natural
features exist which tend to break up this vast district into areas of
independent zoological development. The absence of long and lofty
mountain ranges, the enormous size of the great river basins, and
the general uniformity of climate, equalise the conditions of life
throughout. It will be convenient to break the sub-region up into
provinces, but in most cases no precise line of demarcation can be
laid down.
(a) The Senegambian Province may be regarded as extending
from the mouth of the Senegal River to Cape Palmas. Only 8 genera
of land Mollusca are known, including 4 Limicolaria and 3 Thapsia,
with 1 small Cyclophorus. Fresh-water genera are abundant, and
include most of the characteristic Ethiopian forms.
(b) The West African Province extends from Cape Palmas to the
mouth of the Congo, and is rich in Mollusca. The great Achatina,
largest of land snails, whose shell sometimes attains a length of 6½
in., Limicolaria, Perideris, and Pseudachatina are the characteristic
forms. The Agnatha are represented by Ennea, Streptaxis, and
Streptostele. Rachis and Pachnodus, sub-genera of Buliminus, occur
also on the east coast. A special feature is the development of
several peculiar slug-like genera, e.g. Oopelta, perhaps a form of
Arion; Estria, a slug with an external shell, akin to Parmacella; and
Aspidelus, a form intermediate between Helicarion and Limax.
Claviger, a handsome group akin to Cerithium, is peculiar to the
estuaries of West African rivers.
About sixteen species are known from the Cameroons District, but
no peculiar genera occur. The French Congo District has not yet
been well explored. Tomostele, a genus allied to Streptostele, is
peculiar, and Pseudachatina attains its maximum.
Fig. 217.—Columna
flammea Müll., Princes I.
St. Thomas and Princes Is., in the Gulf of Guinea, are well known.
Princes I. has 22 species, 14 peculiar, and 2 common to St. Thomas
only, one of the latter being the great sinistral Achatina bicarinata
Chem. The remarkable genus Columna (Fig. 217) is peculiar, and
Streptostele (4 sp.) attains its maximum. Peculiar to St. Thomas are
Pyrgina, a turreted form of Stenogyra; Thyrophorella, a sinistral form
of Zonites; and Atopocochlis, a large bulimoid shell, whose true
relationships are not yet known. Homorus, a group of Achatina with
an elongated spire, occurring also in the Angola District and on the
east coast, has 4 species. No fresh-water species have as yet been
discovered in either of the islands.
The Angola and Benguela District, extending from the Congo to
the Cunene R., probably belongs to the West African Sub-region, but
until its fauna is better known it is advisable to consider it apart.
Achatina continues abundant, but the other characteristic West
African forms (Pseudachatina, Streptostele, Perideris) diminish or
are absent altogether. No Helix and only 1 Cyclophorus occur.
Ovampo, Damara, and Great Namaqualand, lying between the
Cumene and Orange rivers, seem to form a transition district
between the West and South African faunas. Helix reappears, while
the characteristic West African genera are almost entirely wanting.
(c) The East African Province extends from about Delagoa Bay to
the Abyssinian shores of the Red Sea. In general out-line the
province consists of a flat marshy district, extending inland for many
miles from the sea; this is succeeded by rising ground, which
eventually becomes a high table-land, often desolate and arid,
whose line of slope lies parallel to the trend of the coast. The
Mollusca are little known, and have only been studied in isolated
districts, usually from the discoveries of exploring expeditions.
The Mozambique District, from Delagoa Bay to Cape Delgado,
includes no genus which does not occur on the west coast, except
Cyclostoma (2 sp.). Trochonanina (4 sp.), Urocyclus, a characteristic
African slug (2 sp.), Rachis (6 sp.), Pachnodus (2 sp.), and Achatina
(5 sp.), are the principal groups.

Fig. 218.—Urocyclus comorensis Fisch., Comoro Is.:


G, Generative orifice; M, mucous gland; O,
orifice leading to internal shell; P, pulmonary
orifice; T, tentacles. (After Fischer.)
The Zanzibar District, from Cape Delgado to the Somali country,
has the same general features. Meladomus, a large sinistral
Ampullaria, is characteristic, while Cyclostoma (5 sp.) becomes more
abundant. Helix is still absent, but the carnivorous forms (Streptaxis
2 sp., Ennea 7 sp.) are rather numerous.
The Somali District is characterised by operculate groups of the
Otopoma type (Georgia, Rochebrunia, Revoilia) whose generic value
is rather doubtful. Petraeus, in an Arabian type, supplants Rachis
and Pachnodus. Achatina is nearly wanting, but Limicolaria has 9
species. A few Helix, said to be of the Pisana group, occur.
The District between the Great Lakes and the coast region is fairly
well known through recent explorations, especially those associated
with Emin Pasha. Streptaxis (6 sp.) and Ennea (24 sp.) are
numerous, Helix is wanting, and the Naninidae are represented by
Trochonanina (7 sp.), and other forms at present grouped under
Nanina or Hyalinia. On the high ground Buliminus, Cerastus, and
Hapalus replace, to some extent, the Achatina and Limicolaria of the
marshy plains. Land operculates (Cyclophorus 1, Cyclostoma 8) are
more numerous; among fresh-water genera we have Lanistes (5
sp.), Cleopatra (3 sp.), Meladomus (1 sp.), and Leroya, a sinistral
form with the facies of a Littorina. The characteristic African bivalves
(Mutela, Spatha, etc.) are few in number.
(d) Province of the Great Lakes.—The Mollusca of the four great
lakes of Eastern Central Africa—Lakes Albert Nyanza (Luta Nzige,
2720 ft.), Victoria Nyanza (Oukéréwé, 3700 ft.), Nyassa (1520 ft.),
and Tanganyika (2800 ft.)—are well known, and supply an
interesting problem in distribution. Those of the three first mentioned
lakes differ in no way from the rest of tropical Africa, but the Mollusca
of Tanganyika include, in addition to the ordinary African element, a
number of peculiar operculate genera, belonging principally to the
Melaniidae and Hydrobiidae. Several of these possess a solidity of
form and compactness of structure which is unusual in fresh-water
genera, and has led to the belief, among some authorities, that they
are the direct descendants of marine species, and that Tanganyika
represents an ancient marine area. This view appears untenable.
The Victoria Nyanza and Nyassa are part of the same system as
Tanganyika, and it is not easy to see how, if Tanganyika were once
an arm of the sea, they were not equally so, especially as they are
several hundred miles nearer the Indian Ocean as at present
defined. Nor, as will be seen from the figures given above, is there
anything in the altitudes which would make us expect anything
exceptional in Tanganyika. The similar case of L. Baikal must be
compared (p. 290), where again a number of specialised forms of
Hydrobia occur.
Of the genera concerned, Paramelania and Nassopsis are forms
of Melaniidae; Tiphobia (Fig. 219), which is allied to Paludomus, is a
compact shell with angulated spinose whorls; Lacunopsis,
Ponsonbya, Limnotrochus, and Tanganyicia are probably forms of
Lithoglyphus, some, as their names denote, being of decidedly
marine facies; Syrnolopsis and Turbonilla (?) look like
Pyramidellidae, Horea and Reymondia like Rissoina; Bourguignatia
appears to belong to Vivipara, with which has now been merged the
genus Neothauma. Recently discovered forms from the adjacent L.
Mweru are evidently of kindred origin.
(e) The Afro-Arabian Province includes Abyssinia, with S. Arabia,
the African shores of the Gulf of Aden, and Socotra. The province
contains a singular mixture of types. The high ground of Abyssinia
stands like a lofty European island in the midst of a tropical plain,
with Palaearctic genera flourishing like hardy northern plants on a
mountain in low latitudes. Helix, Vitrina, and Pupa abound, with a
few Clausilia and even a Limax. On the lower levels occur
Limicolaria (3 sp.), Subulina (7 sp.), Helicarion, and Homorus, but
land operculates are entirely wanting. Characteristic of the province
as a whole are various forms of Buliminus, which in Socotra are
represented by two peculiar sub-genera, Achatinelloides and
Passamaiella. In S. Arabia the mixture of types produces curious
results: the Helix, Clausilia, and Vitrina being Palaearctic, the
Limicolaria and all the operculates Ethiopian, while the single
Trochomorpha is Indian. Indian influence, indeed, comes out
unmistakably throughout the province. Thus in Socotra there are two
Cyclotopsis, in Abyssinia two Africarion (closely related to the Indian
Girasia), two Microcystis, and a Glessula, and in the Scioa district
there is a Sitala. The fresh-water Mollusca of Socotra are Indian
forms.
Fig. 219.—Tiphobia Horei E.
A. Smith, L. Tanganyika.

Fig. 220.—Mollusca
characteristic of L.
Tanganyika: A, Nassopsis
nassa Woodw.; B, Spekia
zonata Woodw.; C,
Syrnolopsis lacustris E. A.
Smith.
Fig. 221.—Achatina zebra
Lam., S. Africa. × ½.
(2) The South African Sub-region.—The principal characteristic
of the Mollusca of S. Africa is the occurrence of numerous small
species of Helicidae, belonging chiefly to the groups Pella, Phasis,
Dorcasia, and Sculptaria, all of which are practically peculiar.
Carnivorous genera are also prominent, Ennea here attaining its
maximum. Rhytida (to which several species still regarded as Pella
belong) is common only to the S. Pacific and Australasia, and forms,
with Isidora among the fresh-water pulmonates, a remarkable link of
connexion. Aerope, the largest of all helicoid carnivorous genera,
and Chlamydephorus, a carnivorous slug with an internal shell, are
peculiar. Achatina is still abundant, but Limicolaria is wanting.
Livinhacea, a form with a continuous peristome, perhaps akin to
Bulimus; Apera, a form of slug; and Coeliaxis, a genus perhaps akin
to the Papuan and Queensland Perrieria, are all peculiar. The land
operculates, which are not numerous, are of the East African type.
Land Mollusca of the S. African Sub-region
Chlamydephorus 1
Ennea 31
Aerope 5
Rhytida 3
Helicarion 3
Trochonanina 1
Trochozonites 1
Limax 1
Apera 1
Vitrina 7
Nanina 6
Conulus 2
Patula 2
Pella 44
Dorcasia 8
Phasis 1
Sculptaria 2
Helix (inc. sed.) 4
Rachis 1
Pachnodus 3
Buliminus (?) 4
Pupa 20
Vertigo 2
Achatina 18
Livinhacea 1
Stenogyra 4
Coeliaxis 1
Succinea 3
Vaginula 2
Cyclophorus 1
Cyclostoma 7
Cyclotus (?) 1
Blanfordia 1
St. Helena.—The Molluscan fauna of St. Helena is perhaps the
most puzzling, as regards its geographical affinities, of any in the
world. It consists of 29 peculiar species of land Mollusca (fresh-water
species being unknown), 19 of which are recently extinct, partly
owing to the destruction of the forest, but are found in considerable
abundance in a state of good preservation.[375] The genera are—
Hyalinia 1
Patula 4 (3 extinct)
Endodonta 10 (7 extinct)
Bulimulus 7 (5 extinct)
Pachyotus 1 (extinct)
Tomigerus (?) 1 (extinct)
Pupa 2 (extinct)
Succinea 3
The 5 genera which concentrate our attention are Patula,
Endodonta, Pachyotus (Fig. 222), Tomigerus, and Bulimulus, all of
which appear utterly strange to an oceanic island in the middle of the
S. Atlantic. Patula and Endodonta are essentially Polynesian forms,
occurring abundantly on all the island groups in the Central Pacific.
Pachyotus, Tomigerus (assuming its correct identification), and
Bulimulus are all S. American forms, the two former being especially
characteristic of Brazil. How this mixture of genera now confined to
regions so widely distant, not only from St. Helena itself, but from
one another, became associated here, is a problem obviously not
easy of solution. The fauna is probably a remnant of a very ancient
type, possibly at one time much more widely distributed. Endodonta
(an essentially insular form, like Omphalotropis) actually occurs on
Fernando Noronha, off the Brazil coast, and we shall see how an
Indian and even a Polynesian element is present off the eastern
coasts of Africa.
Ascension I.—One indigenous species, a so-called Limax, is all
that has ever been discovered.
(3) The Malagasy Sub-region includes Madagascar with its
attendant satellites Bourbon, Mauritius, and Rodriguez, and the
Seychelles and Comoro groups. No land Mollusca are known from
the Amirantes, the Chagos, or from Aldabra. The special
characteristics of the sub-region are the great development of the
carnivorous land Mollusca (Ennea, Gibbus), the occurrence of a
considerable number of true Helicidae of great size and beauty, and
the prominence of the genus Cyclostoma.
(a) The Madagascan Province.—The land Mollusca of
Madagascar, although as yet imperfectly known, possess a striking
individuality. Two of the chief characteristics of the Ethiopian region
are the paucity of its land operculate and of its Helix fauna;
Madagascar is especially distinguished by the rich development of
both these groups. For size, colouring, and beauty of shape, the
Helicidae of the two sub-genera Ampelita and Helicophanta rival, if
they do not surpass, any in the world. They are quite peculiar to this
sub-region, not a trace of them occurring on the Mascarenes,
Seychelles, or even on the Comoros. Helicophanta is distinguished
by the enormous size of its embryonic shell, which persists in the
adult (Fig. 223), and in this respect the group appears to be related
to Acavus (Ceylon, Fig. 204) and Panda (N.E. Australia). As is usual
when Helix is well developed, Nanina (about 12 sp.) is
proportionately scanty.
The African Bulimini (Pachnodus and Rachis) are represented by
two species, but Achatina, so abundant on the mainland, is scarce.
Two other groups of Buliminus, Leucotaenia and Clavator, are
peculiar. The presence of a single Kaliella, specifically identical with
a common Indian form, is very remarkable.
Cyclostoma proper, of which Madagascar is the metropolis, is
richly developed (54 sp.). Many of the species are of great size and
of striking beauty of ornamentation. Unlike its Helicidae, this genus is
not restricted to Madagascar; several species occur on the mainland,
6 on the Comoros, one on the Seychelles, and 16 in Mauritius. The
sub-genera Acroptychia and Hainesia are peculiar.

Fig. 222.—Pachyotus auris


vulpina Desh., St. Helena (sub-
fossil).
Fig. 223.—Helix (Helicophanta)
Souverbiana Fisch.,
Madagascar, showing
embryonic shell. × ⅔.

Fig. 224.—Cyclostoma
campanulatum Pfr., Madagascar.
The fresh-water Mollusca of Madagascar contain further traces of
Indian relationship. Thus we find two species of Paludomus, a genus
whose metropolis is Ceylon, India, and Further India, and which is
barely represented on the Seychelles and in the Somali district.
Melanatria, which is peculiar to Madagascar, has its nearest affinities
in the Cingalese and East Indian faunas. Several of the Melania and
the two Bithynia are of a type entirely wanting in Africa, but common
in the Indo-Malay sub-region. Not a single one of the characteristic
African fresh-water bivalves (Mutela, Spatha, Aetheria, Galatea, etc.)
has been found in Madagascar. On the other hand, certain African
Gasteropoda, such as Cleopatra and Isidora, occur, indicating, in
common with the land Mollusca, that an ultimate land connexion with
Africa must have taken place, but at an immeasurably remote period.
Land and Fresh-water Mollusca of Madagascar
Ennea 9
Urocyclus 2
Helicarion (?) 1
Macrocyclis (?) 1
Kaliella 1
Nanina (inc. sed.) 9
Ampelita 35
Helicophanta 17
Pachnodus 2
Rachis 2
Leucotaenia 2
Clavator 2
Achatina 3
Opeas 2
Subulina 3
Vaginula 4
Limnea 2
Planorbis 3
Isidora 3
Melania 7
Melanatria 4
Paludomus 2
Vivipara 1
Bithynia 2
Cleopatra 2
Ampullaria 6
Cyclophorus 2
Cyclotus (?) 1
Cyclostoma 54
Otopoma 5
Lithidion 1
Acroptychia 3
Hainesia 3
Unio 1
Corbicula 2
Sphaerium 1
Pisidium 1
The Comoro Islands.—This isolated group possesses about 100
species, almost all of which are peculiar. The principal feature is the
rich development of Ennea (30 sp.). On the whole the group shows
more relationship to Madagascar than to the mainland. Thus we
have six species of true Cyclostoma, and only one Achatina, while
among the fresh-water genera is Septaria, which is characteristic of
the whole Malagasy Sub-region, but is absent from the mainland.
The Helicidae are all of insignificant size. Peculiar to the group is the
remarkable genus Cyclosurus (Fig. 152, p. 247).
(b) The Mascarene Province (Mauritius, Bourbon, Rodriguez, and
the Seychelles).—The percentage of peculiar species, which is very
high, can only be paralleled in the case of some of the West Indian
islands, and sufficiently attests the extreme isolation of the group
from Madagascar. We have—
Total sp. Land sp. Fresh-water Peculiar Peculiar to
sp. group
Mauritius 113 104 9 78 102 (90 p.c.)
Bourbon 45 40 5 19 38 (84 p.c.)
Rodriguez 23 19 4 15 21 (95 p.c.)
Seychelles 34 27 7 24 30 (90 p.c.)
The Mollusca of the group exhibit three distinct elements, the
Indigenous, the Madagascan, and the Indian and Australasian.
The genus Pachystyla (Naninidae) is quite peculiar, forming the
main portion of the land snails proper. It attains its maximum in
Mauritius (17 sp.), with 5 sp. in Bourbon and one sub-fossil sp. in
Rodriguez, while in the Seychelles it is absent. But the principal
feature of the Mascarene group is the extraordinary development of
the carnivorous genus Gibbus, which has 27 sp. in Mauritius, 8 in
Bourbon, 4 in Rodriguez; in the Seychelles, it is replaced by
Edentulina and Streptostele. The principal link with Madagascar is
found in a part of the operculate land fauna. Cyclostoma is present
(with Otopoma) in several fine living forms, and the number of sub-
fossil species is a clear indication that this group was, not long ago,
much more abundant, for of the 16 Cyclostoma known from
Mauritius 10 are sub-fossil. The operculates form a decided feature
of the land fauna; thus in Mauritius there are 32 species, or more
than 28 per cent of the whole.

Fig. 225.—Characteristic Mauritian land


shells: A, Gibbus palanga Fér.; A´,
young of same; B, Gibbus
lyonetianus Pall.
Indian and Australasian affinities are unmistakably present. Thus
Omphalotropis, a genus characteristic of small islands, is profusely
represented, but it does not occur in Madagascar or Africa. Two
Helicina (Mauritius and Seychelles) and a single Leptopoma
(possibly a Leptopomoides) are also of eastern relationship.
Cyclotopsis, Cyathopoma, and Geostilbia are markedly Indian
genera. Microcystis, Patula, and Tornatellina are Polynesian.
Hyalimax—and this is a very striking fact—occurs nowhere else but
in the Andamans and Nicobars, and on the Aracan coast. The
nearest relation to the Seychelles Mariaella appears to be the
Cingalese Tennentia. Not a single representative of these eleven
genera has been found even in Madagascar.
The fresh-water Mollusca (omitting the Neritidae) are: Mauritius 9
species, Bourbon 5, Rodriguez 4, Seychelles 6, with only 15 species
in all. The one Planorbis and the Vivipara, the Paludomus and two of
the Melania are of Indian types. The Lantzia (peculiar to Bourbon) is
probably allied to the Indian Camptonyx. Owing to the paucity of
permanent streams, no fresh-water bivalves occur. Among the
Neritidae is a single Septaria, a genus which, though occurring in
Madagascar, is entirely strange to Africa, and is abundant in the
Oriental and Australasian regions.
It would seem probable that when the closer connexion which at
one time undoubtedly existed between India and Eastern Africa
began to be less continuous,[376] the Mascarene group was first
severed from what ultimately became Madagascar, while the
Seychelles, and perhaps the Comoros, still continued united to it.
The Comoros, which lack the great Helices, separated off from
Madagascar first, while the Seychelles continued in more or less
direct union with that island sufficiently long to receive the
progenitors of Stylodonta (a peculiar group of Helix), but became
disunited at an exceedingly remote period.

E. The Nearctic Region

The southern boundary of this region may be regarded as roughly


corresponding to that of the United States, i.e. Lower California and
Mexico are excluded. The southern portion of Florida belongs to the
Antillean sub-region.
The principal characteristic of the Nearctic Region is the
remarkable poverty of its land Mollusca. No district in the world of
equal extent is so poor in genera, while those which occur are
generally of small size, with scarcely anything remarkable either in
colouring or form. The elongated land shells (Clausilia, Buliminus),
so characteristic of Europe, are entirely wanting, but a few
Bulimulus, of Neotropical origin, penetrate Texas, and from the same
sources come a few species of Glandina (as far north as S.
Carolina), Holospira (Texas), and Helicina.
The region falls into two well-marked sub-regions, the N.
American and the Californian, with the Rocky Mountain district as a
sort of debatable ground between them. The Californian sub-region
consists of the narrow strip of country between the Sierra Nevada,
the Cascade Mountains and the coast-line, from San Diego to
Alaska; the N. American sub-region consists of the remainder of the
region.
(1) The N. American Sub-region.—The Carnivorous genera are
represented solely by the few Glandina mentioned above, and by the
indigenous genus Selenites, a form midway between Testacella and
Limax, whose metropolis is on the Pacific slope, but which spreads
eastward into the Antilles. Among the Limacidae, Limax is common
to both sub-regions, but Tebennophorus (4 sp., 3 of which belong to
the genus Pallifera), a genus found also in China and Siam, and
Vitrinozonites do not occur in the Californian. Hyalinia (Zonites) is
fairly abundant, especially in the groups Mesomphix and
Gastrodonta (peculiar to this sub-region), and Hyalinia proper. Patula
is well represented. The Helicidae belong principally to the groups
Mesodon, Stenotrema, Triodopsis, Polygyra, and Strobila, only 6 of
which, out of a total of 84, reach the Pacific slope. Land operculates
are conspicuous for their almost complete absence (see map,
frontispiece).

Fig. 226.—Characteristic North American Mollusca. A,


Helix (Mesodon) palliata Say, Ohio. B, Helix
(Polygyra) cereolus Mühlf., Texas. C, Patula
alternata Say, Tennessee.
The poverty of the land fauna is atoned for by the extraordinary
abundance and variety of the fresh-water genera. A family of
operculates, the Pleuroceridae, with 10 genera and about 450
species, is quite peculiar, a few stragglers only reaching Central
America and the Antilles. The nucleus of their distribution is the
Upper Tennessee River with its branches, and the Coosa River.
They appear to dislike the neighbourhood of the sea, and are never

You might also like