ebook download (eBook PDF) Starting Out with C++: From Control Structures through Objects 8th Edition all chapter

You might also like

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

(eBook PDF) Starting Out with C++:

From Control Structures through


Objects 8th Edition
Go to download the full and correct content document:
https://ebooksecure.com/product/ebook-pdf-starting-out-with-c-from-control-structures
-through-objects-8th-edition/
More products digital (pdf, epub, mobi) instant
download maybe you interests ...

(eBook PDF) Starting Out with C++: From Control


Structures through Objects, Brief Version 8th Edition

http://ebooksecure.com/product/ebook-pdf-starting-out-with-c-
from-control-structures-through-objects-brief-version-8th-
edition/

(eBook PDF) Starting Out with Java: From Control


Structures through Objects, 7th Edition

http://ebooksecure.com/product/ebook-pdf-starting-out-with-java-
from-control-structures-through-objects-7th-edition/

(eBook PDF) Starting Out with C++ from Control


Structures to Objects 9th Edition

http://ebooksecure.com/product/ebook-pdf-starting-out-with-c-
from-control-structures-to-objects-9th-edition/

(eBook PDF) Starting Out with Java: From Control


Structures through Data Structures 3rd Edition

http://ebooksecure.com/product/ebook-pdf-starting-out-with-java-
from-control-structures-through-data-structures-3rd-edition/
(eBook PDF) Starting Out with Java: From Control
Structures through Data Structures 4th Edition

http://ebooksecure.com/product/ebook-pdf-starting-out-with-java-
from-control-structures-through-data-structures-4th-edition/

(eBook PDF) Starting Out with C++: Early Objects 9th


Edition

http://ebooksecure.com/product/ebook-pdf-starting-out-with-c-
early-objects-9th-edition/

Starting Out with C++: Early Objects 9th Edition by


Tony Gaddis (eBook PDF)

http://ebooksecure.com/product/starting-out-with-c-early-
objects-9th-edition-by-tony-gaddis-ebook-pdf/

(eBook PDF) Starting Out with Java: Early Objects 5th


Edition

http://ebooksecure.com/product/ebook-pdf-starting-out-with-java-
early-objects-5th-edition/

(eBook PDF) Starting Out with Java: Early Objects 5th


Global Edition

http://ebooksecure.com/product/ebook-pdf-starting-out-with-java-
early-objects-5th-global-edition/
Contents

Preface xv

CHAPTER 1 Introduction to Computers and Programming 1


1.1 Why Program? 1
1.2 Computer Systems: Hardware and Software 2
1.3 Programs and Programming Languages 8
1.4 What Is a Program Made of? 14
1.5 Input, Processing, and Output 17
1.6 The Programming Process 18
1.7 Procedural and Object-Oriented Programming 22

CHAPTER 2 Introduction to C++ 27


2.1 The Parts of a C++ Program 27
2.2 The cout Object 31
2.3 The #include Directive 36
2.4 Variables and Literals 37
2.5 Identifiers 41
2.6 Integer Data Types 42
2.7 The char Data Type 48
2.8 The C++ string Class 52
2.9 Floating-Point Data Types 54
2.10 The bool Data Type 57
2.11 Determining the Size of a Data Type 58
2.12 Variable Assignments and Initialization 59
2.13 Scope 61
2.14 Arithmetic Operators 61
2.15 Comments 69
2.16 Named Constants 71
2.17 Programming Style 73

vii
viii Contents

CHAPTER 3 Expressions and Interactivity 83


3.1 The cin Object 83
3.2 Mathematical Expressions 89
3.3 When You Mix Apples and Oranges: Type Conversion 98
3.4 Overflow and Underflow 100
3.5 Type Casting 101
3.6 Multiple Assignment and Combined Assignment 104
3.7 Formatting Output 108
3.8 Working with Characters and string Objects 118
3.9 More Mathematical Library Functions 124
3.10 Focus on Debugging: Hand Tracing a Program 130
3.11 Focus on Problem Solving: A Case Study 132

CHAPTER 4 Making Decisions 149


4.1 Relational Operators 149
4.2 The if Statement 154
4.3 Expanding the if Statement 162
4.4 The if/else Statement 166
4.5 Nested if Statements 169
4.6 The if/else if Statement 176
4.7 Flags 181
4.8 Logical Operators 182
4.9 Checking Numeric Ranges with Logical Operators 189
4.10 Menus 190
4.11 Focus on Software Engineering: Validating User Input 193
4.12 Comparing Characters and Strings 195
4.13 The Conditional Operator 199
4.14 The switch Statement 202
4.15 More About Blocks and Variable Scope 211

CHAPTER 5 Loops and Files 227


5.1 The Increment and Decrement Operators 227
5.2 Introduction to Loops: The while Loop 232
5.3 Using the while Loop for Input Validation 239
5.4 Counters 241
5.5 The do-while Loop 242
5.6 The for Loop 247
5.7 Keeping a Running Total 257
5.8 Sentinels 260
5.9 Focus on Software Engineering: Deciding Which Loop to Use 261
5.10 Nested Loops 262
5.11 Using Files for Data Storage 265
5.12 Optional Topics: Breaking and Continuing a Loop 284

CHAPTER 6 Functions 299


6.1 Focus on Software Engineering: Modular Programming 299
6.2 Defining and Calling Functions 300
6.3 Function Prototypes 309
6.4 Sending Data into a Function 311
Contents ix

6.5 Passing Data by Value 316


6.6 Focus on Software Engineering: Using Functions in a
Menu-Driven Program 318
6.7 The return Statement 322
6.8 Returning a Value from a Function 324
6.9 Returning a Boolean Value 332
6.10 Local and Global Variables 334
6.11 Static Local Variables 342
6.12 Default Arguments 345
6.13 Using Reference Variables as Parameters 348
6.14 Overloading Functions 354
6.15 The exit() Function 358
6.16 Stubs and Drivers 361

CHAPTER 7 Arrays 375


7.1 Arrays Hold Multiple Values 375
7.2 Accessing Array Elements 377
7.3 No Bounds Checking in C++ 384
7.4 Array Initialization 387
7.5 The Range-Based for Loop 392
7.6 Processing Array Contents 396
7.7 Focus on Software Engineering: Using Parallel Arrays 404
7.8 Arrays as Function Arguments 407
7.9 Two-Dimensional Arrays 418
7.10 Arrays with Three or More Dimensions 425
7.11 Focus on Problem Solving and Program Design: A Case Study 427
7.12 If You Plan to Continue in Computer Science: Introduction to the
STL vector 429

CHAPTER 8 Searching and Sorting Arrays 457


8.1 Focus on Software Engineering: Introduction to Search Algorithms 457
8.2 Focus on Problem Solving and Program Design: A Case Study 463
8.3 Focus on Software Engineering: Introduction to Sorting Algorithms 470
8.4 Focus on Problem Solving and Program Design: A Case Study 477
8.5 If You Plan to Continue in Computer Science: Sorting and
Searching vectors 485

CHAPTER 9 Pointers 495


9.1 Getting the Address of a Variable 495
9.2 Pointer Variables 497
9.3 The Relationship Between Arrays and Pointers 504
9.4 Pointer Arithmetic 508
9.5 Initializing Pointers 510
9.6 Comparing Pointers 511
9.7 Pointers as Function Parameters 513
9.8 Focus on Software Engineering: Dynamic Memory Allocation 522
9.9 Focus on Software Engineering: Returning Pointers from Functions 526
9.10 Using Smart Pointers to Avoid Memory Leaks 533
9.11 Focus on Problem Solving and Program Design: A Case Study 536
x Contents

