0% found this document useful (0 votes)
19 views

C Programming From Problem Analysis To Program Design 8th Edition Ds Malik instant download

The document provides information about the book 'C Programming From Problem Analysis To Program Design' by D.S. Malik, including links to various editions for download. It also includes details about Cengage Learning's copyright and product information. Additionally, it mentions other related programming books available on the same platform.

Uploaded by

inijakumshe
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
0% found this document useful (0 votes)
19 views

C Programming From Problem Analysis To Program Design 8th Edition Ds Malik instant download

The document provides information about the book 'C Programming From Problem Analysis To Program Design' by D.S. Malik, including links to various editions for download. It also includes details about Cengage Learning's copyright and product information. Additionally, it mentions other related programming books available on the same platform.

Uploaded by

inijakumshe
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/ 82

C Programming From Problem Analysis To Program

Design 8th Edition Ds Malik download

https://ebookbell.com/product/c-programming-from-problem-
analysis-to-program-design-8th-edition-ds-malik-33556422

Explore and download more ebooks at ebookbell.com


Here are some recommended products that we believe you will be
interested in. You can click the link to download.

C Programming From Problem Analysis To Program Design 5th 5th Edition


D S Malik

https://ebookbell.com/product/c-programming-from-problem-analysis-to-
program-design-5th-5th-edition-d-s-malik-2336846

C Programming From Problem Analysis To Program Design 3rd Edition 3rd


Edition Barbara Doyle

https://ebookbell.com/product/c-programming-from-problem-analysis-to-
program-design-3rd-edition-3rd-edition-barbara-doyle-2416182

C Programming From Problem Analysis To Program Design 2nd Barbara


Doyle

https://ebookbell.com/product/c-programming-from-problem-analysis-to-
program-design-2nd-barbara-doyle-2444624

C Programming From Problem Analysis To Program Design 4th Edition Ds


Malik

https://ebookbell.com/product/c-programming-from-problem-analysis-to-
program-design-4th-edition-ds-malik-38548048
C Programming From Problem Analysis To Program Design 4th Edition
Barbara Doyle

https://ebookbell.com/product/c-programming-from-problem-analysis-to-
program-design-4th-edition-barbara-doyle-4178294

C Programming From Problem Analysis To Program Design 6th Edition D S


Malik

https://ebookbell.com/product/c-programming-from-problem-analysis-to-
program-design-6th-edition-d-s-malik-4334672

C Programming From Problem Analysis To Program Design 7th Edition Ds


Malik

https://ebookbell.com/product/c-programming-from-problem-analysis-to-
program-design-7th-edition-ds-malik-5163210

C Programming From Problem Analysis To Program Design 5th Edition


Barbara Doyle

https://ebookbell.com/product/c-programming-from-problem-analysis-to-
program-design-5th-edition-barbara-doyle-10810090

C Programming From Problem Analysis To Program Design Barbara Doyle

https://ebookbell.com/product/c-programming-from-problem-analysis-to-
program-design-barbara-doyle-5498550
C++ Programming:
From Problem Analysis to Program Design

Eighth Edition

D.S. Malik

Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
C++ Programming: From Problem Analysis to Pro- © 2018, 2015, 2013 Cengage Learning®
gram Design, Eighth Edition ALL RIGHTS RESERVED. No part of this work covered by the ­copyright
D.S. Malik herein may be reproduced or distributed in any form or by any means, ex-
cept as permitted by U.S. copyright law, without the prior written permis-
Senior Product Director: Kathleen McMahon sion of the copyright owner.
Product Team Leader: Kristin McNary
Associate Product Manager: Kate Mason For product information and technology assistance, contact us at
Associate Content Development ­Manager: Cengage Learning Customer & Sales Support, 1-800-354-9706
Alyssa Pratt
For permission to use material from this text or product,
Production Director: Patty Stephan
submit all requests online at www.cengage.com/permissions.
Senior Content Project Manager: Jennifer Further permissions questions can be emailed to
Feltri-George permissionrequest@cengage.com.
Manufacturing Planner: Julio Esperas
Art Director/Cover Design: Diana Graham Library of Congress Control Number: 2016960054
Production Service/Composition:
ISBN: 978-1-337-10208-7
SPi Global
Cover Photo: Cebas/Shutterstock.com Cengage Learning
20 Channel Center Street
Boston, MA 02210
USA

Unless otherwise noted all items © Cengage Learning.


Unless otherwise noted, all screenshots are ©Microsoft.

Cengage Learning is a leading provider of customized learning ­solutions


with employees residing in nearly 40 different countries and sales in more
than 125 countries around the world. Find your local representative at
www.cengage.com.

Cengage Learning products are represented in Canada by Nelson


Education, Ltd.

To learn more about Cengage Learning Solutions, visit


www.cengage.com.

Purchase any of our products at your local college store or at our preferred
online store www.cengagebrain.com.
Any fictional data related to persons or companies or URLs used throughout
this book is intended for instructional purposes only. At the time this book
was printed, any such data was fictional and not belonging to any real
persons or companies.
The programs in this book are for instructional purposes only. They have
been tested with care, but are not guaranteed for any particular intent
beyond educational purposes. The author and the publisher do not offer any
warranties or representations, nor do they accept any liabilities with respect
to the programs.

Printed in the United States of America


Print Number: 01 Print Year: 2017

Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
TO
My Daughter

Shelly Malik

Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
viii | C++ Programming: From Problem Analysis to Program Design, Eighth Edition

APPENDIX A   Reserved Words 1309

APPENDIX B   Operator Precedence 1311

APPENDIX C   Character Sets 1313

APPENDIX D   Operator Overloading 1317

APPENDIX E    Additional C11 Topics ONLINE

APPENDIX F    Header Files 1319

APPENDIX G    Memory Size on a System 1329

APPENDIX H    Standard Template Library (STL)  1331

APPENDIX I      Answers to Odd-Numbered Exercises 1369

INDEX 1413

Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
x | C++ Programming: From Problem Analysis to Program Design, Eighth Edition

Quick Review 22

Exercises 24

BASIC ELEMENTS OF C11 27


2
A Quick Look at a C11 Program 28

The Basics of a C11 Program 33


Comments34
Special Symbols 35
Reserved Words (Keywords) 35
Identifiers36
Whitespaces37

Data Types 37
Simple Data Types 38
Floating-Point Data Types 40

Data Types, Variables, and Assignment


Statements42

Arithmetic Operators, Operator Precedence, and Expressions 43


Order of Precedence 45
Expressions47
Mixed Expressions 48

Type Conversion (Casting) 50

string Type 53

Variables, Assignment Statements,


and Input Statements 54
Allocating Memory with Constants and Variables 54
Putting Data into Variables 57

Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Table of Contents | xi

Assignment Statement 57
Saving and Using the Value of an Expression 60
Declaring and Initializing Variables 61
Input (Read) Statement 62
Variable Initialization 65

Increment and Decrement Operators 69

Output71

Preprocessor Directives 78
namespace and Using cin and cout in a Program 79
Using the string Data Type in a Program 80

Creating a C11 Program 80

Debugging: Understanding and Fixing


Syntax Errors 84

Program Style and Form 87


Syntax87
Use of Blanks 88
Use of Semicolons, Brackets, and Commas 88
Semantics88
Naming Identifiers 89
Prompt Lines 89
Documentation90
Form and Style 90

More on Assignment Statements 92

Programming Example: Convert Length 94

Programming Example: Make Change 98

Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
xii | C++ Programming: From Problem Analysis to Program Design, Eighth Edition

Quick Review 102

Exercises104

Programming Exercises 114

INPUT/OUTPUT123
3
I/O Streams and Standard I/O Devices 124
cin and the Extraction Operator >> 125

Using Predefined Functions in a Program 130


cin and the get Function 133
cin and the ignore Function 134
The putback and peek Functions 136
The Dot Notation between I/O Stream Variables
and I/O Functions: A Precaution 139

Input Failure 139


The clear Function 142

Output and Formatting Output 143


setprecision Manipulator 144
fixed Manipulator 145
showpoint Manipulator 146
C1114 Digit Separator 149
setw 150

Additional Output Formatting Tools 152


setfill Manipulator 152
left and right Manipulators 154

Input/Output and the string Type 156

Debugging: Understanding Logic Errors


and Debugging with cout Statements 157

Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Table of Contents | xiii

File Input/Output 160

Programming Example: Movie Tickets


Sale and Donation to Charity 164

Programming Example: Student Grade 170

Quick Review 173

Exercises175

Programming Exercises 181

