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

Download Complete Readings from Programming with C++ 1st Edition Kyla Mcmullen - eBook PDF PDF for All Chapters

Ebookluna.com offers seamless downloads of eBooks across various genres, including programming titles such as 'Readings from Programming with C++' and 'Programming with STM32.' The site provides instant digital products in formats like PDF, ePub, and MOBI, allowing users to choose what suits them best. Users can explore and download a wide range of eBooks to enhance their learning experience.

Uploaded by

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

Download Complete Readings from Programming with C++ 1st Edition Kyla Mcmullen - eBook PDF PDF for All Chapters

Ebookluna.com offers seamless downloads of eBooks across various genres, including programming titles such as 'Readings from Programming with C++' and 'Programming with STM32.' The site provides instant digital products in formats like PDF, ePub, and MOBI, allowing users to choose what suits them best. Users can explore and download a wide range of eBooks to enhance their learning experience.

Uploaded by

shenjucarsan
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/ 66

Experience Seamless Full Ebook Downloads for Every Genre at ebookluna.

com

Readings from Programming with C++ 1st Edition


Kyla Mcmullen - eBook PDF

https://ebookluna.com/download/readings-from-programming-
with-c-ebook-pdf/

OR CLICK BUTTON

DOWNLOAD NOW

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


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

Readings from Programming with C++ 1st Edition Kyla


Mcmullen - eBook PDF

https://ebookluna.com/download/readings-from-programming-with-c-ebook-
pdf/

ebookluna.com

Programming With STM32: Getting Started With the Nucleo


Board and C/C++ - eBook PDF

https://ebookluna.com/download/programming-with-stm32-getting-started-
with-the-nucleo-board-and-c-c-ebook-pdf/

ebookluna.com

(eBook PDF) Programming, Problem Solving and Abstraction


with C

https://ebookluna.com/product/ebook-pdf-programming-problem-solving-
and-abstraction-with-c/

ebookluna.com

Programming in C 1st Edition - eBook PDF

https://ebookluna.com/download/programming-in-c-ebook-pdf/

ebookluna.com
(eBook PDF) C++ Programming: From Problem Analysis to
Program Design 7th

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

ebookluna.com

(Original PDF) C++ Programming From Problem Analysis to


Program Design 8th

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

ebookluna.com

C++ Programming: From Problem Analysis to Program Design


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

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

ebookluna.com

Programming and Problem Solving with Python 1st Edition -


eBook PDF

https://ebookluna.com/download/programming-and-problem-solving-with-
python-ebook-pdf/

ebookluna.com

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


to Objects 9th Edition

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

ebookluna.com
Programming with

C++ KYLA McMULLEN


Elizabeth matthews
June Jamrich Parsons

Australia • Brazil • Canada • Mexico • Singapore • United Kingdom • United States

Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
This is an electronic version of the print textbook. Due to electronic rights restrictions,
some third party content may be suppressed. Editorial review has deemed that any suppressed
content does not materially affect the overall learning experience. The publisher reserves the right
to remove content from this title at any time if subsequent rights restrictions require it. For
valuable information on pricing, previous editions, changes to current editions, and alternate
formats, please visit www.cengage.com/highered to search by ISBN#, author, title, or keyword for
materials in your areas of interest.

Important Notice: Media content referenced within the product description or the product
text may not be available in the eBook version.

Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Readings from Programming with C++ © 2022 Cengage Learning, Inc.
Kyla McMullen, Elizabeth Matthews, WCN: 02-300
June Jamrich Parsons
Unless otherwise noted, all content is © Cengage.
SVP, Higher Education Product Management:
ALL RIGHTS RESERVED. No part of this work covered by the copyright herein
Erin Joyner
may be reproduced or distributed in any form or by any means, except as
VP, Product Management: Thais Alencar permitted by U.S. copyright law, without the prior written permission of the
copyright owner.
Product Team Manager: Kristin McNary

Associate Product Manager: Tran Pham For product information and technology assistance, contact us at
Cengage Customer & Sales Support, 1-800-354-9706
Product Assistant: Tom Benedetto
or support.cengage.com.
Learning Designer: Mary Convertino

Senior Content Manager: Maria Garguilo For permission to use material from this text or product, submit all requests
online at www.cengage.com/permissions.
Digital Delivery Lead: David O’Connor

Technical Editor: John Freitas Library of Congress Control Number: 2020922802

Developmental Editor: Lisa Ruffolo ISBN: 978-0-357-63775-3

Vice President, Marketing – Science, Technology,


Cengage
& Math: Jason Sakos
200 Pier 4 Boulevard
Senior Director, Marketing: Michele McTighe Boston, MA 02210
USA
Marketing Manager: Cassie L. Cloutier

Marketing Development Manager: Cengage is a leading provider of customized learning solutions with
Samantha Best employees residing in nearly 40 different countries and sales in more than
125 countries around the world. Find your local representative at
Product Specialist: Mackenzie Paine
www.cengage.com.
IP Analyst: Ashley Maynard
To learn more about Cengage platforms and services, register or access
IP Project Manager: Cassidie Parker your online learning solution, or purchase materials for your course, visit
www.cengage.com.
Production Service: SPi Global
Notice to the Reader
Designer: Erin Griffin Publisher does not warrant or guarantee any of the products described

Cover Image Source: echo3005/ShutterStock.com herein or perform any independent analysis in connection with any of the
product information contained herein. Publisher does not assume, and
expressly disclaims, any obligation to obtain and include information other
than that provided to it by the manufacturer. The reader is expressly warned
to consider and adopt all safety precautions that might be indicated by the
activities described herein and to avoid all potential hazards. By following
the instructions contained herein, the reader willingly assumes all risks in
connection with such instructions. The publisher makes no representations or
warranties of any kind, including but not limited to, the warranties of fitness
for particular purpose or merchantability, nor are any such representations
implied with respect to the material set forth herein, and the publisher takes
no responsibility with respect to such material. The publisher shall not be
liable for any special, consequential, or exemplary damages resulting, in
whole or part, from the readers’ use of, or reliance upon, this material.

Printed in Mexico
Print Number: 01 Print Year: 2020

Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Brief Contents

prefacexiii Module 17
Polymorphism 309
Module 1
Computational Thinking 1 Module 18
Templates 319
Module 2
Programming Tools 15 Module 19
Linked List Data Structures 333
Module 3
Literals, Variables, and Constants 35 Module 20
Stacks and Queues 353
Module 4
Numeric Data Types and Expressions 49 Module 21
Trees and Graphs 371
Module 5
Character and String Data Types 63 Module 22
Algorithm Complexity and Big-O Notation 395
Module 6
Decision Control Structures 83 Module 23
Search Algorithms 411
Module 7
Repetition Control Structures 103 Module 24
Sorting Algorithms 427
Module 8
Arrays 125 Module 25
Processor Architecture 455
Module 9
Functions 145 Module 26
Data Representation 469
Module 10
Recursion 165 Module 27
Programming Paradigms 491
Module 11
Exceptions 185 Module 28
User Interfaces 507
Module 12
File Operations 205 Module 29
Software Development Methodologies 525
Module 13
Classes and Objects 231 Module 30
Pseudocode, Flowcharts, and Decision Tables 541
Module 14
Methods 245 Module 31
Unified Modeling Language 557
Module 15
Encapsulation 271
GLOSSARY 569
Module 16 Index 583
Inheritance 291

Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Table of Contents

prefacexiii Build Tools 22


The Toolset 22
Module 1 Compilers 23
COMPUTATIONAL THINKING 1 Preprocessors and Linkers 24
Virtual Machines 25
Algorithms2 Interpreters 26
Algorithm Basics 2 Debugging Tools 27
Programming Algorithms 2 Programming Errors 27
“Good” Algorithms 3 Syntax Errors 28
Selecting and Creating Algorithms 4 Runtime Errors 29
Decomposition4 Semantic Errors 29
Decomposition Basics 4 Debugging Utilities 30
Structural Decomposition 5 IDEs and SDKs 32
Functional Decomposition 6 Integrated Development Environments 32
Object-Oriented Decomposition 7 Software Development Kits 32
Dependencies and Cohesion 7
Summary 33
Pattern Identification 8
Key Terms  34
Pattern Identification Basics 8
Repetitive Patterns 8
Module 3
Classification Patterns 9
Abstraction9 LITERALS, VARIABLES, AND
Abstraction Basics 9 CONSTANTS35
Classes and Objects 10
Literals36
Black Boxes 11
Numeric Literals 36
Levels of Abstraction 12
Character and String Literals 37
Summary12 Tricky Literals 38
Key Terms  13 Variables and Constants 38
Variables 38
Module 2 Constants 40
PROGRAMMING TOOLS 15 The Memory Connection 41
Assignment Statements 41
Programming Languages 16 Declaring Variables  41
Hello World! 16 Initializing Variables 42
Programming Language Basics 16 Assigning Variables 43
Syntax and Semantics 17
Input and Output 44
Core Elements 19
Your Toolbox 19 Input to a Variable  44
Output from a Variable 46
Coding Tools 20
Program Editors 20 Summary 46
Basic Structure 21 Key Terms  47

Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Table of Contents v