CHAPTER 10 Characters, C-Strings, and More About the string Class 547
10.1 Character Testing 547
10.2 Character Case Conversion 551
10.3 C-Strings 554
10.4 Library Functions for Working with C-Strings 558
10.5 C-String/Numeric Conversion Functions 569
10.6 Focus on Software Engineering: Writing Your Own
C-String-Handling Functions 575
10.7 More About the C++ string Class 581
10.8 Focus on Problem Solving and Program Design: A Case Study 590

CHAPTER 11 Structured Data 599


11.1 Abstract Data Types 599
11.2 Focus on Software Engineering: Combining Data into Structures 601
11.3 Accessing Structure Members 604
11.4 Initializing a Structure 608
11.5 Arrays of Structures 611
11.6 Focus on Software Engineering: Nested Structures 613
11.7 Structures as Function Arguments 617
11.8 Returning a Structure from a Function 620
11.9 Pointers to Structures 623
11.10 Focus on Software Engineering: When to Use ., When to Use ->,
and When to Use * 626
11.11 Unions 628
11.12 Enumerated Data Types 632

CHAPTER 12 Advanced File Operations 657


12.1 File Operations 657
12.2 File Output Formatting 663
12.3 Passing File Stream Objects to Functions 665
12.4 More Detailed Error Testing 667
12.5 Member Functions for Reading and Writing Files 670
12.6 Focus on Software Engineering: Working with Multiple Files 678
12.7 Binary Files 680
12.8 Creating Records with Structures 685
12.9 Random-Access Files 689
12.10 Opening a File for Both Input and Output 697

CHAPTER 13 Introduction to Classes 711


13.1 Procedural and Object-Oriented Programming 711
13.2 Introduction to Classes 718
13.3 Defining an Instance of a Class 723
13.4 Why Have Private Members? 736
13.5 Focus on Software Engineering: Separating Class Specification
from Implementation 737
13.6 Inline Member Functions 743
13.7 Constructors 746
13.8 Passing Arguments to Constructors 750
Contents xi

13.9 Destructors 758


13.10 Overloading Constructors 762
13.11 Private Member Functions 765
13.12 Arrays of Objects 767
13.13 Focus on Problem Solving and Program Design: An OOP Case Study 771
13.14 Focus on Object-Oriented Programming: Simulating Dice with Objects 778
13.15 Focus on Object-Oriented Programming: Creating an Abstract Array
Data Type 782
13.16 Focus on Object-Oriented Design: The Unified Modeling Language (UML) 785
13.17 Focus on Object-Oriented Design: Finding the Classes and Their
Responsibilities 788

CHAPTER 14 More About Classes 811


14.1 Instance and Static Members 811
14.2 Friends of Classes 819
14.3 Memberwise Assignment 824
14.4 Copy Constructors 825
14.5 Operator Overloading 831
14.6 Object Conversion 858
14.7 Aggregation 860
14.8 Focus on Object-Oriented Design: Class Collaborations 865
14.9 Focus on Object-Oriented Programming: Simulating the Game
of Cho-Han 869

CHAPTER 15 Inheritance, Polymorphism, and Virtual Functions 891


15.1 What Is Inheritance? 891
15.2 Protected Members and Class Access 900
15.3 Constructors and Destructors in Base and Derived Classes 906
15.4 Redefining Base Class Functions 918
15.5 Class Hierarchies 923
15.6 Polymorphism and Virtual Member Functions 929
15.7 Abstract Base Classes and Pure Virtual Functions 945
15.8 Multiple Inheritance 952

CHAPTER 16 Exceptions, Templates, and the Standard Template


Library (STL) 971
16.1 Exceptions 971
16.2 Function Templates 990
16.3 Focus on Software Engineering: Where to Start When Defining Templates 996
16.4 Class Templates 996
16.5 Introduction to the Standard Template Library (STL) 1005

CHAPTER 17 Linked Lists 1025


17.1 Introduction to the Linked List ADT 1025
17.2 Linked List Operations 1027
17.3 A Linked List Template 1043
17.4 Variations of the Linked List 1055
17.5 The STL list Container 1056
xii Contents

CHAPTER 18 Stacks and Queues 1063


18.1 Introduction to the Stack ADT 1063
18.2 Dynamic Stacks 1080
18.3 The STL stack Container 1091
18.4 Introduction to the Queue ADT 1093
18.5 Dynamic Queues 1105
18.6 The STL deque and queue Containers 1112

CHAPTER 19 Recursion 1121


19.1 Introduction to Recursion 1121
19.2 Solving Problems with Recursion 1125
19.3 Focus on Problem Solving and Program Design: The Recursive
gcd Function 1133
19.4 Focus on Problem Solving and Program Design: Solving Recursively
Defined Problems 1134
19.5 Focus on Problem Solving and Program Design: Recursive Linked List
Operations 1135
19.6 Focus on Problem Solving and Program Design: A Recursive Binary
Search Function 1139
19.7 The Towers of Hanoi 1141
19.8 Focus on Problem Solving and Program Design: The QuickSort Algorithm 1144
19.9 Exhaustive Algorithms 1148
19.10 Focus on Software Engineering: Recursion vs. Iteration 1151

CHAPTER 20 Binary Trees 1155


20.1 Definition and Applications of Binary Trees 1155
20.2 Binary Search Tree Operations 1158
20.3 Template Considerations for Binary Search Trees 1175

Appendix A: Getting Started with Alice 1185


Appendix B: The ASCII Character Set 1211
Appendix C: Operator Precedence and Associativity 1213
Quick References 1215
Index 1217
Credit 1237

Online The following appendices are available at www.pearsonhighered.com/gaddis.


Appendix D: Introduction to Flowcharting
Appendix E: Using UML in Class Design
Appendix F: Namespaces
Appendix G: Passing Command Line Arguments
Appendix H: Header File and Library Function Reference
Appendix I: Binary Numbers and Bitwise Operations
Appendix J: Multi-Source File Programs
Appendix K: Stream Member Functions for Formatting
Appendix L: Answers to Checkpoints
Appendix M: Solutions to Odd-Numbered Review Questions
LOCATION OF VIDEONOTES IN THE TEXT

Chapter 1 Introduction to Flowcharting, p. 20


Designing a Program with Pseudocode, p. 20
Designing the Account Balance Program, p. 25
Predicting the Result of Problem 33, p. 26
Chapter 2 Using cout, p. 31
Variabe Definitions, p. 37
Assignment Statements and Simple Math Expressions, p. 62
Solving the Restaurant Bill Problem, p. 80
Chapter 3 Reading Input with cin, p. 83
Formatting Numbers with setprecision, p. 111
Solving the Stadium Seating Problem, p. 142
Chapter 4 The if Statement, p. 154
The if/else statement, p. 166
The if/else if Statement, p. 176
Solving the Time Calculator Problem, p. 221
Chapter 5 The while Loop, p. 232
The for Loop, p. 247
Reading Data from a File, p. 274
Solving the Calories Burned Problem, p. 293
Chapter 6 Functions and Arguments, p. 311
Value-Returnlng Functions, p. 324
Solving the Markup Problem, p. 366
Chapter 7 Accessing Array Elements With a Loop, p. 380
Passing an Array to a Function, p. 407
Solving the Chips and Salsa Problem, p. 448
Chapter 8 The Binary Search, p. 460
The Selection Sort, p. 474
Solving the Charge Account Validation Modification Problem, p. 492
Chapter 9 Dynamically Allocating an Array, p. 523
Solving the Pointer Rewrite Problem, p. 545
Chapter 10 Writing a C-String-Handling Function, p. 575
More About the string Class, p. 581
Solving the Backward String Problem, p. 594
(continued on the next page)
LOCATION OF VIDEONOTES IN THE TEXT (continued)