CONTROL STRUCTURES I
4 (SELECTION)187
Control Structures 188
SELECTION: if AND if . . . else 189
Relational Operators and Simple Data Types 189
Comparing Characters 190
One-Way Selection 191
Two-Way Selection 194
int Data Type and Logical (Boolean) Expressions 198
bool Data Type and Logical (Boolean) Expressions 198
Logical (Boolean) Operators and Logical Expressions 199
Order of Precedence 201

Relational Operators and the string Type 205


Compound (Block of) Statements 207
Multiple Selections: Nested if 207
Comparing if . . . else Statements with a Series of if Statements 210
Short-Circuit Evaluation 211
Comparing Floating-Point Numbers for Equality: A Precaution 212
Associativity of Relational Operators: A Precaution 213

Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
xiv | C++ Programming: From Problem Analysis to Program Design, Eighth Edition

Avoiding Bugs by Avoiding Partially Understood


Concepts and Techniques 215
Input Failure and the if Statement 218
Confusion between the Equality Operator (==)
and the Assignment Operator (=)221
Conditional Operator (?:)223
Program Style and Form (Revisited): Indentation 224

Using Pseudocode to Develop, Test, and Debug a Program 224

switch Structures 227


Avoiding Bugs by Avoiding Partially Understood
Concepts and Techniques (Revisited) 234

Terminating a Program with the assert Function 236

Programming Example: Cable Company Billing 238

Quick Review 244

Exercises245

Programming Exercises 257

CONTROL STRUCTURES II (REPETITION) 265


5
Why Is Repetition Needed? 266

while Looping (Repetition) Structure 269


Designing while Loops 273
Case 1: Counter-Controlled while Loops 274
Case 2: Sentinel-Controlled while Loops 277
Case 3: Flag-Controlled while Loops 283
Case 4: EOF-Controlled while Loops 286
eof Function 287
More on Expressions in while Statements 292

Programming Example: Fibonacci Number 293

for Looping (Repetition) Structure 297

Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Table of Contents | xv

Programming Example: Classifying Numbers 305

do. . .while Looping (Repetition) Structure 309


Divisibility Test by 3 and 9 311
Choosing the Right Looping Structure 313

break and continue Statements 313

Nested Control Structures 315

Avoiding Bugs by Avoiding Patches 321

Debugging Loops 324

Quick Review 324

Exercises326

Programming Exercises 340

USER-DEFINED FUNCTIONS 347


6
Predefined Functions 348

User-Defined Functions 352

Value-Returning Functions 353


Syntax: Value-Returning Function 355
Syntax: Formal Parameter List 355
Function Call 355
Syntax: Actual Parameter List 356
return Statement 356
Syntax: return Statement 356
Function Prototype 360
Syntax: Function Prototype 361
Value-Returning Functions: Some Peculiarities 362
More Examples of Value-Returning Functions 364
Flow of Compilation and Execution 375

Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
xvi | C++ Programming: From Problem Analysis to Program Design, Eighth Edition

Programming Example: Largest Number 376

Void Functions 378

Value Parameters 384

Reference Variables as Parameters 386


Calculate Grade 387

Value and Reference Parameters and Memory Allocation 390

Reference Parameters and Value-Returning Functions 399

Scope of an Identifier 399

Global Variables, Named Constants,


and Side Effects 403

Static and Automatic Variables 411

Debugging: Using Drivers and Stubs 413

Function Overloading: An Introduction 415

Functions with Default Parameters 417

Programming Example: Classify Numbers 420

Programming Example: Data Comparison 425

Quick Review 435

Exercises438

Programming Exercises 453

USER-DEFINED SIMPLE DATA TYPES, NAMESPACES,


7 AND THE STRING TYPE 467
Enumeration Type 468
Declaring Variables 470
Assignment470
Operations on Enumeration Types 471
Relational Operators 471

Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Table of Contents | xvii

Input /Output of Enumeration Types 472


Functions and Enumeration Types 475
Declaring Variables When Defining the Enumeration Type 476
Anonymous Data Types 477
typedef Statement 477

Programming Example: The Game of Rock, Paper, and Scissors 478

Namespaces487

string Type 492


Additional string Operations 496

Programming Example: Pig Latin Strings 505

Quick Review 510

Exercises512

Programming Exercises 517

ARRAYS AND STRINGS 521


8
Arrays523
Accessing Array Components 525
Processing One-Dimensional Arrays 527
Array Index Out of Bounds 531
Array Initialization during Declaration 532
Partial Initialization of Arrays during Declaration 532
Some Restrictions on Array Processing 533
Arrays as Parameters to Functions 534
Constant Arrays as Formal Parameters 535
Base Address of an Array and Array in Computer Memory 537
Functions Cannot Return a Value of the Type Array 540
Integral Data Type and Array Indices 543
Other Ways to Declare Arrays 544

Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
xviii | C++ Programming: From Problem Analysis to Program Design, Eighth Edition

Searching an Array for a Specific Item 544


Sorting547

Auto Declaration and Range-Based For Loops 551

C-Strings (Character Arrays) 552


String Comparison 555
Reading and Writing Strings 556
String Input 556
String Output 558
Specifying Input/Output Files at Execution Time 559
string Type and Input/Output Files 559

Parallel Arrays 560

Two- and Multidimensional Arrays 561


Accessing Array Components 563
Two-Dimensional Array Initialization during Declaration 564
Two-Dimensional Arrays and Enumeration Types 564
Initialization567
Print568
Input568
Sum by Row 568
Sum by Column 568
Largest Element in Each Row and Each Column 569
Passing Two-Dimensional Arrays as Parameters to Functions 570
Arrays of Strings 573
Arrays of Strings and the string Type 573
Arrays of Strings and C-Strings (Character Arrays) 573
Another Way to Declare a Two-Dimensional Array 574
Multidimensional Arrays 575

Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Table of Contents | xix

Programming Example: Code Detection 577

Programming Example: Text Processing 583

Quick Review 590

Exercises592

Programming Exercises 604

RECORDS (STRUCTS)611
9 Records (structs)612
Accessing struct Members 614
Assignment617
Comparison (Relational Operators) 618
Input/Output618
struct Variables and Functions 619
Arrays versus structs620
Arrays in structs620
structs in Arrays 623
structs within a struct 624

Programming Example: Sales Data Analysis 628

Quick Review 642

Exercises643

Programming Exercises 648

CLASSES AND DATA ABSTRACTION 651


10
Classes652
Unified Modeling Language Class Diagrams 656
Variable (Object) Declaration 656
Accessing Class Members 657

Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
xx | C++ Programming: From Problem Analysis to Program Design, Eighth Edition

Built-in Operations on Classes 659


Assignment Operator and Classes 659
Class Scope 660
Functions and Classes 660
Reference Parameters and Class Objects (Variables) 660
Implementation of Member Functions 661
Accessor and Mutator Functions 666
Order of public and private Members of a Class 670
Constructors671
Invoking a Constructor 673
Invoking the Default Constructor 673
Invoking a Constructor with Parameters 674
Constructors and Default Parameters 677
Classes and Constructors: A Precaution 677
In-Class Initialization of Data Members and the Default Constructor 678
Arrays of Class Objects (Variables) and Constructors 679
Destructors681

Data Abstraction, Classes, and Abstract Data Types 682


A struct versus a class 684

Information Hiding 685

Executable Code 689

More Examples of Classes 691

Inline Functions 700

Static Members of a Class 701

Programming Example: Juice Machine 707

Quick Review 722

Exercises724

Programming Exercises 736


Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Table of Contents | xxi

INHERITANCE AND COMPOSITION 743


11
Inheritance744
Redefining (Overriding) Member Functions of the Base Class 747
Constructors of Derived and Base Classes 754
Destructors in a Derived Class 763
Multiple Inclusions of a Header File 764
C11 Stream Classes 768
Protected Members of a Class 769
Inheritance as public, protected, or private 769
(Accessing protected Members in the Derived Class) 770

Composition (Aggregation) 773

Object-Oriented Design (OOD) and


Object-Oriented Programming (OOP) 778
Identifying Classes, Objects, and Operations 780

Programming Example: Grade Report 781

Quick Review 802

Exercises802

Programming Exercises 811

POINTERS, CLASSES, VIRTUAL FUNCTIONS, AND ABSTRACT CLASSES 817


12
Pointer Data Type and Pointer Variables 818
Declaring Pointer Variables 818

Address of Operator (&) 820

Dereferencing Operator (*) 821

Classes, Structs, and Pointer Variables 826

Initializing Pointer Variables 829


Initializing Pointer Variables Using nullptr 829

Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
xxii | C++ Programming: From Problem Analysis to Program Design, Eighth Edition

