100% found this document useful (8 votes)
403 views41 pages

PDF (Original PDF) C++ Programming From Problem Analysis To Program Design 8th Download

From

Uploaded by

suitsbassel90
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
100% found this document useful (8 votes)
403 views41 pages

PDF (Original PDF) C++ Programming From Problem Analysis To Program Design 8th Download

From

Uploaded by

suitsbassel90
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 41

Download the full version of the ebook now at ebooksecure.

com

(Original PDF) C++ Programming From Problem


Analysis to Program Design 8th

https://ebooksecure.com/product/original-pdf-c-
programming-from-problem-analysis-to-program-
design-8th/

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


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

(eBook PDF) C++ Programming: From Problem Analysis to


Program Design 7th

https://ebooksecure.com/product/ebook-pdf-c-programming-from-problem-
analysis-to-program-design-7th/

ebooksecure.com

C++ Programming: From Problem Analysis to Program Design


8th Edition Edition D.S. Malik - eBook PDF

https://ebooksecure.com/download/c-programming-from-problem-analysis-
to-program-design-ebook-pdf/

ebooksecure.com

C++ Programming. Program Design including Data Structures


8th Edition D.S. Malik - eBook PDF

https://ebooksecure.com/download/c-programming-program-design-
including-data-structures-ebook-pdf/

ebooksecure.com

(eBook PDF) Company Law An Interactive Approach by Alex


Wong

https://ebooksecure.com/product/ebook-pdf-company-law-an-interactive-
approach-by-alex-wong/

ebooksecure.com
Top 50 SAT Math Skills, Third Edition Leaf - eBook PDF

https://ebooksecure.com/download/top-50-sat-math-skills-third-edition-
ebook-pdf/

ebooksecure.com

(eBook PDF) Systems Architecture 7th Edition by Stephen D.


Burd

https://ebooksecure.com/product/ebook-pdf-systems-architecture-7th-
edition-by-stephen-d-burd/

ebooksecure.com

(Original PDF) World Architecture: A Cross-Cultural


History 2nd Edition

https://ebooksecure.com/product/original-pdf-world-architecture-a-
cross-cultural-history-2nd-edition/

ebooksecure.com

(eBook PDF) Managing and Using Information Systems: A


Strategic Approach, 6th Edition

https://ebooksecure.com/product/ebook-pdf-managing-and-using-
information-systems-a-strategic-approach-6th-edition/

ebooksecure.com

(eBook PDF) Criminal Investigation: An Illustrated Case


Study Approach

https://ebooksecure.com/product/ebook-pdf-criminal-investigation-an-
illustrated-case-study-approach/

ebooksecure.com
(eBook PDF) Business Driven Technology 9th Edition

https://ebooksecure.com/product/ebook-pdf-business-driven-
technology-9th-edition/

ebooksecure.com
D.S. Malik
Eighth Edition

C++
PROGRAMMING
C++

Program Design
From Problem Analysis to
PROGRAMMING
From Problem Analysis to
Program Design

To register or access your online learning solution or purchase materials


for your course, visit www.cengagebrain.com.
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-208
Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-208
Brief Contents

© HunThomas/Shutterstock.com

PREFACExxxiii

1. An Overview of Computers and Programming Languages 1

2. Basic Elements of C11 27

3. Input/Output 123

4. Control Structures I (Selection) 187

5. Control Structures II (Repetition) 265

6. User-Defined Functions 347

7. User-Defined Simple Data Types, Namespaces,


and the string Type 467

8. Arrays and Strings 521

9. Records (structs)611

10. Classes and Data Abstraction 651

11. Inheritance and Composition 743

12. Pointers, Classes, Virtual Functions, and Abstract Classes 817

13. Overloading and Templates 893

14. Exception Handling 991

15. Recursion 1035

16. Searching, Sorting, and the vector Type 1069

17. Linked Lists 1115

18. Stacks and Queues 1209


Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-208
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-208
Table of Contents

© HunThomas/Shutterstock.com

Prefacexxxiii

AN OVERVIEW OF COMPUTERS
1 AND PROGRAMMING LANGUAGES 1
Introduction2

A Brief Overview of the History of Computers 2

Elements of a Computer System 4


Hardware4
Central Processing Unit and Main Memory 4
Input/Output Devices 5
Software5

The Language of a Computer 6

The Evolution of Programming Languages 7

Processing a C11 Program 9

Programming with the Problem


Analysis–Coding–Execution Cycle11

Programming Methodologies 20
Structured Programming 20
Object-Oriented Programming 20
ANSI/ISO Standard C11 22

