100% found this document useful (6 votes)
341 views

(eBook PDF) Starting Out with C++: From Control Structures through Objects 8th Edition 2024 Scribd Download

The document promotes ebookluna.com as a platform for seamless downloads of various programming ebooks, including multiple editions of 'Starting Out with C++' and 'Starting Out with Java'. It provides links to different ebook formats such as PDF, ePub, and MOBI, along with a detailed table of contents for a C++ programming book. The content covers fundamental programming concepts, C++ syntax, and advanced topics like classes, inheritance, and data structures.

Uploaded by

dubiherzon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (6 votes)
341 views

(eBook PDF) Starting Out with C++: From Control Structures through Objects 8th Edition 2024 Scribd Download

The document promotes ebookluna.com as a platform for seamless downloads of various programming ebooks, including multiple editions of 'Starting Out with C++' and 'Starting Out with Java'. It provides links to different ebook formats such as PDF, ePub, and MOBI, along with a detailed table of contents for a C++ programming book. The content covers fundamental programming concepts, C++ syntax, and advanced topics like classes, inheritance, and data structures.

Uploaded by

dubiherzon
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 45

Experience Seamless Full Ebook Downloads for Every Genre at ebookluna.

com

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


Structures through Objects 8th Edition

https://ebookluna.com/product/ebook-pdf-starting-out-with-c-
from-control-structures-through-objects-8th-edition/

OR CLICK BUTTON

DOWNLOAD NOW

Explore and download more ebook at https://ebookluna.com


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

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


through Objects, Brief Version 8th Edition

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

ebookluna.com

(eBook PDF) Starting Out with Java: From Control


Structures through Objects, 7th Edition

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

ebookluna.com

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


to Objects 9th Edition

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

ebookluna.com

(eBook PDF) Starting Out with Java: From Control


Structures through Data Structures 3rd Edition

https://ebookluna.com/product/ebook-pdf-starting-out-with-java-from-
control-structures-through-data-structures-3rd-edition/

ebookluna.com
(eBook PDF) Starting Out with Java: From Control
Structures through Data Structures 4th Edition

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

ebookluna.com

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


Edition

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

ebookluna.com

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


Gaddis (eBook PDF)

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

ebookluna.com

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


Edition

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

ebookluna.com

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


Global Edition

https://ebookluna.com/product/ebook-pdf-starting-out-with-java-early-
objects-5th-global-edition/

ebookluna.com
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
Random documents with unrelated
content Scribd suggests to you:
were now married, and sat on two golden thrones, looking
wonderfully handsome and happy. Below them on the marble floor
all the lords and ladies were dancing the most graceful dances in the
world, and the musicians placed up in a high gallery sang and played
the most delightful music, while tables covered with nice tarts and
cakes and other beautiful things ran down on each side of the hall.
But notwithstanding that Duldy had married the Princess, and was
going to be king when Arago died, he felt quite unhappy, as the foam
bracelet still clasped his wrist.
“What is the matter, Prince?” asked Elsa, putting her beautiful white
arms round his neck; “you look so sad.”
“I’m afraid of Foamina,” said Duldy, showing Elsa his wrist. “Look at
the foam bracelet chaining my wrist; I cannot get it off. Look, you can
see it quite plainly.”
And indeed they could, a slender ring of white foam which clasped
his wrist so tightly that Duldy felt as though it were the hand of the
enchantress grasping him, to drag him away from his lovely bride to
the depths of her cold pool.
“Is it cold?” asked Elsa.
“Yes, very cold,” replied Duldy disconsolately. “I wish I could take it
off.”
“I think I can do that,” said the Princess, laughing. “If it’s cold, it will
soon melt away under my warm kisses;” and so saying, she bent
down and kissed his wrist three times with her red lips. Much to
Duldy’s surprise, at the first kiss the foam bracelet seemed to grow
loose, at the second it fell off his wrist and lay on the floor like a
white ring, and at the third it vanished with a loud noise.
Duldy was overjoyed that he was now free from the power of the
enchantress, and led the Princess out on to the balcony which
overlooked the river. It was a beautiful night, and Duldy saw the
great white peak of Kel shining against the dark blue sky, and the
heaving waters of the river at his feet. Just as he kissed the lips of
his Princess, a confused noise sounded from the city below. The
river, lashing itself into angry waves, began to rise, and as Duldy and
the Princess, full of dismay, retreated to the hall, a crowd of people
rushed in and stopped the dancing.
“Sire! sire!” they called out to the King, “the river is rising round the
city, and all the fountains are spouting foam! We are lost! we are
lost!”
Everything was in confusion, people rushing here and there
shrieking and crying, while the lights of the city died out, and the
cruel, dark waters kept on rising, until every one thought the whole
city would sink beneath the flood.
Duldy knew it was the work of Foamina, and his mind was quite
satisfied on that point when a great white wave of foam rolled into
the hall over the balcony. On this the Water-witch was riding, singing
loudly,—
“Give me my lover,
King’s daughter, king’s daughter,
Or I will cover
Your city with water.”