Chapter 11 Creating a Structure, p. 601


Passing a Structure to a Function, p. 617
Solving the Weather Statistics Problem, p. 652
Chapter 12 Passing File Stream Objects to Functions, p. 665
Working with Multiple Files, p. 678
Solving the File Encryption Filter Problem, p. 708
Chapter 13 Writing a Class, p. 718
Defining an Instance of a Class, p. 723
Solving the Employee Class Problem, p. 802
Chapter 14 Operator Overloading, p. 831
Class Aggregation, p. 860
Solving the NumDays Problem, p. 885
Chapter 15 Redefining a Base Class Function in a Derived Class, p. 918
Polymorphism, p. 929
Solving the Employee and Production-Worker Classes Problem, p. 963
Chapter 16 Throwing an Exception, p. 972
Handling an Exception, p. 972
Writing a Function Template, p. 990
Storing Objects in a vector, p. 1010
Solving the Exception Project Problem, p. 1024
Chapter 17 Appending a Node to a Linked List, p. 1028
Inserting a Node in a Linked List, p. 1035
Deleting a Node from a Linked List, p. 1039
Solving the Member Insertion by Position Problem, p. 1061
Chapter 18 Storing Objects in an STL stack, p. 1091
Storing Objects in an STL queue, p. 1114
Solving the File Compare Problem, p. 1119
Chapter 19 Reducing a Problem with Recursion, p. 1126
Solving the Recursive Multiplication Problem, p. 1153
Chapter 20 Inserting a Node in a Binary Tree, p. 1160
Deleting a Node from a Binary Tree, p. 1166
Solving the Node Counter Problem, p. 1182
Preface

Welcome to Starting Out with C++: From Control Structures through Objects, 8th edition.
This book is intended for use in a two-semester C++ programming sequence, or an acceler-
ated one-semester course. Students new to programming, as well as those with prior course
work in other languages, will find this text beneficial. The fundamentals of programming
are covered for the novice, while the details, pitfalls, and nuances of the C++ language are
explored in-depth for both the beginner and more experienced student. The book is written
with clear, easy-to-understand language, and it covers all the necessary topics for an intro-
ductory programming course. This text is rich in example programs that are concise, practi-
cal, and real-world oriented, ensuring that the student not only learns how to implement the
features and constructs of C++, but why and when to use them.

Changes in the Eighth Edition


C++11 is the latest standard version of the C++ language. In previous years, while the stan-
dard was being developed, it was known as C++0x. In August 2011, it was approved by
the International Standards Organization (ISO), and the name of the standard was officially
changed to C++11. Most of the popular compilers now support the C++11 standard.
The new C++11 standard was the primary motivation behind this edition. Although this
edition introduces many of the new language features, a C++11 compiler is not strictly
required to use the book. As you progress through the book, you will see C++11 icons in the
margins, next to the new features that are introduced. Programs appearing in sections that
are not marked with this icon will still compile using an older compiler.
Here is a summary of the new C++11 topics that are introduced in this edition:
● The auto key word is introduced as a way to simplify complex variable definitions.
The auto key word causes the compiler to infer a variable’s data type from its initial-
ization value.
● The long long int and unsigned long long int data types, and the LL literal
suffix are introduced.
● Chapter 5 shows how to pass a string object directly to a file stream object’s open
member function, without the need to call the c_str() member function. (A discus-
sion of the c_str()function still exists for anyone using a legacy compiler.)

xv
xvi Preface

● The range-based for loop is introduced in Chapter 7. This new looping mechanism
automatically iterates over each element of an array, vector, or other collection,
without the need of a counter variable or a subscript.
● Chapter 7 shows how a vector can be initialized with an initialization list.
● The nullptr key word is introduced as the standard way of representing a null
pointer.
● Smart pointers are introduced in Chapter 9, with an example of dynamic memory
allocation using unique_ptr.
● Chapter 10 discusses the new, overloaded to_string functions for converting numeric
values to string objects.
● The string class’s new back() and front() member functions are included in
Chapter 10’s overview of the string class.
● Strongly typed enums are discussed in Chapter 11.
● Chapter 13 shows how to use the smart pointer unique_ptr to dynamically allocate
an object.
● Chapter 15 discusses the override key word and demonstrates how it can help prevent
subtle overriding errors. The final key word is discussed as a way of preventing a virtual
member function from being overridden.
In addition to the C++11 topics, the following general improvements were made:
● Several new programming problems have been added to the text, and many of the
existing programming problems have been modified to make them unique from previ-
ous editions.
● The discussion of early, historic computers in Chapter 1 is expanded.
● The discussion of literal values in Chapter 2 is improved.
● The introduction of the char data type in Chapter 2 is reorganized to use character
literals in variable assignments before using ASCII values in variable assignments.
● The discussion of random numbers in Chapter 3 is expanded and improved, with the
addition of a new In the Spotlight section.
● A new Focus on Object-Oriented Programming section has been added to Chapter 13,
showing how to write a class that simulates dice.
● A new Focus on Object-Oriented Programming section has been added to Chapter 14,
showing an object-oriented program that simulates the game of Cho-Han. The program
uses objects for the dealer, two players, and a pair of dice.

Organization of the Text


This text teaches C++ in a step-by-step fashion. Each chapter covers a major set of topics
and builds knowledge as the student progresses through the book. Although the chapters
can be easily taught in their existing sequence, some flexibility is provided. The diagram
shown in Figure P-1 suggests possible sequences of instruction.
Preface xvii

Figure P-1

Chapter 1
Introduction

Chapters 2–7
Basic Language
Elements

Chapter 8 Chapter 9 Chapter 12


Searching and Pointers Advanced File
Sorting Arrays Operations*

*A few subtopics in
Chapter 12 require
Chapter 10 Chapters 9 and 11.
Characters, Strings, Chapter 11
and the string Class Structures

Chapter 13
Introduction to
Classes

Chapter 14
More About Classes

Chapter 15
Inheritance and
Polymorphism

Chapter 16
Exceptions,
Templates, and STL

Chapter 17
Linked Lists

Chapter 18 Chapter 19
Stacks and Queues Recursion

Chapter 20
Binary Trees
xviii Preface

Chapter 1 covers fundamental hardware, software, and programming concepts. You may
choose to skip this chapter if the class has already mastered those topics. Chapters 2 through
7 cover basic C++ syntax, data types, expressions, selection structures, repetition structures,
functions, and arrays. Each of these chapters builds on the previous chapter and should be
covered in the order presented.
After Chapter 7 has been covered, you may proceed to Chapter 8, or jump to either Chapter
9 or Chapter 12. (If you jump to Chapter 12 at this point, you will need to postpone sections
12.7, 12.8, and 12.10 until Chapters 9 and 11 have been covered.)
After Chapter 9 has been covered, either of Chapters 10 or 11 may be covered. After Chap-
ter 11, you may cover Chapters 13 through 17 in sequence. Next you can proceed to either
Chapter 18 or Chapter 19. Finally, Chapter 20 may be covered.
This text’s approach starts with a firm foundation in structured, procedural programming
before delving fully into object-oriented programming and advanced data structures.

Brief Overview of Each Chapter


Chapter 1: Introduction to Computers and Programming
This chapter provides an introduction to the field of computer science and covers the fun-
damentals of programming, problem solving, and software design. The components of pro-
grams, such as key words, variables, operators, and punctuation are covered. The tools of
the trade, such as pseudocode, flow charts, and hierarchy charts are also presented.

Chapter 2: Introduction to C++


This chapter gets the student started in C++ by introducing data types, identifiers, vari-
able declarations, constants, comments, program output, simple arithmetic operations, and
C-strings. Programming style conventions are introduced and good programming style
is modeled here, as it is throughout the text. An optional section explains the difference
between ANSI standard and pre-standard C++ programs.