Copyright 2018 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. WCN 02-200-208
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-208
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-208
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-208
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-208
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-208
Visit https://testbankfan.com
now to explore a rich
collection of testbank or
solution manual and enjoy
exciting offers!
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-208
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-208
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-208
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-208
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-208
Exploring the Variety of Random
Documents with Different Content
export of cotton to so considerable an amount. I found the best-
informed opinion in Southern Nigeria imbued with the belief that the
1911 crop will be a poor one, though better than last year’s, but that
the prospects for the crop of 1912 are good. The newly opened
ginnery at Oshogbo is said to be doing well. The ginnery at Oyo,
however, is apparently lying idle. At any rate, it had done nothing, I
was there informed, ever since it was put up, some four years ago. A
good deal seems to have been spent upon the experimental
plantation at Ibadan, with indifferent results. It has now been taken
over by the Government, whose officers, I was informed, found it in a
very neglected condition.
Personally, I do not attach, in a sense unfavourable to the growth
of the industry, much importance to the drop in the output. The field,
it must always be remembered, is small, the entire Western Province
being only 27,640 miles square, and much of it, as already stated,
covered with forest. In West Africa new industries are always liable
to violent fluctuations. The drop in the maize export is much more
considerable than the falling off in cotton. Unfavourable seasons, too
much rain or too little, late sowing, and other considerations play a
determining part in these matters. Things move very slowly in West
Africa as a rule. The cotton crop is not the easiest to handle.
Compared with ground nuts, for instance, it entails a great deal more
time and trouble. All kinds of obstacles have to be encountered and
overcome which people at home have difficulty in fully appreciating.
The experimental stage of any enterprise, especially in a place like
West Africa, is bound to leave openings for error, and error in West
Africa is a costly luxury. The Protectorate is under considerable
obligations to the Association for the good work it has done and is
doing.
It seems to me that the British Cotton-growing Association may
perhaps find it advisable, so far as the Western Province of Southern
Nigeria is concerned, to reconsider two aspects of its policy.
Fundamentally that policy is without question sound—viz. the
recognition that agricultural development in West Africa can only be
possible on any scale worth mentioning when undertaken by the
natives themselves. A policy of large plantations run under white
supervision by hired native labour will not pay in West Africa, and,
politically speaking, is virtually impossible. The Association should
receive public support in resisting any pressure which might be
placed upon it to alter its fundamental policy by those of its
supporters who may be impatient of a comparatively slow advance—
slow, i.e., in comparison with the unwise optimism displayed by
some of the Association’s friends upon public platforms. I doubt,
however, if an export trade in cotton will ever reach substantial
proportions—let us say 100,000 bales per annum twenty years
hence—in the Western Province unless the element of competition is
introduced. Hitherto, by combining with the merchants, the
Association has established a fixed buying price. In the initial stages
this was a good thing. The native farmer wanted the certainty that his
crop would be purchased if he were induced to grow it. Now that the
industry is well on in its stride it may be seriously questioned whether
the Yoruba farmer, the certainty of sale notwithstanding, will be
content with the prices offered him under the monopoly agreement
now obtaining. He has always the oil palm to fall back upon; but he
has, in addition, cocoa and maize. Cocoa is rapidly increasing, and
the profit realized by the cultivator is a good one. The timber trade,
too, is growing slowly, and the forest is always yielding fresh
elements of trade. The bulk of the cotton produced in the Western
Province to-day is roughly similar to “middling American,” which is
now quoted, I believe, at 8d. a pound, but some of the Yoruba cotton
fetches up to 3d. above “middling American.” It is asserted by the
Association that 4 lbs. of seed cotton are required in the Western
Province to produce 1 lb. of lint. The native cultivator is (now)
supposed to get from the combine—i.e. from the Association and the
merchants, as the case may be—from 1d. to 1⅛d. per lb. of seed
cotton. I say “supposed,” because I was informed that the actual
producer had not always got the amount which he was understood to
be getting. As regards Northern Nigeria, until the close of last year
the native had never been paid 1d. a lb. cash, and I was given to
understand that conditions had been much the same in the Southern
Protectorate, except at Ilushi, where it was proved to my satisfaction
that the amount of 1d. cash had actually been paid.
The Association reckons, I understand, that at this rate every
pound of lint landed in Liverpool costs the Association 6½d. I cannot
check that figure. I merely quote it. But one may point out that in
addition to the profit at the present price of “middling American”
disclosed by this estimate, there must be a considerable profit to the
Association on the seed, which, upon arrival in England, is worth, I
believe, between £5 and £6 per ton. Moreover, as already stated,
some of this Yoruba cotton is fetching a higher price than “middling
American,” and I do not think it is beyond the mark to say that, but
for the fact that the Association’s ginneries are not continuously
employed, the Association’s profits on Southern Nigerian cotton to-
day would be substantial. It must be fairly obvious from what
precedes that if the industry were placed upon an ordinary
commercial footing like any other, with merchants competing on the
spot for the raw material, the Yoruba farmer would have no difficulty
in obtaining very much more than he gets at present for his crop.
Cultivation, under those circumstances, would become
proportionately more profitable and a greater acreage would be laid
out in cotton. No doubt it would cut both ways, the native restricting
his acreage when the price fell, but it may be fairly argued that no
special reason now exists for treating the cotton industry on an
artificial basis, that it must take its chance like any other, and like any
other become subject to ordinary economic ups and downs. We
cannot expect the native farmer to concentrate upon one particular
crop if he can make a greater profit in cultivating another. No industry
can develop healthily on artificial lines. If this suggestion were
thought worthy of consideration, the Association’s rôle could be
confined to ginning, and, if asked to do so, selling on commission, or
that rôle might be combined with buying and selling in cases where
the producers preferred to deal with the Association, or found it more
convenient to carry the cotton direct to the various ginneries. That,
no doubt, would force the Association into competition with the
merchants, and the merchants, bringing out their own gins (if it paid
them to do so), might cause the Association’s position to become
precarious. The first alternative would, therefore, appear the most
desirable, the merchants being the buyers and the Association, the
ginners, and, if necessary, sellers on commission. Each force would
then be operating within its natural orbit, and an unnatural alliance
would cease, unnatural in the sense that one price means one
market, and that one market is not an inducement to economic
expansion, especially when the price of other tropical products
produced by the Yoruba farmer with an open free market to deal in
has been steadily rising during the last few years. The Association
has always contended that its primary object is not money making,
but the establishment in our oversea dependencies of an Imperial
cotton industry calculated in the course of time to relieve Lancashire,
in whole or in part, of her dangerous dependence on American
speculators.
The other point which those responsible for the management of
the Association might conceivably think over, is one that impressed
me in Northern Nigeria when inspecting the beautifully kept cotton
plantations in the Kano and Zaria provinces. I was later on to find
that it was one upon which very strong, though not unanimous,
opinions were held by persons of experience and judgment in the
Southern Protectorate. A great deal of energy, and doubtless money
too, is apparently expended by the Association in experimenting with
and distributing seeds of non-indigenous varieties of cotton. Now,
although one cannot say without careful cultivation, speaking of the
north, one can at least say without perpetually improving scientific
cultivation extending over a century, Nigeria is able to produce
indigenous cotton, fetching to-day 1¼d., 2d., and even 3d. per lb.
above “middling American.” Does not this fact constitute the
strongest of pleas for concentrating upon the improvement of the
indigenous varieties instead of distributing effort by worrying about
the introduction of exotics? If these indigenous plants, without a
century’s scientific care, can produce cotton superior in value to
“middling American,” what could they not do with a tithe of the
attention which has been lavished upon the industry in the States? I
know the experts will argue that the indigenous varieties make a lot
more wood, and that an acre planted with American varieties will
yield much more lint than an acre planted with a Nigerian variety. Not
being an expert I would not venture to dispute this. All that I would
make bold to query would be whether experiments tending to prove
it have in Nigeria been sufficiently continuous and carried out under
conditions of fairness to the indigenous cotton sufficiently conclusive
to place the matter beyond the pale of discussion. Even if this were
so, I am not sure that it could be taken as an irrefutable reply to the
contention I have ventured to put forward. For, on the other side,
must be reckoned the diseases which invariably attack all exotics,
animal, vegetable, and human, introduced into the West African
forest region. At every halt on my trek from Riga-Chikum to Kano, a
matter of twelve days, wherever I saw cotton plantations, and often
enough at points on the road, I made it my business whenever
practicable to put a number of questions to the Sarikis (chiefs) and to
individual farmers on the subject of cotton-growing. I always
prefaced these questions with an assurance that I did not belong to
the Government and that I was not a commercial man, but merely a
Mallam (I believe my interpreter sometimes inserted on his own
account the word “wise” before Mallam), who travelled about and
wrote “books,” and that my friends could therefore feel satisfied that
they would not be causing me any pleasure at all by answering my
questions in any particular manner—that, in short, I did not care a
row of yams what their answer might be. One question I never failed
to ask was whether the Government had distributed seed to that
particular village or in that particular area, and if so, what result had
followed the sowing of it? Sometimes the answer was in the
negative. When it was in the affirmative it was invariably the same.
The Government seed had come. It had been sown. But it was “no
good.” Now, I disclaim all attributes of wisdom in this matter of
cotton. But I beg you to believe me when I say that the Hausa farmer
is no fool.[14]
CHAPTER III
THE COTTON INDUSTRY—continued