The Princess shrieked and hid her face on Duldy’s shoulder, while
Arago and all the people around looked at the witch in dismay.
Suddenly Duldy recollected how Salamander had promised to help
him, so he called out,—
“Salamander,
O, withstand her!
She has brought her
Cruel water.
Drive from land her,
Salamander!”

The witch laughed loudly, and the wave rolled on, amid the
lamentations sounding from the city below, when suddenly, in the
place where the Fountain of Jewels had been, a tall flame shot up,
and out of it flashed Salamander, glowing like a beautiful crimson
star.
“Foamina, beware!” he cried, shaking a torch which he held in his
hand; “or I will burn up your springs, scorch your forests, and crush
you for ever.”
“No, you won’t,” said Foamina, flinging her white arms aloft. “This
shepherd is mine—mine! and you can do nothing.”
“Can’t I?” cried Salamander, waving his torch. “Behold!”
There was a great roar, like the report of a thousand cannons, and
every one looked through the open window with a cry of alarm.
Far away, from the snowy peak of Kel shot a tall column of red flame,
with a black cloud above it spreading over the midnight sky, and
vividly bright streams of burning lava began to run down the white
snow like veins of fire.
“Oh, my springs, my springs!” shrieked Foamina wildly; “they will all
be burned up, and I’ll die—I can’t put that fire out.”
“No, you cannot,” said Salamander sternly; “nor will I till you give up
all claim to Duldy.”
“I do! I do!” shrieked the Water-witch, listening with terror to the roar
of the fire mountain.
“And tell Duldy who he really is?” said Salamander relentlessly.
“Yes! yes!” cried Foamina, who was now getting thinner and thinner
as the hot lava scorched her springs in the distant mountain. “Only
stop that cruel, cruel fire!”
“Who am I?” asked Duldy. “Quick! tell me, and Salamander will stop
the fire.”
“You are the son of the old King,” cried Foamina wildly. “I drowned
your mother and carried you off. I surrender all claim to you now,
only stop the fire—stop the fire!”
“You will never do cruel things again?” said Salamander.
“Never!—never!” said the Water-witch, who was now writhing on the
floor.
“Then make the waters leave the city,” cried Duldy.
The Water-witch flew to the window and muttered some words,
whereupon the river sank down to its usual level, all the fountains
stopped pouring out jets of foam, and in a short time the city was as
dry and clean as if no waters had been there at all.
“Now go!” cried Salamander, and stretched out his torch towards the
mountain. Immediately the column of fire sank back again, the
smoke vanished and nothing could be seen but the snow-white
peak, the dark blue sky, and the serene moon. As soon as Foamina
saw this, she gave a cry of joy, and, flinging herself in a foaming
torrent from the window, vanished in the river, and was never seen
again.
Then Salamander turned to Duldy and Arago, who stood near,
delighted with the defeat of the Water-witch.
“You heard what Foamina said,” he observed to Duldy; “you are the
son of the old king, and ought to reign now.”
“And so he shall,” cried Arago, taking off his beautiful silver crown
and placing it on Duldy’s head. “I will give up the throne to Duldy and
my daughter, and become prime minister once more. Hail, King
Duldy!”
“No, he must not be called Duldy,” said Salamander, smiling, “but by
his father’s name. So, Hail, King Sama!”
Then all present, including Arago, kneeled down before Duldy, who
ascended the throne with his silver crown, and his beautiful Queen
Elsa by his side.
“Be happy,” cried Salamander; “you have a kind heart, and that
always brings happiness.”
Whereupon he vanished, and was never more seen again, nor did
he allow the mountain of Kel to breathe fire any more. So King Sama
and Queen Elsa ruled over the land of Metella, and were very, very
happy, and were guided by the advice of Arago, who once more
became prime minister.
Duldy brought Dull and Day from the forest, and gave them a
beautiful palace to live in, but they did not like the city life, and went
back again to their cottage, where they died
after many years.
So Duldy became king after all, but while his
people hailed him as King Sama, his beautiful
wife called him nothing but Duldy, the
shepherd lad who had released her from the
enchantment of the Water-witch.
MOON FANCIES