Dynamic Variables 830


Operator new 830
Operator delete 831

Operations on Pointer Variables 835

Dynamic Arrays 837


Arrays and Range-Based for Loops (Revisited) 840
Functions and Pointers 841
Pointers and Function Return Values 842
Dynamic Two-Dimensional Arrays 842

Shallow versus Deep Copy and Pointers 845

Classes and Pointers: Some Peculiarities 847


Destructor848
Assignment Operator 849
Copy Constructor 851

Inheritance, Pointers, and Virtual Functions 858


Classes and Virtual Destructors 865

Abstract Classes and Pure Virtual Functions 866

Address of Operator and Classes 874

Quick Review 876

Exercises879

Programming Exercises 890

OVERLOADING AND TEMPLATES 893


13
Why Operator Overloading Is Needed 894

Operator Overloading 895


Syntax for Operator Functions 896
Overloading an Operator: Some Restrictions 896
Pointer this 899
Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Table of Contents | xxiii

Friend Functions of Classes 904


Operator Functions as Member Functions
and Nonmember Functions 907
Overloading Binary Operators 910
Overloading the Stream Insertion (<<) and Extraction (>>) Operators 916
Overloading the Assignment Operator (=)921
Overloading Unary Operators 929
Operator Overloading: Member versus Nonmember 935
Classes and Pointer Member Variables (Revisited) 936
Operator Overloading: One Final Word 936

Programming Example: clockType936

Programming Example: Complex Numbers 945

Overloading the Array Index (Subscript) Operator ([]) 950

Programming Example: newString952

Function Overloading 959

Templates959
Function Templates 959
Class Templates 961

C1111 Random Number Generator 969

Quick Review 971

Exercises973

Programming Exercises 981

EXCEPTION HANDLING 991


14
Handling Exceptions within a Program 992
C11 Mechanisms of Exception Handling 996
try/catch Block 996
Using C11 Exception Classes 1003

Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
xxiv | C++ Programming: From Problem Analysis to Program Design, Eighth Edition

Creating Your Own Exception Classes 1007


Rethrowing and Throwing an Exception 1016

Exception-Handling Techniques 1020


Terminate the Program 1020
Fix the Error and Continue 1020
Log the Error and Continue 1021

Stack Unwinding 1022

Quick Review 1025

Exercises1027

Programming Exercises 1033

RECURSION1035
15
Recursive Definitions 1036
Direct and Indirect Recursion 1038
Infinite Recursion 1038

Problem Solving Using Recursion 1039


Tower of Hanoi: Analysis 1049

Recursion or Iteration? 1049

Programming Example: Converting a Number from


Binary to Decimal 1051

Programming Example: Converting a Number from Decimal to Binary 1055

Quick Review 1058

Exercises1059

Programming Exercises 1064

Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Table of Contents | xxv

SEARCHING, SORTING,
16 AND THE VECTOR TYPE 1069
List Processing 1070
Searching1070
Bubble Sort 1071
Insertion Sort 1075
Binary Search 1079
Performance of Binary Search 1082

vector Type (class)1083


Vectors and Range-Based for Loops 1088
Initializing vector Objects during Declaration 1090

Programming Example: Election Results 1091

Quick Review 1105

Exercises1106

Programming Exercises 1111

LINKED LISTS 1115


17
Linked Lists 1116
Linked Lists: Some Properties 1117
Deletion1123
Building a Linked List 1124

Linked List as an ADT 1129


Structure of Linked List Nodes 1130
Member Variables of the class linkedListType 1130
Linked List Iterators 1131
Print the List 1137
Length of a List 1138

Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
xxvi | C++ Programming: From Problem Analysis to Program Design, Eighth Edition

Retrieve the Data of the First Node 1138


Retrieve the Data of the Last Node 1138
Begin and End 1138
Copy the List 1139
Destructor1140
Copy Constructor 1140
Overloading the Assignment Operator 1141

Unordered Linked Lists 1141


Search the List 1142
Insert the First Node 1143
Insert the Last Node 1144
Header File of the Unordered Linked List 1149

Ordered Linked Lists 1150


Search the List 1151
Insert a Node 1152
Insert First and Insert Last 1156
Delete a Node 1157
Header File of the Ordered Linked List 1158

Print a Linked List in Reverse Order


(Recursion Revisited) 1161
printListReverse1163

Doubly Linked Lists 1164


Default Constructor 1167
isEmptyList1167
Destroy the List 1167
Initialize the List 1168
Length of the List 1168
Print the List 1168
Reverse Print the List 1168
Search the List 1169
First and Last Elements 1169
Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Table of Contents | xxvii

Circular Linked Lists 1175

Programming Example: DVD Store 1176

Quick Review 1196

Exercises1196

Programming Exercises1203

STACKS AND QUEUES 1209


18
Stacks1210
Stack Operations 1212

Implementation of Stacks as Arrays 1214


Initialize Stack 1217
Empty Stack 1218
Full Stack 1218
Push1218
Return the Top Element 1220
Pop1220
Copy Stack 1222
Constructor and Destructor 1222
Copy Constructor 1223
Overloading the Assignment Operator (=)1223
Stack Header File 1224

Programming Example: Highest GPA 1228

Linked Implementation of Stacks 1232


Default Constructor 1235
Empty Stack and Full Stack 1235
Initialize Stack 1236
Push1236
Return the Top Element 1238

Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
xxviii | C++ Programming: From Problem Analysis to Program Design, Eighth Edition

Pop1238
Copy Stack 1240
Constructors and Destructors 1241
Overloading the Assignment Operator (=)1241
Stack as Derived from the class unorderedLinkedList 1244

Application of Stacks: Postfix Expressions Calculator 1245


Main Algorithm 1248
Function evaluateExpression 1248
Function evaluateOpr 1250
Function discardExp 1252
Function printResult 1252

Removing Recursion: Nonrecursive Algorithm


to Print a Linked List Backward 1255

Queues1259
Queue Operations 1260
Implementation of Queues as Arrays 1262
Linked Implementation of Queues 1271
Queue Derived from the class unorderedLinkedListType 1276

Application of Queues: Simulation 1277


Designing a Queuing System 1278
Customer1279
Server1282
Server List 1285
Waiting Customers Queue 1289
Main Program1291

Quick Review 1295

Exercises1296

Programming Exercises 1305

Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Table of Contents | xxix

APPENDIX A: RESERVED WORDS 1309

APPENDIX B: OPERATOR PRECEDENCE 1311

APPENDIX C: CHARACTER SETS 1313


ASCII (American Standard Code for Information Interchange) 1313

EBCDIC (Extended Binary Coded Decimal Interchange Code) 1314

APPENDIX D: OPERATOR OVERLOADING 1317

APPENDIX E: ADDITIONAL C11 TOPICS ONLINE


Binary (Base 2) Representation of a Nonnegative Integer E-1
Converting a Base 10 Number to a Binary Number (Base 2) E-1
Converting a Binary Number (Base 2) to Base 10 E-3
Converting a Binary Number (Base 2) to Octal (Base 8)
and Hexadecimal (Base 16) E-4

More on File Input/Output E-6


Binary Files E-6
Random File Access E-12

Naming Conventions of Header Files in


ANSI/ISO Standard C11 and Standard C11E-20

APPENDIX F: HEADER FILES 1319

Header File cassert (assert.h)1319

Header File cctype (ctype.h)1320

Header File cfloat (float.h)1321

Header File climits (limits.h)1322

Header File cmath (math.h)1324


Header File cstddef (stddef.h)1325
Header File cstring (string.h)1325
HEADER FILE string1326

Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
xxx | C++ Programming: From Problem Analysis to Program Design, Eighth Edition

APPENDIX G: MEMORY SIZE ON A SYSTEM 1329

APPENDIX H: STANDARD TEMPLATE LIBRARY (STL) 1331


Components of the STL 1331

Container Types 1332


Sequence Containers 1332
Sequence Container: Vectors 1332
Member Functions Common to All Containers 1340
Member Functions Common to Sequence Containers 1342
copy Algorithm 1342
Sequence Container: deque1346
Sequence Container: list1349

Iterators1354
IOStream Iterators 1354
Container Adapters 1355

Algorithms1358
STL Algorithm Classification 1358
STL Algorithms 1360
Functions fill and fill_n1361
Functions find and find_if1362
Functions remove and replace1363
Functions search, sort, and binary_search1365

APPENDIX I: ANSWERS TO ODD-NUMBERED EXERCISES 1369

Chapter 1 1369

Chapter 2 1372

Chapter 3 1376

Chapter 4 1377

Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Table of Contents | xxxi

Chapter 5 1380