Cotton is grown extensively in parts of Northern Nigeria, not for


export—outside the Hausa provinces—but for home consumption. In
Kano province—28,600 square miles in extent with 2,500,000
inhabitants, more than one-fourth of the total population of the
Protectorate—its cultivation is accompanied by what can, without
exaggeration, be termed a national industry of weaving,
manufacturing, embroidering, and dyeing the garments, both under-
garments and over-garments, which the Kano people wear. But not
the Kano people alone. For many centuries, for nearly 1000 years
probably, the Kanawa have been famed throughout the great region
comprised between the bend of the Niger and the ocean as the
expert cotton manufacturers of Africa; the most interesting region in
all the Dark Continent, where divers races have ceaselessly
intermingled, attracted thither by its fertile soil and abundant
pastures; Libyan and Berber, Egyptian and Semite, and the
mysterious Fulani. Three-fourths of the “men of the desert,” too, the
fierce-eyed, black-lithamed Tuareg, descendants of the Iberians,
who roam over the vast spaces between Tripoli and the Chad,
replenish their wardrobes from the Kano looms. Throughout Bornu,
Wadai, and Baghirmi, in the northern German Cameroons as far east
as Darfur, Kano cloths hold unquestioned sway. The Kanawa are not
the only Nigerians who manufacture cotton goods; but they are the
only people among whom the industry may be truly called a national
one. As carried out in Kano province this industry adds dignity,
interest, and wealth to the life of the people, assists their inventive
faculties, intensifies their agricultural lore, and sustains several other
branches of industrial activity, binding in close alliance of material
interest the agriculturist and the artisan. It gives a healthy, attractive
employment to many thousand homes—employment carried on in
the free air of heaven, beneath the bright sunshine of Africa. It has
become a part of the national life, the pride and profit of the people.
Men, women, and children participate in it, the men clearing the
ground, hoeing and sowing, the women and children doing the
picking, the women cleaning the lint of the seeds (on flat stones),
teasing, the men weaving, tailoring, and usually, but not always,
embroidering. Woven in long, narrow strips, the manufactured article
is of remarkable durability and firmness of texture. The
predominating dye is the blue of the indigo plant, extensively
cultivated for the purpose, dyepits being common all over the
province. The embroidery, both in regard to design and execution, is
astonishingly handsome, and the colours harmoniously blended. A
fine specimen of a finished riga—the outer robe covering the
shoulders, with an aperture for the head and neck, and falling in
folds to the knee—is a work of art of which any people in any country
might be proud. It is a very heavy garment, and it is costly. But it is
suitable for the cold nights and chilly mornings, and it lasts for years.