Module 4 Module 6
Numeric Data Types and Decision Control
Expressions 49 Structures 83
Primitive Data Types 50 If-Then Control Structures 84
Data Types 50 Control Structures 84
Primitive Data Types 50 Decision Logic 85
Composite Data Types 51 If-Then Structures 85
Numeric Data Types 52 Relational Operators 87
Integer Data Types 52 The Equal Operator 87
Floating-Point Data Types 53 Using Relational Operators 88
Mathematical Expressions 54 Boolean Expressions and Data Types 89
Arithmetic Operators 54 Multiple Conditions 91
Order of Operations 56 If-Then-Else Structures 91
Compound Operators 56 Nested-If Structures 93
Numeric Data Type Conversion 58 Else If Structures 96
Convert Integers and Floating-Point Numbers 58 Fall Through 97
Rounding Quirks 59 Conditional Logical Operators 100
Formatting Output 60 The AND Operator 100
Formatted Output 60 The OR Operator 101
Formatting Parameters 60 Summary 102
Summary 62 Key Terms 102
Key Terms 62

Module 7
Module 5 Repetition Control
CHARACTER AND STRING DATA TYPES 63 Structures 103
Character Data Types 64 Count-Controlled Loops 104
Working with Character Data 64 Loop Basics 104
Character Memory Allocation 65 Control Statements 105
Digits 66 For-Loops 105
Character Output Format 67 User-Controlled Loops 108
Character Manipulation 68
Counters and Accumulators 109
String Data Types 69 Loops That Count 109
Working with String Data 69 Loops That Accumulate 111
Escape Characters 70
String Indexes 71
Nested Loops 112
Loops Within Loops 112
String Functions 72
Inner and Outer Loops 113
String Manipulation 72
String Length 72 Pre-Test Loops 116
Change Case 73 While-Loops 116
Find the Location of a Character 74 Infinite Loops 117
Retrieve a Substring 75 Breaking Out of Loops 118
Concatenation and Typecasting 76 Post-Test Loops 120
Concatenated Output 76 Do-Loops 120
Concatenated Variables 77 Test Conditions and Terminating
Coercion and Typecasting 78 Conditions 123
Summary 80 Summary 124
Key Terms 81 Key Terms 124

Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
vi Programming with C++

Module 8 Pass by Reference 161


Namespaces 162
Arrays 125
Summary 163
Array Basics 126
Key Terms 163
Magic Rectangles 126
Array Characteristics 127
Array Use Cases 128 Module 10
One-Dimensional Arrays 128 Recursion 165
Initialize Numeric Arrays 128
Key Components of Recursion 165
Initialize String Arrays 130
The Recursive Mindset 165
Array Input and Output 130 Recursion Basics 167
Output an Array Element 130 When to Use Recursion 171
Index Errors 131
Using Recursion to Solve Complex
Traverse an Array 132
Problems 171
Input Array Elements 133
Designing Recursive Structures 171
Array Operations 135 Linear Recursion 174
Change an Array Element 135 Branching Recursion 175
Find an Array Element 135
Managing Memory during Recursion 179
Sum Array Elements 137
Memory Management 179
Two-Dimensional Arrays 137 Stable Recursion 182
Two-Dimensional Array Basics 137
Summary 183
Initialize a Two-Dimensional Array 138
Output a Two-Dimensional Array 139 Key Terms 183
Sum Array Columns and Rows 141
Summary 143 Module 11
Key Terms 144 Exceptions 185
Defining Exceptions 185
Module 9 Errors in Code 185
Functions 145 Exception Types 187

Function Basics 146 Dealing with Exceptions 189


Function Classifications 146 Handling Others’ Exceptions 189
Programmer-Defined Functions 146 Try and Catch Blocks 189
Flow of Execution 147 Using Exceptions 198
Function Advantages 147 Throwing Exceptions 198
Void Functions 148 When to Bail 202
Void Function Basics 148 Summary 203
Function Pseudocode 149
Key Terms 203
Functions with Parameters 150
Function Parameters 150
Module 12
Function Arguments 150
The Handoff 152 File Operations 205
Return Values 153 File Input and Output 206
Return Values 153 The Purpose of Files 206
Return Type 156 Anatomy of a File 210
Function Signature 157 File Usage 212
Scope 157 Processing a File 214
Scope Basics 157 Accessing Files 214
Pass by Value 160 Streaming and Buffering 214

Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Table of Contents vii

Reading from a File 216 Method Cascading and Method Chaining 263
Opening a File for Reading 216 Calling Multiple Methods on the Same Object 263
Reading from a File 218 Using Constructors 266
Closing a File 222 Specifying How to Construct an Object 266
Closing Files after Use 222 Constructing an Object from Another Object 268
Trying to Close a File 222 Summary 269
Creating and Writing New Files 222
Key Terms 269
Creating a File 222
Opening a File for Writing 223 Module 15
Writing to and Appending a File 224
Anticipating Exceptions 228 Encapsulation 271
Summary 229 Components of Class Structure 271
Key Terms 230 Data Hiding 271
Designing Objects 273
Self-Reference Scope 276
Module 13 Accessor and Mutator Context 277
Classes and Objects 231 Viewing Data from an Object 277
Classes in Object-Oriented Programming 232 Changing Data in an Object 278
Representing the Real World with Code 232 Using Constructors 280
Using Classes 232 Parameters and Arguments 280
Class Components 233 Default Parameters and Constructor
Using Objects 236 Overloading 281
Creating Objects 236 Encapsulation Enforcement
Objects as Variables 238 with Access Modifiers 283
Object-Oriented Features and Principles 238 Access Modifiers 283
Using Static Elements in a Class 239 Public Variables and Methods 283
Private Variables and Methods 284
Static Member Variables 239
Static Methods 240 Interfaces and Headers 286
Static Classes 241 Interfaces 286
Characteristics of Objects Programming an Interface 287
in Object-Oriented Programs 242 Summary 290
Object Identity 242 Key Terms 290
Object State 242
Object Behavior 243 Module 16
Summary 244 Inheritance 291
Key Terms 244 Using Inheritance 291
Creating Classes from Other Classes 291
Module 14 Family Trees in OOP 292
Methods 245 Levels of Access 295
Necessary Components for Inheritance 296
Using Methods 245
Defining a Parent Class 296
Why Use Methods? 245 Defining a Child Class 297
Anatomy of a Method 251
Creating a Child Class That Inherits
Using Methods 251
from a Parent Class 298
Changing the Default Behavior
Inheritance Syntax 298
of an Object 255 Customizing Behavior 301
Using Objects as Regular Variables 255
Overloading Methods 258 Summary 307
Setting One Object to Equal Another 262 Key Terms 307

Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
viii Programming with C++

Module 17 The Find Method 346


The Insert Method 347
Polymorphism 309
Summary 350
The Purpose of Polymorphism 309
Key Terms 351
Flexibility While Coding 309
Dynamic Binding Under the Hood 314
Polymorphism Basics 314 Module 20
Classes Within Classes 314 Stacks and Queues 353
Objects as Other Objects 315 Stacks 353
Virtual Functions 316 Stack Basics 353
Anticipating Customization 316 Stack Use Cases 355
Abstract Classes 317 Built-in Stacks 356
Summary 318 Code a Stack 357

Key Terms 318


Queues 362
Queue Basics 362
Module 18 Queue Use Cases 363
Code a Queue 364
Templates 319
Summary 369
Template Basics 319
Key Terms 369
Data Abstraction 319
Template Structure and Use 322
Module 21
Tricky Templating 328
Advanced Templating 328
Trees and Graphs 371
Templated Objects as Arguments 330 Nonlinear Data Structures 371
Templates as a Problem-Solving Linear versus Nonlinear Structures 371
Approach 331 Nonlinear Building Blocks 373
Designing a Template 331 Tree Structures 373
When to Use Templates 331 Tree Basics 373
Summary 331 Tree Properties 376
Trees as Recursive Structures 376
Key Terms 332
Solving Problems Using Trees 379
Module 19 Tree Applications 379
Linked List Data Data Storage in Trees 380
Graph Structures 387
Structures 333
Graph Basics 387
Linked List Structures 334 Directed and Undirected Graphs 388
Data Structure Selection 334 Solving Problems with Graphs 388
Data Structure Implementation 335 Graph Applications 388
Linked List Basics 336 Computing Paths 389
Types of Linked Lists 337
Summary 394
Singly Linked Lists 337
Doubly Linked Lists 338 Key Terms 394
Circular Linked Lists 339
Linked List Characteristics 339 Module 22
Code a Linked List 342 Algorithm Complexity
The Node Class 342 and Big-O Notation 395
The LinkedList Class 343
The Append Method 343 Big-O Notation 396
Linked List Traversal 345 Algorithm Complexity 396

Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Table of Contents ix