Chapter 6 1382

Chapter 7 1385

Chapter 8 1387

Chapter 9 1389

Chapter 10 1391

Chapter 11 1395

Chapter 12 1398

Chapter 13 1400

Chapter 14 1402

Chapter 15 1405

Chapter 16 1406

Chapter 17 1407

Chapter 18 1409

INDEX1413

Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
xxxiv | C++ Programming: From Problem Analysis to Program Design, Eighth Edition

Traditionally, a C++ programming neophyte needed a working knowledge of another


programming language. This book assumes no prior programming experience.
­However, some adequate mathematics background, such as college algebra, is required.

Changes in the Eighth Edition


The eighth edition contains more than 250 new and updated exercises, requiring new
solutions, and more than 20 new programming exercises.
This edition also introduces C++14 digit separator (Chapter 3), C++11 class inline
functions (Chapter 10), updated C++11 class data members initialization during
declaration (Chapter 10), and C++11 random generators (Chapter 13). The C-string
functions such as strcpy, strcmp, and strcat have been deprecated, and might give
warning messages when used in a program. Furthermore, the functions strncpy and
strncmp might not be implemented in all versions of C++ Therefore, in Chapter 13,
we have modified the Programming Example newString to reflect these changes by
including functions to copy a character array.

Approach
The programming language C++, which evolved from C, is no longer considered an
industry-only language. Numerous colleges and universities use C++ for their first
programming language course. C++ is a combination of structured programming
and object-oriented programming, and this book addresses both types.
This book can be easily divided into two parts: structured programming and object-
oriented programming. The first 9 chapters form the structured programming part;
Chapters 10 through 14, 17, and 18 form the object-oriented part. However, only the
first six chapters are essential to move on to the object-oriented portion.
In July 1998, ANSI/ISO Standard C++ was officially approved. This book focuses on
ANSI/ ISO Standard C++. Even though the syntax of Standard C++ and ANSI/ISO
Standard C++ is very similar, Chapter 7 discusses some of the features of ANSI/ISO
Standard C++ that are not available in Standard C++.
Chapter 1 briefly reviews the history of computers and programming languages. The
reader can quickly skim through this chapter and become familiar with some of the
hardware components and the software parts of the computer. This chapter contains
a section on processing a C++ program. This chapter also describes structured and
object-oriented programming.
Chapter 2 discusses the basic elements of C++ After completing this chapter, ­students
become familiar with the basics of C++ and are ready to write programs that are

Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Preface | xxxv

complicated enough to do some computations. Input/output is fundamental to any


programming language. It is introduced early, in Chapter 3, and is covered in detail.
Chapters 4 and 5 introduce control structures to alter the sequential flow of execu-
tion. Chapter 6 studies user-defined functions. It is recommended that readers with
no prior programming background spend extra time on Chapter 6. Several examples
are provided to help readers understand the concepts of parameter passing and the
scope of an identifier.
Chapter 7 discusses the user-defined simple data type (enumeration type), the
namespace mechanism of ANSI/ISO Standard C++ and the string type. The earlier
versions of C did not include the enumeration type. Enumeration types have very lim-
ited use; their main purpose is to make the program readable. This book is organized
such that readers can skip the section on enumeration types during the first reading
without experiencing any discontinuity, and then later go through this section.
Chapter 8 discusses arrays in detail. This chapter also discusses range-based for
loops, a feature of C++11 Standard, and explains how to use them to process the ele-
ments of an array. Limitations of ranged-based for loops on arrays passed as param-
eters to functions are also discussed. Chapter 8 also discusses a sequential search
algorithm and a selection sort algorithm. Chapter 9 introduces records (structs).
The introduction of structs in this book is similar to C structs. This chapter is
optional; it is not a prerequisite for any of the remaining chapters.
Chapter 10 begins the study of object-oriented programming (OOP) and introduces
classes. The first half of this chapter shows how classes are defined and used in a
program. The second half of the chapter introduces abstract data types (ADTs). The
inline functions of a classes are introduced in this chapter. Also, the section “In-Class
Initialization of Data Members and the Default Constructor” has been updated.
­Furthermore, this chapter shows how classes in C++ are a natural way to implement
ADTs. Chapter 11 continues with the fundamentals of object-oriented design (OOD)
and OOP and discusses inheritance and composition. It explains how classes in C++
provide a natural mechanism for OOD and how C++ supports OOP. Chapter 11 also
discusses how to find the objects in a given problem.
Chapter 12 studies pointers in detail. After introducing pointers and how to use them
in a program, this chapter highlights the peculiarities of classes with pointer data
members and how to avoid them. Moreover, this chapter discusses how to create and
work with dynamic two-dimensional arrays, and also explains why ranged-based for
loops cannot be used on dynamic arrays. Chapter 12 also discusses abstract classes
and a type of polymorphism accomplished via virtual functions.
Chapter 13 continues the study of OOD and OOP. In particular, it studies polymorphism
in C++ The chapter specifically discusses two types of polymorphism—overloading

Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
xxxvi | C++ Programming: From Problem Analysis to Program Design, Eighth Edition

and templates. Moreover, C++11 random number generators are introduced in this
chapter.
Chapter 14 discusses exception handling in detail. Chapter 15 introduces and dis-
cusses recursion. Moreover, this is a stand-alone chapter, so it can be studied anytime
after Chapter 9. Chapter 16 describes various searching and sorting algorithms as
well as an introduction to the vector class.
Chapters 17 and 18 are devoted to the study of data structures. Discussed in detail
are linked lists in Chapter 17 and stacks and queues in Chapter 18. The programming
code developed in these chapters is generic. These chapters effectively use the funda-
mentals of OOD.
Appendix A lists the reserved words in C++. Appendix B shows the precedence and
associativity of the C++ operators. Appendix C lists the ASCII (American Standard
Code for Information Interchange) and EBCDIC (Extended Binary Coded Decimal
Interchange Code) character sets. Appendix D lists the C++ operators that can be
overloaded.
Appendix E, provided online, has three objectives. First, we discuss how to convert
a number from ­decimal to binary and binary to decimal. We then discuss binary
and random access files in detail. Finally, we describe the naming conventions of
the header files in both ANSI/ISO Standard C++ and Standard C++. Appendix
F discusses some of the most widely used library routines, and includes the names
of the standard C++ header files. The programs in Appendix G show how to print
the memory size for the built-in data types on your system. Appendix H gives an
­introduction to the Standard Template Library, and Appendix I provides the answers
to odd-numbered exercises in the book.

How to Use the Book


This book can be used in various ways. Figure 1 shows the dependency of the chapters.
In Figure 1, dotted lines mean that the preceding chapter is used in one of the sections
of the chapter and is not necessarily a prerequisite for the next chapter. For example,
Chapter 8 covers arrays in detail. In Chapters 9 and 10, we show the relationship
between arrays and structs and arrays and classes, respectively. However, if Chapter 10
is studied before Chapter 8, then the section dealing with arrays in Chapter 10 can
be skipped without any discontinuation. This particular section can be studied after
studying Chapter 8.
It is recommended that the first six chapters be covered sequentially. After covering
the first six chapters, if the reader is interested in learning OOD and OOP early, then
Chapter 10 can be studied right after Chapter 6. Chapter 7 can be studied anytime
after Chapter 6.

Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
xlvi | C++ Programming: From Problem Analysis to Program Design, Eighth Edition

?? PowerPoint Presentations. This text provides PowerPoint slides


to accompany each chapter. Slides are included to guide classroom
presentation, to make available to students for chapter review, or to
print as classroom handouts.

?? Solutions. Solutions to review questions and exercises are provided to


assist with grading.

?? Test Bank®. Cengage Learning Testing Powered by Cognero is a flexible,


online system that allows you to:

?? author, edit, and manage test bank content from multiple Cengage
Learning solutions

?? create multiple test versions in an instant

?? deliver tests from your LMS, your classroom, or anywhere you want

Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-203
Discovering Diverse Content Through
Random Scribd Documents
scrawny neck—soon death would take them away. And she knew how he
feared death; she had heard him mumble to himself. It had perplexed her
that Caterina had been fond of him but she let them alone, hoping the
innocence of one would offset the vices of the other. Well, it had been a
brief affection. She wondered how she condescended to treat him humanely,
almost with affection sometimes.

Pouring herself more coffee she tried to shake her mood and said the
first thing that came to mind:

"What have you been thinking about?"

"I? Oh, I was thinking of Italy. What were you thinking about?"

"Don Fernando. Caterina. Life and death."

"I was thinking of home. Very foolish of me. I guess I'm ... well,
sentimental." He patted his bald spot.