THERE was once a girl called Lurina, who dwelt with her parents in
a cottage on the edge of a great forest, which was said to be
enchanted. She was an only child, and her parents, whose names
were Panus and Cora, were very fond of her, although she certainly
gave them a great deal of trouble. Not that she was naughty in any
way, for no one could have been better or more obedient; but she
was generally very dull and sleepy all the day, and only woke up at
night-time, when she liked to wander outside in the moonlight,
instead of going to bed. This habit led her parents to think she had
faery blood in her veins, and, although Panus was a dull, stupid man,
he nevertheless remembered how very peculiar his old grandmother
had been in her actions.
Another curious thing was that Lurina had been born just at full
moon, which is the time when all the faeries hold their great monthly
festival, and Cora remembered hearing them singing a birth-song
about little Lurina, who lay by her side. So there was no doubt but
that the faery blood which flowed in the veins of the old grandmother
had missed a generation, and once more came out in Lurina. Panus
and Cora therefore let her do just as she liked, which was the best
thing they could do, as they had been told by a Wise Woman who
lived near them.
Lurina was a most beautiful girl, with golden hair, a delicate white
skin, and dark, dark eyes, which had a somewhat mournful look in
their depths. When she arrived at the age of eighteen, a young
woodman called Berl fell in love with her, and, after some hesitation,
Lurina promised to become his wife, provided he let her do exactly
as she pleased, and did not stop her night wanderings.
“You can go into the forest whenever you like,” said Berl, kissing her;
“but why do you not come when the sun is bright, instead of the
feeble moonlight?”
“I don’t like the sun,” said Lurina, pouting, “it
makes everything so hot and disagreeable;
but the moonlight is so soft and beautiful that I
love it. Besides, you don’t know what strange
fancies come to me when the moon is
shining.”
“What kind of fancies?” asked Berl, who was a
somewhat dull youth.
“Oh, all sorts of beautiful things,” replied
Lurina dreamily; “lovely little men and women
dressed in green, who dance lightly on the
emerald turf, and strange, sweet songs which sound like rushing
water and the whispering of leaves. I dream about them when I’m in
the wood, but nowhere else.”
Berl was now convinced that Lurina had faery blood in her veins, and
attended the festivals of the faeries, which she called moon fancies;
but, being a very cautious man, he said nothing to Lurina;
nevertheless, before he got married he consulted the Wise Woman.
She was really a very wonderful old woman,
with snow-white hair and a form nearly bent
double with age. She listened to Berl’s story
about Lurina’s moon fancies, and then spoke
in a harsh, determined voice.
“Your future wife has dealings with the
faeries,” she said, looking at Berl from under
her bushy white eyebrows; “but what she sees
at night in the forest are real truths, and not
fancies as she thinks. My advice to you is not
to marry her, lest evil befall you.”
But Berl was too much in love with the beautiful Lurina to take this
advice, so he said nothing, but asked Panus and Cora to let him
marry their daughter at once, which they were very pleased to do, for
he was quite a rich man among the woodmen and, moreover, very
good-natured.
The wedding-day arrived at last, and Lurina was married to Berl by
the village pastor. Those who thought she had faery blood in her
veins said she would never be able to enter the church; but, much to
their surprise, nothing unusual occurred at the ceremony, so they
began to think Lurina was only a dull, stupid girl after all. This was a
mistake, however, as you will soon hear.
Berl and Lurina took up their abode in a pretty
cottage under the shade of a great oak, and
lived very happily for a long time. Lurina was
still dreamy and quiet all the day, but as Berl
was generally at work in the wood, he did not
notice it much. At night-time, however, she still
wandered into the forest, especially when the moon was very bright,
and this habit began to annoy Berl very much, but as he had given
his word not to interfere with Lurina, he said nothing.
One night, however, when the moon was full, and the whole of the
forest was bathed in the pale, cold light, he woke up, and, missing
his wife from his side, knew that she had gone into the forest to
indulge in her moon fancies. Berl sprang out of bed, and just caught
a glimpse of her shadow disappearing among the trunks of the trees;
so he rapidly slipped on his clothes and hurried after her, being
determined to find out why she was so fond of these midnight
wanderings.
“She’s going to a meeting of the faeries,” thought Berl, as he ran
across the lawn. “I hope the little people won’t be angry if they see
me; but my wife will protect me.”
For you must know that the faeries never like their revels gazed
upon by mortal eye, and if they catch any one looking they pinch him
black and blue; so Berl had good reason to be afraid of venturing
into the enchanted wood at night.
He followed his wife cautiously, always keeping her in sight, but
taking care she should not see him, when suddenly she crossed an
open glade and vanished. Berl ran after her, but could find no trace
of Lurina at all, and was quite disconsolate, when all at once he
espied her sitting at the foot of a great beech tree, leaning against
the trunk, with her beautiful face looking pale and white in the
moonshine. Having watched her for a long time, he ventured to
approach and call her by name, but, to his astonishment, she did not
answer nor express surprise at seeing him, but simply stared across
the glade with vague, unseeing eyes.
Emboldened by her silence, Berl ran up and fell on his knees with a
little laugh, thinking she would scold him for having dared to follow
her. He was perplexed, however, to see that she still did not seem to
notice him, and when at last he took one of her hands, it was as cold
as ice. Starting up in alarm, he looked closely at her, and found that
she did not breathe—placed his hand on her heart, and discovered
that it did not beat.
“Why, she’s dead!” he cried in alarm. “Lurina, it is I, your husband,
Berl.”
Still Lurina did not answer. So, convinced she was dead, Berl threw
her body over his shoulder and hurried home. When he got inside,
he did everything he could to revive her, but it was no use; the
beautiful Lurina was dead, and Berl sat all night beside her body,
weeping bitterly.
At the first red flush of dawn, he went from house to house, telling
Lurina’s parents and all the neighbours that his wife had died the
preceding night in the forest. Every one came to Berl’s house to see
if it was true, and offer advice, which one’s neighbours are very fond
of doing. Among those who came was the Wise Woman, who
surveyed the beautiful Lurina for some time in silence, then laughed
loudly.
“Why do you laugh?” asked Berl, angry with her for doing so.
“I laugh at your folly,” said the Wise Woman, looking oddly at him.
“Lurina is no more dead than I am.”
“But her heart is not beating, and she does not breathe,” said Panus
quickly.
“Nevertheless, she is not dead,” replied the Wise Woman quietly.
“Have you ever seen her like this before?” she added, turning to
Cora.
“No, never,” answered Cora, who was weeping bitterly.
“Ah! that is because you never followed her to the forest as Berl did,”
said the Wise Woman thoughtfully. “I told you, Berl, that your wife
had faery blood in her veins, and you should have taken my advice
about the marriage.”
“Well, it’s too late now to blame me,” said Berl roughly, for he did not
like to be reproached. “What am I to do?”
“I will tell you,” observed the Wise Woman. “Come to my cottage at
once.”
So Berl left the body of his beautiful Lurina with her parents, and
walked with the Wise Woman to her cottage, which was just on the
verge of the wood, but protected from the entry of the faeries by a
rusty horse-shoe fastened on the door.
When Berl entered, the Wise Woman drew a
circle on the ground with her magic staff,
whereupon a ring of pale flickering fire
appeared; then she pulled seven hairs out of
the tail of her black cat, and threw them into
the midst of the circle, where they began to
twist about in a most surprising manner. While
they were doing this, the Wise Woman waved
her staff seven times in the air, muttering
strange words, and a white smoke arose from
the centre of the fire circle where the hairs
were jumping about. This white smoke went up like a white cloud,
then suddenly vanished, and Berl saw a little man, all dressed in red,
sitting in the centre of the circle.
“Well, what do you want?” he said graciously
to the Wise Woman, whose bright eyes
sparkled when she saw him.
“Why did Lurina die?” asked the Wise
Woman. “Tell me, Pop.”
“She’s not dead at all,” answered Pop quickly;
“she is a faery, and went into the woods to attend the festival. As she
could not join the revels of Oberon in her human body, which would
be too big, she left it behind, leaning against the trunk of a beech
tree, and her faery body went to dance with the faeries. Of course,
when Berl took her body away, she could not find it again when she
returned, and she never will find it till it’s brought back to the same
place.”
“What is to be done, then?” asked the Wise
Woman.
“Berl must take Lurina’s body back again from
where he brought it,” said Pop; “but before
Lurina’s faery body can come back to it, Berl
will have to get permission for it to do so from
Oberon.—Now let me go, I’ve told you all I
know.”
The Wise Woman waved her staff again, the
white smoke came down on the little red man
like an extinguisher, then everything vanished, and Berl found
himself standing outside the door of the cottage, with the Wise
Woman smiling at him.
“You heard what Pop said,” she observed kindly; “you will have to go
to the court of King Oberon, and ask him to let your wife come back.”
“But will he do so?” asked Berl doubtfully.
“Ah, that I do not know,” said the Wise Woman; “but as the faeries
may treat you badly for looking at their festival, take this sprig of the
rowan tree, and it will protect you. Don’t forget to take Lurina’s body
back to the beech tree.”
Berl took the sprig of rowan with its red berries that she handed to
him, and walked away to his own cottage. He did not tell any one
what the Wise Woman had said, but managed to put off all their
questions by pretending to be too grieved to speak. So one after
another the neighbours departed, until only Panus and Cora were
left, and they, too, after kissing the pale lips of Lurina, went away,
leaving Berl alone.
Berl waited impatiently for night to come, and as soon as the moon
was glowing like glittering silver in the starry sky, he took Lurina up in
his arms, and, carrying her into the forest, placed her in the same
position as he had found her, leaning against the trunk of the beech
tree.
When he had done this, he looked round perplexed, for he did not
know how to find the faery court, but, taking out the rowan twig, he
looked at it earnestly, wondering if it would by some magic means
show him the way. But the rowan twig made no sign, and Berl put up
the hand in which he held it to take off his cap and fasten it in it,
when the twig happened to strike his ear, and immediately the silent
forest became full of sounds.
He heard the most delightful music, then a burst of gay laughter,
and, following the direction from whence they proceeded, he came
upon a wide open glade, with a smooth green sward upon which the
moon was shining. Still, though he looked very hard, he could not
see a faery; then, suddenly remembering how the rowan twig had
bewitched his ears, he took it out of his hat, and pressed the red
berries against his eyes. To his delight, he now saw that all the
sward was covered with thousands of little men and women all
dressed in pale green, and at the end was a throne of great white
lilies, upon which sat the King and Queen of Faeryland. All round the
glade were a circle of glow-worms, whose pale lights illuminated the
festival, and the bright moonlight pouring down through the boughs
of the trees made everything as bright as day.