Chapter 3: Expressions and Interactivity


In this chapter the student learns to write programs that input and handle numeric, char-
acter, and string data. The use of arithmetic operators and the creation of mathematical
expressions are covered in greater detail, with emphasis on operator precedence. Debug-
ging is introduced, with a section on hand tracing a program. Sections are also included on
simple output formatting, on data type conversion and type casting, and on using library
functions that work with numbers.

Chapter 4: Making Decisions


Here the student learns about relational operators, relational expressions and how to con-
trol the flow of a program with the if, if/else, and if/else if statements. The condi-
tional operator and the switch statement are also covered. Crucial applications of these
constructs are covered, such as menu-driven programs and the validation of input.
Preface xix

Chapter 5: Loops and Files


This chapter covers repetition control structures. The while loop, do-while loop, and for
loop are taught, along with common uses for these devices. Counters, accumulators, run-
ning totals, sentinels, and other application-related topics are discussed. Sequential file I/O
is also introduced. The student learns to read and write text files, and use loops to process
the data in a file.

Chapter 6: Functions
In this chapter the student learns how and why to modularize programs, using both void
and value returning functions. Argument passing is covered, with emphasis on when argu-
ments should be passed by value versus when they need to be passed by reference. Scope of
variables is covered, and sections are provided on local versus global variables and on static
local variables. Overloaded functions are also introduced and demonstrated.

Chapter 7: Arrays
In this chapter the student learns to create and work with single and multidimensional
arrays. Many examples of array processing are provided including examples illustrating
how to find the sum, average, highest, and lowest values in an array and how to sum the
rows, columns, and all elements of a two-dimensional array. Programming techniques using
parallel arrays are also demonstrated, and the student is shown how to use a data file as
an input source to populate an array. STL vectors are introduced and compared to arrays.

Chapter 8: Sorting and Searching Arrays


Here the student learns the basics of sorting arrays and searching for data stored in them.
The chapter covers the Bubble Sort, Selection Sort, Linear Search, and Binary Search algo-
rithms. There is also a section on sorting and searching STL vector objects.

Chapter 9: Pointers
This chapter explains how to use pointers. Pointers are compared to and contrasted with
reference variables. Other topics include pointer arithmetic, initialization of pointers, rela-
tional comparison of pointers, pointers and arrays, pointers and functions, dynamic mem-
ory allocation, and more.

Chapter 10: Characters, C-strings, and More About the string Class
This chapter discusses various ways to process text at a detailed level. Library functions for
testing and manipulating characters are introduced. C-strings are discussed, and the tech-
nique of storing C-strings in char arrays is covered. An extensive discussion of the string
class methods is also given.

Chapter 11: Structured Data


The student is introduced to abstract data types and taught how to create them using struc-
tures, unions, and enumerated data types. Discussions and examples include using pointers
to structures, passing structures to functions, and returning structures from functions.
xx Preface

Chapter 12: Advanced File Operations


This chapter covers sequential access, random access, text, and binary files. The various
modes for opening files are discussed, as well as the many methods for reading and writing
file contents. Advanced output formatting is also covered.

Chapter 13: Introduction to Classes


The student now shifts focus to the object-oriented paradigm. This chapter covers the fun-
damental concepts of classes. Member variables and functions are discussed. The student
learns about private and public access specifications, and reasons to use each. The topics of
constructors, overloaded constructors, and destructors are also presented. The chapter pres-
ents a section modeling classes with UML and how to find the classes in a particular problem.

Chapter 14: More About Classes


This chapter continues the study of classes. Static members, friends, memberwise assign-
ment, and copy constructors are discussed. The chapter also includes in-depth sections on
operator overloading, object conversion, and object aggregation. There is also a section on
class collaborations and the use of CRC cards.

Chapter 15: Inheritance, Polymorphism, and Virtual Functions


The study of classes continues in this chapter with the subjects of inheritance, polymor-
phism, and virtual member functions. The topics covered include base and derived class con-
structors and destructors, virtual member functions, base class pointers, static and dynamic
binding, multiple inheritance, and class hierarchies.

Chapter 16: Exceptions, Templates, and the Standard


Template Library (STL)
The student learns to develop enhanced error trapping techniques using exceptions. Discus-
sion then turns to function and class templates as a method for reusing code. Finally, the
student is introduced to the containers, iterators, and algorithms offered by the Standard
Template Library (STL).

Chapter 17: Linked Lists


This chapter introduces concepts and techniques needed to work with lists. A linked list
ADT is developed and the student is taught to code operations such as creating a linked list,
appending a node, traversing the list, searching for a node, inserting a node, deleting a node,
and destroying a list. A linked list class template is also demonstrated.

Chapter 18: Stacks and Queues


In this chapter the student learns to create and use static and dynamic stacks and queues. The
operations of stacks and queues are defined, and templates for each ADT are demonstrated.

Chapter 19: Recursion


This chapter discusses recursion and its use in problem solving. A visual trace of recursive
calls is provided, and recursive applications are discussed. Many recursive algorithms are
presented, including recursive functions for finding factorials, finding a greatest common
Preface xxi

denominator (GCD), performing a binary search, and sorting (QuickSort). The classic Tow-
ers of Hanoi example is also presented. For students who need more challenge, there is a
section on exhaustive algorithms.

Chapter 20: Binary Trees


This chapter covers the binary tree ADT and demonstrates many binary tree operations. The
student learns to traverse a tree, insert an element, delete an element, replace an element, test
for an element, and destroy a tree.

Appendix A: Getting Started with Alice


This appendix gives a quick introduction to Alice. Alice is free software that can be used to
teach fundamental programming concepts using 3D graphics.

Appendix B: ASCII Character Set


A list of the ASCII and Extended ASCII characters and their codes.

Appendix C: Operator Precedence and Associativity


A chart showing the C++ operators and their precedence.

The following appendices are available online at www.pearsonhighered.com/gaddis.

Appendix D: Introduction to Flowcharting


A brief introduction to flowcharting. This tutorial discusses sequence, selection, case, repeti-
tion, and module structures.

Appendix E: Using UML in Class Design


This appendix shows the student how to use the Unified Modeling Language to design
classes. Notation for showing access specification, data types, parameters, return values,
overloaded functions, composition, and inheritance are included.

Appendix F: Namespaces
This appendix explains namespaces and their purpose. Examples showing how to define a
namespace and access its members are given.

Appendix G: Passing Command Line Arguments


Teaches the student how to write a C++ program that accepts arguments from the command
line. This appendix will be useful to students working in a command line environment, such
as Unix, Linux, or the Windows command prompt.

Appendix H: Header File and Library Function Reference


This appendix provides a reference for the C++ library functions and header files discussed
in the book.

Appendix I: Binary Numbers and Bitwise Operations


A guide to the C++ bitwise operators, as well as a tutorial on the internal storage of integers.
xxii Preface

Appendix J: Multi-Source File Programs


Provides a tutorial on creating programs that consist of multiple source files. Function
header files, class specification files, and class implementation files are discussed.

Appendix K: Stream Member Functions for Formatting


Covers stream member functions for formatting such as setf.

Appendix L: Answers to Checkpoints


Students may test their own progress by comparing their answers to the checkpoint exer-
cises against this appendix. The answers to all Checkpoints are included.

Appendix M: Solutions to Odd-Numbered Review Questions


Another tool that students can use to gauge their progress.

Features of the Text