"You've been homesick as long as I can remember," she said.

"Come, come now," he said. "I haven't been that bad, have I?"

Chavela went about opening windows and candle flames wavered from
the cool, damp but refreshing air. The clack-a-clack of hundreds of
blackbirds resounded from their roosting place in the Indian laurels at the
lagoon end of the garden.

Gabriel lit a kerosene lamp and placed it on the piano and excused
himself.

"Good-night, Angelina ... I must visit Viosco ... he's sick ... thanks for the
coffee...."

She hunched on a sofa, her feet under a velvet cushion, eyes on the
irresolute candles. Shall I confess to Gabriel that I like to walk naked in my
fur? Shall I tell him about the girl at the convent? Shall I tell him why Raul
married me? Confess. Must we all confess, confess how lonely we are?
Later, in the chapel, she prayed for Vicente and herself. The place was
dimly lit but the darkness and her rebozo could not shut out the Petacans,
the lame, the sick, the hungry: they whimpered for clothes, medicine, alms:
they fought for food, stole, got drunk, killed. They had never crowded about
her before and their ghostly presence drove her to her room.

Raul had stayed in a peasant hut during the rain, a thatched room where
woven fronds, carefully herringboned, shut out most of the downpour. A pig
slept in a corner. Raul sat on a wooden chest; the owner and his wife
squatted on a mat. Above the pig, in a sisal hammock, swung a child.
Another hammock was looped over a peg, its pouch resembling a gray
moth's case. The deluge shut out nearly all light. Through the open doorway
mist drubbed. Nobody tried to talk. Raul dozed. When the rain stopped, he
thanked the pair, accepted a chunk of sugar cane for Chico, and got on his
horse and rode off.

Chico trotted briskly, whiffing the rain-washed air as they followed a


trail through pastureland where knots of Herefords grazed. Belly high to the
horse, a stone wall paralleled the trail, iguanas here and there.

At a bend, Chico whirled sidewise, and pain from his bullet wound shot
through Raul. He thought he might topple, but somehow managed to keep
his saddle, as the horse pirouetted. Shouting, commanding, he dug his
spurs. The horse screamed. Then, Raul saw the snake, a good-sized rattler.

Dragging violently at the bit, he checked Chico underneath some orange


trees and dismounted, thoroughly disgusted.

"You fool. Haven't you ever seen a rattler before? You ought to learn a
thing or two. You crazy fool—you're no colt!"

The snake slithered away through the grass.

At the dam, the foreman told Raul that they had less than a week's work,
though the cracks in the dam appeared formidable. Raul sucked his pipe,
nodded his head, simply agreeing. The place oozed gnats and flies.
Sandpipers paraded the shallows.
Remaining on his horse, Raul chatted with the workers, all of them in
breechclouts or shorts. A number wore conical hats of a nearby mountaineer
clan. The southerners had bodies like chocolate. Some spoke no Spanish.
Through the years, Raul had acquired an Indian vocabulary of sorts and he
tried to josh the men but none of his jokes got across. He slapped at gnats,
and left as soon as he could.

On his way home, he felt a sense of freedom. The breadth of the land
affected him. Uncle Roberto had said: "It does something to a man to live
on a place you can't ride across in days." Though Raul had been born at
Petaca, he realized there were parts he had never seen, hill country,
mountain fields, lava terrain, streams. A subforeman insisted that a lake
existed in Sector 25. Recently someone told of Indians camping in 31,
thatched huts in a valley of willows.

As dusk brought the swallows and bats, Raul remembered Petacan


outings in all kinds of weather, high volcano climbs with lightning flashing
from rock to rock, river explorations, treks across pasture lands, trails to
milpas, trails through steamy canyons choked with red-barked trees. They
had herded cattle, roped yearlings, branded, dehorned; they had driven
herds of sheep and goat; they had chased wild horses. Gathered around
campfires, they had eaten from chuck wagons. Years past, they had packed
burro trains into the Mountain Rancheria area in search of gold and silver.
They had hunted deer in the uplands, tigres in the marsh grass of the coastal
land, iguanas where the palmera whined, alligator and ibis in the lagoons,
wolf and bear midway up the great peak, eagles at the summit.

At first, he had tried to share these things with Angelina but she had not
cared for the rough life and so he had gone with his men, storing up the
hours, making his own calendar, riding most often with Manuel, including
Lucienne when he dared.

High up, in the darkening sky, a hawk drifted.

Surely, the Medinas were monarchs of a kind.

Lights burned at Petaca, in the windows and in the kerosene lamps atop
the wooden posts in the courtyard. Raul saw rurales, some mounted, some
afoot, their uniforms unmistakable. He had heard that they had been
encountered in the remote sections of the hacienda but this was the first
time he had seen them and he was glad to have an indication of their
interest in apprehending Pedro. His trip to Colima had been successful.

He did not doubt that his father knew where Pedro had gone. (Would this
new stroke end his life?) Some said guns were being smuggled, bought and
sold. At other haciendas, men had been placed on guard duty. Count de
Selva, it was rumored, had clamped men in irons for demanding the right to
buy matches in Colima.

A peculiar fear washed over him, as he rode into Petaca. It seemed to be


hooked up in his mind with the birthday party Lucienne was planning next
week at Palma Sola. A foolish fear, no doubt.

11
As he stood in the living room at Lucienne's, a little tipsy, glass in hand,
Roberto las Casas called the roll, talking to himself:

"Baroness Radziwill and family, Count and Countess de Selva (the old
boy's not doing well), Lucienne (very pretty), Joaquín Siquiros, Federicka
Kolb (ah!), Benito Serrato (new mayor of Colima), Raul, Gabriel, Jesús
Peza, General Matanzas (drunk) ... quite a birthday gathering...."

Roberto flicked ash from his beautifully tailored dinner suit and lifted his
glass. For a man in his late fifties, he was handsome. Standing to one side,
near some candles, his diamond cuff links and studs glittered. Bald as a man
can be, he had the air of a diplomat. Angular, taller than Raul, he had none
of Raul's physical toughness ... he was a Guadalajara lawyer, promoter of
mining interests and capable dabbler in city real estate. His mother had been
the sister of Raul's mother. He liked the city, but appreciated Petaca's
spaciousness, hunts, rodeos, fiestas and gambling.

Tonight the roulette wheel spun and the tiny pelota clicked like a race
horse; it clicked and stopped, and the sound of the surf came through the
room. For days the wind had boiled offshore and now the rollers foamed
and thudded.

"Twenty," Joaquin Siquiros called.

"Twenty," someone repeated.

No one had placed money on that number and the wheel began again.

"Forty-one," Siquiros called, in his boyish voice.

Roberto strolled from guest to guest, drinking, eating, chatting, bored


with roulette since he had lost heavily; the asthmatic Selva had stolen his
luck and Lucienne had won more than her share of the evening's cash. He
found Lucienne, beside a big mafafa, and put his arm around her.

"Were you lucky the last round?" he asked.

"Yes, but where have you been?"

"Just talking to people, catching up on Palma gossip."

"You're drinking too much."

"Not too much. I'm just tall and hold more. I leave the drinking to the
Baroness. See, she can hardly take in her winnings." He laughed gently.

Half asleep, losing, gaining, she leaned on the roulette table, jewels
sparkling in her hair.

"... Sister of the Polish pope," said Roberto. "Let's have something to
eat," he whispered. "Food has been known to help people in my condition.
May I bring you some sandwiches?"
"Please. I'm really hungry."

He served sandwiches and entremés from a silver tray that salt air and
time had darkened to a pewter finish.

"Now, my dear, I'll get us some coffee. Let's sit here."

"Twenty-four," Siquiros called.

"Mine, mine!" shouted the Baroness.

"Where did you buy that lovely gown? In Paris?" asked Roberto,
bringing the coffee, and sitting down by Lucienne.

"In Rome," she said.

"Rome ... I remember Rome ... but I never saw a gown like yours there."
He sipped his drink and said: "Lucienne, you're a beautiful woman; you
make the gown more beautiful."

Lucienne laughed happily.

"I'm fairly sober," he said. "And it is your birthday.... Shall I go on?


About your hair, your tiara ... your..."

"Ah, no ... no more, dear Roberto." But her hand went to her platinum
tiara; she pushed it forward on her head; the rubies, diamonds and sapphires
seemed to glow a little more. The gown was dark, almost a velvet green,
very long, very simple. She wore no jewelry other than the tiara, a
Humboldt heirloom.

"You know, it's almost 2:00 A.M.," she said.

"Why do you think about time on your birthday! When it's four, we'll be
able to see the sun. Has it been a wonderful party?"