WOMEN COTTON SPINNERS.


MEN WEAVING.

It is impossible to separate the cultivation of cotton from the


agricultural pursuits of the people generally. Cotton, like cassava,
onions, ochro, pepper, ground nuts, and beans, takes its place as
one of the secondary crops. The people are primarily a people of
agriculturists, raising vast quantities of cereals year after year for
home consumption and export to other districts—guinea-corn and
millet, yams, maize, a little wheat. In the Kano Emirate or division—
as distinct from what is known as the Kano province—the population
is exceedingly dense, and virtually the whole land is under
cultivation. I have seen nothing more remarkable in the way of
cultivation either in France or Flanders. And it is all done with the
galma, a peculiar kind of short-handled hoe, which would break the
back of an English labourer to use, but which the Hausa will wield for
hours together. The pattern of the galma is of great antiquity. It came
from ancient Egypt, with the original inhabitants probably; the
plough, which was used in Egypt when intercourse was frequent
between the valleys of the Nile and Niger, never seems to have
penetrated so far West—a curious and unexplained fact.
Long, deep, broad, parallel ridges cover the surface of the land,
dotted here and there with magnificent specimens of the locust-bean
tree, the shea, the tamarind, and many other varieties, under whose
shade it seems a favourite device to grow a catch crop of pepper.
How does the soil retain, year after year, its nutritive properties? That
is the secret of the Kanawa, who from generation to generation have
studied it in conjunction with the elements, as the Niger pilots have
learned to read the face of the waters and can steer a steam launch
where no white man could without running his craft upon a
sandbank, especially at low water. That they have acquired the
necessary precise knowledge as to the time to prepare the land for
sowing; when to sow and how to sow; how long to let the land lie
fallow; what soils suit certain crops; what varieties of the same crop
will succeed in some localities and what varieties in others; how to
irrigate the land situate in the vicinity of the waterways and planted
with secondary crops in the dry season; how to ensure rotation with
guinea-corn, millet, ground nuts, and beans; when to arrange with
the Fulani herdsmen to pasture their cattle upon the land—so much
at least the outsider interested in agricultural problems can gauge to
some extent. For miles and miles around Kano city one passes
through a smiling country dotted with farms, riven by fine, broad
native roads lined with hedges of euphorbias and other plants.
Great care is lavished upon the cotton and cassava plantations—
the two chief secondary crops. When the cotton fields are in the
neighbourhood of a road, and very often when they are not, they are
surrounded by tall fencing, eight to ten feet in height, usually
composed of reeds and grass or guinea-corn stalks, to protect them
from the depredations of cattle, sheep, and goats, all of which
abound. In April and May, with the advent of the early rains, the land
is cleared and hoed into furrows and ridges. Along the ridges drills
are made at a distance of two and a half to three feet apart, the seed
dropped in, and the ridge hoed up. In some districts, however, this
custom is varied by the ridges being made after the sowing. The
water lies in the hollows between the ridges, prevents the seeds
from being washed away by the torrential downpour, and allows air
to circulate freely, thus keeping the plants in a healthy state. A month
later, when the plants have grown to a foot or more, the ground is
again hoed. That is the first sowing. With variations according to
localities there are successive sowings up to July and even August.
The success of these late sowings depends very much upon the
extent to which the land has been previously manured. Conditions
are slightly different with the variety of cotton grown, but as a rule the
plants are in a fit condition for picking about five months after
sowing. December, January, March, and April appear to be the
months when cotton is most abundant in the markets. In November
and December of last year I observed that while in some of the fields
the pods were bursting well and picking beginning, in others they
were still in full flower; in others, again, they had not reached the
flowering stage. Speaking generally, the plantations were in excellent
condition, and the absence of weeds would have done credit to an
up-to-date British farmer. But the difference in vigour of plant growth
was very marked—affected, doubtless, by locality and manuring or
the lack of it. One of the finest plantations I saw was at Gimmi, to the
north of Zaria province, and the intelligent sariki (chief) of that village
informed me that his people not infrequently treated the plant as a
perennial up to the third year, when it was plucked up. I
subsequently ascertained that in the Hadeija division of the Kano
province, where the soil has a good underlying moisture, the
perennial treatment is carried on sometimes for no less than seven
years. After the third year the annual crop decreases. When so
treated the plant is invariably manured.
I found it exceedingly difficult to obtain reliable figures as to the
average yield of cotton per acre in any one district, or the average
acreage under cultivation; and the Residents share the view that
only continuous residence in the country by a Hausa-speaking (that
is essential) European expert in constant and close touch with the
farmers will permit of anything approaching exact information being
acquired on the point. In the Katagum division of Kano province an
acre is said to produce an average of 266 lbs. The average annual
acreage under cotton in Katsina is said to be 16,000 acres. In Zaria
province the soil, which is a sandy clay, the subsoil being reached at
six inches, is generally rather poor, and the farmer is not so great an
expert as his Kano colleague. In some places it is so poor that one
hundred plants are said to be required to produce a single riga. In
the true cotton-farming districts of the northern part of the province—
such as Soba, Gimba, and Dillaya—the soil is, however, very much
better, obtaining more moisture than the higher ground of Kano
province and producing even finer cotton. Broadly, the problem
which faces the native farmer in Zaria province is how to increase
the fertility of his land. Artificial chemical manuring is out of the
question; the rains would wash it all out of the soil. Green manuring
is well understood but might be improved. The introduction of one or
two shallow ploughs might work wonders by showing the farmers
how the subsoil could be broken up, but the experiment would have
to be carefully demonstrated. The native is only affected by actual
demonstration, and, so far, demonstrations inspired by Europeans
designed to show the Hausa farmer how to improve his agricultural
systems have done little more than provoke a smile. The white man
has failed where the black man has succeeded, because the white
man thought he knew local conditions and did not. A Government
experimental farm was started at Maiganna rather late last year, the
sowings being made in July, if I remember rightly, seventeen miles
from Zaria city. This is an excellent initiative which it is to be hoped
will be maintained. It is really Government work. The British Cotton-
growing Association should be spared all expense of this kind. Two
varieties indigenous to the southern provinces (Bassa and Ilorin) and
“Nyassaland upland” were planted. I was told last November by the
official in charge that the indigenous varieties were doing fairly well,
but that the “Nyassaland” was suffering from red-leaf. The British
Cotton-growing Association was then about to put up a large and
costly ginnery at Zaria. The operation is proceeding, and a
substantial quantity of cotton has already been bought. I will refer to
that later on. Meantime I cannot help thinking that it might have been
better to have waited a little and set up the ginnery at Kano.
However, this is merely a personal opinion.
The chief varieties of indigenous cotton grown in the Kano
province are three in number. The first is known under the four
following names—gundi, bagwandara, lutua, or mailaushi; the
second as chukwi or labai. These two are the best kinds, their quality
being about the same. The third is called yerkarifi or yergeri. It is of
an inferior quality with a shorter staple, usually but not always grown
where the soil is not naturally rich enough to support the other kinds.
It is the yerkarifi variety, I gathered, which is more often used as a
perennial. It fetches a lower price on the local markets and takes a
month longer to mature. Cotton plants are fairly free from insect
pests, but the following are identified: the cotton boll worm (tsutsa),
what is described, doubtfully, as an ant which attacks the root (zago),
and two species of blight (makau and madi). The native remedy,
apart from constant hoeing, is to light a fire to windward, upon which
the dried leaves of a certain plant, and also dried fish, are thrown.
The question of indigenous versus exotic varieties here crops up
again. One hears talk of flooding the country with exotic seed and
doing away altogether with the indigenous varieties. I refer to Zaria,
where some five hundred bags of exotic seed—or at least non-local
seed—were distributed this spring after a palaver with the Emir and
his principal headmen. No doubt it may be all right. From the non-
expert point of view it seems dangerous. As already stated, African
insect life fastens with relentless savagery upon exotic plant life, just
as it revels in nice fresh blood out from Europe. One season’s failure
with an exotic or non-local variety, sown by instructions of the Emir’s
headmen in lieu of the indigenous kind, might create a prejudice in
the native’s mind that it would take years to remove. Concentration
upon improving the fertility of the soil, and therefore the quality and
quantity of the local varieties (combined, of course, with seed
selection) would be a slower process. It is just possible that it might
be a wiser one.
The distribution of the cotton now grown in Zaria and Kano
provinces is as follows: Zaria is visited by the weavers (or their
representatives) of Kano and of French territory—from the
neighbourhood of Zinder principally. They buy up between them
virtually the whole crop, importing live stock and manufactured
goods, which they dispose of in the markets for silver coin, buying
with that coin the cotton. What is not taken by the Zinder people is
taken by Kano. The Kano division of the Kano province consumes all
the cotton it grows. So does the Katagum division. The Katsina
division exports a percentage to Kano and consumes the rest. The
soil of this division compares unfavourably with that of Kano, except
in the southern district, where it is even better than in Kano. In this
district cotton-growing forms the principal means of livelihood of the
inhabitants. The total annual output of the Kano province is
estimated at about 5200 tons—3500 from the Kano division, 1000
from the Katsina division, 700 from Katagum-Hadeija. But these
figures are mere estimates, and not over-reliable at that. The country
is too extensive and the British occupation too recent to permit of
accuracy in such matters at present. I was unable to obtain even an
estimate of the Zaria output, which is, of course, very much lower—
probably about one-fifth, or less than that at Kano.
As already remarked, the whole of the crop now grown is used by
the local industry (except the Association’s purchases this year,
which I will refer to in a moment). So far this industry not only shows
no signs of decreasing, but the demand, especially from the
southern markets is, I was told, steadily increasing. The advent of
the railway may, apart from the activities of the Association, modify
the situation appreciably through the increasing influx of Manchester
goods. As well-being increases—and up to a certain point it is doing
and will do so as the result of our occupation—the consumption of
Manchester goods wall doubtless increase, but it does not altogether
follow that the output of the native looms will decrease. It is curious
that the Kano weavers themselves think that the railway will enlarge
their market. I was informed that the natives of the south, who have
been in touch with Manchester cotton goods for many years, very
much prefer the Kano cloths, which although dearer, are much more
durable. In the north I heard frequent complaints of the quality of the
Manchester goods imported. Many of them, so I was told, were
much too thin, and so heavily starched that on the first washing they
became threadbare and useless. I saw nothing on sale in the
markets from Manchester suited for the early and late hours of the
day. Cheap prints are all very well for the hot hours of the late
morning and afternoon. But the people require warmer garments
than that. I used to strike camp when trekking at about 5 a.m. or 5.30
a.m., and at that time, and for a couple of hours afterwards, I was
glad of two sweaters over a khaki shirt, riding. When the sun goes
down it is equally chilly. The robes worn by the better-class natives
are of a consistency and weight which would astonish us here.
I am persuaded that the British Cotton-growing Association is in
every way worthy of support, that its ideal is a fine one and a
patriotic one, and that the West African dependencies of Southern
and Northern Nigeria are very much indebted to it. At the same time I
should not be giving honest expression to the views I have rightly or
wrongly formed if I did not enter a caveat against any Government
action calculated to undermine or destroy the weaving industry of the
Kano province. That industry may disappear as the result of natural
causes. But nothing should be done by the Administration to assist
its decay. Frankly, I am compelled to state that from the standpoint of
the happiness and welfare of these Hausa people, our wards, the
disappearance of their national industry would be deplorable. It
would lower their outlook and stunt their development, and send
them down in the scale of civilization. Their intelligence is of an order
which would enable them under tuition to advance their methods of
production beyond the hand-loom. While the duty of the
Administration to lend its moral support, as it is doing, from the
Governor, Sir Henry Hesketh Bell (who is most interested in this
question) downwards, to any legitimate effort directed at increasing
the area of cotton under cultivation, increasing the yield per acre by
improving the fertility of the soil, facilitating communication and the
accessibility of markets, is unquestioned, I submit that there is an
equally clear call of duty on its part to encourage rather than
discourage an indigenous industry of great antiquity, of wonderful
promise, which is at once a source of profit to, and an elevating
influence in, the life of the people of the land.
I have now endeavoured to sketch the chief factors to be
considered in estimating the possibilities of a substantial export trade
in raw cotton from Northern Nigeria. There remains to be examined
the question of price and of competing articles of production. The
British Cotton-growers Association’s début at Zaria has been
attended with no little success. They bought this season, I believe,
something like 60,000 lbs. of cotton, a considerable proportion of
which, I am informed, came from the Katsina division of Kano. Whilst
the Association’s buyers, lent to its representative by the authorities,
could not compete in price with the Kano and Zinder buyers in the
big markets, they competed successfully with them in the remoter
small markets of the province which buyers from the native weaving
interest do not usually visit.
I hope I shall not be thought desirous of “crabbing” the
Association’s efforts or minimising what they have accomplished if I
venture to point out that there would be some danger—of which the
Association is doubtless aware—in drawing too definite conclusions
from these first and satisfactory results. The taxes fell due in Zaria
province at the time of the maturing of the crop, and the growers
were anxious for cash to meet them. The Emir of Katsina is a very
intelligent man and wishful of encouraging in every way he can any
desires he deems the Government to entertain. His influence would
be directed to giving a tangible proof of his interest and goodwill.
This desire would be shared by his people, by whom he is personally
respected. It would be unwise, however, to imagine that Katsina
farmers will permanently be willing to send their cotton all the way to
Zaria for 1d. per lb., when in the ordinary run of things they can get
as much, if not more, than 1d. from the native weaving interest. If the
cotton were bought on the spot the farmers might be willing to sell at
1d. The question of price is bound to play an important part in the
interesting developments which have now begun. Taking year in year
out, the local price of cotton in Zaria and Kano varies from 1¼d. to
2d. per lb. in the seed. In Zaria last November and December it
varied from 1⅝d. to 2d. In Kano it kept at 2d. throughout November,
December, and part of January, having fallen from 2¼d. in
September. In the latter part of January it fell temporarily to 1d. It
went up again to 2d. in February. The bright side consists in the
possibility—the probability, perhaps—that the knowledge of a
permanent and unlimited market at a fixed price, albeit a low one, in
their midst will incline farmers to patronize that market (and increase
their acreage), assuring them as it does of an immediate sale.
Personally, I cannot but think that the Association will have to put up
its price if it is to obtain substantial quantities. Competition here, as
in Southern Nigeria, would undoubtedly tend to increase production,
but I believe that the advent of the European merchant to Zaria and
Kano is to be characterized by the same arrangement as I have
already commented upon in Southern Nigeria. There is, of course,
what there is not in Southern Nigeria, an element of competition in
the Northern provinces—viz. the native weaving interest—and the
play of these two forces, if both are allowed a fair field, will, no doubt,
have a stimulating effect in itself.
Another element comes in here which is worthy of note. I refer to
the price of foodstuffs. Everywhere the price of foodstuffs is growing
with our occupation of the country. Round the main highways and
large markets it has risen enormously in the past eighteen months.
In one part of the Niger province the native farmer now reckons upon
getting, I was informed, £8 to £10 per acre out of yams. Cotton at 1d.
per lb. would bring him in from £3 to £4. That is rather an extreme
case, I admit, nor does the whole country produce yams, and the
farmers generally do not appear yet to have fully grasped the
economic importance for them of the increased demand for
foodstuffs. On the other hand, it is, of course, true that the sowing of
cotton between the ordinary food crops is not uncommon.
I have thought it well to describe the position just as I read it, and
to make certain suggestions, the outcome of personal observation
and discussion on the spot. It may well be that in certain respects I
have read the situation wrong and that the suggestions made are
faulty. Prediction at the present time, I am convinced, must be largely
made in the dark, and they are no friends of the British Cotton-
growing Association who describe the outlook in Nigeria in “high
falutin’” terms. It is too soon to say how matters will develop. That
development will in any case be slow may be taken for granted. The
Administration is in urgent need of a properly equipped agricultural
department with at the head of it the very best man that money can
secure.
Reviewing the whole situation, the only definite conclusions I have
been able to arrive at in my own mind are—first, that all attempts at
giving an artificial basis to cotton production in the Nigerias will, in
the long run, defeat its own ends; secondly, that by some means or
other the price paid to the native farmer must be raised if any
extension of the industry worth talking about is to be looked for.
Everywhere in Northern Nigeria, whether the personal view inclines
to optimism or pessimism, I found the officials without exception
deeply interested in and anxious to assist in every way the effort to
build up an export industry in cotton, and fully persuaded of the great
importance and value of the work of the Association.
CHAPTER IV
THE LIQUOR TRAFFIC IN SOUTHERN NIGERIA