Asymptotic Analysis 397 Quicksort 438


Asymptotic Notation 398 Defining the Quicksort Algorithm 438
Time Complexity 398 Quicksort Properties 446
Big-O Metrics 398 Merge Sort 447
Constant Time 399 Defining the Merge Sort Algorithm 447
Linear Time 399 Merge Sort Properties 453
Quadratic Time 400
Summary 454
Logarithmic Time 401
Key Terms 454
Space Complexity 403
Memory Space 403 Module 25
Constant Space Complexity 404
Linear Space Complexity 404 Processor Architecture 455
Complexity Calculations 405 Processor Organization 456
Line-by-Line Time Complexity 405 Integrated Circuits 456
Combine and Simplify 406 Moore’s Law 458
A Mystery Algorithm 407 CPUs 458
Low-Level Instruction Sets 459
Summary 409
Microprocessor Instruction Sets 459
Key Terms 409 RISC and CISC 460
Machine Language 460
Module 23 Assembly Language 461

Search Algorithms 411 Microprocessor Operations 462


Processing an Instruction 462
Using Search Algorithms 412 The Instruction Cycle 462
Search Basics 412 High-Level Programming Languages 464
Performing a Linear Search 413 Evolution 464
Looking for a Needle in a Haystack 413 Teaching Languages 465
Evaluating Search Time 416 The C Family 465
Web Programming Languages 466
Performing a Binary Search 416 Characteristics 466
Shrinking the Search Space 416 Advantages and Disadvantages 467
Implementing Binary Search 418
Summary 467
Using Regular Expressions
Key Terms 468
in Search Algorithms 423
Specifying a Search Pattern 423 Module 26
Regular Expression Search Operators 423
Data Representation 469
Summary 426
Bits and Bytes 470
Key Terms 426
Digital Data 470
Bits 471
Module 24 Bytes 472
Sorting Algorithms 427 Binary 474
Binary Numbers 474
Qualities of Sorting Algorithms 428 Binary to Decimal 475
Ordering Items 428 Decimal to Binary 476
Time Complexity in Sorting Algorithms 428 Binary Addition 477
Sorting Properties 430 Negative Numbers 478
Bubble Sort 431 Hexadecimal 480
Defining the Bubble Sort Algorithm 431 Colors 480
Bubble Sort Properties 437 Hexadecimal Numbers 481

Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
x Programming with C++

Binary-Hex-Binary Conversions 481 Speech Synthesis 516


Hex-Decimal Conversion 482 Designing Programs for Voice User Interfaces 517
Information Density 483 Virtual Environment Interfaces 517
ASCII and Unicode 483 Virtual Environments 517
ASCII 483 Virtual Environment Interface Components 518
Extended ASCII 484 Programming the Virtual Interface 519
Unicode 485 Accessibility and Inclusion 520
Memory Allocation 486 Accessibility Guidelines 520
Memory and Storage 486 Inclusive Design 521
Storage Devices 487 Summary 524
Memory 487
Key Terms 524
Summary 489
Key Terms 489
Module 29
Software Development
Module 27
Methodologies 525
Programming Paradigms 491
Software Development 526
Imperative and Declarative Paradigms 492
The Software Development Life Cycle 526
Think Outside the Box 492
Efficiency, Quality, and Security 527
The Procedural Paradigm 493 The Waterfall Model 528
Procedural Basics 493
Structured Analysis and Design 528
Characteristics of Procedural Programs 494
Waterfall Advantages and Disadvantages 529
Procedural Paradigm Applications 496
The Agile Model 530
The Object-Oriented Paradigm 497
Incremental Development 530
Objects, Classes, and Methods 497
Agile Methodologies 530
Characteristics of Object-Oriented Programs 499
Agile Advantages and Disadvantages 531
Object-Oriented Applications 501
Coding Principles 532
Declarative Paradigms 501
Efficient Coding 532
Declarative Basics 501
Modularized Code 533
Characteristics of the Declarative
Clean Coding 534
Paradigm 504
Secure Coding 534
Applications for Declarative Paradigms 504
Success Factors 536
Summary 505 Testing 536
Key Terms 505 Levels of Testing 536
Unit Testing 537
Module 28 Integration Testing 538
System Testing 539
User Interfaces 507 Acceptance Testing 539
User Interface Basics 508 Regression Testing 539
UI and UX 508 Summary 540
UI Components 508
Key Terms 540
Selecting a UI 510
Command-Line User Interfaces 510
Module 30
Command-Line Basics 510
Command-Line Program Design 510 Pseudocode, Flowcharts,
Graphical User Interfaces 512 and Decision Tables 541
GUI Basics 512 Pseudocode 542
GUI Program Design 514
From Algorithms to Pseudocode 542
Voice User Interfaces 515 Pseudocode Basics 544
Voice Interface Basics 515 Pseudocode Guidelines 545
Speech Recognition 515 Writing Pseudocode 547

Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Table of Contents xi

Flowcharts 548 UML Diagram Parts 558


Flowchart Basics 548 Class Diagram Basics 558
Drawing Flowcharts 548 Use Case Diagram Basics 559
Flowchart Tools 549 Sequence Diagrams 561
Decision Tables 551 Using UML to Structure Programs 562
Decision Table Basics 551 UML Associations 562
List the Conditions 551 Translating UML to Code 564
List All Possible Alternatives 552 Summary 568
Specify Results and Rules 552
Interpret Rules 553 Key Terms 568
Optimize the Rules 554
Check for Completeness and Accuracy 555
GLOSSARY 569
Summary 555
index 583
Key Terms 556

Module 31
Unified Modeling Language 557
Purpose of Unified Modeling
Language (UML) 557
Communicating Ideas to Other Programmers 557

Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Preface

Welcome to Readings from Programming with C11.


This text includes the stand-alone lessons and read-
C11 Version
ings from MindTap for Programming with C11 and is We recommend downloading the latest version of
intended to be used in conjunction with the MindTap C11 before beginning this text. C1114 was used to
Reader for a complete learning experience. test all C11 code presented in the module figures.

MindTap Overview MindTap Features


Programming with C 11 presents conceptual, lan- In addition to the readings included within this text,
guage-agnostic narrative with language-specific assets, the MindTap includes the following:
ungraded C11 coding Snippets, language-agnostic test Course Orientation: Custom videos and readings pre-
banks, and additional instructor resources. The goal of pare students for the material and coding experiences
this digital product is to develop content around the they will encounter in their course.
concepts that are essential for understanding Com-
Videos: Animated videos demonstrate new program-
puter Science from a language-agnostic perspective.
ming terms and concepts in an easy-to-understand for-
Learners will gain a foundational understanding of
mat, increasing student confidence and learning.
procedural programming, computer science concepts,
and object-oriented programming. Instructors have Coding Snippets: These short, ungraded coding activities
identified the need for language-agnostic, conceptual are embedded within the MindTap Reader and provide
content that can be paired with hands-on practice in students an opportunity to practice new programming
a specific language. This 31-module text is designed to concepts “in-the-moment.” Additional language-specific
provide that conceptual content paired with language- “bridge content” helps transition the student from con-
specific examples and hands-on learning activities in ceptual understanding to application of C11 code.
C11. Language-specific Examples: Figures within the nar-
rative illustrate the application of general concepts in
C11 code.
Course Objectives:
• Develop a foundational knowledge of
coding principles, vocabulary, and core Instructor & Student Resources
concepts. Additional instructor and student resources for
• Use new foundational knowledge to this product are available online. Instructor assets
learn C11 programming skills. include an Instructor’s Manual, Teaching Online
• Practice emerging coding skills in a low- Guide, ­PowerPoint® slides, and a test bank powered
risk environment. by ­Cognero®. Student assets include source code
• Apply learned concepts and skills to files and coding Snippets ReadMe. Sign up or sign in
assignments/activities that mimic real- at www.cengage.com to search for and access this
world experiences and environments. product and its online resources.

Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
About the Authors

Dr. Kyla McMullen is a tenure-track faculty member published research in the areas of procedural genera-
in the University of Florida’s Computer & Information tion, video game enjoyment factors, and freshwater
Sciences & Engineering Department, specializing in algae identification with HCI.
Human-Centered Computing. Her research interests June Jamrich Parsons is an educator, digital book
are in the perception, applications, and development pioneer, and co-author of Texty and McGuffey Award-
of 3D audio technologies. Dr. McMullen has authored winning textbooks. She co-developed the first com-
over 30 manuscripts in this line of research and is the mercially successful multimedia, interactive digital
primary investigator for over 2 million dollars’ worth textbook; one that set the bar for platforms now
of sponsored research projects. being developed by educational publishers. Her
Dr. Elizabeth A. Matthews is an Assistant Professor of career includes extensive classroom teaching, prod-
Computer Science at Washington and Lee University. uct design for eCourseware, textbook authoring for
She has taught computer science since 2013 and has Course Technology and Cengage, Creative Strategist
been an active researcher in human–computer inter- for MediaTechnics Corporation, and Director of Con-
action and human-centered computing. Matthews has tent for Veative Virtual Reality Labs.

Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Acknowledgments