"Very wonderful, Roberto."

"Have you opened my gift?"


"Tomorrow."

"Tomorrow," he agreed, and took a sandwich from the tray on a side


table. "Come, Raul, join us," he said, grasping his cousin's arm. "Aren't you
hungry? We have a sandwich tray here."

"I've been hungry all evening," said Raul. "Lucienne, where are the
venison steaks you promised?"

"You don't sound like a man who has lost a lot of money," said Roberto.

"I didn't lose so much."

"I'll see to it that you win next year," said Lucienne, bringing him close.

"What could he win next year that he hasn't got now?" laughed Roberto.
"Here, Raul, take my chair. I feel better.... I'll try a whirl at that wheel again.
What's your lucky number, Lucienne?"

Outside, on the ocean porch, the orchestra began a plaintive


Veracruzana, with the violins carrying the melody, the horns a trifle slow,
the surf coming through.

Oblivious of the orchestra, General Matanzas sat at the old Chickering;


his fingers fished for a sentimental song to match his intoxicated mood. He
swayed on his bench, his belly sagging, his epaulettes bobbing. Smoke from
some candles on the piano drifted across his gray-white head and beard.

"It's really bad news about Díaz," said Raul to Lucienne. "He shouldn't
resign. If he must resign, he should appoint a capable successor. The more I
think about it, the less I like the situation. De Selva says we're in for bad
times."

"Come, come," said Lucienne. She leaned over and brushed crumbs
from his trousers. "I think Díaz will die in office. He should, just to please
us. And, anyhow, this is my party...."

"Maybe you don't grasp the significance," he said.


"A man in his eighties has a plan."

"But nobody knows his plan."

"We live a long way from the capital. We'll get some accurate news
soon. Our president is no fool."

Federicka Kolb, a friend of the Humboldts for years, paused before


Lucienne and Raul, smiled and offered them cigarettes. She was an
attractive heavy-set person, with a light complexion and especially
intelligent mouth and eyes.

"Darling," asked Lucienne, "what is the latest news about President


Díaz? Is there anything we can depend on?"

"General Matanzas said he has resigned and left the country," said
Federicka.

"The highest authority," said Lucienne, glancing at the general, who had
put his head on his arms.

"I'll talk to him later," said Raul. "Is there any word of a successor? Has
Matanzas been in Mexico City recently?"

"I was in Mexico City last week," said Federicka, her face pleasant and
calm. "People say Díaz wants Mexico to become a democracy. Díaz wants
the Indians to vote."

The orchestra had stopped playing and Baroness Radziwill overheard


Federicka's last sentence.

"That's utterly ridiculous," she cried, her black eyes snapping. "Not one
Indian in ten thousand can read or write. Is Díaz too old to think?"

"They can read at the point of a gun," said Serrato, the young Colima
mayor, his lips twisting.

Federicka took up the challenge: "All of us can remember faithful


Indians. When Lucienne's mother and father drowned in the surf, who tried
to save them? The Indians who were fishing nearby. Itzla drowned. He gave
his life. When my father built the railroad to Cuernavaca, he learned to like
them."

"Long live Porfirio Díaz," cried Serrato dully.

"Long live Díaz," others echoed.

"Maybe I've drunk too much coffee," Roberto muttered under his breath.
"What's all this?"

"I'm no Díaz man. How do you feel about Petaca and what I'm doing?"
Raul asked him.

"Well," said Roberto, grinning, "Fernando, like Díaz, has served his
time. I want to see what you can do."

He opened his silver cigarette case and rubbed a smudge from the
initials. He felt sleepy, tired of this room and its old-fashioned furniture. A
little sickish, he headed for the porch and the cool sea air. Being alone could
be comforting.

"I tell you, we're in for bad times," de Selva sermonized before a group.
"Our haciendas are threatened by renegades. Don Raul was wounded by
one of those fools who wants to grab our land. We have to carry guns ... I go
about armed."

Raul led Lucienne to the long, cool porch and they danced to a Strauss
waltz ... the ocean beating hard.

"Hold me close, Raul."

"Are you falling asleep?"

"I've been thinking of my presents, what fun it's going to be, opening
them."

"When will you open them?"


"At lunch tomorrow ... just the two of us."

"Open them now."

"It's fun to wait. When there aren't so many people around."

"Shall I tell you what Roberto gave you?"

"Tell me ... please."

"Two gold-plated faucets for your bathroom ... in fourteen karats."

"Oh, no. I'll never believe that. How silly!"

"Come on, let's open his package."

"All right, let's open it, let's open all my presents."

They went into the living room, laughing heartily.

Roberto listened to their laughter, as he got ready for bed, his bedroom
door half-open. He envied their love. A fine house in Colonia Vallarta had
not added up to happiness for him. His wife thought him a clown, not a wit.
Now, the Díaz news had disheartened him and he tossed his shirt over one
of Lucienne's plants, beside the four-poster. Stretching, he breathed in the
cool air, glad to be back by the ocean. It would be fun to see how Lucienne
felt about those faucets tomorrow ... he had paid a pretty penny for them....

In the morning, Raul met Lucienne in the greenhouse, whose salt-rimed


windows faced the sea, a ramshackle Swiss-style conservatory built by her
father when he, too, had dabbled in plants and flowers. When Raul came in,
she was adjusting salt screens.

"Good morning. You're up early."

"Good morning, darling. You're lazy. I've already had a swim."

"You should have wakened me."


"But you were so comfortable, I just slipped out of bed."

"Have you had breakfast, Lucienne?"

"I'm waiting for you."

"I often think of you working here. Your world is something you can
touch. When we were little you had a garden of your own ... all these years
this has been your life ... this and your friends."

"But has anything come of it?"

"I'd like to marry you."

"Raul, don't talk that way, especially before breakfast. An agnostic must
be left to her plants."

"I want to break away.... I want Angelina to live permanently in


Guadalajara."

She lifted a watering can and began sprinkling seedlings.

"Let's be realistic: who broke away first, you or Angelina?"

"I can't say."

"Really?"'

"Really, I don't know ... and what could it matter?"

Drops from the watering can fell on her fresh white cotton dress.

"This is no way to begin the day," she said. "Let's make it a happy day. I
think we should have breakfast."

They ate at a square table in her dining room, facing the ocean through
many French windows. On three sides, in round bamboo barrels and special
boxes, tropical plants grew lavishly, most of them dark green, many of them
climbing as high as the ceiling. It was like being inside a miniature park.
Barefooted girls served. A girl brought in a blue glass pitcher filled with red
roses and placed the bouquet in the center of the table.

"I feel better," said Raul.

"One should never talk marriage in a greenhouse."

Raul grinned.

"Has everyone gone home?" he asked.

"I think so ... even Roberto."

"What was his hurry?"

"To get the train in Colima."

"He should have waited for me."

"I told him you needed sleep ... that I needed you."

Mona wandered in and Lucienne fed her pieces of tortillas. Her short-
haired terrier appeared and the two dogs raised such a hullabaloo the maids
had to chase them outside.

"What happened to your baby fox?" said Raul, eating mamey.

"It got away, somehow. What's become of Vicente's honey bear?"

"He's around. Vicente likes him."

"How's Vicente doing?"

"Fine. He's a great boy."

"And what does Angelina write ... or should I ask?"

"She wrote strangely."


"How do you mean?"

"She told about a round of parties, and then made curious remarks about
Caterina."

"Are you worried about her?"

"Something's wrong." But he avoided saying anything more.

While a girl removed their fruit husks, they smiled sadly at each other.
His hand grasped hers. They wanted to push aside unhappiness. The girl set
down a platter of golden-brown pámpanos ringed with sliced limes.

"I'd like to walk to the old church this afternoon," he said.

"The old church? Why?"

"I've always liked it ... let me serve you, Lucienne ... nobody knows how
long it's been there. It was a lighthouse for years, wasn't it? I haven't seen it
for ages."

"Big fig trees are smashing it, lifting walls: one side's trapped in the
roots of a huge fig. Treasure hunters have dug up the floors ever since
somebody found a tiny gold ship there."

"Do you think anyone found a ship of gold?"

"I doubt it. But you'll see lots of lizards; they attend Mass faithfully."
She blushed.

He laughed out, and said: "Who's the priest ... a sea gull?"