As soon as the faeries discovered that Berl could really see them at
their revels, they shrieked with rage, and hundreds of the little green
creatures swarmed up on his body to pinch him black and blue. Berl
was in a great fright at first, till he suddenly remembered what the
Wise Woman had said about the rowan sprig, so immediately called
out—
“Magic branch of rowan tree,
Work the charm and set me free.”

At once there was a dead silence, and all the faeries fell to the
ground like withered leaves in autumn. Some of them ran to the
throne of lilies, and spoke to the King, upon which Oberon stepped
down, and, followed by a long train, walked up to Berl and
commanded him to sit down. Berl did so, and then Oberon struck the
ground with his wand, whereupon a great red rose sprang up, in
which he took his seat with Queen Titania, while the other faeries
gathered round and prepared to listen.
“Now, mortal,” said Oberon in a dignified manner, “how is it that with
an earthly eye you have beheld the unseen revels of the faeries?”
“It was by this rowan twig, your Majesty,” said Berl, showing Oberon
the sprig; “the Wise Woman gave it to me as a protection, in case
the faeries should be angry.”
“We are only angry with evil-disposed people,” said Oberon gently;
“and if you come here with a pure heart, no one will harm you. What
do you want with us?”
“I want my wife Lurina,” said Berl boldly.
There was a cry of astonishment at this. Suddenly a faery flew
forward on emerald wings, and, as she stood before Oberon, Berl
saw that it was Lurina.
“Yes, your Majesty,” said the faery Lurina, “I am his wife, but he lost
me through his curiosity, as your Majesty knows. I was exiled from
Faeryland many years ago, and condemned to dwell in a human
body. I lived in Lurina’s body, but was allowed by the Queen to join in
the faery revels at night. I told my husband not to follow me, but he
did so, and found my human body lying as if dead under the beech
tree, because I had left it to attend the festival. When I went back, I
could not find it, so had to stay in the forest all day as a faery.”
“Is this true?” asked Oberon, turning to Titania.
“Perfectly true,” answered Titania. “It was I who punished Lurina by
exiling her from Faeryland, but now I think she is punished enough,
and, as she has lost her human body through no fault of her own,
she is pardoned.”
On hearing these words, the faery Lurina dropped on her knees and
kissed the Queen’s hand, then flew off to be congratulated on her
good luck by her faery friends. But Berl was not at all pleased to
think he had lost his wife for ever, and spoke to the King.
“But what am I to do, your Majesty?” he said, with tears in his eyes.
“I love Lurina very much, and don’t want to lose her.”
“There is only one thing to be done,” said Oberon. “Have you
brought back the human body of Lurina?”
“Yes, your Majesty; it’s under the beech tree,” replied Berl eagerly.
“Then I’ll tell you what I’ll do,” said the King. “As the Queen has
pardoned Lurina, of course she can’t go back, as no faery likes to
live in your world; but the faery Mala has been very naughty of late,
so I will condemn her to inhabit your wife’s body, and stay in exile
until she is good enough to come back to court.”
“But that won’t be Lurina,” said Berl.
“She will wear Lurina’s body,” replied Oberon, laughing; “and no one
but yourself will be the wiser. Leave the forest at once, and to-
morrow morning you will see your wife come to the cottage door.
Strike up, music!”
Whereupon the faery music began to play loudly—the blue bells
rang merry chimes, the grasshoppers creaked gaily, and the wind
commenced to sigh among the forest leaves.
Berl dare not disobey the King’s command, and, after seeing Oberon
return to the throne of white lilies, and all the faeries commence their
dance again, he arose to his feet. As he did so, he accidentally
dropped the rowan twig, which was snatched up by a faery at once,
and then the whole of the faery revel vanished. Berl could see
nothing of the dancing, nor hear anything of the music, but only
beheld the smooth green lawn, the myriad trees around, and the
round orb of the moon.
There was nothing left to do but to return home, which he did at
once, and you may be sure he got very little sleep that night. At early
dawn he was standing at his cottage door, looking towards the wood,
when he beheld Lurina tripping gaily towards him, singing merrily.
When she saw Berl, she flung herself into his arms.
“Dear Berl, here I am at last!” she cried, kissing him.
“But you are the faery Mala,” said Berl, looking at her in perplexity.
“Who is the faery Mala?” asked Lurina, who had forgotten all about
her faery existence now she was in a human body. “I never heard of
her. I went into the forest and fell asleep, I suppose. When I awoke I
came straight back to you.”
Berl was a wise man, and said no more, but kissed his newly-
recovered wife heartily, then called all the neighbours to congratulate
him, which they did loudly.
When they told Lurina she had been dead, she declared it was
nonsense, as it was only a sleep, and soon every one believed it
except Berl and the Wise Woman, to whom Berl told all about his
reception by Oberon.
Lurina became bright and gay all day, and never more wandered into
the forest to indulge in moon fancies, so Berl thought the faery Mala
must have been exiled altogether from Faeryland.
She was very good indeed, so good that Berl was quite afraid lest
she should be called back to Faeryland, but as yet that has not
happened.
THE ROSE-PRINCESS
I.