The unique approach for this book required a ­seasoned friends who help me to remain sane, remind me of who
team. Our thanks to Maria Garguilo who ushered the I am, and never let me forget whose I am.
manuscripts through every iteration and kept tight Elizabeth Matthews: I want to thank my parents,
rein on the schedule; to Mary E. Convertino who sup- Drs. Geoff and Robin Matthews, for their support and
plied her expertise in learning design; to Lisa R
­ uffolo understanding in my journey. I would also like to thank
for her excellent developmental edit; to Courtney my advisor, Dr. Juan Gilbert, for seeing my dream to
Cozzy who coordinated the project; to Kristin McNary the end. Finally, I would like to thank my cats, Oreo
for her leadership in Cengage’s computing materials; and Laptop, who made sure that writing this book was
to Rajiv Malkan (Lone Star College) for his instruc- interrupted as often as possible.
tional input; to Wade Schofield (Liberty University) June Jamrich Parsons: Computer programming can
for his reviewing expertise; and to John Freitas for his be a truly satisfying experience. The reward when a
meticulous code review. It was a pleasure to be part program runs flawlessly has to bring a smile even
of this professional and talented team. We hope that to the most seasoned programmers. Working with
instructors and students will appreciate our efforts three programming languages for this project at the
to provide this unique approach to computer science same time was certainly challenging but provided
and programming. insights that can help students understand com-
Kyla McMullen: Above all things, I would like to thank putational thinking. I’ve thoroughly enjoyed work-
God for giving me the gifts and talents that were uti- ing with the team to create these versatile learning
lized to write this book. I would like to thank my amaz- resources and would like to dedicate my efforts to
ing husband Ade Kumuyi for always being my rock, my mom, who has been a steadfast cheerleader for
sounding board, and biggest cheerleader. I thank my me throughout my career. To the instructors and stu-
parents, Rita and James McMullen for all of their sacri- dents who use this book, my hope is that you enjoy
fices to raise me. Last but not least, I thank my spirited programming as much as I do.

Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
MODULE

1
COMPUTATIONAL
THINKING
LEARNING OBJECTIVES:
1.1 ALGORITHMS 1.2.3 Differentiate the concepts of algorithms and
decomposition.
1.1.1 Define the term “algorithm” as a series of steps for
solving a problem or carrying out a task. 1.2.4 Identify examples of structural decomposition.
1.1.2 State that algorithms are the underlying logic for 1.2.5 Identify examples of functional decomposition.
computer programs. 1.2.6 Identify examples of object-oriented decomposition.
1.1.3 Define the term “computer program.” 1.2.7 Provide examples of decomposition in technology
1.1.4 Provide examples of algorithms used in everyday applications.
technology applications. 1.2.8 Explain how dependencies and cohesion relate to
1.1.5 Confirm that there can be more than one algorithm decomposition.
for a task or problem and that some algorithms 1.3 PATTERN IDENTIFICATION
may be more efficient than others.
1.3.1 Define the term “pattern identification” as a technique
1.1.6 Explain why computer scientists are interested in for recognizing similarities or characteristics among
algorithm efficiency. the elements of a task or problem.
1.1.7 List the characteristics of an effective algorithm. 1.3.2 Identify examples of fill-in-the-blank patterns.
1.1.8 Write an algorithm for accomplishing a simple, 1.3.3 Identify examples of repetitive patterns.
everyday technology application.
1.3.4 Identify examples of classification patterns.
1.1.9 Write an alternate algorithm for an everyday
technology task. 1.3.5 Provide examples of pattern identification in the real
world and in technology applications.
1.1.10 Select the more efficient of the two algorithms you
have written. 1.4 ABSTRACTION
1.2 DECOMPOSITION 1.4.1 Define the term “abstraction” as a technique for
generalization and for simplifying levels of complexity.
1.2.1 Define the term “decomposition” as a technique for
dividing a complex problem or solution into smaller 1.4.2 Explain why abstraction is an important computer
parts. science concept.
1.2.2 Explain why decomposition is an important tool for 1.4.3 Provide an example illustrating how abstraction can
computer scientists. help identify variables.

Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
2 PROGRAMMING WITH C++

1.4.4 Provide examples of technology applications that 1.4.6 Explain how the black box concept is an
have abstracted or hidden details. implementation of abstraction.
1.4.5 Provide an example illustrating the use of a class as 1.4.7 Identify appropriate levels of abstraction.
an abstraction of a set of objects.

1.1 ALGORITHMS
Algorithm Basics (1.1.1, 1.1.4)
A password might not be enough to protect your online accounts. Two-factor authentication adds an extra layer
of protection. A common form of two-factor authentication sends a personal identification number (PIN) to your
cell phone. To log in, you perform the series of steps shown in Figure 1-1.

Connect to the site’s login page.


Enter your user ID.
Enter your password.
Wait for a text message containing a PIN
to arrive on your smartphone.
On the site’s the login page, enter the PIN.

Figure 1-1 Steps for two-factor authentication

The procedure for two-factor authentication is an example of an algorithm. In a general sense, an algorithm
is a series of steps for solving a problem or carrying out a task.
Algorithms exist for everyday tasks and tasks that involve technology. Here are some examples:

• A recipe for baking brownies


• The steps for changing a tire
• The instructions for pairing a smart watch with your phone
• The payment process at an online store
• The procedure for posting a tweet

Programming Algorithms (1.1.2, 1.1.3, 1.1.5)


Algorithms are also an important tool for programmers. A programming algorithm is a set of steps that speci-
fies the underlying logic and structure for the statements in a computer program. You can think of programming
algorithms as the blueprints for computer programs.
A computer program is a set of instructions, written in a programming language such as C++, Python, or
Java, that performs a specific task when executed by a digital device. A computer program is an implementation
of an algorithm.

Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Module 1 Computational Thinking 3

Q Programming algorithms tell the computer what to do. Can you tell which of these algorithms
is a programming algorithm?
Algorithm 1: Algorithm 2:
Connect to the website’s login page. Prompt the user to enter a user ID.
Enter your user ID. Prompt the user to enter a password.
Enter your password. Make sure that the user ID and password match.
Wait for a text message containing a PIN to If the user ID and password match:
arrive on your smartphone. Generate a random PIN.
On the website’s login page, enter the PIN. Send the PIN to user’s phone.
Prompt the user to enter the PIN.
If the PIN is correct:
Allow access.

A Algorithm 1 is not a programming algorithm because it outlines instructions for the user.
Algorithm 2 is a programming algorithm because it specifies what the computer is supposed
to do. When you formulate a programming algorithm, the instructions should be for the
computer, not the user.

There can be more than one programming algorithm for solving a problem or performing a task, but some
algorithms are more efficient than others.

Q Here are two algorithms for summing the numbers from 1 to 10. Which algorithm is more
efficient?
Algorithm 1: Algorithm 2:
Add 1 1 2 to get a total. Get the last number in the series (10).
Repeat these steps nine times: Divide 10 by 2 to get a result.
Get the next number. Add 10 1 1 to get a sum.
Add this number to the total. Multiply the result by the sum.

A Both algorithms contain four instructions, but Algorithm 2 is more efficient. You can use it to
amaze your friends by quickly calculating the total in only four steps. Algorithm 1 is also four
lines long, but two of the instructions are repeated nine times. Counting the first step, that’s
19 steps to complete this task!

“Good” Algorithms (1.1.6, 1.1.7)


Computer scientists are interested in designing what they call “good” algorithms. A good algorithm tends
to produce a computer program that operates efficiently, quickly, and reliably. Good algorithms have these
characteristics:
Input: The algorithm applies to a set of specified inputs.
Output: The algorithm produces one or more outputs.
Finite: The algorithm terminates after a finite number of steps.
Precise: Each step of the algorithm is clear and unambiguous.
Effective: The algorithm successfully produces the correct output.

Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
4 PROGRAMMING WITH C++

When formulating an algorithm, you can easily check to make sure it satisfies all the criteria for a good algo-
rithm. You can see how these criteria apply to an algorithm in Figure 1-2.

Is there input? Yes.

Get the last number in the series (10).


Divide 10 by 2 to get a RESULT. Are the steps precise and
Add 10 + 1 to get a SUM. unambiguous? Yes.
Multiply the RESULT by the SUM to
Does the algorithm terminate? Does the algorithm produce
produce a total.
Yes, after the fourth step. the correct output?
Yes, it is 55.
Is there output? Yes.

Figure 1-2 Is this a good algorithm?

Selecting and Creating Algorithms (1.1.8, 1.1.9, 1.1.10)