"Do you remember the huge tree that grew in front of this house?" she
asked. "Our palma sola? It was the tallest palm I've ever seen. Papa loved it.
It really hurt him when it blew down.... Raul, have more beans while they're
hot. I'm so pleased with my new cook. She's one of the best I've ever
had...."
After breakfast, Lucienne showed him her seedling acacias for it was
early and the conservatory was still cool. A butterfly coasted about
complacently, above the tiers of seedlings now ready for transplanting.
Below the trays, on the floor, rare coconuts split their husks, their yellow
sprouts resembling boars' tusks. In a bottomless dugout canoe, filled with
sand and shells, grew dwarf cacti, mammillaria, opuntia and cholla.

"Isn't that your father's canoe?" he asked.

"Yes," she said. "I just keep it.... I like it here, a memento."

"Wasn't it filled with ferns?"

"Yes, it was."

Mona came trotting in and Raul picked her up and stroked her shaggy
gray head and shoved some of her hair out of her eyes ... her tongue licked.

"We never escape the past, do we?" he said.

The past accompanied him as he rode home. With Manuel, he rode


across country, under ceibas and palm, the trail winding, sometimes across
streams, sometimes through boulder-piled land. They talked about Pedro.
The people at Mountain Rancheria reported he was living there, buying and
selling guns. The rurales had to be informed. It was a six-day trip. Would
they go after him?

White ibis and rosy spoonbill flew up from a small lake ... a blue heron
sat on a dead and leafless tree, its wings outspread in the sun. An alligator
splashed away from the shore as the horses trotted along a shell-strewn
beach.

"Do you remember this lake?" Raul asked.

"Sure. We shot a grandfather alligator here, years ago."

"I bagged a tigre in the bush," grinned Raul, "a fast, running shot."

"There are no tigres around now."


"I suppose not," said Raul. "We should go tigre hunting, way up the
volcano, where there are plenty of them. Let's try our luck one of these
days."

Dismounting, they rested under cocos de aceite, a woodland of


thousands of short-trunked palms. They nibbled tortillas and a coil of
cheese, an armadillo scrabbling in the distance.

"I remember that when it rains here the gnats take over," said Raul.

"Ssh, see, over there," whispered Raul.

Regardless of men and horses, three raccoons, one behind the other, filed
toward the water. All stared at the ground, their tails low; the leader had an
injured paw and limped badly.

"They're late for their food," said Raul.

"Something must have delayed them," said Manuel.

Raul dug for his pipe and filled it and Manuel rolled a cigarette and they
lit from the same match. Again, something ignited in their eyes—they felt
their close communion. Saddlebag under his head, Raul smoked, the smoke
climbing and climbing, the cocos de aceite completely windless.

A blue flycatcher lit on a mossy log, where it preened its wing and tail
feathers lazily.

"Have you heard that the flycatcher is from Quetzalcoatl?" asked Raul.

"Yes, I've heard that," said Manuel.

"I wonder why the old gods died," Raul said.

"People say they died because no one cared any more. Why does
anything die, Don Raul?" Manuel shook his head; he removed his hat and
forked his fingers through his hair. Faced by his own question, he felt tired,
old. The forest could answer that question. Bending over his cigarette,
sheltering it, smelling it, he listened to the woods.
"We couldn't go on living, all of us," he said, exhaling after a long drag,
the smoke flooding over his eyes. "Some of us must be lost, in jungles, in
rivers, fall on the sides of mountains, take sick of fever, be buried in ruins
and little roadside places."

"But the gods weren't buried," objected Raul.

"They were buried at Tenochtitlan, at Monte Albán, at temples in


Yucatán."

The flycatcher went on preening its lovely feathers.

Manuel lowered his voice: "Perhaps the old gods may return. I've heard
it said...."

12
"I guess it was quite a party," said Fernando.

"Yes, Father."

"Who was there?"

"General Matanzas, Serrato, Roberto ... the Count, Jesús Peza, the
Radziwills, Federicka ... several asked about you."

"Don't be so damn' polite."

The old man screwed round among his pillows, his cot in the patio of the
serpent fountain. Slouched among pillows and sheets, he resembled a
beachcomber, a feudal derelict. Behind him hung one of Alberto's cages, an
azulejo fluttering inside. Columnar cypress sliced the sky.
Raul perched on a cane chair, his hat on the floor beside him. He had just
returned from an inspection of the lagoon irrigation project, a job that
would put fifteen hectares of land under cultivation.

"I saw your cancellations in the books," Fernando cried, the flames in his
eyes starting. "I want those cancellations stopped." His voice sounded
childish.

Raul did all he could to control himself: he fished out his pipe, nicked
off scale, stared at it, silent.

"You can't alter our records," Fernando exclaimed.

"I'm not keeping our people in servitude," Raul declared.

"Will you free them?" Fernando cried, lips wide. "They'll kill you!"

"We've had them killed. Perhaps it's their turn."

"You talk like a madman!"

"Hasn't it been insane to think we can destroy and destroy and go on


destroying?"

"We must eat," said Fernando foolishly. He wanted to see clearly: the
damn' scum floated about at any time, blocking, filtering; he rubbed his
eyes.

"I'm going about the job of changing things as slowly as possible. The
lagoon project is coming along. I've had the dam repaired in Sector 17.
Petaca is being improved. Our people have a right to a better way...." He
thought he could not go on defending himself, repressing his feelings. "You
say we must eat. God knows we've never gone hungry, we Medinas!"

"Listen," Fernando said. "I've disposed of my mining shares in Pachuca


Incorporated. The money is banked in my name now."

Raul had counted on the dividends for further improvements. He had


counted on them as a financial buffer as well. His lips went white.
"Did you hear me?"

"I heard you."

"You talk of improvements. I'll cut your income. I can control Petaca."
Fernando's sheet billowed and sank back.

"You can't!" Raul exclaimed.

"Raul—you can't better Petaca on one hand and undermine it on the


other. Your radical ideas will ruin us."

"So we must hold our own by destroying others."

"It's a system like any other."

"That's no excuse."

"What will you do? Divide our land? The Indians owned it once. Will
you give it back?" His voice crackled.

"That can be answered later," Raul said.

"When? Tomorrow? Next month? How long will you wait?"

Raul replaced his pipe in his pocket and forced himself to reply: "I
haven't decided how to act."

"You'd give our land away!"

"No, Father. I won't give up Petaca."

Fernando forced a quaking hand from under the sheet and wedged a
pillow behind his back. Except for a general diffusion of yellowish light, he
could see nothing.

"I'm almost blind," he mumbled. "When is that optical fool coming from
Colima to fit my glasses? Blind ... you know what it is to be going blind?
Give me a drink."
As the old man drank, he thought of Pedro; he trembled; his fear of death
returned, and he did not want Raul dead.

"Don't go, Raul. Sit down, wait."

Raul held the empty glass and remained standing.

"Did General Matanzas speak to you ... of a new president?" he asked,


with difficulty. He had difficulty in swallowing.

"No. He was drunk."

"Who is to take over Mexico ... does anyone say?"

"Nobody knows."

"What utter fools," he growled. "A ship without a helmsman.... And here
at Petaca I must fight you." Then he said, sadly: "This is a time of rumors
about revolt, about partition of land.... I don't like a time of rumors." He
cleared his throat.

For the first time during their conversation, Raul considered his father
carefully; he saw that he had lost weight; the gnarled face had shrunken;
both hands trembled now. No one had troubled to wash his hands. No one
had combed his hair.

Raul went for Chavela and brought her back with comb and brush and
pan of warm water and cake of soap. As she held the basin, he washed his
father's hands, remembering some old legend of men deriving power and
adding to their own longevity by such an act. Chavela dried Fernando's
hands and washed his face as he lay with eyes closed, silent. He fell asleep,
while she combed and brushed his hair. Raul got his hat and climbed the
stair to his room. At another time he would question Fernando about Pedro's
gun smuggling.

In his bedroom, he smelled Angelina's perfume and, as he changed from


boots to shoes, he went over their disaffection, wanting, no matter how
absurd, how contradictory, a touchstone that might bring about harmony.
Downstairs, Gabriel rested, seated in a big armchair, drowned in a book,
his robe pulled up from his legs, his sandals kicked off. Light from the
veranda drilled holes through his spectacles as he read.

"When did you come in?" asked Raul, poking about.

"I've been at the bookcase quite a while. Last week I got lost in Josse's
Historia and now I'm trying Locke's essay on Understanding."

"I'm the one who needs understanding."

"Not as much as I need it," said Gabriel. "What is it we need at Petaca?"


he wanted to know.

"Friendship."

"Can that be it, Raul?"

"You taught me that, Gabriel. You've looked after the cuts and bruises
and listened to the bitter stories. You've found ways of expressing
friendship in the little things, a new altar cloth, medicine for Motilinia, a
straw horse for a boy's birthday."