THE QUEEN WHO DID NOT BELIEVE IN FAERIES.

ONCE upon a time there was a King and Queen who reigned over a
most beautiful country. They were very rich and very happy, and
lived in a most gorgeous palace, the grand gardens of which sloped
down to the blue sea, on which sailed many richly-laden ships,
carrying merchandise to the capital city of the kingdom.
The palace was built of silver and ivory, and adorned with pale blue
velvet hangings, upon which were painted the most exquisite
pictures in the world. It stood on a high green hill, and far below lay
the immense city of Buss, with its wide streets, many towers, and
glittering fountains. As the King and Queen looked down from their
beautiful castle on to the mighty city and great green plains which
surrounded it, they ought to have been happy, but, curious to say,
they were not. They had everything in the world to make them happy
except one thing, and that one thing they longed for ardently, the
more so because they did not see any chance of obtaining it.
“Ah, if I only had a child!” sighed the Queen.
“Yes; a little boy,” said the King.
“Or a little girl,” retorted the Queen. “Don’t you know any faeries, my
dear, who would gratify our one desire?”
“No,” replied the King, shaking his head sadly. “My great-grandfather
was the last person who ever saw a faery; no one has ever seen one
since.”
“I don’t believe they exist,” said the Queen angrily.
“Oh yes, they do,” observed her husband. “This palace is said to
have been built by faery hands.”
“I don’t believe they exist,” declared the Queen again. “If they did,
they would surely help me by giving me a little girl or boy. What’s the
good of faeries if they don’t help you?”
“I wish they would help me,” sighed his Majesty; “all my subjects are
getting so unruly that I don’t know but what there will be a revolution,
and they’ll put some one else on the throne.”
“Who else could they find?” asked the Queen curiously.
“Oh, I’m not certain of that,” replied the King. “You see, my
grandfather, who was the first of our dynasty, ascended the throne
by the help of the faeries, and the king who was deposed vanished,
but they say some of his descendants live there;” and he pointed
downward to the city.
“And there they will stay,” said the Queen angrily. “I don’t believe a
word of it. Faeries indeed! they don’t exist.”
“But they do,” persisted the King.
“Pooh!” replied her Majesty. “Pooh!”
Now, when the Queen said “Pooh!” her husband knew it was no use
talking any more, so he retired to his cabinet to look over some
petitions from starving people, while the Queen went down with the
ladies-in-waiting to walk in the garden.
It was really a delightful garden, filled with the most wonderful
flowers. There were great beds of scented carnations, glowing with
bright colours, red and white foxgloves, in whose deep bells the
faeries were said to hide, masses of snowy white lilies, and a great
mixture of marigolds, hollyhocks, sweet-williams, daisies, buttercups,
and dahlias, which made the whole ground look like a brightly-
coloured carpet. And as for the roses—oh, what a quantity of
charming roses there were growing there! Red roses, varying in
colour from a deep scarlet to a pale pink; white roses looking like
snowflakes; yellow roses that glittered like gold, and faintly-tinted
tea-roses that perfumed the still air with their sweet odours. Oh, it
was really a famous garden, and bloomed all the year round, for the
kingdom was situated in the region of perpetual summer, where
snow never fell and frost never came.
The Queen, whose name was Flora, wandered disconsolately about
the garden, quite discontented with the beautiful flowers, because
she could not obtain the wish of her heart. The ladies-in-waiting
began to pluck flowers in order to adorn the royal dinner-table, and
Queen Flora walked on alone towards a great white rose tree that
was covered with blossoms. As she stood looking at it, she suddenly
heard a tiny laugh, and a great white rose unfolded its petals,
showing a golden heart, and also a dainty little faery dressed in
delicate green leaves, with a crown of little white rosebuds, and a
wand made of a blade of grass. When the Queen saw her, she was
much astonished, because she did not believe in faeries, but, now
she really saw one, she had to believe her own eyes.
“I am called Rosina,” said the faery in a sweet, low voice, “and I
heard you say you did not believe faeries existed; now you see they
do, because I am a faery.”
“Yes, you must be a faery,” replied the Queen, clasping her hands,
“because no human being could be so small.”
“Oh, I can be any size I please,” said the Faery Rosina, with a laugh,
and, stepping down from the rose, she alighted on the ground, and
instantly grew as tall as the Queen herself.
“Oh, you are a real, real faery!” cried Flora in
delight. “But why do the faeries not appear
now?”
“Because the land is so badly governed,” said
Rosina in a severe tone. “Yourself and the
King only think of luxury, and never of
assisting the poor people; but I am going to
cure you both of such neglect.”
“But how?” asked the Queen, trembling.
“By giving you your wish,” said the faery,
plucking a white rosebud off the tree. “Lay this bud beside your bed
to-night, and at the dawn of day it will change into a beautiful little
baby Princess, which is what you want.”
“Oh yes, yes!” cried the Queen; “I do want a Princess.”
“Every night at sundown,” said the faery slowly, “the Princess will
once more change into a flower, and become a human being again
at sunrise.”
“But will she change like this all her life?” asked the Queen, in great
dismay, for she did not like to have such a curious baby.
“She will be a Princess by day and a rosebud by night,” said Rosina,
smiling, “until she marries the great-grandson of the King whom your
husband’s grandfather deposed from the throne.”
“And where is this Prince to be found?” demanded the Queen
breathlessly. “I’ll marry my Princess to him at once.”
“You can’t do that,” said the faery, shaking her head. “The exiled
Prince does not know who he is, and the Princess herself will have
to tell him he is of the royal blood. When she does that, and you
marry them to one another, the spell will be removed, and she will be
a Princess both by day and by night.”
“I don’t see how she’s ever going to find this lost Prince!” said the
Queen angrily. “I shall certainly not let my child run about the world
looking for him.”
“Fate is stronger than you are,” replied the faery, “and you will see
what you will see.” So saying, she suddenly disappeared, and, as
the white rose slowly curled up its petals, the Queen knew the Faery
Rosina was inside.
The ladies-in-waiting, who had seen the Queen talking to a strange
lady, dared not approach before, but now they saw their royal
mistress was alone, they ventured to come near, and one of them
offered to take the white rosebud which the Queen held.
“Oh no!” cried Flora, hastily drawing back her hand; “I am going to
keep this rosebud. It is my”—
She was going to say Princess, but, thinking it wiser to keep her own
counsel, she held her tongue, and, on returning to the palace, told no
one but the King about the faery’s promise. The King laughed at her,
and said he did not believe her story—that she must be dreaming;
but the Queen persisted in her tale, that the rosebud would become
a Princess, and placed it on a velvet cushion by the side of her bed.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

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

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookluna.com

You might also like