Before coding, programmers consider various algorithms that might apply to a problem. You can come up with
an algorithm in three ways:
Use a standard algorithm. Programmers have created effective algorithms for many computing
tasks, such as sorting, searching, manipulating text, encrypting data, and finding the shortest path.
When you are familiar with these standard algorithms, you can easily incorporate them in programs.
Perform the task manually. When you can’t find a standard algorithm, you can formulate an
algorithm by stepping through a process manually, recording those steps, and then analyzing their
effectiveness.
Apply computational thinking techniques. Computational thinking is a set of techniques designed
to formulate problems and their solutions. You can use computational thinking techniques such as
decomposition, pattern identification, and abstraction to devise efficient algorithms. Let’s take a look
at these techniques in more detail.

1.2 DECOMPOSITION
Decomposition Basics (1.2.1)
A mobile banking app contains many components. It has to provide a secure login procedure, allow users to
manage preferences, display account balances, push out alerts, read checks for deposit, and perform other tasks
shown in Figure 1-3.
The algorithm for such an extensive app would be difficult to formulate without dividing it into smaller parts,
a process called decomposition. When devising an algorithm for a complex problem or task, decomposition can
help you deal with smaller, more manageable pieces of the puzzle.

Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Module 1 Computational Thinking 5

Fraud alerts

Change user
Secure login
preferences

Account balance Deposits

iStock.com/vector.S
Pay bills Withdrawals

Transfer money

Figure 1-3 A mobile banking app handles many


interacting tasks

Structural Decomposition (1.2.2, 1.2.3, 1.2.4, 1.2.7)


The first step in decomposition is to identify structural units that perform distinct tasks. Figure 1-4 illustrates
how you might divide a mobile banking app into structural units, called modules.

Mobile banking

Passcode/challenge Account Payments and


Secure login
question changes management transfers

Two-factor
Balances Bill pay
authentication

Fingerprint Mobile check


Alerts
sign-in deposits

Direct Money
deposits transfers

Figure 1-4 Structural decomposition diagram

Structural decomposition is a process that identifies a hierarchy of structural units. At the lowest levels
of the hierarchy are modules, indicated in yellow in Figure 1-4, that have a manageable scope for creating
algorithms.

Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
6 PROGRAMMING WITH C++

Q Which module of the hierarchy chart is not fully decomposed?


A The module for modifying passwords and challenge questions could be further decomposed
into two modules: one module that allows users to change their passwords and one for
changing their challenge questions.

Here are some tips for creating a structural decomposition diagram:

• Use a top-down approach. The nodes at the top break down into component parts in the nodes below them.
• Label nodes with nouns and adjectives, rather than verbs. For example, “Account management” is the
correct noun phrase, rather than a verb phrase, such as “Manage accounts.”
• Don’t worry about sequencing. Except for the actual login process, the components in a mobile bank-
ing system could be accessed in any order. This is a key difference between an algorithm and decom-
position. An algorithm specifies an order of activities, whereas decomposition specifies the parts of
a task.

Functional Decomposition (1.2.5)


Functional decomposition breaks down modules into smaller actions, processes, or steps. Figure 1-5 illustrates
a functional decomposition of the two-factor authentication module.

Verify login attempts

Verify password Verify PIN

Validate Compare
Generate Send PIN
Prompt for Prompt for user ID and Prompt user user-entered Handle
one-time to
user ID password password for PIN PIN to mismatches
PIN mobile
match generated PIN

Look up Compare Look up Generate


stored entered Handle user text Nodes in green are
user ID and date with mismatches mobile message specific enough to
password stored data number with PIN become steps in an
algorithm.

Nodes in yellow
require further
decomposition.

Figure 1-5 Functional decomposition diagram

Notice how the levels of the functional decomposition diagram get more specific until the nodes in the lowest
levels begin to reveal instructions that should be incorporated in an algorithm.
Here are some tips for constructing functional decomposition diagrams and deriving algorithms from them:

• Label nodes with verb phrases. In contrast to the nodes of a structural decomposition diagram, the
nodes of a functional decomposition are labeled with verb phrases that indicate “what” is to be done.
• Sequence from left to right. Reading left to right on the diagram should correspond to the sequence in
which steps in the algorithm are performed.

Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Module 1 Computational Thinking 7

Object-Oriented Decomposition (1.2.6)


Another way to apply decomposition to a module is to look for logical and physical objects that a computer
program will manipulate. Figure 1-6 illustrates an object-oriented decomposition of the two-factor authentica-
tion module.

Each node
represents an
object.
PIN generator
Methods
Login screen Attribute: One-time PIN describe what an
object can do.
Attribute: Entered user ID Method: Generate random PIN
Attribute: Entered password Method: Send PIN to mobile
number
Method: Display login boxes
Method: Verify entered user ID
and password
Method: Verify PIN
Method: Handle mismatches

Valid user

Attribute: Valid user ID


Attribute: Valid password Attributes
Attribute: Mobile number describe an
object.

Figure 1-6 Object-oriented decomposition diagram

An object-oriented decomposition does not produce a hierarchy. Instead it produces a collection of objects
that can represent people, places, or things.
Tips for object-oriented decomposition:

• Node titles are nouns. Each node in the object-oriented decomposition diagram is labeled with a noun.
• Attributes are nouns. A node can contain a list of attributes, which relate to the characteristics of an object.
• Methods are verb phrases. An object can also contain methods, which are actions that an object can
perform. You may need to devise an algorithm for each method.
• Sketch in connection arrows. Connection arrows help you visualize how objects share data.

Dependencies and Cohesion (1.2.8)


You might wonder if there is a correct way to decompose a problem or task. In practice, there may be several
viable ways to apply decomposition, but an effective breakdown minimizes dependencies and maximizes cohe-
sion among the various parts.
The principles of decomposition are:

• Minimize dependencies. Although input and output may flow between nodes, changing the instructions
in one module or object should not require changes to others.
• Maximize cohesion. Each object or module contains attributes, methods, or instructions that perform a
single logical task or represent a single entity.

Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
8 PROGRAMMING WITH C++

1.3 PATTERN IDENTIFICATION


Pattern Identification Basics (1.3.1, 1.3.2)
The Amaze-Your-Friends math trick for quickly adding numbers from 1 to 10 is very simple:
Get the last number in the series (10).
Divide 10 by 2 to get a result.
Add 10 1 1 to get a sum.
Multiply the result by the sum.

Q Try the algorithm yourself. What is your answer?


A If your math is correct, your answer should be 55.

Now, what if the challenge is to add the numbers from 1 to 200? That algorithm looks like this:
Get the last number in the series (200).
Divide 200 by 2 to get a result.
Add 200 1 1 to get a sum.
Multiply the result by the sum.
Notice a pattern? This fill-in-the-blank algorithm works for any number:
Get the last number in the series (____________________).
Divide ____________________ by 2 to get a result.
Add ____________________ 1 1 to get a sum.
Multiply the result by the sum.
The process of finding similarities in procedures and tasks is called pattern identification. It is a useful com-
putational thinking technique for creating algorithms that can be used and reused on different data sets. By recog-
nizing the pattern in the Amaze-Your-Friends math trick, you can use the algorithm to find the total of any series
of numbers.

Repetitive Patterns (1.3.3)


In addition to fill-in-the-blank patterns, you might also find repetitive patterns as you analyze tasks and problems.
Think about this algorithm, which handles logins to a social media site:
Get a user ID.
Get a password.
If the password is correct, allow access.
If the password is not correct, get the password again.
If the password is correct, allow access.
If the password is not correct, get the password again.
If the password is correct, allow access.
If the password is not correct, get the password again.
If the password is correct, allow access.
If the password is not correct, lock the account.

Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Module 1 Computational Thinking 9

Q How many repetition patterns do you recognize?


A Two lines are repeated three times:
If the password is not correct, get the password again.
If the password is correct, allow access.

Recognizing this repetition, you can streamline the algorithm like this:
Get a password.
Repeat three times:
If the password is correct, allow access.
If the password is not correct, get the password again.
If the password is correct, allow access.
If the password is not correct, lock the account.

Classification Patterns (1.3.4, 1.3.5)


Everyone who subscribes to a social media site has a set of login credentials. Here are Lee’s and Priya’s:
Lee’s login credentials: Priya’s login credentials:
Lee’s user ID: [email protected] Priya’s user ID: [email protected]
Lee’s password: MyCat411 Priya’s password: ouY52311v
Lee’s mobile number: 415-999-1234 Priya’s mobile number: 906-222-0987
The series of attributes that define each user’s login credentials have a pattern of similarities. Each user
has three attributes: a user ID, a password, and a mobile number. By recognizing this pattern, you can create a
template for any user’s login credentials like this:
User ID: ____________________
Password: ____________________
Mobile number: ____________________
You can often discover classification patterns in the attributes that describe any person or object. Identify-
ing classification patterns can help you design programs that involve databases because the template identifies
fields, such as User ID, that contain data.
Classification patterns also come in handy if you want to design programs based on the interactions among
a variety of objects, rather than a step-by-step algorithm. In some programming circles, templates are called
classes because they specify the attributes for a classification of objects. For example, people classified as social
media subscribers have attributes for login credentials. Vehicles classified as cars have attributes such as color,
make, model, and VIN number. Businesses classified as restaurants have a name, hours of operation, and a menu.