Concept Each major section of the text starts with a concept statement.
Statements This statement summarizes the ideas of the section.
Example Programs The text has hundreds of complete example programs, each
designed to highlight the topic currently being studied. In most
cases, these are practical, real-world examples. Source code for
these programs is provided so that students can run the programs
themselves.
Program Output After each example program there is a sample of its screen
output. This immediately shows the student how the program
should function.
In the Spotlight Each of these sections provides a programming problem and a
detailed, step-by-step analysis showing the student how to
solve it.
VideoNotes A series of online videos, developed specifically for this book, is
available for viewing at www.pearsonhighered.com/gaddis.
Icons appear throughout the text alerting the student to videos
about specific topics.
Checkpoints Checkpoints are questions placed throughout each chapter as
a self-test study aid. Answers for all Checkpoint questions can
be downloaded from the book’s Companion Web site at www.
pearsonhighered.com/gaddis. This allows students to check how
well they have learned a new topic.
Notes Notes appear at appropriate places throughout the text. They are
short explanations of interesting or often misunderstood points
relevant to the topic at hand.
Preface xxiii

Warnings Warnings are notes that caution the student about certain C++
features, programming techniques, or practices that can lead to
malfunctioning programs or lost data.
Case Studies Case studies that simulate real-world applications appear in
many chapters throughout the text. These case studies are de-
signed to highlight the major topics of the chapter in which they
appear.
Review Questions Each chapter presents a thorough and diverse set of review
and Exercises questions, such as fill-in-the-blank and short answer, that check
the student’s mastery of the basic material presented in the chap-
ter. These are followed by exercises requiring problem solving
and analysis, such as the Algorithm Workbench, Predict the Out-
put, and Find the Errors sections. Answers to the odd-numbered
review questions and review exercises can be downloaded from
the book’s Companion Web site at www.pearsonhighered.com/
gaddis.
Programming Each chapter offers a pool of programming exercises designed
Challenges to solidify the student’s knowledge of the topics currently being
studied. In most cases the assignments present real-world prob-
lems to be solved. When applicable, these exercises include input
validation rules.
Group Projects There are several group programming projects throughout the
text, intended to be constructed by a team of students. One
student might build the program’s user interface, while another
student writes the mathematical code, and another designs and
implements a class the program uses. This process is similar to
the way many professional programs are written and encourages
team work within the classroom.
Software Available for download from the book’s Companion Web site at
Development www.pearsonhighered.com/gaddis. This is an ongoing project
Project: that instructors can optionally assign to teams of students. It
Serendipity systematically develops a “real-world” software package: a
Booksellers point-of-sale program for the fictitious Serendipity Booksellers
organization. The Serendipity assignment for each chapter adds
more functionality to the software, using constructs and tech-
niques covered in that chapter. When complete, the program will
act as a cash register, manage an inventory database, and produce
a variety of reports.
C++ Quick For easy access, a quick reference guide to the C++ language is
Reference Guide printed on the last two pages of Appendix C in the book.

11 C++11 Throughout the text, new C++11 language features are


introduced. Look for the C++11 icon to find these new features.
xxiv Preface

Supplements
Student Online Resources
Many student resources are available for this book from the publisher. The following items
are available on the Gaddis Series Companion Web site at www.pearsonhighered.com/gaddis:
● The source code for each example program in the book
● Access to the book’s companion VideoNotes
● A full set of appendices, including answers to the Checkpoint questions and answers
to the odd-numbered review questions
● A collection of valuable Case Studies
● The complete Serendipity Booksellers Project

Integrated Development Environment (IDE) Resource Kits


Professors who adopt this text can order it for students with a kit containing five popular
C++ IDEs (Microsoft® Visual Studio Express Edition, Dev C++, NetBeans, Eclipse, and
CodeLite) and access to a Web site containing written and video tutorials for getting started
in each IDE. For ordering information, please contact your campus Pearson Education rep-
resentative or visit www.pearsonhighered.com/cs.

Online Practice and Assessment with MyProgrammingLab


MyProgrammingLab helps students fully grasp the logic, semantics, and syntax of pro-
gramming. Through practice exercises and immediate, personalized feedback, MyProgram-
mingLab improves the programming competence of beginning students who often struggle
with the basic concepts and paradigms of popular high-level programming languages.
A self-study and homework tool, a MyProgrammingLab course consists of hundreds of
small practice exercises organized around the structure of this textbook. For students, the
system automatically detects errors in the logic and syntax of their code submissions and
offers targeted hints that enable students to figure out what went wrong—and why. For
instructors, a comprehensive gradebook tracks correct and incorrect answers and stores the
code inputted by students for review.
MyProgrammingLab is offered to users of this book in partnership with Turing’s Craft, the
makers of the CodeLab interactive programming exercise system. For a full demonstration,
to see feedback from instructors and students, or to get started using MyProgrammingLab
in your course, visit www.myprogramminglab.com.

Instructor Resources
The following supplements are available to qualified instructors only:
• Answers to all Review Questions in the text
• Solutions for all Programming Challenges in the text
• PowerPoint presentation slides for every chapter
• Computerized test bank
Another random document with
no related content on Scribd:
eyes with her own liquid eyes, and seemed ready to fall into his
arms, when I got up behind him and lighted a giant fire cracker and
put it under his chair and just as the fuse was sputtering, I said, “Pa,
ma wants you at the hotel,” and the fireworks went off, the woman
threw a fit and Pa raised up out of the smoke and looked at me and
said, “Now, where in hell did you come from just at this time?” and
the head waiter took the woman into a private room to bring her out
of her fit, the waiters opened the windows to let the smoke out, and
the crowd stampeded, and the police came in to pull the place and
find the anarchist who threw the bomb, and Pa took me by the hand
and we walked up the sidewalk to a corner, and when we got out of
sight of the crowd Pa said, “Hennery, your ma ain’t here, is she?” in
a pitiful tone, and I said no she wasn’t along with me this trip, and Pa
said, “Hennery, you make me weary,” and we walked along to the
hotel, Pa asking me so many questions about home that it was a like
a catekism.
The Fireworks Went Off—the Woman Threw a Fit, and Pa
Raised Out of the Smoke.

When we got to the hotel and went to Pa’s room and I told him what I
had been doing since he abandoned me, he said he was proud of
me, and now he had plenty of work and adventure for me to keep
him in.
He said he had tried several airships, by having someone else go up
in them, and that he was afraid to go up in one himself, and he
seemed glad that I had been ballooning around home, and he said
he could use me to good advantage.
I asked him about the woman he was talking to about marriage, and
he said that was all guff, that she had a husband who had invented a
new airship, and he was trying to get title to it for use in America, for
war purposes, and that the only way to get on the right side of these
French women was to talk about marriage and money, because for
money any of them would leave their husbands on fifteen minutes’
notice. He said he had arranged for a trial of the airship the next day,
from a place out in the country, and that I could go up with the
inventor of the ship and see how it worked and report, so we went to
bed and I slept better than I had since I shipped on the cattle ship.
In the morning while we were taking baths and preparing for
breakfast, I found that Pa had been flying pretty high on government
money, and he had all kinds of gold and paper money and bonds,
and he made people think he owned most of America.
Pa asked me how the people at home looked upon his absence, and
if they advanced any theories as to the cause of his being abroad,
and I told him that everybody from the President down to Rockefeller
knew about what he was out looking after, and that when I left Bob
Evans at Fortress Monroe he told me to tell Pa to send a mess of
airships to him so he would meet them when he got to San
Francisco, as he wanted to paralyze the Japs if they got busy around
the fleet, which pleased Pa, and he said, “Just tell the people to wait,
and I will produce airships that can fight battles in the clouds, but it
will take time.”
Then we went out in the country about a dozen miles, and met the
inventor and his wife, and the inventor filled a big balloon that looked
like a weiner sausage with gas that he made over a fire out in a field,
and the inventor and I got on a bamboo frame under the balloon, and
he turned on the gasoline that runs the wheel for steering, and they
cut her loose and we went up about fifty feet and sailed around the
country a half mile either way and watched Pa and the wife of the
inventor as they sat under a tree and talked politics.
We came back after a while and Pa was proud of me for having so
much nerve, and I told him the government at home was
complaining because Pa didn’t go up in the airships, cause they said
he couldn’t buy airships intelligently unless he tried them out, and
that if he didn’t look out they would send some expert out to take his
place and spend the money, and as we were landed on the ground I
dared Pa to get on the frame and go up with us for a little spin, and
he was afraid the woman would think he was a coward if he didn’t,
so he got up and straddled the ridge pole of the bamboo frame, and
said he would take a whirl at it if it killed him. The balloon thing
couldn’t quite lift all of us, so I got off and give her a lift, and up she
went with the inventor steering, and Pa hanging on for dear life and
saying, “Now I lay me down to sleep.”