Quiet, Gabriel thumbed the leather book; for years he had encouraged
one after another; it pleased him that Raul should speak out. What he had
accomplished he could not say.

One force had worked consistently against him and that was Don
Fernando.... As enemies, they had stormed over every sector of the
hacienda. Already Raul had re-opened the school and secured a teacher, an
able young man from Manzanillo, handy with guitar and songs. Secretly,
Gabriel was a little jealous of Raul's successes. But he knew the inner man,
the inner conflicts, and probed no more.

Both read in the shuttered, still living room. The bookcase occupied a
corner, the top of it strewn with bric-a-brac: silver cup, barometer, Dresden
doll, porcelain animals, the deed box.
Raul took down the Journal of Las Casas and after reading a while at
random he said, "I never find much time for reading any more."

"In Italy, I read a book a fortnight ... that was my goal."

"Perhaps life was easier in Italy."

"It's a matter of habit," said Gabriel.

"I'm sure you're right. I get more out of my smoking than I do out of my
reading."

"When I first came, I read till late every night," Gabriel said.

"I remember how late your light used to burn."

"Well, my eyes aren't up to that kind of reading any more," said Gabriel,
regretfully, and fingered the bow of his glasses.

In a loud voice, Salvador called Raul from the doorway of the veranda.

"Tomás is hurt," he said, as if reporting the weather.

"Which Tomás?" asked Raul, laying down his book. Petaca had two,
little and big, both stable workers.

"Little Tomás."

"What happened?" asked Raul, rising.

"His leg."

"Yes."

"A horse kicked him. I think the leg is broken."

"I'll go with you," said Gabriel.


The man lay on the ground in a stall, almost buried in gray straw and
gray light. An enormous dusty cobweb drooped above him.

"Are you badly hurt?" asked Raul.

"Yes ... patrón."

"Where?"

"My leg, patrón."

"Where—down low, or high up?"

"Low."

"Umm, I wouldn't want you kicked in the groin. Help me lay him flat,
Gabriel."

Storni knelt in the dirt and together they made Little Tomás more
comfortable. They removed his sandals and explored the injured leg; the
break was obvious.

"Let's take him to my place," said Gabriel.

"Where do you want him?" asked Salvador, and bending over he


gathered Tomás as if he were a child.

Tomás began to whimper.

"No, no ... take me to my hut," Tomás begged. "Patrón ... por favor."

"It's closer," said Raul. "Take him to his own place."

It made no difference to Salvador; he said something cheery and


swaggered out of the stall and across the stable yard to the row of huts built
recently. Tomás and a friend shared a hut. Salvador laid him on a straw mat,
just as he would set down pottery. The man-length space had no
furnishings, but Tomás' macaw wabbled in and climbed onto his arm and,
when Raul scared off the parrot, it squatted in a corner and clicked its beak
peevishly.

"I'll go for Velasco," said Gabriel. "I'll get him here as soon as I can,
Tomás."

Raul had Salvador bring water; there in the hut some of Tomás' fear
vanished; he managed a twisted grin; his face, streaked with straw and
sweat, had the eagerness and pathos of a student. Salvador's corn cob
fingers removed straw from his hair; sitting beside Salvador, Raul lit a
cigarette and then a second one for Tomás.

"What horse kicked you?" he asked.

Salvador picked up more straws.

"Yours ... Don Raul."

"Chico! That damn' horse! What the hell was Chico doing in that stall,
Tomás?"

"I was leading him ... to be shod ... he kicked me ... I fell into that stall ...
I fell."

"Ah," said Raul, smoking, disappointed in Chico.

Later, outside the stable, he watched men curing a batch of iguana hides;
they had the pelts submerged in a chemical solution and kneaded them with
wooden mauls. Other men padded saddles with milkweed and sewed and
polished leather. Under a thatched ramada they had a dozen saddles on
saw-horses; he noticed one of his own, a reddish McClellan, from Texas.
The air smelled of leather, strong saddle soap and polish. Sun streaked the
stable wall. Raul strolled among his men, chatting, whistling, smoking.

A teenager, in torn shorts, gutted a snake. Above him, head high from the
ground, in a carved niche, stood the figure of St. Christopher. A Medina had
placed it there generations ago, a pink stone carving done by a local artisan.
A snakeskin dangled from St. Christopher's arm and another swung from
the saint's sandal. The snake collector looked worried as Raul inspected his
workshop.

"Why do you want so many skins?" Raul asked. "Are you trying to get
rid of all our snakes?"

"No ... to make belts."

"You cure them for belts?"

"I can make other things." The youngster could scarcely work his
tongue; he thought Raul would accuse him of selling his products; he
leaned over so far his straight hair touched his bloody knife.

"What can you make?"

"A pouch ... maybe a hatband."

"Make me a tobacco pouch. I'd like a small one, about this big."

"Yes, sir." (Faintly)

"Make me a good one."

"Yes, sir."

He believed in the man's kindness.

The snake boy and Little Tomás and his father faded from Raul's mind as
he walked toward the burial plot in the grove. Juggling a smooth white
stone, he walked past the rear of the mill; above—he did not stop to look—
gulls cried. Usually gulls did not fly this far inland. A dog barked ... it might
have been Mona chasing after a girl's ball.

The graves had been redecorated with shells; the jungle had been pushed
back; lianas had been cut; vines had been ripped down; trees had been
trimmed. For the first time in years he read his mother's name on her
marker. Her marker consisted of a red cantera globe; he sat on it and
listened to the gabble of parrots and still, high up, somewhere, the cry of
gulls.

In a few weeks Caterina's bronze figure would be cast and, if the artist
remained faithful to his sketches, it would be a graceful girl bearing a
bouquet of roses in her arms, her dress swirling over bare feet. Soon it
would acquire a patina and become part of the jungle. Perhaps it would tell
others what a beautiful child she had been. Perhaps ... then he remembered
his murdered grandfather and looked at the marker Roberto had set up, a
dignified shaft of fluted marble. Time had cracked the stone and quakes had
knocked it out of line ... nothing defied the years.

Nothing had helped his father forget his crime.... He, too, was buried
here, the best of him, the kindness that a man normally had.

He returned slowly to the house and sat on the long veranda. Men had
gathered in the court; one had a guitar and his voice had the old pleading
tone. Rocking on an old hide rocker, Raul listened to the singer as the sky
filled with stars. The big dipper hung above the court. Someone lit a
bonfire. Suddenly, Raul realized that Manuel had been sitting near him for
some time.

13
June 19, 1911

"Dear Estelle,

"As you said, it must be destiny that brings me back. Something rules
me. As I rode out of Guadalajara, I felt a harshness clawing at my brain.
Poor thing, she can't tell the shape of her mind or why it cries so, or what it
wants. Of course it wants you, but there is this something else, dark, darker
than I dare admit.

"So when I got back to help with the fiesta, I wanted to see if I could
straighten myself out a little. I fixed all the clothes for the Virgin, and
dressed. I thought: this is the last time. But Trini came in and we got to
laughing.

"Fiestas are such bores, and this one was no exception. They praised
Farias for getting in the best corn crop ever. There were Indian dances—the
viejitos were best.... Doblado killed his bulls as badly as ever ... fireworks ...
and all the time I kept thinking of Lucienne, because she came and met
Raul secretly. So people told me. I wanted to get sick.

"Raul and I had a bad quarrel, at supper, only yesterday. He said: I want
you to live in Guadalajara permanently.' 'Why?' I asked. 'Can't you stand me
any more?' And he turned white. I thought he would choke. I just stared at
the candle flames prettily. I wonder how you would handle him? He said:
'You came back to fix the Virgin's wardrobe. It's something you always
liked to do. You can come back to Petaca, any time. I'm not banishing you.'

"'So I can come back sometimes—how nice! And do you want to keep
Vicente forever?' I cried.

"'We can share him, as you like. We can work that out later.'

"'Why later? Later! Haven't we waited too long?'

"'Too long for what?'

"'For me."

"It went on and on. He says it's for my own good. But now I'm sick, and
I can't go away...."

Abruptly, she got up from her desk. Barefoot, in a loose gray robe, she
walked to the veranda windows, already hating what she felt she might see:
men on horseback, women and children, people walking and talking. She
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.

More than just a book-buying platform, we strive to be a bridge


connecting you with timeless cultural and intellectual values. With an
elegant, user-friendly interface and a smart search system, you can
quickly find the books that best suit your interests. Additionally,
our special promotions and home delivery services help you save time
and fully enjoy the joy of reading.

Join us on a journey of knowledge exploration, passion nurturing, and


personal growth every day!

ebookbell.com

You might also like