1.4 ABSTRACTION
Abstraction Basics (1.4.1, 1.4.2, 1.4.3)
Think back to the Amaze-Your-Friends math trick. By identifying a pattern, you formulated a general algorithm
that works for a sequence of any length, whether it is a sequence of 1 to 10 or 1 to 200.
Get the last number in the series (____________________).
Divide ____________________ by 2 to get a result.

Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
10 PROGRAMMING WITH C++

Add ____________________ 1 1 to get a sum.


Multiply the result by the sum.
In this algorithm, the blank line is an abstraction that represents the last number in the sequence. An abstraction
hides details, simplifies complexity, substitutes a generalization for something specific, and allows an algorithm to
work for multiple inputs.
Abstraction is a key element of computational thinking and helps programmers in a multitude of ways.
If you’ve programmed before, you’ll recognize that in the Amaze-Your-Friends algorithm, the blanks could
become a variable with a name such as last_number. Result and sum are also variables because they represent
values that change depending on the numbers in the sequence
Get the last_number
Divide last_number by 2 to get a result.
Add last_number 1 1 to get a sum.
Multiply the result by the sum.
A variable is an abstraction because rather than representing a specific number, it can be used to represent
many different numbers.

Classes and Objects (1.4.4, 1.4.5)


Abstraction has uses other than identifying variables. It is important for understanding how to represent real-
world and conceptual objects. Remember the pattern you discovered for social media login credentials? With a
little modification, it becomes a template that can be applied to any subscriber:
Class: LoginCredentials
Attribute: user_ID
Attribute: user_password
Attribute: mobile_number
The LoginCredentials class is an abstraction that contains a set of attributes. The class was formed by
abstracting away, or removing, details for any specific subscriber.
Abstractions are handy for any programs that deal with real-world objects in addition to technology objects,
such as login credentials.

Q Can you envision a class that’s an abstraction of the collection of objects shown in Figure 1-7?
Budnyi/Shutterstock.com

12 oz water glass 5 oz martini glass 8 oz wine glass 10 oz water goblet

Figure 1-7 Abstract the details from this collection of glassware

Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s).
Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it.
Random documents with unrelated
content Scribd suggests to you:
The Project Gutenberg eBook of Insect
manufactures
This ebook is for the use of anyone anywhere in the United
States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it away
or re-use it under the terms of the Project Gutenberg License
included with this ebook or online at www.gutenberg.org. If you
are not located in the United States, you will have to check the
laws of the country where you are located before using this
eBook.

Title: Insect manufactures

Author: Anonymous

Release date: May 14, 2024 [eBook #73626]

Language: English

Original publication: London: Society for Promoting Christian


Knowledge, 1847

Credits: Richard Tonsing, deaurider, and the Online Distributed


Proofreading Team at https://www.pgdp.net (This file
was produced from images generously made available
by The Internet Archive)

*** START OF THE PROJECT GUTENBERG EBOOK INSECT


MANUFACTURES ***
Transcriber’s Note:
New original cover art included with this eBook is
granted to the public domain.
INSECT MANUFACTURES.

PUBLISHED UNDER THE DIRECTION OF THE COMMITTEE OF


GENERAL LITERATURE AND EDUCATION, APPOINTED BY THE
SOCIETY FOR PROMOTING CHRISTIAN KNOWLEDGE.

LONDON:
PRINTED FOR THE
SOCIETY FOR PROMOTING CHRISTIAN
KNOWLEDGE.
SOLD AT THE DEPOSITORY,
GREAT QUEEN STREET, LINCOLN’S INN FIELDS
AND 4, ROYAL EXCHANGE.

1847.
LONDON
R. CLAY, PRINTER, BREAD STREET HILL.
CONTENTS.
Page
INTRODUCTION 3

CHAPTER I.
MANUFACTURE OF SILK BY CATERPILLARS OF VARIOUS KINDS 9

CHAPTER II.
MANUFACTURE OF SILK BY THE SILKWORM 31

CHAPTER III.
MANUFACTURE OF SILK BY SPIDERS 55

CHAPTER IV.
MANUFACTURE OF WAX BY THE HIVE BEE, THE HUMBLE BEE,
AND THE WHITE WAX INSECT OF CHINA 73

CHAPTER V.
MANUFACTURE OF HONEY BY THE HIVE BEE 99

CHAPTER VI.
MANUFACTURE OF COCHINEAL BY THE COCCUS CACTI, OR
COCHINEAL INSECT 113

CHAPTER VII.
MANUFACTURE OF GUM LAC BY THE LAC INSECT 133

CHAPTER VIII.
MANUFACTURE OF NUT GALLS BY THE GALL INSECT 143

CHAPTER IX.
OTHER INSECT PRODUCTIONS USEFUL TO MAN 154
INTRODUCTION.

If we are struck with wonder and admiration at the progress of the


arts and manufactures, and have daily reason to congratulate
ourselves on the skill and ingenuity of our fellow-creatures, by which
our comforts and conveniences are so much increased; it must also
occasionally have crossed our minds, that some of the meaner
creatures, though not gifted with our reasoning powers, and
therefore not able to profit by the experience of the past, are yet
employed in their several departments, and according to their
several wants, in exceedingly curious and useful manufactures,
mostly designed for the shelter and preservation of themselves or
their offspring, but serving, not unfrequently, a higher purpose, in
administering to the wants of mankind.
In reading the history, or in watching the proceedings of birds and
insects, how many remarkable instances do we meet with of that
which may be called manufacture, though performed without hands!
How curious to watch in the early spring the proceedings of those
busy basket-making birds, the rooks! Rude and clumsy as their nests
may at first appear, it is just the sort of workmanship best calculated
for their wants. They do not, indeed, choose the smooth and flexible
osier-twigs which we should think necessary for basket-making, but
they contrive by means of brittle, dead, forked sticks, to plait
together a strong bristling out-work, within which they interweave a
finer basket-work of fibrous roots, rude indeed, but not inelegant or
unsuitable. Then, among birds and insects too, what persevering and
industrious carpenters, masons, tailors, miners, and weavers may we
not find. Perhaps there are not many persons who have watched the
mason-wasps boring their galleries in brick or sand, or building the
round towers which serve them as out-works; nor the mason-bee, as
she plasters together her neat mud-wall cottage or cell, as the future
habitation of her young; but there are few persons unacquainted with
the masonry of the chimney swallow, or of the house-martin
twittering on the eaves. With no other tools than those which nature
supplies, how cleverly do these creatures shape and mould their
nests into the required form, using for their work a mortar carefully
prepared by their own labour and skill, and just of the consistency
required. Few, again, may have had an opportunity of seeing
carpenter-bees boring holes in posts or palings, and forming their
smoothly chiselled cells, or of inspecting the partitioned galleries dug
out in old timber by carpenter-wasps; but perhaps many persons
have observed the colonies of emmets, or carpenter-ants, working in
the trunks of decaying oak or willow trees; or they may have listened
to that interesting carpenter-bird, the wood-pecker, tapping and
boring into trees, in pursuit of insects, and for the purpose of making
a nesting-place for its young. Most of us know only by hearsay that
there are tailor-birds, common enough in American orchards, who
sew together broad pieces of grass to make their nests, working them
through and through, as if actually done with a needle; but almost
every one can say from his own knowledge, that there are weaver-
birds, such as our common hedge-sparrow and chaffinch, who weave
a circular piece of haircloth for the interior of their nests, each hair
being collected and interwoven singly, and always bent so as to lie
smoothly in the hollow of the nest. Then who shall describe all the
wondrous proceedings of tent-making caterpillars, upholsterer-bees,
turret-building ants, net-making spiders, paper and card-making
wasps, and spinning worms? Volumes have been written, and
volumes might still be written on the history of these creatures. Any
one possessing a garden, and taking delight therein, has ample
opportunity of watching the habits of birds and insects, and of
confirming, if not of adding to, the accounts given by naturalists, of
the commoner species. But we must still be indebted to the patient
observations of those who have made insects or birds their especial
study, for many of the most curious particulars, and for all our
knowledge of rare or foreign species.
Interesting as is the whole subject of bird and insect manufactures,
there is one department in which we are more concerned than the
rest; namely, that in which the product can be applied to our own
use, either in the way of food or clothing. Now this department is
supplied wholly by insects, no bird, that we are aware of, producing
by its own manufacturing powers, any substance that can be so
employed, unless, indeed, we except the curious edible nests of the
Java swallow, which have been converted by the taste of oriental
epicures into an article of food.
Let us then proceed to notice such of the insect manufactures as
are useful to man, and trace, at the same time, the history and
performances of these small but not insignificant manufacturers.
CHAPTER I.
MANUFACTURE OF SILK BY CATERPILLARS
OF VARIOUS KINDS.

The most important of all the insect manufactures is doubtless that