Up She Went with the Inventor Steering, and Pa Hanging On


for Dear Life.
I have seen some scared men in my life, but when the machine got
up about as high as a house, so Pa couldn’t get off, and the woman
waved a handkerchief at Pa, he swallowed his Adam’s apple and
said, “Let her go Gallagher,” and Gallagher, the Frenchman, let her
go.
Well, you’d a died to see the thing wobble and see Pa cling on with
his feet and hands. For about a quarter of a mile she went queer, like
a duck that has been wing-tipped, and then she began to descend.
First she passed over a lot of cows that women were milking, and
the cows stampeded one way and the women the other way, and the
women were scared more than the cows, cause when they got out
from under the ship they prayed, but the cows didn’t.
Then the ship struck a field where about forty women were piling
onions on the ground, and it just scattered women and onions all
over the field, and of all the yelling you ever heard that was the
worst.
Pa yelled to them that if he ever got off that hay rack alive he would
pay the damages, and he thought he was swearing at them. Then
the worst thing possible happened. The airship went up over a tree,
and Pa was scared and he grabbed a limb and let go of the bamboo,
and there he was in the top of a thornapple tree. The balloon went
over all right, and the inventor steered it away to where it started
from, and the woman and I watched Pa. The thorns were about two
inches long and more than a hundred of them got into Pa and he
yelled all kinds of murder, and then the women who owned the cows
and onions the ship had wrecked surrounded the tree with hoes and
rakes and pitchforks, and they made such a frantic noise that Pa did
not dare to come down out of the tree. So Pa told us to take the train
back to Paris and send the American Consul and the police and a
hook and ladder company to get him down and protect him.
I told Pa I didn’t want to go off and leave him to be killed by strange
women, and maybe eaten by wolves before morning, but he said,
“Don’t talk back to me, you go and send that patrol wagon and the
hook and ladder truck, and be quick about it or I won’t do a thing to
you when I catch you.”
So we went and put the airship in a barn and went back to town and
turned in a police and fire alarm to rescue Pa. The chief said there
was no use in going out there in the country before morning,
because the women couldn’t get up the thornapple tree and Pa
couldn’t get down. So I went to bed and dreamed about Pa all night,
and had a perfectly lovely time.
CHAPTER X.
Pa Had the Hardest Time of His Life in Paris—Pa Drinks Some Goat
Milk Which Gives Him Ptomaine Poison in His Inside Works—Pa
Attends the Airship Club in the Country—Pa Draws on American
Government for $10,000.