Apart from religious questions there is probably no subject upon


which it is more difficult to secure reasonable discussion and study
than the subject of drink; none upon which it is more easy to
generalize, or which lends itself more readily to prejudice and
misunderstanding of the real points at issue. That moral reformers in
England and elsewhere should feel strongly about drink is natural
enough. A considerable proportion of the population of this country,
of France, Germany, Belgium, and other European States live
wretched and unhealthy lives. They are over-worked, under-fed,
herded in insanitary tenements with insufficient space, ventilation,
and light, under conditions which preclude decency and breed moral
and physical diseases. Their horizon is one dead, uniform, appalling
greyness from birth to death. Who can feel surprise that people thus
situated should seek momentary forgetfulness in drink? The drink
problem in Europe is not a cause but an effect. The cause lies deep
down in the failure-side of our civilization, and statesmen worthy of
the name are grappling with it everywhere. Those of us who think we
see beyond an effect, are striving to prevent the reproduction in
tropical Africa of this failure-side of our civilization. We are striving to
maintain the economic independence of the West African; to ensure
him a permanency of free access to his land; to preserve his healthy,
open-air life of agriculturist and trader, his national institutions, his
racial characteristics and his freedom. We are endeavouring to show
him to the people of Europe, not as they have been taught by long
years of unconscious misrepresentation to regard him, but as he
really is. We feel that if we can protect the West African from the
profounder economic and social perils which encompass him on
every side; from the restless individualism of Europe; from unfair
economic pressure threatening his free and gradual development on
his own lines; from the disintegrating social effects of well-meaning
but often wrongly informed and misdirected philanthropic effort; from
political injustice—that if we are able to accomplish this even in small
measure, the question of drink, while requiring attention, becomes
one of secondary importance. The West African has always been a
moderate drinker. From time immemorial he has drunk fermented
liquors made from various kinds of corn, and from different kinds of
palm trees. It is not a teetotal race, as the North American race was.
It is a strong, virile race, very prolific.
Unfortunately this question of drink has been given a place in the
public mind as regards Southern Nigeria altogether disproportionate
to the position it does, and should, hold. It has been erected for
many sincere, good people into a sort of fetish, obscuring all the
deeper issues arising from the impact upon the West African of
civilization at a time when civilization has never been so feverishly
active, so potent to originate vast changes in a few short years. The
temperance reformer in England strikes, often blindly, at “drink”
anywhere and everywhere on the same principle, utterly oblivious to
physiological and climatic differences; he cannot see beyond or
behind the subject which specially interests him and which has
become his creed. The use of intoxicants of some kind is common to
humanity all over the world. It responds to a need of the human
body. Christ Himself did not condemn its use, since He Himself, the
Sacred Writings tell us, changed water into wine at a marriage feast.
Excessive indulgence in liquor, like indulgence in any other form of
human appetite, is a human failing. It is not the drink which is an evil,
but the abuse of it. The abuse of liquor nine times out of ten is the
outcome of social discomfort and unhappiness, a way of escape, like
a narcotic, from the pangs of conscience, or of misery. People who
concentrate merely upon effects are unsound guides when
constructive measures are required. The temperance reformer in
England approaches the question of drink in West Africa from the
subjective point of view which characterizes the home outlook upon
most questions lying outside the home latitudes. Saturated with his
home experience, the English temperance reformer places the West
African in the same economic and social setting as the European
and argues on parallel lines. To that mode of reasoning, three-
fourths of the evils which civilization has inflicted upon coloured
races may be traced. Nothing is more curious or more saddening to
observe than the unfailing success of such methods of thought
translated into public action, in their effect upon home sentiment.
Consumption sweeping through the ranks of a coloured people as
the consequence of the educationary and religious processes of
Europeanism may make a holocaust of human victims. The public
remains indifferent. European marriage laws; European ethics, or
nominal ethics, in the matter of sex relationship; the European
individualistic social system grafted upon the communal life of a
coloured people—these things may produce widespread human
misery and immorality. The public is cold and unconcerned.
European interference and innovation in social customs and usages
essential to the well being, to the political and racial needs of a
coloured people in one stage of development, but repugnant to
European twentieth-century notions, may cause social disturbance
and widespread anarchy which those who are responsible for such
interference can never themselves witness, let alone suffer from. It is
virtually impossible to arouse popular interest. For these and kindred
disasters are very largely brought about by the uninstructed zeal of
God-fearing, Christian men and women in Europe who judge other
countries by their own, other peoples by their own people, other
needs by their own needs, with the best of intentions and with the
purest of motives; and outside a small band of students, ethnologists
and experienced officials, the public mind is scandalized and even
incensed if any one ventures to doubt the excellent results
necessarily flowing from disinterested action. It is disinterested:
therefore it must be right. That is the popular belief and the general
fallacy.
Poor Mary Kingsley, who knew her West Africa as few have ever
known it and who had the true scientific mind, fought hard against
this ingrained characteristic of the Anglo-Saxon temperament. But
she fought in vain. Despite her charity, the geniality and the humour
in which she clothed her truths, she had against her the whole
weight of what is called the philanthropic school of home opinion,
responsible for so much good and yet for so much unconscious
harm.

You might also like