of silk-spinning. It seems almost past belief that the magnificent
velvets, satins, and silks which form so elegant a part of female attire,
and which are heaped together in such costly profusion in the shops
of the metropolis, and in those of all considerable towns, whether in
our own, or in foreign countries—that these splendid fabrics,
together with all ribbons, gauzes, damasks, or other articles
composed of silk, should owe the raw material of which they are
formed to the labours of a race of little creeping caterpillars, which in
this their early and imperfect state spin for themselves cocoons, or
cases of silk, where they may quietly undergo their changes until they
become perfect winged insects.
The astonishing task of supplying silk for the whole civilized world
is performed almost without exception by the common silkworm, or
caterpillar of the mulberry-tree moth. But it must not be supposed
that this is the only silk-producing insect. On the contrary, all the
caterpillars of butterflies and moths have the power of spinning a
certain quantity of silken thread, however small, and however
inferior to that of the silkworm, properly so called. It is very common
in gardens to see numbers of caterpillars dangling by their silken
threads from the young branches of fruit-trees. In this way they let
themselves down, or break their fall if blown off by the wind, or
otherwise shaken from their favourite tree. And in the case of some
caterpillars when the insect has completed the term of its existence
and becomes a chrysalis, it suspends itself by silken cords to some
fixed point, where it remains in complete repose, without food,
perhaps for months before the perfect winged insect bursts forth, as
different a creature from the caterpillar
as the chrysalis is from either,—and yet
these are but three different states of
existence of the same insect.
Accordi
ng to the
particular
species of
caterpilla
r, the silk
will vary
in
strength
and
fineness,
and also
in colour,
but
seldom
will it be
found CHRYSALIS SUSPENDED BY
SILKEN CORDS.
strong
enough,
or in sufficient quantity to be of use to
us. The insects themselves employ it in
many ways for their own safety and
shelter. How common it is to find some
of the leaves of a lilac-tree made up
into little rolls, or folded together at
their edges, where they stick so fast
that it requires some little force to pull
them asunder. This is the work of a
CATERPILLAR SUSPENDED small caterpillar, whose subsistence is
BY ITS SILKEN THREAD. found on that tree. A single egg has
been laid on each leaf selected by the
parent moth, and soon after it is
hatched, the caterpillar begins rolling up the lilac leaf, and fastening
the edges with silk. This is a work of time, but gradually proceeds as
the caterpillar increases in strength, until at last it is shut up in a
gallery of its own making, safe from the attacks of birds and larger
insects. The leaves of various other trees are rolled in a somewhat
similar manner, as those of the oak, the willow, and the rose, and
also those of humbler plants, as the plantain, nettle, thistle, &c. The
mode in which these leaf-rolling caterpillars set to work to form
convenient habitations of the leaves of the plants on which they feed,
is well described by Kirby and Spence.

OAK LEAF ROLLED BY A CATERPILLAR.

“Some of these merely connect together with a few silken threads


several leaves, so as to form an irregular packet, in the centre of
which the little hermit lives. Others confine themselves to a single
leaf, of which they simply fold one part over the other. A third
description form and inhabit a sort of roll, by some species made
cylindrical, by others conical, resembling the papers in which grocers
put their sugar, and as accurately constructed; only there is an
opening left at the smaller extremity for the egress of the insect in
case of need. If you were to see one of these rolls, you would
immediately ask by what mechanism it could possibly be made—how
an insect, without fingers, could contrive to bend a leaf into a roll,
and to keep it in that form until fastened with the silk which holds it
together? The following is the operation: the little caterpillar first
fixes a series of silken cables from one side of the leaf to the other:
she next pulls at these cables with her feet; and when she has forced
the sides to approach, she fastens them together with stronger
threads of silk. If the insect finds that one of the larger nerves of the
leaf is so strong as to resist her efforts, she weakens it by gnawing it
here and there half through. What engineer could act more
sagaciously? To form one of the conical or horn-shaped rolls, which
are not composed of a whole leaf, but of a long triangular portion cut
out of the edge, some other manœuvres are requisite. Placing herself
upon the leaf, the caterpillar cuts out with her jaws the piece which is
to compose her roll. She does not, however, entirely detach it; it
would then want a base. She detaches that part only which is to form
the contour of the horn. This portion is a triangular strap, which she
rolls as she cuts. When the body of the horn is finished, as it is
intended to be fixed upon the leaf in nearly an upright position, it is
necessary to elevate it. To effect this, she proceeds as we should with
an inclined obelisk. She attaches threads, or little cables, towards the
point of the pyramid, and raises it by the weight of her body.”
Other larvæ form their habitations wholly of silk: one that inhabits
the leaves of pear-trees forms a little tent; another a sort of cloak;
another, as in the case of the silkworm, a complete ball of silk.
PENDULOUS NESTS OF CATERPILLARS.

Among leaf-rolling caterpillars, one of the most curious is


described by Bonnet, in which the nest hangs suspended from the
branch of a fruit-tree by a strong silken thread. It is formed of one or
two leaves neatly folded and fastened together with silk, and in this
small enclosure several caterpillars live harmoniously together.
LEAF CUTTING CATERPILLAR.

There is also a very curious and beautiful nest formed by a rare


insect, which has only yet been observed in its caterpillar state; but
its proceedings therein are interesting and highly remarkable. The
length of the body in this caterpillar varies from six to eight inches,
the thickness is half a line. The general colour is bluish green,
tending to yellow about the head; the feet are black, and six in
number. At the extremity of the body are two points projecting
sideways. The eyes are visible and prominent in this caterpillar, and
besides the antennæ there are two or three pairs of palpi or feelers,
which perform the office of hands. This insect inhabits the nut-tree,
and cuts out from its leaves a most ingenious case, which serves for
its dwelling-place. This case is of a singular form, being an elongated
cone, very narrow at the extremity, and tolerably wide at the orifice.
It is formed of a strip of nut-leaf, wound up in a spiral manner, but
so cleverly contrived that the strip is very narrow at the extremity,
and gradually widens as the work proceeds. This happens from the
gradual progress of the work, which is begun in the early stage of the
caterpillar’s existence, when it does not require a large dwelling-
place, and becomes more and more extended to suit the growth of its
inmate. When it is completed, it is rather more than an inch long,
and two lines in diameter at the orifice. The outside of the case
presents the upper surface of the leaf in which the indentations are
preserved. The dwelling is a spacious one for the caterpillar, so that it
can turn round in it with perfect ease. The band of which the cone is
composed is taken from the edge of the leaf, which the caterpillar
cuts away in proportion as it winds it round its own body. When one
portion has taken the required form, a little more is cut out, but
always in a direction parallel with the edge of the leaf. While the
insect is thus gradually rolling itself up in a case, it also feeds
vigorously on the leaf, taking care, however, always to spare the band
which forms its habitation. Another part of the cleverness of this
insect consists in maintaining this strip of leaf in its spiral form,
which would otherwise naturally unwind by its own weight, and
flutter in the wind as a torn fragment. Here it is that silk is again
skilfully employed. The caterpillar commences much as other leaf-
rolling insects do, by fastening a thread to the edge of the leaf and
drawing it towards the desired point. But as the work proceeds the
insect generally has three skeins or bands of silk extended from the
opening of its case to the leaf. The first is the shortest and the most
direct, issuing from the interior of the roll; the second is fastened to
the middle of the last spiral, and extends to the leaf; the third is more
extensive still, and all three are admirably disposed for keeping the
leaf bent to the proper form. These skeins are composed of a great
number of threads parallel with each other, which not only serve to
retain the leaf in its spiral form, but also serve the caterpillar as a
kind of ladder, by which it mounts, and on which it rests while
cutting out fresh portions of leaf.
It sometimes happens accidentally to this caterpillar that the case
becomes detached from the leaf, or naturalists have purposely
severed a portion to see what would be the result; but this does not
greatly disturb the insect, for as long as a single thread of silk
remains to hold the pieces together, the caterpillar is able to repair
the evil. It will unite the fractured portion almost imperceptibly by
means of silken threads, and proceed with its case as before; but if
the leaf dry up and wither, the insect is
then compelled to desert it, and to
select a younger and fresher leaf for its
operations.
What is still more curious, on the
completion of the dwelling, the
caterpillar sometimes wishes to make
an excursion to another part of the leaf,
and to take its house with it, and this it
accomplishes in the following manner.
Coming more than three parts out of
the cone, the creature makes new
skeins in advance of the old, and
attempts to pull the cone forward by
their means; but finding that this does
not succeed, it bends its body back, and
quickly severs the old threads and the
portion of leaf which keeps the case
immovable. It is now able to draw the
case onwards a certain distance, after
which it has only to repeat the
operation, and make other new skeins
LEAF-NEST UNWOUND. in advance of these, to continue its
onward journey. Thus it arrives at the
opposite edge of the leaf, where it
carefully adjusts its case to the under side, fastening it with great
ingenuity, and drawing the threads tighter where the cone is not
properly balanced. In all these cases, silk is the useful material by
which the caterpillar secures its nest, and provides for its own safety:
it is also a constant resource in case of danger, or of accident, as the
following anecdote will show. A caterpillar of the goat-moth, being
confined in a smooth glass sugar-basin, managed to crawl up the
slippery sides and escape. This excited great surprise in the naturalist
(Rösel) who had imprisoned the creature, and he therefore took
occasion closely to watch its proceedings when again placed in a
similar vessel. It was with surprise and admiration that he now saw
the caterpillar constructing a silken ladder on the side of the glass;
the natural gum of the silk being sufficient to secure it even to that
perfectly smooth surface. Up this ladder the creature crawled, and
thus easily and expeditiously made its escape.
Silkworms abound in our own
country, as well as in others; but the
silk they spin is too fragile and scanty
to be employed for other purposes than
their own. It is different with some of
the caterpillars of India. Although the
great supply of silk is there obtained, as
with us, from the silkworm of the
mulberry-tree, yet the caterpillars of
various moths also furnish a
considerable quantity. The most
important of these are the Tusseh and
Arindy silkworms, both natives of
Bengal. The first feeds on the leaves of
the jujube tree and of the asseen, and is
found in such abundance as from time
immemorial to have afforded a
constant supply of coarse, dark-
coloured silk, which is woven into a
cheap but very durable cloth.