Pa has had the hardest time of his life in Paris, and if I ever pitied a
man it was Pa.
You see that last fly in the airship pretty near caused him to cash in
his chips and go over the long road to the hereafter, cause he got
blood poison from the thorns that run into him where he landed in the
top limbs of the thorn apple tree, and he sprained his arm and one
hind leg while being taken down with a derrick, and then before we
left the country town for Paris he drank some goat’s milk, which gave
him ptomaine poison in his inside works, and a peasant woman who
sewed up his pants where they were torn on the tree pricked him
with a needle, and he swelled up so he was unable to sit in a car
seat, and his face was scratched by the thorns of the tree, and there
were blotches all over him, so when we got to Paris the health
officers thought he had smallpox and sent him to a pest house, and
they wouldn’t let me in, but vaccinated me and turned me loose, and
I went to the hotel and told about where Pa was and all about it, and
they put our baggage in a sort of oven filled with sulphur and
disinfected it and stole some of it, and they made me sleep in a dog
kennel, and for weeks I had to keep out of sight, until Pa was
discharged from the hospital, and the friends of Pa out at the airship
club in the country got Pa’s airship that he bought for a government
out of the tree and took it to the club and presented a bill for two
hundred dollars, and I only had seven dollars, so they held it for
ransom.
Gee, but I worried about Pa!
Well, one day Pa showed up at the hotel looking like he had been in
a railroad wreck, and he was so thin his clothes had to be pinned up
with safety pins, and he had spent all his money and was bursted.
The man who hired Pa in Washington to go abroad and buy airships
for the government told Pa to use his own money for a month or two
and then draw on the secretary of the treasury for all he needed, so
before Pa went to the hospital he drew on his government for ten
thousand dollars, and when he came back there was a letter for him
from the American consul in Paris telling him to call at the office, so
Pa went there and they arrested him on the charge of skull dugging.
They said he had no right to draw for any money on the government
at Washington. Pa showed his papers with the big seal on, and the
consul laughed in Pa’s face, and Pa was hot under the collar and
wanted to fight, but they showed him that the papers he had were no
good, and that he had been buncoed by some fakir in Washington,
who got five hundred dollars from Pa for securing him a job as
government agent, and all his papers authorized him to do was to
travel at his own expense and to buy all the airships he wanted to
with his own money, and Pa had a fit. All the money he had spent
was a dead loss, and all he had to show for it was a punctured
airship, which he was afraid to ride in.
Pa swore at the government, at the consul and at the man who
buncoed him, and they released him from arrest when he promised
that he would not pose any more as a government agent, and we
went back to the hotel.
“Well, this is a fine scrape you have got me in,” says Pa, as we went
to our room. “What in thunder did I have to do about it?” says I, just
like that. “I wasn’t with you when you framed up this job and let a
man in Washington skin you out of your money by giving you a soft
snap which has exploded in your hands. Gee, Pa, what you need is
a maid or a valet or something that will hold on to your wad.” Pa said
he didn’t need anybody to act as a guardian to him, cause he had all
the money he needed in his letter of credit to the American Express
Company in Paris, and he knew how to spend his money freely, but
he did hate to be buncoed and made the laughing stock of two
continents.
So Pa and I went down to the express office, and Pa gave the man
in charge a paper, and the grand hailing sign of distress, and he
handed out bags of gold and bales of bills, and Pa hid a lot in his
leather belt and put some in his pockets, and said: “Come on, Henry,
and we will see this town and buy it if we like it.”
Well, we went out after dark and took in the concert halls and things,
and Pa drank wine and I drank nothing but ginger ale, and women
who waited on us sat in Pa’s lap and patted his bald head and tried
to feel in his pockets, but Pa held on to their wrists and told them to
keep away, and he took one across his knee and slapped her across
the pajamas with a silver tray, and I thought Pa was real saucy.
A head waiter whispered to me and wanted to know what ailed the
old sport, and I told him Pa was bitten by a wolf in our circus last
year and we feared he was going to have hydrophobia, and always
when these spells come on the only thing to do was to throw him into
a tank of water, and I should be obliged to them if they would take Pa
and duck him in the fountain in the center of the cafe and save his
life.
Pa was making up with the girl he had paddled with the silver tray,
buying champagne for her and drinking some of it himself out of her
slipper, when the head waiter called half a dozen Frenchmen who
were doing police duty and told them to duck Pa in the fountain, and
they grabbed him by the collar and the pants and made him walk
turkey towards the fountain, and he held on to the girl, and the
Frenchmen threw Pa and the girl into the brink with a flock of ducks,
and they went under water, and Pa came up first yelling murder, and
then the girl came up hanging to Pa’s neck, and she gave a French
yell of agony, and Pa gave the grand hailing sign of distress and
yelled to know if there was not an American present that would
protect an American citizen from the hands of a Paris mob. The
crowd gathered around the circular fountain basin, and one drunken
fellow jumped in the water and was going to hold Pa’s head under
water while the girl found his money, when Pa yelled “Hey, Rube,”
the way they do in a circus when there is a fight, and by ginger it
wasn’t a second before half a dozen old circus men that used to
belong to the circus when Pa was manager in the States made a
rush for the fountain, knocked the Frenchmen gally west and pulled
Pa out of the water and let him drain off, and they said, “Hello, old
man, how did you happen to let them drown you?” and Pa saw who
the boys were and he hugged them and invited them to all take
something and then go to his hotel.
When Pa paid the check for the drinks they charged in two ducks
they said Pa killed in the tank by falling on them. But Pa paid it and
was so tickled to meet the old circus boys that he gave the girl he
went in swimming with a twenty franc note, and after staying until
along towards morning we all got into and on top of a hack and went
to the hotel and sat up till daylight talking things over.
We found the Circus boys were on the way to Germany to go with
the Hagenbach outfit to South Africa to capture Wild Animals for
circuses, and when Pa told the boss, who was one of Hagenbach’s
managers, about his airship and what a dandy thing it would be to
sail around where the lions and tigers live in the Jungle, and lasso
them from up in the air, out of danger, he engaged Pa and me to go
along, and I guess we will know all about Africa pretty soon.
The next day we went out to the club where Pa keeps his airship,
with the boss of Hagenbach’s outfit and a cowboy that used to be
with Pa’s circus, to practice lassoing things. They got out the
machine and Pa steered it, and the boss and I were passengers, and
the cowboy was on the railing in front with his lariat rope, and we
sailed along about fifty feet high over the farms, until we saw a big
goat. The cowboy motioned for Pa to steer towards the goat, and
when we got near enough the cowboy threw the rope over the goat’s
horns and tightened it up, and Mr. Goat came right along with us,
bleating and fighting. We led the goat about half a mile over some
fences, and finally came down to the ground to examine our catch,
and we landed all right, and Hagenbach’s boss said it was the
greatest scheme that ever was for catching wild animals, and he
doubled Pa’s salary and said we would pack up the next day and go
to the Hagenbach farm in Germany and take a steamer for South
Africa in a week.
They were talking it over and the cowboy had released the goat,
when that animal made a charge with his head on our party. He
struck Pa below the belt, butted the boss in the trousers until he laid
down and begged for mercy, stabbed the cowboy with his horns and
then made a hop, skip and jump for the gas bag, burst a hole in it,
and when the gas began to escape the goat’s horns got caught in
the gas bag and the goat died from the effects of the gas, and we
were all glad until about fifty peasant women came across the fields
with agricultural implements and were going to kill us all.
Pa said, “Well, what do you know about that,” but the women were
fierce and wanted our blood. The boss could talk French, and he
offered to give them the goat to settle it, but they said it was their
goat any way, and they wanted blood or damages.
Pa said it was easier to give damages than blood, and just as they
were going to cut up the gas bag the boss settled with them for
about twenty dollars, and hired them to haul the airship to the
nearest station, and we shipped it to Berlin and got ready to follow
the next day.
Pa says we will have a high old time in Africa. He says he wants to
ride up to a lion’s den in his airship and dare the fiercest lion to come
out and fight, and that he wouldn’t like any better fun than to ride
over a royal bengal tiger in the jungle and reach down and grab his
tail and make him synawl like a tom cat on a fence in the alley.
He talks about riding down a herd of elephants and picking out the
biggest ones and roping them; and the way Pa is going to scare
rhinoceroses and hippopotamuses and make them bleat like calves
is a wonder.
I think Pa is the bravest man I ever saw, when he tells it, but I
noticed when we had that goat by the horns and he was caught in a
barbed wire fence, so the airship had to slow down until he came
loose, Pa turned as pale as a sheet, and when the goat bucked him
in the stomach Pa’s lips moved as though in praying. Well, anyway,
this trip to Africa to catch wild animals is going to show what kind of
sand there is in all of us.
CHAPTER XI.
The Boy and His Pa Leave France and Go to Germany, Where They
Buy an Airship—They Get the Airship Safely Landed—Pa and the
Boy With the Airship Start for South Africa—Pa Shows the Men
What Power He Has Over the Animal Kingdom.

I was awful glad to get out of France and into Germany, and when
we had got the airship safely landed at the Hagenbach stock farm
and boxed and baled ready to load on a boat for South Africa, and all
hands had drank a few schooners of beer, and felt brave enough to
tackle any wild animal that walks the earth, I listened to the big talk
and the gestures, though I couldn’t understand a word they said,
except when they held up their fingers for more beer.
I felt that we had got among Americans again, because all a German
needs to be an American is to be able to talk a little broken English.
The French are all right in their way, but they are too polite. If a
Frenchman wants to order you out of his place he is so polite about it
that you think he wants you to stay there always and be at home.
If a German wants you to get out he says “Rouse” in a hoarse voice,
and if you don’t rouse he gives you a swift kick in the pants and you
instinctively catch on to the fact that you are due some other place.
The Germans that are with us on the animal hunt in South Africa all
speak English, and while at the Hagenbach farm Pa convinced
everybody that he was the bravest animal man in the world, “cause
he would go up to any cage where the animals had been tamed and
act as free with them as though he did not know fear,” and he went
around in his shirt sleeves the way he used to in the circus, and
would pat a lion on the head, and if the animal growled Pa would
scowl at him and make the lion believe Pa was king of beasts.
Pa has found that putting on a pair of automobile goggles and
getting down on his hands and knees and crawling towards the
animal in captivity frightens the animal into a fit, but I guess when he
tries that stunt on wild animals on the veldt of Africa he will find it
does not work so well.
I expect to have to bring Pa back the way they transport canned
sausage, after a few wild lions and tigers and hippopotamuses have
used him for a cud to chew on.
Before we took the steamer for South Africa I had the first serious
talk with Pa that I have had since I joined him in Paris. I said, “Pa,
don’t you think this idea of chasing wild animals in Africa with an
airship is going to be a sort of a dangerous proposition?” and Pa
began to look brave, and he said, “Hennery, this is an age of
progress, and we have to get out of the rut, and catch up with the
procession and lead it. The old way of capturing wild animals by
enticing them into baited traps and letting them touch a spring and
imprison themselves is about as dangerous as catching mice in a
wire trap with a piece of cheese for bait.
“Of course, we shall take along all of the traps and things usually
used for that purpose, because roping animals from an airship is
only an experiment, and we want to be on the safe side, but if the
airship proves a success I will be considered the pioneer in airship
wild animal capturing, and all animal men will bow down to your Pa,
see, and my fortune will be made. We will get into the animal country
and locate a few lions and tigers, first, and sail over their lairs in the
jungle, and while I hold the steering apparatus our cowboys will sit
on the bamboo rails of the ship and throw the rope over their necks,
and when they find we have got them where the hair is short they will
lie down and bleat like a calf, and when we dismount and go up to
them to tie their legs they will be so tame they will eat out of your
hand.
“I have got it all figured out in my mind and I don’t want you or
anybody else to butt in with any discouraging talk, for I won’t have it.”
“But suppose the airship gets caught in a tree?” I said to Pa. “Well,
then, we will tie up and catch baboons,” said Pa. “Everything goes
with your Pa, Hennery.”
Well, it was like moving a circus to get the stuff loaded for South
Africa, as we had more than fifty cages to put animals in to bring
home, and tents and food enough for an arctic expedition, and over
two hundred men, and several tame lionesses and female tigers to
use for decoys, and some elephants for Judases to rope in the wild
animals, and when we got started it was more than a week before
we struck the coast of Africa, and all there was to do on the trip was
to play poker and practice on the tame animals.
We almost lost a tame lioness. Pa wanted to show the men what
power he had over the animal kingdom and he induced the manager
to turn Carrie Nation, the big lioness, loose on deck, while Pa put on
his auto goggles and scared her. Gee, but I thought I was an orphan
for sure. The boys had trained that lioness to be a retriever, like a
water spaniel, and on every trip some of the boys would jump
overboard when there was no sea on and let Carrie jump over the
rail and rescue them, so when they let her out she thought there was
going to be a chance for her to get her regular salt water bath, and
that it was expected that she would do her stunt at rescuing a human
being.
When she was let out of her cage and the crowd was lined up all
around the rail, and she saw Pa in the middle of the deck, on all
fours, with the black goggles on, she looked around at the crowd of
her friends as much as to say, “What is the joke?” but she sidled up
to Pa and lashed her tail around and began to play with Pa as a
kitten would play with a ball of yarn.
She put her paw on Pa and rolled him over, and when Pa got right
side up and crawled towards her looking fierce, she side stepped
and cuffed him on the jaw and everybody laughed except Pa.
Then Pa thought he would make a grandstand play and drive her
back in her cage, and he started towards her real fast on his hands
and knees, and gave a “honk-honk” like an auto, and we thought she
was scared, but I guess she wasn’t frightened so you would notice it,
for she jumped sideways and got around behind Pa, and I said, “Sick
him, Carrie,” and by gosh she grabbed Pa by the slack of his pants
and made a rush for the railing, and before I could grab her by the
tail she jumped right overboard with Pa in her mouth, and landed
kersplash in the deep blue sea, with Pa yelling to the men to take her
off.

Pa Gave a “Honk, Honk” Like an Auto, But the Lion Wasn’t


Frightened So You Would Notice.

We all rushed to the rail, and I began to cry, but the boys told me not
to be scared, as Carrie would bring Pa to the yawl all right.
The men launched a life boat and the lioness was swimming around
with Pa in her teeth, as though she was a dog with a rag doll in its
mouth.
Pa was swallowing salt water and saying something that sounded
like “Now I lay me,” and Carrie was trying to keep his head out of the
water by lifting hard on his pants, and finally the life boat got near
them and they grabbed Pa by the legs and pulled him in and he laid
down in the bottom of the boat, and the lioness climbed over the side
and began to shake herself, and then she licked the salt water off,
and when the boat came alongside she jumped up on the deck and
rolled over and turned somersaults, and then they pulled Pa on deck
and when he got his sea legs on he said to the manager of the
expedition and the captain of the boat, “Gentlemen, I have rescued
your lion, and I claim salvage, and you can give me credit for
whatever she is worth as a show animal,” and then Carrie went to
her cage, and everybody patted Pa on the back and made him think
he had saved a thousand-dollar lion from drowning.
Pa asked me to accompany him to our stateroom, and when the
door was closed and he saw my tear-stained face, he said, “You
think you are dam smart, don’t you? I heard you say sick him to that
old moth-eaten lion, and now don’t you ever interfere with my plans
again. I got that lion so frightened by my fierce look, and the noise I
made, that she jumped overboard, and I went along to save her.
Now, help me off with my clothes and rub me down, and I will go out
and chase a tiger round the deck, and make it climb up into the
rigging and beg to be taken down. That is the kind of a man your Pa
is,” and Pa began to shuck himself, and I rubbed him down as if he
was a race horse. I can see that when we come to the wild animal
fields Pa is going to astonish the natives.
We landed at a port in South Africa in the night, and before morning
we had all our stuff on a special train and about daylight we pulled
out for a place about three hundred miles from the coast, and the
next day we were in camp with the tents all up and the cages in
place, and had engaged two hundred negroes with no clothes on to
help us.
When they saw the airship spread out ready to be filled with gas
when we got ready to use it, some of them deserted, but we got
others to take their places.
I suppose when we fill that gas bag with chemical gas and it begins
to flop around, there won’t be a negro left in Africa.
We were in wild animal country all right. The first night the lions in
the jungle kept us awake, and Carrie Nation answered every time
the wild lions bellowed, until Pa had to go and maul her with a
bamboo club.
The next morning there were lion tracks all around camp, and Pa
says the trouble is going to be that the lions will hunt us instead of
our having to go after them.
A drove of zebras stampeded by our camp the first morning, a
couple of giraffes were looking us over from a hill top, and a
rhinoceros went through the camp and stole a smoked ham.
Pa is so scared he stays in his tent most of the time and shivers. He
says he has got chills and fever, but I can tell when a man’s heart
comes up in his mouth, and chokes him.
I told him this morning that if he showed the white feather now it was
all off with him, and the Hagenbach’s would leave him in Africa to be
adopted by a tribe. Pa said, “You watch me when we get to catching
animals. I will make any animal that crosses my path think he has
run into a live wire.”
Well, I hope Pa will not be a coward.
CHAPTER XII.
All Kinds of Climates in South Africa—Pa Hires Men to Capture Wild
Animals—The Boy and His Pa Capture Some Tigers and a Big Lion
—They Have a Narrow Escape from a Rhinoceros.

I don’t know whether I like the climate of South Africa or not, but you
can have any kind of climate you are looking for, from the Alaska
kind to the tropical kind, the same day.
I think it is the climate that makes all the animals so mad. One
minute a lion or a tiger may be lolling with his tongue out, fighting
flies and scratching fleas, and the next minute there are icicles on his
moustache, and he has to crawl into a hole in the ground to keep
from freezing.
These natives beat me. They do not wear any clothes except a doily,
made of bark or grass, over their loins, and from the doily, above and
below, their skin is bare, and they ought to be arrested for disorderly
conduct and exposure, but their skin is thick and warty like a
rhinoceros, and when it freezes it looks like pickled pigs’ feet.
One man we have hired to help capture animals is a native chief with
sixty wives, and he has brought them all to camp with him, and we
have to feed them, and it is rumored the women all have their caps
set for Pa, if the husband dies, and Pa is afraid they will kill their old
man and select Pa to fill the vacancy, that being the unwritten law
that a man’s wives can select a husband.
Gee, if I had to be a stepson to all those sixty senegambians that
look like monkeys in the face and when on dress parade like oxen, I
should die, or they would, if I could find chloroform enough to go
around.
Well, Pa is trying his best to save the life of that husband of the sixty
wives, and every time one of the wives pats Pa on the back or
chucks him under the chin he has a chill, and I know he will do
something desperate if they get after him in flocks.
I suppose I ought not to have done it, but I told one of the wives who
understands a little English that Pa liked to be hugged and
squeezed, and held on the girls’ laps, so when we get through work
at night and sit around the camp fire they take turns holding Pa on
their laps, and he thinks one of the women broke one of his ribs
hugging him, cause they are strong as giants, and have a terrible
squeeze.
I told one of them she could make herself solid with Pa if she could
get him a nice long snake, so she went off into the jungle alone and
came back dragging a snake more than twenty feet long, and put it
in Pa’s tent when he was asleep. When Pa woke up in the morning
and found the snake coiled upon his blanket he threw a fit and went
to the doctor and got some medicine for chills and fever, and we put
the snake into a cage to sell to a menagerie.

You might also like