SILKEN LADDER SPUN BY


THE GOAT-MOTH
CATERPILLAR.
THE TUSSEH SILKWORM.

When the caterpillars approach their full size they are too heavy to
crawl in search of their food with the back upwards, as is usual with
most caterpillars, but traverse the small branches suspended by the
feet, as is shown in the figure.
COCOON OF THE TUSSEH SILKWORM.

When the caterpillar is ready to spin its cocoon, it connects by


means of the silk, (which is always glutinous when newly spun,) two
or three new leaves into an outer envelope, which serves as a basis to
spin the complete cocoon in, besides the cocoon being suspended
from a branch of the tree in a wonderful manner, by a thick, strong,
consolidated cord, spun of the same material by this persevering
creature.
The cocoon is of an exact oval shape, and very firm in texture: in it
the animal remains dormant, and perfectly protected, for about nine
months, namely from October until July; so that it makes its
appearance in time for the caterpillars to come into existence, when
Providence has furnished them with the greatest plenty of proper
food. When the insect is prepared to make its escape and be changed
into its perfect state, it discharges from its mouth a large quantity of
liquid, with which the upper end of the case is so perfectly softened
as to enable the moth to work its way out in a very short time; an
operation which is always performed during the night. In their
perfect state these insects do not exist many days: the female
deposits her eggs in the branches of the tree she may be resting on, to
which they adhere firmly by means of the gluten they are covered
with when newly laid.
The eggs are white, round, and compressed, with a depression in
the centre on each side. They hatch in from two to four weeks,
according to the state of the weather. The larvæ or caterpillars
acquire their full size, which is about four inches in length, and three
in circumference, in about six weeks: they are nearly the colour of the
leaves they feed on, with a light yellowish stripe on each side; under
these stripes the middle segments are marked with an oblong gold-
coloured speck. The back is also marked with a few round darker
coloured spots, from which issue a few long, coarse, distinct hairs,
while others of smaller size are scattered over the insect.
The Tusseh silkworm is found in such abundance over many parts
of Bengal and the adjoining provinces, as to afford to the natives a
large supply of the durable, coarse, dark-coloured silk, already
mentioned, commonly called Tusseh silk, which is woven into a kind
of cloth called Tusseh doot’hies, much worn by Brahmins and other
sects of Hindoos. This substance would no doubt be highly useful to
the inhabitants of many parts of America and the south of Europe,
where a cheap, light, cool, durable dress, such as this silk makes, is
much wanted. Millions of cocoons of the Tusseh silkworm are
annually collected in the jungle, and brought to the silk factories near
Calcutta. In other parts the people gather and transplant them to the
trees near their own dwellings, that they may watch over the safety of
the caterpillars, which are very liable to be devoured by crows during
the day time, and by bats at night.
The Arindy silkworm feeds only on the leaves of the Palmi Christi;
it produces so delicate and flossy a silk that it cannot be wound from
the cocoons; it is therefore spun like cotton, and the thread woven
into a coarse kind of white cloth, of a loose texture, but so durable
that a person can scarcely in his lifetime wear out a garment made of
it.
Eleven different species of silkworm have been enumerated as
natives of India, which has thus the internal means of providing the
whole of Europe with a material which would rival cotton and
woollen cloth, and would often be preferred to both, could it be
obtained at a low price. The produce of the Arindy silkworm, when
sent to this country was much admired, and some manufacturers to
whom it was shown seemed to think that they had been hitherto
deceived in the account of the shawls of India being made from the
wool of a goat, and that this silk, if sent home, could be made into
shawls equal to any manufactured in India.
Many of the larvæ of the European moths afford a very strong silk,
and it is said, that a manufacture of silk from the cocoons of the
emperor moth was at one time established in Germany. There is no
doubt, however, that silk might be collected in abundance from many
native silkworms in America. Cocoons have been described eight
inches long, made of grey silk, which the inhabitants of
Chilpancingo, Tixtala, and other places in South America,
manufacture into stockings and handkerchiefs. Humboldt also
observed similar nests in the provinces of Mechoacan, and the
mountains of Santa Rosa; they were of dense tissue, resembling
Chinese paper, of a brilliant whiteness, and formed of distinct and
separate layers. The interior layers, which are the thinnest, and of
extraordinary transparency, were used by the ancient Mexicans as
writing tablets.
CHAPTER II.
MANUFACTURE OF SILK BY THE
SILKWORM.

We now come to the most important of all silk-spinning insects,


the common silkworm, or caterpillar of the mulberry-tree moth. The
labours of this insect were known and appreciated in other parts of
the world long before we had tidings of its existence; so that the
peasantry of other lands were clad in raiment which our kings would
have been proud to wear. “When silk was so scarce in this country
that James the First, while King of Scotland, was forced to beg of the
Earl of Mar the loan of a pair of silk stockings to appear in before the
English ambassador, enforcing his request with the cogent appeal,
‘for ye would not, sure, that your king should appear as a scrub
before strangers;’ nay, long before this period, even prior to the time
that silk was valued at its weight in gold at Rome, and the Emperor
Aurelian refused his empress a robe of silk because of its dearness,
the Chinese peasantry in some of the provinces, millions in number,
were clothed with this material; and for some thousand years to the
present time, it has been both there and in India (where a class
whose occupation was to attend silkworms appears to have existed
from time immemorial, being mentioned in the oldest Sanscrit
books,) one of the chief objects of cultivation and manufacture. You
will admit, therefore, that when nature
——Set to work millions of spinning worms,
That in their green shops weave the smooth-haired silk
To deck her sons,

she was conferring upon them a benefit scarcely inferior to that


consequent upon the gift of wool to the fleecy race, or a fibrous rind
to the flax or hemp plants; and that mankind is not under much less
obligation to Pamphila, who, according to Aristotle, was the
discoverer of the art of unwinding and weaving silk, than to the
inventors of the spinning of those products.”

EGGS AND SILKWORMS IN THE FIRST AGE.

It is so common an amusement with young persons in this country


to procure the eggs of silkworms, rear the insects, and watch their
changes that numbers are acquainted with the growth, habits, and
manner of spinning of these interesting creatures. Perhaps a sheet of
paper is given to a little boy or girl, on which are a number of small
specks, no bigger than pins’ heads: these specks, the child is told, are
silkworms’ eggs, and if he keeps them dry during winter, and then
places them in a sunny window in spring, he will get a number of
caterpillars from them. Taking care to do this, the child is delighted
some fine morning to see a few little dark coloured worms crawling
about the paper, while others are just issuing from the eggs. Perhaps
a difficulty now arises about their food. In warm countries the leaves
of the mulberry-tree are ready for the insects as soon as they are
hatched; but in England, unless the eggs are purposely kept back, by
putting them in a cold place, the caterpillars come out before the
mulberry-tree has put forth its leaves. A few tender leaves of the
lettuce are therefore spread lightly over the young caterpillars, and
upon these they mount, and at last begin to feed, after searching in
vain for their natural food. But the worms do not thrive on this diet,
and it is much better so to manage the eggs that they may be hatched
when the young leaves of the mulberry are just opening. These form
the best possible food in that tender state, and in order to economise
it, the leaves should be cut in small pieces; because the caterpillars
feed only on the edges, and thus great part of a leaf, when given to
them whole, is entirely wasted.

THE WHITE MULBERRY.

(Morus alba.)

In Italy, where great attention is paid to the cultivation of the


silkworm, the eggs are hatched in a room heated by a stove, and the
young caterpillars are then removed on their mulberry-leaves to a
cooler apartment called the nursery, where they are managed with
great care and skill. Wicker shelves are arranged in the room at
convenient distances, and are lined with paper, on which the worms
are placed. Care is taken to place together only such worms as are
hatched at the same time, for without this precaution the treatment,
with respect to food, could not be regulated, and the moultings
would not take place at the same time. Great care is also taken to
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

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

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookluna.com

You might also like