100% found this document useful (1 vote)
28 views

An Introduction to Programming with C 8th Edition Diane Zak pdf download

The document provides information about various programming textbooks available for download, including 'An Introduction to Programming with C' by Diane Zak and other titles related to programming and technology. It highlights the availability of instant digital products in different formats such as PDF, ePub, and MOBI. Additionally, it includes details about the structure and content of the 8th edition of 'An Introduction to Programming with C++' by Diane Zak.

Uploaded by

duprebigosqt
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 (1 vote)
28 views

An Introduction to Programming with C 8th Edition Diane Zak pdf download

The document provides information about various programming textbooks available for download, including 'An Introduction to Programming with C' by Diane Zak and other titles related to programming and technology. It highlights the availability of instant digital products in different formats such as PDF, ePub, and MOBI. Additionally, it includes details about the structure and content of the 8th edition of 'An Introduction to Programming with C++' by Diane Zak.

Uploaded by

duprebigosqt
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/ 60

An Introduction to Programming with C 8th

Edition Diane Zak download

https://ebookname.com/product/an-introduction-to-programming-
with-c-8th-edition-diane-zak/

Get Instant Ebook Downloads – Browse at https://ebookname.com


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

Clearly Visual Basic Programming with Microsoft Visual


Basic 2012 3rd Edition Diane Zak

https://ebookname.com/product/clearly-visual-basic-programming-
with-microsoft-visual-basic-2012-3rd-edition-diane-zak/

CGI Perl Web Warrior Series 1st Edition Diane Zak

https://ebookname.com/product/cgi-perl-web-warrior-series-1st-
edition-diane-zak/

Microsoft Visual C 2010 An Introduction to Object


Oriented Programming 4th Edition Joyce Farrell

https://ebookname.com/product/microsoft-visual-c-2010-an-
introduction-to-object-oriented-programming-4th-edition-joyce-
farrell/

The Protection of Archaeological Heritage in Times of


Economic Crisis 1st Edition Elena Korka (Ed.)

https://ebookname.com/product/the-protection-of-archaeological-
heritage-in-times-of-economic-crisis-1st-edition-elena-korka-ed/
Policy Concertation and Social Partnership in Western
Europe Lessons for the Twenty First Century 1st Edition
Stefan Berger

https://ebookname.com/product/policy-concertation-and-social-
partnership-in-western-europe-lessons-for-the-twenty-first-
century-1st-edition-stefan-berger/

Lectures on Quantum Groups 2nd Edition Pavel Etingof

https://ebookname.com/product/lectures-on-quantum-groups-2nd-
edition-pavel-etingof/

Functional Food Ingredients and Nutraceuticals


Processing Technologies 1st Edition John Shi

https://ebookname.com/product/functional-food-ingredients-and-
nutraceuticals-processing-technologies-1st-edition-john-shi/

The I L Peretz Reader Peretz

https://ebookname.com/product/the-i-l-peretz-reader-peretz/

The Most Controversial Decision Truman the Atomic Bombs


and the Defeat of Japan 1st Edition Wilson D. Miscamble
C.S.C.

https://ebookname.com/product/the-most-controversial-decision-
truman-the-atomic-bombs-and-the-defeat-of-japan-1st-edition-
wilson-d-miscamble-c-s-c/
Gale Encyclopedia of Science 3rd Edition K. Lee Lerner
And Brenda Wilmoth Lerner

https://ebookname.com/product/gale-encyclopedia-of-science-3rd-
edition-k-lee-lerner-and-brenda-wilmoth-lerner/
An Introduction to
Programming with C++

Copyright 2016 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 2016 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.
Eighth Edition

An Introduction to
Programming with C++

Diane Zak

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

Copyright 2016 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 2016 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.
An Introduction to Programming with C++, © 2016 Cengage Learning
Eighth Edition
WCN: 02-200-203
Diane Zak
Product Director: Kathleen McMahon ALL RIGHTS RESERVED. No part of this work covered by the copyright
herein may be reproduced, transmitted, stored or used in any form or by
Product Team Manager: Kristin McNary any means graphic, electronic, or mechanical, including but not limited to
Senior Product Manager: Jim Gish photocopying, recording, scanning, digitizing, taping, Web distribution,
Senior Content Developer: Alyssa Pratt information networks, or information storage and retrieval systems, except
as permitted under Section 107 or 108 of the 1976 United States Copyright
Product Assistant: Abigail Pufpaff
Act, without the prior written permission of the publisher.
Marketing Manager: Eric LaScola
Senior Production Director:
For product information and technology assistance, contact us at
Wendy Troeger Cengage Learning Customer & Sales Support, 1-800-354-9706
Production Director: Patty Stephan For permission to use material from this text or product, submit all
Senior Content Project Manager: requests online at www.cengage.com/permissions
Jennifer K. Feltri-George Further ­permissions ­questions can be emailed to
permissionrequest@cengage.com
Managing Art Director: Jack Pendleton
Cover image(s):
Library of Congress Control Number: 2015940474
© Rudchenko Liliia/Shutterstock.com
ISBN: 978-1-285-86011-4
Unless otherwise noted all screenshots are
Cengage Learning
courtesy of Microsoft Corporation
20 Channel Center Street
Open Clip art source: OpenClipArt Boston, MA 02210
USA

Cengage Learning is a leading provider of customized learning solutions


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

Cengage Learning products are represented in Canada by


Nelson Education, Ltd.

For your course and learning solutions, visit www.cengage.com


Purchase any of our products at your local college store or at our
preferred online store www.cengagebrain.com
Notice to the Reader
Publisher does not warrant or guarantee any of the products described herein or
perform any independent analysis in connection with any of the product informa-
tion 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 the United States of America


Print Number: 01 Print Year: 2016

Copyright 2016 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.
v

Brief Contents

Pref ace . . . . . . . . . . . . . . . . . . . . . . . . . xi v
Read T h is B ef o re You Begi n . . . . . . . . . . . . . . . xv i i i
Chapt e r 1 A n I n t ro du ct io n to Programmi ng . . . . . . . . . . . . . . 1
Chapt e r 2 B eg in n in g t h e Probl em- Sol v i ng Process . . . . . . . . . . . 23
Chapt e r 3 Var iables an d Constants . . . . . . . . . . . . . . . . . 51
Chapt e r 4 Co m plet in g t h e Probl em- Sol v i ng Process . . . . . . . . . . 75
Chapt e r 5 T h e Select io n Structure . . . . . . . . . . . . . . . . . 113
Chapt e r 6 M o re o n t h e Selecti on Structure . . . . . . . . . . . . . 157
Chapt e r 7 T h e Repet it io n Structure . . . . . . . . . . . . . . . . 201
C HAPT E R 8 M o re o n t h e Repeti ti on Structure . . . . . . . . . . . . . 247
C HAPT E R 9 Valu e-Ret u r n in g Functi ons . . . . . . . . . . . . . . . . 279
C HAPT E R 10 Vo id F u n ct io n s . . . . . . . . . . . . . . . . . . . . . 329
C HAPT E R 11 On e-Dim en s io n a l Array s . . . . . . . . . . . . . . . . . 369
C HAPT E R 12 Tw o -Dim en s io n a l Array s . . . . . . . . . . . . . . . . . 425
C HAPT E R 13 St r in g s . . . . . . . . . . . . . . . . . . . . . . . . 461
C HAPT E R 14 Sequ en t ial A ccess Fi l es . . . . . . . . . . . . . . . . . 511
C HAPT E R 15 Clas s es an d Obj ects . . . . . . . . . . . . . . . . . . 551
A pp endix A C+ + Keyw o rds . . . . . . . . . . . . . . . . . . . . . 593
A pp endix B A SC II Co des . . . . . . . . . . . . . . . . . . . . . . 595
A pp endix C Co m m o n Syn t ax Errors . . . . . . . . . . . . . . . . . 597
A pp endix D Ho w To B o xes . . . . . . . . . . . . . . . . . . . . . 599
I n dex . . . . . . . . . . . . . . . . . . . . . . . . . 603

The Answers.pdf and data files can be found online at CengageBrain.com.

Copyright 2016 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

Contents

Pref ace . . . . . . . . . . . . . . . . . . . . . . . . . xi v
R ead T h is B ef o re Yo u Begi n . . . . . . . . . . . . . . . xv i i i

Chapt e r 1 A n I n t ro du ct io n t o Programmi ng . . . . . . . . . . . . . . 1
Programming a Computer . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
The Programmer’s Job . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Employment Opportunities . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
A Brief History of Programming Languages . . . . . . . . . . . . . . . . . . . . 3
Machine Languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Assembly Languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
High-Level Languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Control Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
The Sequence Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
The Selection Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
The Repetition Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
LAB 1-1 Stop and Analyze . . . . . . . . . . . . . . . . . . . . . . . . . . 10
LAB 1-2 Plan and Create . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
LAB 1-3 Modify . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
LAB 1-4 What’s Missing? . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Chapter Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

Chapter 2 B eg in n in g t h e Pro blem- Sol v i ng Process . . . . . . . . . . . 23


Problem Solving . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Solving Everyday Problems . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Creating Computer Solutions to Problems . . . . . . . . . . . . . . . . . . . . 25
Step 1—Analyze the Problem . . . . . . . . . . . . . . . . . . . . . . . . . 26
Hints for Analyzing Problems . . . . . . . . . . . . . . . . . . . . . . . . . 26
Step 2—Plan the Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Step 3—Desk-Check the Algorithm . . . . . . . . . . . . . . . . . . . . . . . 31
The Gas Mileage Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
LAB 2-1 Stop and Analyze . . . . . . . . . . . . . . . . . . . . . . . . . . 36
LAB 2-2 Plan and Create . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
LAB 2-3 Modify . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
LAB 2-4 What’s Missing? . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
LAB 2-5 Desk-Check . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
LAB 2-6 Debug . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

Copyright 2016 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.
vii
 

Chapter Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

Chapt er 3 Var iables an d Constants . . . . . . . . . . . . . . . . . 51


Beginning Step 4 in the Problem-Solving Process . . . . . . . . . . . . . . . . 52
Internal Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Selecting a Name for a Memory Location . . . . . . . . . . . . . . . . . . . . 53
Revisiting the Addison O’Reilly Problem from Chapter 2 . . . . . . . . . . . . . 54
Selecting a Data Type for a Memory Location . . . . . . . . . . . . . . . . . . 55
How Data Is Stored in Internal Memory . . . . . . . . . . . . . . . . . . . . 57
Selecting an Initial Value for a Memory Location . . . . . . . . . . . . . . . . . 60
Declaring a Memory Location . . . . . . . . . . . . . . . . . . . . . . . . . 62
LAB 3-1 Stop and Analyze . . . . . . . . . . . . . . . . . . . . . . . . . . 64
LAB 3-2 Plan and Create . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
LAB 3-3 Modify . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
LAB 3-4 What’s Missing? . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
LAB 3-5 Desk-Check . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
LAB 3-6 Debug . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
Chapter Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71

Chapt er 4 Co m plet in g t h e Probl em- Sol v i ng Process . . . . . . . . . . 75


Finishing Step 4 in the Problem-Solving Process . . . . . . . . . . . . . . . . . 76
Getting Data from the Keyboard . . . . . . . . . . . . . . . . . . . . . . . . 76
Displaying Messages on the Computer Screen . . . . . . . . . . . . . . . . . . 78
Arithmetic Operators in C++ . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Type Conversions in Arithmetic Expressions . . . . . . . . . . . . . . . . . . 82
The static_cast Operator . . . . . . . . . . . . . . . . . . . . . . . . . 83
Assignment Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Arithmetic Assignment Operators . . . . . . . . . . . . . . . . . . . . . . . 87
Step 5—Desk-Check the Program . . . . . . . . . . . . . . . . . . . . . . . 88
Step 6—Evaluate and Modify the Program . . . . . . . . . . . . . . . . . . . . 90
LAB 4-1 Stop and Analyze . . . . . . . . . . . . . . . . . . . . . . . . . . 94
LAB 4-2 Plan and Create . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
LAB 4-3 Modify . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
LAB 4-4 What’s Missing? . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
LAB 4-5 Desk-Check . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
LAB 4-6 Debug . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Chapter Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104

Copyright 2016 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
Contents 

Chapt e r 5 T h e Select io n St r u ct u re . . . . . . . . . . . . . . . . . 113


Making Decisions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
Flowcharting a Selection Structure . . . . . . . . . . . . . . . . . . . . . . . 116
Coding Selection Structures in C++ . . . . . . . . . . . . . . . . . . . . . . 118
Comparison Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
Swapping Numeric Values . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
Displaying the Area or Circumference . . . . . . . . . . . . . . . . . . . . . 124
Logical Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
Using the Truth Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
A Different Version of the Area or Circumference Program . . . . . . . . . . . . 130
Summary of Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
Converting a Character to Uppercase or Lowercase . . . . . . . . . . . . . . . 133
Formatting Numeric Output . . . . . . . . . . . . . . . . . . . . . . . . . . 134
LAB 5-1 Stop and Analyze . . . . . . . . . . . . . . . . . . . . . . . . . . 137
LAB 5-2 Plan and Create . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
LAB 5-3 Modify . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
LAB 5-4 What’s Missing? . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
LAB 5-5 Desk-Check . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
LAB 5-6 Debug . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
Chapter Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147

Chapt er 6 M o re o n t h e Select io n Structure . . . . . . . . . . . . . 1 57


Nested Selection Structures . . . . . . . . . . . . . . . . . . . . . . . . . . 158
Flowcharting a Nested Selection Structure . . . . . . . . . . . . . . . . . . . 161
Coding a Nested Selection Structure . . . . . . . . . . . . . . . . . . . . . . 163
Logic Errors in Selection Structures . . . . . . . . . . . . . . . . . . . . . . 165
First Logic Error: Using a Compound Condition Rather Than a Nested
Selection Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
Second Logic Error: Reversing the Outer and Nested Decisions . . . . . . . . . 169
Third Logic Error: Using an Unnecessary Nested Selection Structure . . . . . . 169
Fourth Logic Error: Including an Unnecessary Comparison in a Condition . . . . 170
Multiple-Alternative Selection Structures . . . . . . . . . . . . . . . . . . . . 173
The switch Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
LAB 6-1 Stop and Analyze . . . . . . . . . . . . . . . . . . . . . . . . . . 177
LAB 6-2 Plan and Create . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
LAB 6-3 Modify . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
LAB 6-4 What’s Missing? . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
LAB 6-5 Desk-Check . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
LAB 6-6 Debug . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
Chapter Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187

Copyright 2016 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.
ix
 

Chapt e r 7 T h e Repet it io n Structure . . . . . . . . . . . . . . . . 201


Repeating Program Instructions . . . . . . . . . . . . . . . . . . . . . . . . 202
Using a Pretest Loop to Solve a Real-World Problem . . . . . . . . . . . . . . . 204
Flowcharting a Pretest Loop . . . . . . . . . . . . . . . . . . . . . . . . . 206
The while Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
Using Counters and Accumulators . . . . . . . . . . . . . . . . . . . . . . . 211
The Stock Price Program . . . . . . . . . . . . . . . . . . . . . . . . . . 213
Counter-Controlled Pretest Loops . . . . . . . . . . . . . . . . . . . . . . . 217
The for Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
The Total Payroll Program . . . . . . . . . . . . . . . . . . . . . . . . . . 220
The Tip Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
Another Version of the Commission Program . . . . . . . . . . . . . . . . . 224
The Even Integers Program . . . . . . . . . . . . . . . . . . . . . . . . . 226
LAB 7-1 Stop and Analyze . . . . . . . . . . . . . . . . . . . . . . . . . . 229
LAB 7-2 Plan and Create . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
LAB 7-3 Modify . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
LAB 7-4 What’s Missing? . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
LAB 7-5 Desk-Check . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
LAB 7-6 Debug . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
Chapter Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239

Chapter 8 M o re o n t h e Repeti ti on Structure . . . . . . . . . . . . . 247


Posttest Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
Flowcharting a Posttest Loop . . . . . . . . . . . . . . . . . . . . . . . . . 250
The do while Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . 252
Nested Repetition Structures . . . . . . . . . . . . . . . . . . . . . . . . . 254
The Clock Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
The Car Depreciation Program . . . . . . . . . . . . . . . . . . . . . . . . . 258
LAB 8-1 Stop and Analyze . . . . . . . . . . . . . . . . . . . . . . . . . . 262
LAB 8-2 Plan and Create . . . . . . . . . . . . . . . . . . . . . . . . . . . 263
LAB 8-3 Modify . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267
LAB 8-4 What’s Missing? . . . . . . . . . . . . . . . . . . . . . . . . . . . 267
LAB 8-5 Desk-Check . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267
LAB 8-6 Debug . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268
Chapter Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268
Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270

Chapter 9 Valu e-Ret u r n in g Functi ons . . . . . . . . . . . . . . . . 279


Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280
Value-Returning Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
The pow Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281

Copyright 2016 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
Contents 

The sqrt Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282


The Hypotenuse Program . . . . . . . . . . . . . . . . . . . . . . . . . . 283
The rand , srand , and time Functions . . . . . . . . . . . . . . . . . . . . . 285
The Guessing Game Program . . . . . . . . . . . . . . . . . . . . . . . . 289
Creating Program-Defined Value-Returning Functions . . . . . . . . . . . . . . . 291
Calling a Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293
The Savings Account Program . . . . . . . . . . . . . . . . . . . . . . . . 295
Function Prototypes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298
Completing the Savings Account Program . . . . . . . . . . . . . . . . . . . 298
The Scope and Lifetime of a Variable . . . . . . . . . . . . . . . . . . . . . . 304
LAB 9-1 Stop and Analyze . . . . . . . . . . . . . . . . . . . . . . . . . . 305
LAB 9-2 Plan and Create . . . . . . . . . . . . . . . . . . . . . . . . . . . 307
LAB 9-3 Modify . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314
LAB 9-4 What’s Missing? . . . . . . . . . . . . . . . . . . . . . . . . . . . 314
LAB 9-5 Desk-Check . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315
LAB 9-6 Debug . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316
Chapter Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317
Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320

Chapt er 10 Vo id F u n ct io n s . . . . . . . . . . . . . . . . . . . . . 329
Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 330
Creating Program-Defined Void Functions . . . . . . . . . . . . . . . . . . . . 331
Passing Variables to a Function . . . . . . . . . . . . . . . . . . . . . . . . 337
Reviewing Passing Variables by Value . . . . . . . . . . . . . . . . . . . . . 338
Passing Variables by Reference . . . . . . . . . . . . . . . . . . . . . . . 341
LAB 10-1 Stop and Analyze . . . . . . . . . . . . . . . . . . . . . . . . . 345
LAB 10-2 Plan and Create . . . . . . . . . . . . . . . . . . . . . . . . . . 347
LAB 10-3 Modify . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356
LAB 10-4 What’s Missing? . . . . . . . . . . . . . . . . . . . . . . . . . . 356
LAB 10-5 Desk-Check . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356
LAB 10-6 Debug . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357
Chapter Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358
Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 360

Chapter 11 On e-Dim en s io n al Ar r ay s . . . . . . . . . . . . . . . . . 369


Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 370
One-Dimensional Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . 370
Declaring and Initializing a One-Dimensional Array . . . . . . . . . . . . . . . 371
Entering Data into a One-Dimensional Array . . . . . . . . . . . . . . . . . . 373
Displaying the Contents of a One-Dimensional Array . . . . . . . . . . . . . . 375
The Calories Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . 376
Passing a One-Dimensional Array to a Function . . . . . . . . . . . . . . . . . 382
Calculating a Total and an Average . . . . . . . . . . . . . . . . . . . . . . . 384

Copyright 2016 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.
xi
 

The Social Media Program—Searching an Array . . . . . . . . . . . . . . . . . 385


The Currency Converter Program—Accessing an Individual Element . . . . . . . . 388
The Highest Number Program—Finding the Highest Value . . . . . . . . . . . . 391
Parallel One-Dimensional Arrays . . . . . . . . . . . . . . . . . . . . . . . . 396
Sorting the Data Stored in a One-Dimensional Array . . . . . . . . . . . . . . . 399
LAB 11-1 Stop and Analyze . . . . . . . . . . . . . . . . . . . . . . . . . 406
LAB 11-2 Plan and Create . . . . . . . . . . . . . . . . . . . . . . . . . . 407
LAB 11-3 Modify . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 411
LAB 11-4 What’s Missing? . . . . . . . . . . . . . . . . . . . . . . . . . . 411
LAB 11-5 Desk-Check . . . . . . . . . . . . . . . . . . . . . . . . . . . . 411
LAB 11-6 Debug . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412
Chapter Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 413
Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 414
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 416

Chapter 12 Tw o -Dim en s io n al Array s . . . . . . . . . . . . . . . . . 425


Using Two-Dimensional Arrays . . . . . . . . . . . . . . . . . . . . . . . . . 426
Declaring and Initializing a Two-Dimensional Array . . . . . . . . . . . . . . . 427
Entering Data into a Two-Dimensional Array . . . . . . . . . . . . . . . . . . 428
Displaying the Contents of a Two-Dimensional Array . . . . . . . . . . . . . . 431
The Chapton Company Program . . . . . . . . . . . . . . . . . . . . . . . 432
Accumulating the Values Stored in a Two-Dimensional Array . . . . . . . . . . . 434
Searching a Two-Dimensional Array . . . . . . . . . . . . . . . . . . . . . . 436
Passing a Two-Dimensional Array to a Function . . . . . . . . . . . . . . . . . 443
LAB 12-1 Stop and Analyze . . . . . . . . . . . . . . . . . . . . . . . . . 444
LAB 12-2 Plan and Create . . . . . . . . . . . . . . . . . . . . . . . . . . 446
LAB 12-3 Modify . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 449
LAB 12-4 What’s Missing? . . . . . . . . . . . . . . . . . . . . . . . . . . 449
LAB 12-5 Desk-Check . . . . . . . . . . . . . . . . . . . . . . . . . . . . 449
LAB 12-6 Debug . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 450
Chapter Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 450
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 450
Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 451
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 452

Chapter 13 St r in g s . . . . . . . . . . . . . . . . . . . . . . . . 461
The string Data Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . 462
Getting String Input from the Keyboard . . . . . . . . . . . . . . . . . . . . . 462
The Primrose Auction House Program . . . . . . . . . . . . . . . . . . . . . 464
The ignore Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . 468
Determining the Number of Characters in a string Variable . . . . . . . . . . . 471
Accessing the Characters in a string Variable . . . . . . . . . . . . . . . . . 473
Searching the Contents of a string Variable . . . . . . . . . . . . . . . . . . 477
Removing Characters from a string Variable . . . . . . . . . . . . . . . . . . 481
Replacing Characters in a string Variable . . . . . . . . . . . . . . . . . . . 484
Inserting Characters Within a string Variable . . . . . . . . . . . . . . . . . 485

Copyright 2016 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.
xii
Contents 

Duplicating a Character Within a string Variable . . . . . . . . . . . . . . . . 487


Concatenating Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . 489
LAB 13-1 Stop and Analyze . . . . . . . . . . . . . . . . . . . . . . . . . 491
LAB 13-2 Plan and Create . . . . . . . . . . . . . . . . . . . . . . . . . . 492
LAB 13-3 Modify . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 497
LAB 13-4 What’s Missing? . . . . . . . . . . . . . . . . . . . . . . . . . . 497
LAB 13-5 Desk-Check . . . . . . . . . . . . . . . . . . . . . . . . . . . . 498
LAB 13-6 Debug . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 498
Chapter Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 499
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 500
Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 501
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 504

Chapter 14 Sequ en t ial A cces s F iles . . . . . . . . . . . . . . . . . 511


File Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 512
Creating File Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 512
Opening a Sequential Access File . . . . . . . . . . . . . . . . . . . . . . . 514
Determining Whether a File Was Opened Successfully . . . . . . . . . . . . . 516
Writing Data to a Sequential Access File . . . . . . . . . . . . . . . . . . . . 518
Reading Information from a Sequential Access File . . . . . . . . . . . . . . . 519
Testing for the End of a Sequential Access File . . . . . . . . . . . . . . . . 522
Closing a Sequential Access File . . . . . . . . . . . . . . . . . . . . . . . . 522
The eBook Collection Program . . . . . . . . . . . . . . . . . . . . . . . . . 523
LAB 14-1 Stop and Analyze . . . . . . . . . . . . . . . . . . . . . . . . . 528
LAB 14-2 Plan and Create . . . . . . . . . . . . . . . . . . . . . . . . . . 530
LAB 14-3 Modify . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 539
LAB 14-4 What’s Missing? . . . . . . . . . . . . . . . . . . . . . . . . . . 540
LAB 14-5 Desk-Check . . . . . . . . . . . . . . . . . . . . . . . . . . . . 540
LAB 14-6 Debug . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 541
Chapter Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 541
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 542
Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 543
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 544

Chapter 15 Clas s es an d Object s . . . . . . . . . . . . . . . . . . 551


Object-Oriented Terminology . . . . . . . . . . . . . . . . . . . . . . . . . . 552
Defining a Class in C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . 553
Instantiating an Object and Referring to a Public Member . . . . . . . . . . . . 556
Exa mple 1—A Class That Contains a Private Data Member
and Public Member Methods . . . . . . . . . . . . . . . . . . . . . . . 557
Header Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 561
Example 2—A Class That Contains a Parameterized Constructor . . . . . . . . . 562
Example 3—Reusing a Class . . . . . . . . . . . . . . . . . . . . . . . . . 565
Example 4—A Class That Contains Overloaded Methods . . . . . . . . . . . . . 566
LAB 15-1 Stop and Analyze . . . . . . . . . . . . . . . . . . . . . . . . . 569
LAB 15-2 Plan and Create . . . . . . . . . . . . . . . . . . . . . . . . . . 571
LAB 15-3 Modify . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 576

Copyright 2016 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.
xiii
 

LAB 15-4 What’s Missing? . . . . . . . . . . . . . . . . . . . . . . . . . . 576


LAB 15-5 Desk-Check . . . . . . . . . . . . . . . . . . . . . . . . . . . . 576
LAB 15-6 Debug . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 578
Chapter Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 578
Key Terms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 579
Review Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 580
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 581

App endix A C+ + Keyw o rds . . . . . . . . . . . . . . . . . . . . . 593

A pp endix B A SC II Co des . . . . . . . . . . . . . . . . . . . . . . 595

A pp endix C Co m m o n Syn t ax Errors . . . . . . . . . . . . . . . . . 597

A pp endix D H o w To B o xes . . . . . . . . . . . . . . . . . . . . . 599

In dex . . . . . . . . . . . . . . . . . . . . . . . . . 603

The Answers.pdf and data files can be found online at CengageBrain.com.

Copyright 2016 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.
xiv

Preface

An Introduction to Programming with C++, Eighth Edition uses the C++ programming language
to teach programming concepts. This book is designed for a beginning programming course.
Although the book provides instructions for using several specific C++ compilers (such as
® ®
Microsoft Visual C++ , Dev-C++, and Code::Blocks), it can be used with most C++ compilers,
often with little or no modification.

Organization and Coverage


An Introduction to Programming with C++, Eighth Edition contains 15 chapters and several
appendices. In the chapters, students with no previous programming experience learn how to
plan and create well-structured programs. They also learn how to write programs using the
sequence, selection, and repetition structures, as well as how to create and manipulate functions,
sequential access files, arrays, strings, classes, and objects.

Approach
An Introduction to Programming with C++, Eighth Edition is distinguished from other textbooks
because of its unique approach, which motivates students by demonstrating why they need to
learn the concepts and skills presented. Each chapter begins with an introduction to one or more
programming concepts. The concepts are illustrated with code examples and sample programs.
The sample programs allow the student to observe how the current concept can be used before
they are introduced to the next concept. The concepts are taught using standard C++ commands.
Following the concept portion in each chapter (except Chapter 1) are six labs: Stop and Analyze,
Plan and Create, Modify, What’s Missing?, Desk-Check, and Debug. Each lab teaches students
how to apply the chapter concepts; however, each does so in a different way.

Features
An Introduction to Programming with C++, Eighth Edition is an exceptional textbook because it
also includes the following features:
READ THIS BEFORE YOU BEGIN This section is consistent with Cengage Learning’s
unequaled commitment to helping instructors introduce technology into the classroom.
­Technical considerations and assumptions about hardware, software, and default settings are
listed in one place to help instructors save time and eliminate unnecessary aggravation.

LABS  Each chapter (except Chapter 1) contains six labs that teach students how to
apply the concepts taught in the chapter to real-world problems. In the first lab,
which is the Stop and Analyze lab, students are expected to stop and analyze an
­existing program. Students plan and create a program in the Plan and Create lab,
which is the second lab. The third lab is the Modify lab. This lab requires students to

Copyright 2016 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.
xv
Organization and Coverage 

modify an existing program. In the fourth lab, which is the new What’s Missing? lab, students are
asked to find one or more missing instructions in a program. However, before they can
­accomplish this task, they must put the existing instructions in the proper order. The fifth lab is
the Desk-Check lab, in which students follow the logic of a program by desk-checking it. The
sixth lab is the Debug lab. This lab gives students an opportunity to find and correct the errors in
an existing program. Answers to the labs are provided in the Answers.pdf file available at
­CengageBrain.com. Providing the answers allows students to determine whether they have
­mastered the material covered in the chapter.

HOW TO BOXES The How To boxes in each chapter summarize important concepts and
­ rovide a quick reference for students. The How To boxes that introduce new statements,
p
­operators, stream manipulators, or functions contain the syntax and examples of using the syntax.
STANDARD C++ SYNTAX Like the previous edition of the book, this edition uses the standard
C++ syntax in the examples, sample programs, and exercises in each chapter.
PSEUDOCODE AND FLOWCHARTS Both planning tools are shown for many of the programs
within the chapters.
TIP  These notes provide additional information about the current concept. Examples
include alternative ways of writing statements, warnings about common mistakes made
when using a particular command, and reminders of related concepts learned in previous
chapters.
MINI-QUIZZES Mini-Quizzes are strategically placed to test students’ knowledge at various
points in each chapter. Answers to the quiz questions are provided in the Answers.pdf file,
allowing students to determine whether they have mastered the material covered thus far before
continuing with the chapter.
WANT MORE INFO? FILES These notes direct students to files that accompany
each chapter in the book. The files contain additional examples and further
­explanations of the concepts covered in the chapter. The files are in PDF format and
are available online at CengageBrain.com. Search for the ISBN associated with your
book (from the back cover of your book) using the search box at the top of the page.
This will take you to the product page where free companion resources can be found.
SUMMARY A Summary section follows the labs in each chapter. The Summary section recaps
the programming concepts and commands covered in the chapter.
KEY TERMS Following the Summary section in each chapter is a listing of the key terms
­introduced throughout the chapter, along with their definitions.
REVIEW QUESTIONS Review Questions follow the Key Terms section in each chapter.
The Review Questions test the students’ understanding of what they learned in the chapter.
PAPER AND PENCIL EXERCISES The Review Questions are followed by Pencil
and Paper Exercises, which are designated as TRY THIS, MODIFY THIS,
­INTRODUCTORY, INTERMEDIATE, ADVANCED, and SWAT THE BUGS. The
answers to the TRY THIS Exercises are provided at the end of the chapter. The
ADVANCED Exercises provide practice in applying cumulative programming k­ nowledge or
allow students to explore alternative solutions to programming tasks. The SWAT THE BUGS
­Exercises provide an opportunity for students to detect and correct errors in one or more lines
of code.

Copyright 2016 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.
xvi
Contents Organization and Coverage

COMPUTER EXERCISES The Computer Exercises provide students with additional


Computer
practice of the skills and concepts they learned in the chapter. The Computer
­Exercises are designated as TRY THIS, MODIFY THIS, INTRODUCTORY,
­INTERMEDIATE, ADVANCED, and SWAT THE BUGS. The answers to the
TRY THIS Exercises are provided at the end of the chapter. The ADVANCED Exercises provide
practice in applying cumulative programming knowledge or allow students to explore a­ lternative
solutions to programming tasks. The SWAT THE BUGS Exercises provide an opportunity for
students to detect and correct errors in an existing program.

New to this Edition!


ANSWERS.PDF FILE The answers to the Mini-Quizzes and Labs are now contained
in the Answers.pdf file (rather than in Appendix A); this file is available to students at
­CengageBrain.com.
NEW EXAMPLES, PROGRAMS, LABS, QUESTIONS, AND EXERCISES  The chapters
­contain new code examples, sample programs, Labs, Review Questions, and Exercises.
WHAT’S MISSING? LAB The chapters contain a new Lab called What’s Missing?.
In the What’s Missing? Lab, students must determine the one or more missing
­instructions in a program. However, before they can do this, they must first put the
existing instructions in the proper order.

VIDEOS These notes direct students to videos that accompany each chapter in the
book. Many of the videos have been revised from the previous edition. The videos
explain and/or demonstrate one or more of the chapter’s concepts. The videos are
­available online at CengageBrain.com. Search for the ISBN associated with your book (from the
back cover of your book) using the search box at the top of the page. This will take you to the
product page where free companion resources can be found.
INSTALLATION VIDEOS These videos, which have been revised from the previous
edition, show students how to install various C++ compilers (such as Microsoft Visual
C++, Dev-C++, and Code::Blocks). The videos are named Ch04-Installation
­developmentTool, where developmentTool is the name of the C++ development tool ­covered in
the video. The videos are available online at CengageBrain.com. Search for the ISBN associated
with your book (from the back cover of your book) using the search box at the top of the page.
This will take you to the product page where free companion resources can be found.
STEP-BY-STEP INSTRUCTIONS This book is accompanied by files that contain ­step-by-step
instructions for completing Labs 4-2, 4-3, 4-4, 4-6, 5-2, 5-3, and 5-6 using various
C++ ­compilers. The files, which have been revised from the previous edition, are named
Ch04-Lab4-X developmentTool.pdf and Ch05-Lab5-X developmentTool.pdf, where X represents
the lab number, and developmentTool is the name of the C++ development tool covered in the
file. The files are in PDF format and are available online at www.cengagebrain.com. Search for
the ISBN associated with your book (from the back cover of your book) using the search box at
the top of the page. This will take you to the product page where free companion resources can
be found.
APPENDICES Appendices B, C, D, and E are now Appendices A, B, C, and D. The information
in Appendix A from the previous edition is now contained in the Answers.pdf file.
POW FUNCTION The pow function is now covered along with the built-in value-returning
functions in Chapter 9 (rather than in Chapter 8).

Copyright 2016 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.
xvii
Acknowledgments 

Instructor Resources
The following resources are available on the Instructor Companion Site (sso.cengage.com) to
instructors who have adopted this book. Search for this title by ISBN, title, author, or keyword.
From the Product Overview page, select the Instructor’s Companion Site link to access your
complementary resources.
INSTRUCTOR’S MANUAL The Instructor’s Manual follows the text chapter by chapter to assist
you in planning and organizing an effective, engaging course. The manual includes learning
objectives, chapter overviews, ideas for classroom activities, and additional resources. A sample
course Syllabus is also available.
TEST BANK Cengage Learning Testing Powered by Cognero is a flexible, online system that
allows you to:
•• author, edit, and manage test bank content from multiple Cengage Learning solutions
•• create multiple test versions in an instant
•• deliver tests from your LMS, your classroom or wherever you want

POWERPOINT PRESENTATIONS This book comes with Microsoft PowerPoint slides for
each chapter. These are included as a teaching aid for classroom presentation, to make ­available
to students on the network for chapter review, or to be printed for classroom distribution.
­Instructors are encouraged to customize the slides to fit their course needs, and may add slides
to cover additional topics using the complete Figure Files from the text, also available on the
Instructor Companion Site.
SOLUTION FILES Solutions to the Labs, Review Questions, Pencil and Paper Exercises, and
Computer Exercises are available. The Solution Files also contain the sample programs that
appear in the figures throughout the book.
DATA FILES Data Files are required to complete many Labs and Computer Exercises in this
book. They are available on the Instructor Companion Site as well as on CengageBrain.com.

Acknowledgments
Writing a book is a team effort rather than an individual one. I would like to take this
­opportunity to thank my team, especially Alyssa Pratt (Senior Content Developer), Jennifer
K. Feltri-George (Senior Content Project Manager), Marisa Taylor (Senior Project Manager),
and Nicole Ashton, Serge Palladino, Chris Scriver (Quality Assurance). Thank you for your
­support, enthusiasm, patience, and hard work; it made a difficult task much easier. Last, but
certainly not least, I want to thank Fred D’Angelo, Pima Community College East Campus;
Charles ­Nelson, Rock Valley College; and Mark Shellman, Gaston College for their invaluable
ideas and comments.
Diane Zak

Copyright 2016 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.
xviii

Read This Before


You Begin

Technical Information
Data Files
You will need data files to complete the Labs and Computer Exercises in this book. Your
­instructor may provide the data files to you. You may obtain the files electronically at
­CengageBrain.com. Search for the ISBN associated with your book (from the back cover of your
text) using the search box at the top of the page. This will take you to the product page where
free companion resources can be found.
Each chapter in this book has its own set of data files, which are stored in a separate folder
within the Cpp8 folder. The files for Chapter 4 are stored in the Cpp8\Chap04 folder. Similarly,
the files for Chapter 5 are stored in the Cpp8\Chap05 folder. Throughout this book, you will be
instructed to open files from or save files to these folders.
You can use a computer in your school lab or your own computer to complete the Labs and
Computer Exercises in this book.

Using Your Own Computer


To use your own computer to complete the Labs and Computer Exercises in this book, you will
need a C++ compiler. This book is accompanied by videos that show students how to install
various C++ compilers (such as Microsoft Visual C++, Dev-C++, and Code::Blocks). The
­videos are named Ch04-Installation development Tool, where development Tool is the name of
the C++ development tool covered in the video. You may obtain the files electronically at
CengageBrain.com. Search for the ISBN associated with your book (from the back cover of
your book) using the search box at the top of the page. This will take you to the product page
where free ­companion resources can be found.
The book was written and Quality Assurance tested using Microsoft Visual C++ in Visual
Studio Ultimate 2015. It also was tested using Code::Blocks and Dev-C++. However, the book
can be used with most C++ compilers, often with little or no modification. At the time of
this writing, you can download a free copy of the Community Edition of Visual Studio 2015,
which contains the Visual C++ compiler, at https://www.visualstudio.com/en-us/downloads/
visual-studio-2015-downloads-vs.

Copyright 2016 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.
Chapter 1
An Introduction to
Programming

After studying Chapter 1, you should be able to:

Define the terminology used in programming


Explain the tasks performed by a programmer
Understand the employment opportunities for programmers and
software engineers
Explain the history of programming languages
Explain the sequence, selection, and repetition structures
Write simple algorithms using the sequence, selection, and repetition
structures

Copyright 2016 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
Chapter 1 An Introduction to Programming

Programming a Computer
In essence, the word programming means giving a mechanism the directions to accomplish a
task. If you are like most people, you’ve already programmed several mechanisms, such as your
digital video recorder (DVR), cell phone, or coffee maker. Like these devices, a computer also is a
mechanism that can be programmed.
The directions (typically called instructions) given to a computer are called computer ­programs
or, more simply, programs. The people who write programs are called p ­ rogrammers. Program-
mers use a variety of special languages, called programming languages, to ­communicate with the
computer. Some popular programming languages are C++, Visual Basic, C#, Java, and Python. In
this book, you will use the C++ programming language.

The Programmer’s Job


When a company has a problem that requires a computer solution, typically it is a programmer
who comes to the rescue. The programmer might be an employee of the company; or he or she
might be a freelance programmer, which is a programmer who works on temporary contracts
Ch01-Programmers rather than for a long-term employer.
To begin the process of developing a program, the programmer meets with the user, who is
the person (or persons) responsible for describing the problem. In many cases, this person or
­persons also will eventually use the ­solution. Depending on the complexity of the problem,
multiple programmers may be involved, and they may need to meet with the user several
times. Programming teams often contain ­subject matter experts, who may or may not be
­programmers. For example, an accountant might be part of a team working on a program that
requires accounting expertise. The purpose of the ­initial meetings with the user is to determine
the exact problem and to agree on a solution.
After the programmer and user agree on the solution, the programmer begins converting the solu-
tion into a computer program. During the conversion phase, the programmer meets ­periodically
with the user to determine whether the program fulfills the user’s needs and to refine any details
of the solution. When the user is satisfied that the program does what he or she wants it to do, the
programmer rigorously tests the program with sample data before releasing it to the user, who will
test it further to verify that it correctly solves the problem. In many cases, the programmer also
provides the user with a manual that explains how to use the program. As this process indicates,
the creation of a good computer solution to a problem—in other words, the creation of a good
program—requires a great deal of interaction between the programmer and the user.

Employment Opportunities
When searching for a job in computer programming, you will encounter ads for “computer
programmers” as well as for “computer software engineers.” Although job titles and descriptions
vary, computer software engineers typically are responsible for designing an ­appropriate ­solution
Ch01-Programmer to a user’s problem, while computer programmers are responsible for translating the solution
Qualities into a language that the computer can understand—a process called coding. Software engineer-
ing is a higher-level position that requires the ability to envision solutions. Using a construction
analogy, software engineers are the architects, while programmers are the carpenters.
Keep in mind that, depending on the employer and the size and complexity of the user’s ­problem,
the design and coding tasks may be performed by the same employee, no matter what his or her
job title is. In other words, it’s not unusual for a software engineer to code his or her solution, just
as it’s not unusual for a programmer to have designed the solution he or she is coding.

Copyright 2016 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.
3
A Brief History of Programming Languages 

Programmers and software engineers need to have strong problem-solving and analytical skills,
as well as the ability to communicate effectively with team members, end users, and other non-
technical personnel. Typically, computer software engineers are expected to have at least a bach-
elor’s degree in software engineering, computer science, or mathematics, along with practical
work experience, especially in the industry in which they are employed. Computer programmers
usually need at least an associate’s degree in computer science, mathematics, or information sys-
tems, as well as proficiency in one or more programming languages.
Computer programmers and software engineers are employed by companies in almost every
industry, such as telecommunications companies, software publishers, financial institutions,
insurance carriers, educational institutions, and government agencies. The Bureau of Labor
Statistics predicts that employment of computer software engineers will increase by 22 p ­ ercent
from 2012 to 2022. The employment of computer programmers, on the other hand, will
increase by 8 percent over the same period. In addition, consulting opportunities for freelance
­programmers and software engineers are expected to increase as companies look for ways to
reduce their payroll expenses.
There is a great deal of competition for programming and software engineering jobs, so jobseekers
will need to keep up to date with the latest programming languages and technologies. A competitive
edge may be gained by obtaining vendor-specific or language-specific certifications, as well as knowl-
edge of a prospective employer’s business. More information about computer programmers and
computer software engineers can be found on the Bureau of Labor Statistics Web site at www.bls.gov.

A Brief History of Programming Languages


Just as human beings communicate with each other through the use of languages such as E ­ nglish,
Spanish, Hindi, and Chinese, programmers use a variety of programming languages to commu-
nicate with the computer. In the next sections, you will follow the progression of ­programming
languages from machine languages to assembly languages, and then to high-level languages. Ch01-History

Machine Languages
Within a computer, all data is represented by microscopic electronic switches that can be either
off or on. The off switch is designated by a 0, and the on switch is designated by a 1. Because
computers can understand only these on and off switches, the first programmers had to write
the program instructions using nothing but combinations of 0s and 1s; for example, a program
might contain the instruction 00101 10001 10000. Instructions written in 0s and 1s are called
machine language or machine code. The machine languages (each type of machine has its
own language) represent the only way to communicate directly with the computer. As you can
imagine, programming in machine language is very tedious and error-prone and requires highly
trained programmers.

Assembly Languages
Slightly more advanced programming languages are called assembly languages. The assembly
languages simplify the programmer’s job by allowing the programmer to use mnemonics in
place of the 0s and 1s in the program. Mnemonics are memory aids—in this case, alphabetic
abbreviations for instructions. For example, most assembly languages use the mnemonic ADD
to represent an add operation and the mnemonic MUL to represent a multiply operation. An
­example of an instruction written in an assembly language is ADD bx, ax.
Programs written in an assembly language require an assembler, which also is a program,
to convert the assembly instructions into machine code—the 0s and 1s the computer can

Copyright 2016 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
Chapter 1 An Introduction to Programming

understand. Although it is much easier to write programs in assembly language than in machine
language, programming in assembly language still is tedious and requires highly trained
­programmers. Programs written in assembly language are machine specific and usually must be
rewritten in a different assembly language to run on different computers.

High-Level Languages
High-level languages represent the next major development in programming languages.
­ igh-level languages are a vast improvement over machine and assembly languages because
H
they allow the programmer to use instructions that more closely resemble the English language.
An example of an instruction written in a high-level language is grossPay = hours * rate. In
addition, high-level languages are more machine independent than are machine and assembly
languages. As a result, programs written in a high-level language can be used on many different
types of computers.
Programs written in a high-level language usually require a compiler, which also is a program,
to convert the English-like instructions into the 0s and 1s the computer can understand. Some
high-level languages also offer an additional program called an interpreter. Unlike a compiler,
which translates all of a program’s high-level instructions before running the program, an
­interpreter translates the instructions line by line as the program is running.
Like their predecessors, the first high-level languages were used to create procedure-oriented
programs. When writing a procedure-oriented program, the programmer concentrates on
the major tasks that the program needs to perform. A payroll program, for example, typically
performs several major tasks, such as inputting the employee data, calculating the gross pay,
calculating the taxes, calculating the net pay, and outputting a paycheck. The programmer must
instruct the computer every step of the way, from the start of the task to its completion. In a
procedure-oriented program, the programmer determines and controls the order in which the
computer processes the instructions. In other words, the programmer must determine not only
the proper instructions to give the computer but the correct sequence of those instructions as
well. Examples of high-level languages used to create procedure-oriented programs include
COBOL (Common Business-Oriented Language), BASIC (Beginner’s All-Purpose Symbolic
Instruction Code), and C.

Most objects More advanced high-level languages can be used to create object-oriented programs in ­addition
in an ­object- to procedure-oriented ones. Different from a procedure-oriented program, which focuses
oriented on the individual tasks the program must perform, an object-oriented program requires
program are the ­programmer to focus on the objects that the program can use to accomplish its goal. The
designed objects can take on many different forms. For example, programs written for the Windows
to perform multiple
­environment typically use objects such as check boxes, list boxes, and buttons. A payroll
tasks. These tasks are
­program, on the other hand, might utilize objects found in the real world, such as a time card
programmed using the
same techniques used object, an employee object, or a check object.
in procedure-oriented Because each object in an object-oriented program is viewed as an independent unit, an object
programming.
can be used in more than one program, usually with little or no modification. A check object
used in a payroll program, for example, also can be used in a sales revenue program (which
receives checks from customers) and an accounts payable program (which issues checks to
creditors). The ability to use an object for more than one purpose enables code reuse, which
saves ­programming time and money—an advantage that contributes to the popularity of

Copyright 2016 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.
5
Control Structures 

­ bject-oriented programming. Examples of high-level languages that can be used to create both
o
procedure-oriented and object-oriented programs include C++, Visual Basic, Java, and C#. In this
book, you will learn how to use the C++ programming language to create ­procedure-oriented
and object-oriented programs.

The answers
Mini-Quiz 1-1 to Mini-Quiz
­questions are
contained in the
1. Instructions written in 0s and 1s are called _________________________ language.
Answers.pdf file.
2. When writing a(n) _________________________ program, the programmer
­concentrates on the major tasks needed to accomplish a goal.
a. procedure-oriented
b. object-oriented

3. When writing a(n) _________________________ program, the programmer breaks up a


­problem into interacting objects.
a. procedure-oriented
b. object-oriented

4. Most high-level languages use a(n) _________________________ to translate the


instructions into a language that the computer can understand.

Control Structures
All computer programs, no matter how simple or how complex, are written using one or more
of three basic structures: sequence, selection, and repetition. These structures are called c
­ ontrol
structures or logic structures because they control the flow of a program’s logic. In other
words, they control the order in which the computer executes the program’s instructions. You
will use the sequence structure in every program you write. In most programs, you also will
use the selection and repetition structures. This chapter gives you an introduction to the three
control structures. More detailed information about each structure, as well as how to implement
these structures using the C++ language, is provided in subsequent chapters.

The Sequence Structure


You use the sequence structure each time you follow a set of step-by-step instructions, in order,
from beginning to end. The instructions might be a recipe for making chocolate chip cookies.
Or, they might be the MapQuest directions to your favorite restaurant. They could also be the
instructions for assembling a robot, which are shown in Figure 1-1. The instructions shown in
the figure are called an algorithm, which is a set of step-by-step instructions for accomplishing
a task.

Copyright 2016 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.
Discovering Diverse Content Through
Random Scribd Documents
dismissed without a character. She too wanders off forlorn into a
world that has no haven of rest or voice of welcome for her—
wanders off, without so much as a dirty bundle in her hand—
wanders off, voiceless, with the unchanging grin on the smut-
covered face. How shocked we should all be, if we opened a book
about a savage country, and saw a portrait of Number Two in the
frontispiece as a specimen of the female population!
Number Three comes to us all the way from Wales; arrives late one
evening, and is found at seven the next morning, crying as if she
would break her heart, on the door-step. It is the first time she has
been away from home. She has not got used yet to being a forlorn
castaway among strangers. She misses the cows of a morning, the
blessed fields with the blush of sunrise on them, the familiar faces,
the familiar sounds, the familiar cleanliness of her country home.
There is not the faintest echo of mother's voice, or of father's sturdy
footfall here. Sweetheart John Jones is hundreds of miles away; and
little brother Joe toddles up door-steps far from these to clamour for
the breakfast which he shall get this morning from other than his
sister's hands. Is there nothing to cry for in this? Absolutely nothing,
as Mrs. Glutch thinks. What does this Welsh barbarian mean by
clinging to my area-railings when she ought to be lighting the fire;
by sobbing in full view of the public of Smeary Street when the
lodgers' bells are ringing angrily for breakfast? Will nothing get the
girl in-doors? Yes, a few kind words from the woman who passes by
her with my breakfast will. She knows that the Welsh girl is hungry
as well as home-sick, questions her, finds out that she has had no
supper after her long journey, and that she has been used to
breakfast with the sunrise at the farm in Wales. A few merciful
words lure her away from the railings, and a little food inaugurates
the process of breaking her in to London service. She has but a few
days allowed her, however, to practise the virtue of dogged
resignation in her first place. Before she has given me many
opportunities of studying her character, before she has done knitting
her brows with the desperate mental effort of trying to comprehend
the mystery of my illness, before the smut has fairly settled on her
rosy cheeks, before the London dirt has dimmed the pattern on her
neat print gown, she, too, is cast adrift into the world. She has not
suited Mrs. Glutch (being, as I imagine, too offensively clean to form
an appropriate part of the kitchen furniture)—a friendly maid-of-all-
work, in service near us, has heard of a place for her—and she is
forthwith sent away to be dirtied and deadened down to her proper
social level in another Lodging-house.
With her, my studies of character among maids-of-all-work come to
an end. I hear vague rumours of the arrival of Number Four. But
before she appears, I have got the doctor's leave to move into the
country, and have terminated my experience of London lodgings, by
making my escape with all convenient speed from the perpetual
presence and persecutions of Mrs. Glutch. I have witnessed some
sad sights during my stay in Smeary Street, which have taught me
to feel for my poor and forlorn fellow-creatures as I do not think I
ever felt for them before, and which have inclined me to doubt for
the first time whether worse calamities might not have overtaken me
than the hardship of falling ill.
SKETCHES OF CHARACTER.—II.
A SHOCKINGLY RUDE ARTICLE.

[Communicated by A Charming Woman.]


Before I begin to write, I know that this will be an unpopular
composition in certain select quarters. I mean to proceed with it,
however, in spite of that conviction, because when I have got
something on my mind, I must positively speak. Is it necessary, after
that, to confess that I am a woman? If it is, I make the confession—
to my sorrow. I would much rather be a man.
I hope nobody will be misled by my beginning in this way, into
thinking that I am an advocate of the rights of women. Ridiculous
creatures! they have too many rights already; and if they don't hold
their chattering tongues, one of these days the poor dear deluded
men will find them out.
The poor dear men! Mentioning them reminds me of what I have
got to say. I have been staying at the seaside, and reading an
immense quantity of novels and periodicals, and all that sort of
thing, lately; and my idea is, that the men-writers (the only writers
worth reading) are in the habit of using each other very unfairly in
books and articles, and so on. Look where I may, I find, for instance,
that the large proportion of the bad characters in their otherwise
very charming stories, are always men. As if women were not a
great deal worse! Then, again, most of the amusing fools in their
books are, strangely and unaccountably, of their own sex, in spite of
its being perfectly apparent that the vast majority of that sort of
character is to be found in ours. On the other hand, while they make
out their own half of humanity (as I have distinctly proved) a great
deal too bad, they go to the contrary extreme the other way, and
make out our half a great deal too good. What in the world do they
mean by representing us as so much better, and so much prettier,
than we really are? Upon my word, when I see what angels the dear
nice good men make of their heroines, and when I think of myself,
and of the whole circle of my female friends besides, I feel quite
disgusted,—I do, indeed.
I should very much like to go into the whole of this subject at once,
and speak my sentiments on it at the fullest length. But I will spare
the reader, and try to be satisfied with going into a part of the
subject instead; for, considering that I am a woman, and making
immense allowances for me on that account, I am really not
altogether unreasonable. Give me a page or two, and I will show in
one particular, and, what is more, from real life, how absurdly partial
the men-writers are to our sex, and how scandalously unjust they
are to their own.
Bores.—What I propose is, that we take for our present example
characters of Bores alone. If we were only to read men's novels,
articles, and so forth, I don't hesitate to say we should assume that
all the Bores in the human creation were of the male sex. It is
generally, if not always, a man, in men's books, who tells the long-
winded story, and turns up at the wrong time, and makes himself
altogether odious and intolerable to everybody he comes in contact
with, without being in the least aware of it himself. How very unjust,
and, I must be allowed to add, how extremely untrue! Women are
quite as bad, or worse. Do, good gentlemen, look about you
impartially, for once in a way, and own the truth. Good gracious! is
not society full of Lady-Bores? Why not give them a turn when you
write next?
Two instances: I will quote only two instances out of hundreds I
could produce from my own acquaintance. Only two: because, as I
said before, I am reasonable about not taking up room. I can put
things into a very small space when I write, as well as when I travel.
I should like the literary gentleman who kindly prints this (I would
not allow a woman to print it for any sum of money that could be
offered me) to see how very little luggage I travel with. At any rate,
he shall see how little room I can cheerfully put up with in these
pages.
My first Lady-Bore—see how quickly I get to the matter in hand,
without wasting so much as a single line in prefatory phrases!—my
first Lady-Bore is Miss Sticker. I don't in the least mind mentioning
her name; because I know, if she got the chance, she would do just
the same by me. It is of no use disguising the fact, so I may as well
confess at once that Miss Sticker is a fright. Far be it from me to give
pain where the thing can by any means be avoided; but if I were to
say that Miss Sticker would ever see forty again, I should be guilty of
an unwarrantable deception on the public. I have the strongest
imaginable objection to mentioning the word petticoats; but if that is
the only possible description of Miss Sticker's figure which conveys a
true notion of its nature and composition, what am I to do? Perhaps
I had better give up describing the poor thing's personal
appearance. I shall get into deeper and deeper difficulties, if I
attempt to go on. The very last time I was in her company, we were
strolling about Regent Street, with my sister's husband for escort. As
we passed a hairdresser's shop, the dear simple man looked in, and
asked me what those long tails of hair were for, that he saw hanging
up in the windows. Miss Sticker, poor soul, was on his arm, and
heard him put the question. I thought I should have dropped.
This is, I believe, what you call a digression. I shall let it stop in,
however, because it will probably explain to the judicious reader why
I carefully avoid the subject—the meagre subject, an ill-natured
person might say—of Miss Sticker's hair. Suppose I pass on to what
is more importantly connected with the object of these pages—
suppose I describe Miss Sticker's character next.
Some extremely sensible man has observed somewhere, that a Bore
is a person with one idea. Exactly so. Miss Sticker is a person with
one idea. Unhappily for society, her notion is, that she is bound by
the laws of politeness to join in every conversation which happens to
be proceeding within the range of her ears. She has no ideas, no
information, no flow of language, no tact, no power of saying the
right word at the right time, even by chance. And yet she will
converse, as she calls it. "A gentlewoman, my dear, becomes a mere
cipher in society unless she can converse." That is her way of
putting it; and I deeply regret to add, she is one of the few people
who preach what they practise. Her course of proceeding is, first, to
check the conversation by making a remark which has no kind of
relation to the topic under discussion. She next stops it altogether by
being suddenly at a loss for some particular word which nobody can
suggest. At last the word is given up; another subject is started in
despair; and the company become warmly interested in it. Just at
that moment, Miss Sticker finds the lost word; screams it out
triumphantly in the middle of the talk; and so scatters the second
subject to the winds, exactly as she has already scattered the first.
The last time I called at my aunt's—I merely mention this by way of
example—I found Miss Sticker there, and three delightful men. One
was a clergyman of the dear old purple-faced Port-wine school. The
other two would have looked military, if one of them had not been
an engineer, and the other an editor of a newspaper. We should
have had some delightful conversation if the Lady-Bore had not been
present. In some way, I really forget how, we got to talking about
giving credit and paying debts; and the dear old clergyman, with his
twinkling eyes and his jolly voice, treated us to a professional
anecdote on the subject.
"Talking about that," he began, "I married a man the other day for
the third time. Man in my parish. Capital cricketer when he was
young enough to run. 'What's your fee?' says he. 'Licensed
marriage?' says I; 'guinea of course.'—'I've got to bring you your
tithes in three weeks, sir,' says he; 'give me tick till then.' 'All right,'
says I, and married him. In three weeks he comes and pays his
tithes like a man. 'Now, sir,' says he, 'about this marriage-fee, sir? I
do hope you'll kindly let me off at half-price, for I have married a
bitter bad 'un this time. I've got a half-a-guinea about me, sir, if
you'll only please to take it. She isn't worth a farthing more—on the
word of a man, she isn't, sir!' I looked hard in his face, and saw two
scratches on it, and took the half-guinea, more out of pity than
anything else. Lesson to me, however. Never marry a man on credit
again, as long as I live. Cash on all future occasions—cash down, or
no marriage!"
While he was speaking, I had my eye on Miss Sticker. Thanks to the
luncheon which was on the table, she was physically incapable of
"conversing" while our reverend friend was telling his humorous little
anecdote. Just as he had done, and just as the editor of the
newspaper was taking up the subject, she finished her chicken, and
turned round from the table.
"Cash down, my dear sir, as you say," continued the editor. "You
exactly describe our great principle of action in the Press. Some of
the most extraordinary and amusing things happen with subscribers
to newspapers——"
"Ah, the Press!" burst in Miss Sticker, beginning to converse. "What a
wonderful engine! and how grateful we ought to feel when we get
the paper so regularly every morning at breakfast. The only question
is—at least, many people think so—I mean with regard to the Press,
the only question is whether it ought to be——"
Here Miss Sticker lost the next word, and all the company had to
look for it.
"With regard to the Press, the only question is, whether it ought to
be——O, dear, dear, dear me!" cried Miss Sticker, lifting both her
hands in despair, "what is the word?"
"Cheaper?" suggested our reverend friend. "Hang it, ma'am! it can
hardly be that, when it is down to a penny already."
"O no; not cheaper," said Miss Sticker.
"More independent?" inquired the editor. "If you mean that, I defy
anybody to find more fearless exposures of corruption——"
"No, no!" cried Miss Sticker, in an agony of polite confusion. "I didn't
mean that. More independent wasn't the word."
"Better printed?" suggested the engineer.
"On better paper?" added my aunt.
"It can't be done—if you refer to the cheap press—it can't be done
for the money," interposed the editor, irritably.
"O, but that's not it!" continued Miss Sticker, wringing her bony
fingers, with horrid black mittens on them. "I didn't mean to say
better printed, or better paper. It was one word I meant, not two.—
With regard to the Press," pursued Miss Sticker, repeating her own
ridiculous words carefully, as an aid to memory, "the only question
is, whether it ought to be——Bless my heart, how extraordinary!
Well, well, never mind: I'm quite shocked, and ashamed of myself.
Pray go on talking, and don't notice me."
It was all very well to say, Go on talking; but the editor's amusing
story about subscribers to newspapers, had been, by this time,
fatally interrupted. As usual, Miss Sticker had stopped us in full flow.
The engineer considerately broke the silence by starting another
subject.
"Here are some wedding-cards on your table," he said, to my aunt,
"which I am very glad to see there. The bridegroom is an old friend
of mine. His wife is really a beauty. You know how he first became
acquainted with her? No? It was quite an adventure, I assure you.
One evening he was on the Brighton Railway; last down train. A
lovely girl in the carriage; our friend Dilberry immensely struck with
her. Got her to talk after a long time, with great difficulty. Within half
an hour of Brighton, the lovely girl smiles, and says to our friend,
'Shall we be very long now, sir, before we get to Gravesend?' Case of
confusion at that dreadful London Bridge Terminus. Dilberry
explained that she would be at Brighton in half an hour, upon which
the lovely girl instantly and properly burst into tears. 'O, what shall I
do! O, what will my friends think!' Second flood of tears.—'Suppose
you telegraph?' says Dilberry soothingly.—'O, but I don't know how!'
says the lovely girl. Out comes Dilberry's pocket-book. Sly dog! he
saw his way now to finding out who her friends were. 'Pray let me
write the necessary message for you,' says Dilberry. 'Who shall I
direct to at Gravesend?'—'My father and mother are staying there
with some friends,' says the lovely girl. 'I came up with a day-ticket,
and I saw a crowd of people when I came back to the station, all
going one way, and I was hurried and frightened, and nobody told
me, and it was late in the evening, and the bell was ringing, and, O
Heavens! what will become of me!' Third burst of tears.—'We will
telegraph to your father,' says Dilberry. 'Pray don't distress yourself.
Only tell me who your father is.'—'Thank you a thousand times,'
says the lovely girl, 'my father is——'"
"Anonymous!" shouts Miss Sticker, producing her lost word with a
perfect burst of triumph. "How glad I am I remembered it at last!
Bless me," exclaims the Lady-Bore, quite unconscious that she has
brought the engineer's story to an abrupt conclusion, by giving his
distressed damsel an anonymous father; "Bless me! what are you all
laughing at? I only meant to say that the question with regard to the
Press was, whether it ought to be anonymous. What in the world is
there to laugh at in that? I really don't see the joke."
And this woman escapes scot-free, while comparatively innocent
men are held up to ridicule, in novel after novel, by dozens at a
time! When will the deluded male writers see my sex in its true
colours, and describe it accordingly? When will Miss Sticker take her
proper place in the literature of England?

My second Lady-Bore is that hateful creature, Mrs. Tincklepaw.


Where, over the whole interesting surface of male humanity
(including Cannibals)—where is the man to be found whom it would
not be scandalous to mention in the same breath with Mrs.
Tincklepaw? The great delight of this shocking woman's life, is to
squabble with her husband (poor man, he has my warmest
sympathy and best good wishes), and then to bring the quarrel away
from home with her, and to let it off again at society in general, in a
series of short spiteful hints. Mrs. Tincklepaw is the exact opposite of
Miss Sticker. She is a very little woman; she is (and more shame for
her, considering how she acts) young enough to be Miss Sticker's
daughter; and she has a kind of snappish tact in worrying innocent
people, under every possible turn of circumstances, which
distinguishes her (disgracefully) from the poor feeble-minded Maid-
Bore, to whom the reader has been already introduced. Here are
some examples—all taken, be it observed, from my own personal
observation—of the manner in which Mrs. Tincklepaw contrives to
persecute her harmless fellow-creatures wherever she happens to
meet with them:
Let us say I am out walking, and I happen to meet Mr. and Mrs.
Tincklepaw. (By the bye, she never lets her husband out of her sight
—he is too necessary to the execution of her schemes of petty
torment. And such a noble creature, to be used for so base a
purpose! He stands six feet two, and is additionally distinguished by
a glorious and majestic stoutness, which has no sort of connection
with the comparatively comic element of fat. His nature, considering
what a wife he has got, is inexcusably meek and patient. Instead of
answering her, he strokes his magnificent flaxen whiskers, and looks
up resignedly at the sky. I sometimes fancy that he stands too high
to hear what his dwarf of a wife says. For his sake, poor man, I hope
this view of the matter may be the true one.)
I am afraid I have contrived to lose myself in a long parenthesis.
Where was I? O! out walking and happening to meet with Mr. and
Mrs. Tincklepaw. She has had a quarrel with her husband at home,
and this is how she contrives to let me know it.
"Delightful weather, dear, is it not?" I say, as we shake hands.
"Charming, indeed," says Mrs. Tincklepaw. "Do you know, love, I am
so glad you made that remark to me, and not to Mr. Tincklepaw?"
"Really?" I ask. "Pray tell me why?"
"Because," answers the malicious creature, "if you had said it was a
fine day to Mr. Tincklepaw, I should have been so afraid of his
frowning at you directly, and saying, 'Stuff! talk of something worth
listening to, if you talk at all.' What a love of a bonnet you have got
on! and how Mr. Tincklepaw would have liked to be staying in your
house when you were getting ready to-day to go out. He would have
waited for you so patiently, dear. He would never have stamped in
the passage; and no such words as, 'Deuce take the woman! is she
going to keep me here all day?' would by any possibility have
escaped his lips. Don't love! don't look at the shops, while Mr.
Tincklepaw is with us. He might say, 'Oh, bother! you're always
wanting to buy something!' I shouldn't like that to happen. Should
you, dear?"
Once more. Say I meet Mr. and Mrs. Tincklepaw at a dinner-party,
given in honour of a bride and bridegroom. From the instant when
she enters the house, Mrs. Tincklepaw never has her eye off the
young couple. She looks at them with an expression of heart-broken
curiosity. Whenever they happen to speak to each other, she
instantly suspends any conversation in which she is engaged, and
listens to them with a mournful eagerness. When the ladies retire,
she gets the bride into a corner; appropriates her to herself for the
rest of the evening; and persecutes the wretched young woman in
this manner:—
"May I ask, is this your first dinner, since you came back?"
"O, no! we have been in town for some weeks."
"Indeed? I should really have thought, now, that this was your first
dinner."
"Should you? I can't imagine why."
"How very odd, when the reason is as plain as possible! Why, I
noticed you all dinner time, eating and drinking what you liked,
without looking at your husband for orders. I saw nothing rebellious
in your face when you eat all these nice sweet things at dessert.
Dear! dear! don't you understand? Do you really mean to say that
your husband has not begun yet? Did he not say, as you drove here
to day, 'Now, mind, I'm not going to have another night's rest
broken, because you always choose to make yourself ill with stuffing
creams and sweets, and all that sort of thing?' No!!! Mercy on me,
what an odd man he must be! Perhaps he waits till he gets home
again? O, come, come, you don't mean to tell me that he doesn't
storm at you frightfully, for having every one of your glasses filled
with wine, and then never touching a drop of it, but asking for cold
water instead, at the very elbow of the master of the house? If he
says, 'Cursed perversity, and want of proper tact' once, I know he
says it a dozen times. And as for treading on your dress in the hall,
and then bullying you before the servant, for not holding it up out of
his way, it's too common a thing to be mentioned—isn't it? Did you
notice Mr. Tincklepaw particularly? Ah, you did, and you thought he
looked good-natured? No! no! don't say any more; don't say you
know better than to trust to appearances. Please do take leave of all
common sense and experience, and pray trust to appearances,
without thinking of their invariable deceitfulness, this once. Do, dear,
to oblige me."
I might fill pages with similar examples of the manners and
conversation of this intolerable Lady-Bore. I might add other equally
aggravating characters, to her character and to Miss Sticker's,
without extending my researches an inch beyond the circle of my
own acquaintance. But I am true to my unfeminine resolution to
write as briefly as if I were a man; and I feel that I have said
enough, already, to show that I can prove my case. When a woman
like me can produce, without the least hesitation, or the slightest
difficulty, two such instances of Lady-Bores as I have just exhibited,
the additional number which she might pick out of her list, after a
little mature reflection, may be logically inferred by all impartial
readers.
In the meantime, let me hope I have succeeded sufficiently well in
my present purpose to induce our next great satirist to pause before
he, too, attacks his harmless fellow-men, and to make him turn his
withering glance in the direction of our sex. Let all rising young
gentlemen who are racking their brains in search of originality, take
the timely hint which I have given them in these pages. Let us have
a new fictitious literature, in which not only the Bores shall be
women, but the villains too. Look at Shakespeare—do, pray, look at
Shakespeare. Who is most in fault, in that shocking business of the
murder of King Duncan? Lady Macbeth, to be sure! Look at King
Lear, with a small family of only three daughters, and two of the
three, wretches; and even the third an aggravating girl, who can't be
commonly civil to her own father in the first Act, out of sheer
contradiction, because her elder sisters happen to have been civil
before her. Look at Desdemona, who falls in love with a horrid
copper-coloured foreigner, and then, like a fool, instead of managing
him, aggravates him into smothering her. Ah! Shakespeare was a
great man, and knew our sex, and was not afraid to show he knew
it. What a blessing it would be, if some of his literary brethren, in
modern times, could muster courage enough to follow his example!
I have fifty different things to say, but I shall bring myself to a
conclusion by only mentioning one of them. If it would at all
contribute towards forwarding the literary reform that I advocate, to
make a present of the characters of Miss Sticker and Mrs.
Tincklepaw, to modern writers of fiction, I shall be delighted to
abandon all right of proprietorship in those two odious women. At
the same time, I think it fair to explain that when I speak of modern
writers, I mean gentlemen-writers only. I wish to say nothing uncivil
to the ladies who compose books, whose effusions may, by the rule
of contraries, be exceedingly agreeable to male readers; but I
positively forbid them to lay hands upon my two characters. I am
charmed to be of use to the men, in a literary point of view, but I
decline altogether to mix myself up with the women. There need be
no fear of offending them by printing this candid expression of my
intentions. Depend on it, they will all declare, on their sides, that
they would much rather have nothing to do with me.
NOOKS AND CORNERS OF HISTORY.

II.
THE GREAT (FORGOTTEN) INVASION.

Preamble.
It happened some sixty years ago; it was a French invasion; and it
actually took place in England. Thousands of people are alive at the
present moment, who ought to remember it perfectly well. And yet it
has been forgotten. In these times, when the French invasion that
may come, turns up perpetually, in public and in private, as a subject
of discussion—the French invasion that did come, is not honoured
with so much as a passing word of notice. The new generation
knows nothing about it. The old generation has carelessly forgotten
it. This is discreditable, and it must be set right; this is a dangerous
security, and it must be disturbed; this is a gap in the Modern
History of England, and it must be filled up.
Fathers and mothers, read and be reminded; British youths and
maidens, read and be informed. Here follows the true history of the
great forgotten Invasion of England, at the end of the last century;
divided into scenes and periods, and carefully derived from proved
and written facts recorded in Kelly's History of the Wars:
I. Of the French Invasion as seen from Ilfracombe.
On the twenty-second day of February, in the year seventeen
hundred and ninety-seven, the inhabitants of North Devonshire
looked towards the Bristol Channel, and saw the French invasion
coming on, in four ships.
The Directory of the French Republic had been threatening these
islands some time previously; but much talk and little action having
characterised the proceedings of that governing body in most other
matters, no great apprehension was felt of their really carrying out
their expressed intention in relation to this country. The war
between the two nations was, at this time, confined to naval
operations, in which the English invariably got the better of the
French. North Devonshire (as well as the rest of England) was aware
of this, and trusted implicitly in our supremacy of the seas. North
Devonshire got up on the morning of the twenty-second of February,
without a thought of the invasion; North Devonshire looked out
towards the Bristol Channel, and there—in spite of our supremacy of
the seas—there the invasion was, as large as life.
Of the four ships which the Directory had sent to conquer England,
two were frigates and two were smaller vessels. This formidable
fleet sailed along, in view of a whole panic-stricken, defenceless
coast; and the place at which it seemed inclined to try the invading
experiment first, was Ilfracombe. The commander of the expedition
brought his ships up before the harbour, scuttled a few coasting
vessels, prepared to destroy the rest, thought better of it, and
suddenly turned his four warlike sterns on North Devonshire, in the
most unaccountable manner. History is silent as to the cause of this
abrupt and singular change of purpose. Did the chief of the invaders
act from sheer indecision? Did he distrust the hotel accommodation
at Ilfracombe? Had he heard of the clotted cream of Devonshire, and
did he apprehend the bilious disorganisation of the whole army, if
they once got within reach of that luscious delicacy? These are
important questions, but no satisfactory answer can be found to
them. The motives which animated the commander of the invading
Frenchmen, are buried in oblivion: the fact alone remains, that he
spared Ilfracombe. The last that was seen of him from North
Devonshire, he was sailing over ruthlessly to the devoted coast of
Wales.
II. Of the French Invasion as seen by Welshmen in general.
In one respect it may be said that Wales was favoured by
comparison with North Devonshire. The great fact of the French
invasion had burst suddenly on Ilfracombe; but it only dawned in a
gradual manner on the coast of Pembrokeshire. In the course of his
cruise across the Bristol Channel, it had apparently occurred to the
commander of the expedition, that a little diplomatic deception, at
the outset, might prove to be of ultimate advantage to him. He
decided, therefore, on concealing his true character from the eyes of
the Welshmen; and when his four ships were first made out, from
the heights above Saint Bride's Bay, they were all sailing under
British colours.
There are men in Wales, as in the rest of the world, whom it is
impossible to satisfy; and there were spectators on the heights of
Saint Bride's who were not satisfied with the British colours, on this
occasion, because they felt doubtful about the ships that bore them.
To the eyes of these sceptics all four vessels had an unpleasantly
French look, and manœuvred in an unpleasantly French manner.
Wise Welshmen along the coast collected together by twos and
threes, and sat down on the heights, and looked out to sea, and
shook their heads, and suspected. But the majority, as usual, saw
nothing extraordinary where nothing extraordinary appeared to be
intended; and the country was not yet alarmed; and the four ships
sailed on till they doubled Saint David's Head; and sailed on again, a
few miles to the northward; and then stopped, and came to single
anchor in Cardigan Bay.
Here, again, another difficult question occurs, which recalcitrant
History once more declines to solve. The Frenchmen had hardly
been observed to cast their single anchors in Cardigan Bay, before
they were also observed to pull them up again, and go on. Why?
The commander of the expedition had doubted already at
Ilfracombe—was he doubting again in Cardigan Bay? Or did he
merely want time to mature his plans; and was it a peculiarity of his
nature that he always required to come to anchor before he could
think at his ease? To this mystery, as to the mystery at Ilfracombe,
there is no solution; and here, as there, nothing is certainly known
but that the Frenchman paused—threatened—and then sailed on.
III. Of One Welshman in Particular, and of what he saw.
He was the only man in Great Britain who saw the invading army
land on our native shores—and his name has perished.
It is known that he was a Welshman, and that he belonged to the
lower order of the population. He may be still alive—this man, who is
connected with a crisis in English History, may be still alive—and
nobody has found him out; nobody has taken his photograph;
nobody has written a genial biographical notice of him; nobody has
made him into an Entertainment; nobody has held a
Commemoration of him; nobody has presented him with a
testimonial, relieved him by a subscription, or addressed him with a
speech. In these enlightened times, this brief record can only single
him out and individually distinguish him—as the Hero of the
Invasion. Such is Fame.
The Hero of the Invasion, then, was standing, or sitting—for even on
this important point tradition is silent—on the cliffs of the Welsh
coast, near Lanonda Church, when he saw the four ships enter the
bay below him, and come to anchor—this time, without showing any
symptoms of getting under weigh again. The English colours, under
which the Expedition had thus far attempted to deceive the
population of the coast, were now hauled down, and the threatening
flag of France was boldly hoisted in their stead. This done, the boats
were lowered away, were filled with a ferocious soldiery, and were
pointed straight for the beach.
It is on record that the Hero of the Invasion distinctly saw this; and
it is not on record that he ran away. Honour to the unknown brave!
Honour to the solitary Welshman who faced the French army!
The boats came on straight to the beach—the ferocious soldiery
leapt out on English soil, and swarmed up the cliff, thirsting for the
subjugation of the British Isles. The Hero of the Invasion, watching
solitary on the cliffs, saw the Frenchmen crawling up below him—
tossing their muskets on before them—climbing with the cool
calculation of an army of chimney-sweeps—nimble as the monkey,
supple as the tiger, stealthy as the cat—hungry for plunder,
bloodshed, and Welsh mutton—void of all respect for the British
Constitution—an army of Invaders on the Land of the Habeas
Corpus!
The Welshman saw that, and vanished. Whether he waited with
clenched fist till the head of the foremost Frenchman rose parallel
with the cliff-side, or whether he achieved a long start, by letting the
army get half-way up the cliff, and then retreating inland to give the
alarm—is, like every other circumstance in connection with the Hero
of the Invasion, a matter of the profoundest doubt. It is only known
that he got away at all, because it is not known that he was taken
prisoner. He parts with us here, the shadow of a shade, the most
impalpable of historical apparitions. Honour, nevertheless, to the
crafty brave! Honour to the solitary Welshman who faced the French
army without being shot, and retired from the French army without
being caught!
IV. Of what the Invaders did when they got on shore.
The Art of Invasion has its routine, its laws, manners, and customs,
like other Arts. And the French army acted strictly in accordance with
established precedents. The first thing the first men did, when they
got to the top of the cliff, was to strike a light and set fire to the
furze-bushes. While national feeling deplores this destruction of
property, unprejudiced History looks on at her ease. Given Invasion
as a cause, fire follows, according to all known rules, as an effect. If
an army of Englishmen had been invading France under similar
circumstances, they, on their side, would necessarily have begun by
setting fire to something; and unprejudiced History would, in that
case also, have looked on at her ease.
While the furze-bushes were blazing, the remainder of the invaders
—assured by the sight of the flames, of their companions' success so
far—was disembarking, and swarming up the rocks. When it was
finally mustered on the top of the cliff, the army amounted to
fourteen hundred men. This was the whole force which the Directory
of the French Republic had thought it desirable to despatch for the
subjugation of Great Britain. History, until she is certain of results,
will pronounce no opinion on the wisdom of this proceeding. She
knows that nothing in politics, is abstractedly rash, cruel,
treacherous, or disgraceful—she knows that Success is the sole
touchstone of merit—she knows that the man who fails is
contemptible, and the man who succeeds is illustrious, without any
reference to the means used in either case; to the character of the
men; or to the nature of the motives under which they may have
proceeded to action. If the Invasion succeeds, History will applaud it
as an act of heroism: if it fails, History will condemn it as an act of
folly.
It has been said that the Invasion began creditably, according to the
rules established in all cases of conquering. It continued to follow
those rules with the most praiseworthy regularity. Having started
with setting something on fire, it went on, in due course, to
accomplish the other first objects of all Invasions, thieving and killing
—performing much of the former, and little of the latter. Two rash
Welshmen, who persisted in defending their native leeks, suffered
accordingly: the rest lost nothing but their national victuals, and
their national flannel. On this first day of the Invasion, when the
army had done marauding, the results on both sides may be thus
summed up. Gains to the French:—good dinners, and protection
next the skin. Loss to the English:—mutton, stout Welsh flannel, and
two rash countrymen.
V. Of the British Defence, and of the way in which the women
contributed to it.
The appearance of the Frenchmen on the coast, and the loss to the
English, mentioned above, produced the results naturally to be
expected. The country was alarmed, and started up to defend itself.
On the numbers of the invaders being known, and on its being
discovered that, though they were without field-pieces, they had
with them seventy cart-loads of powder and ball, and a quantity of
grenades, the principal men in the country bestirred themselves in
setting up the defence. Before nightfall, all the available men who
knew anything of the art of fighting were collected. When the ranks
were drawn out, the English defence was even more ridiculous in
point of numbers than the French attack. It amounted, at a time
when we were at war with France, and were supposed to be
prepared for any dangers that might threaten—it amounted,
including militia, fencibles, and yeomanry cavalry, to just six hundred
and sixty men, or, in other words, to less than half the number of
the invading Frenchmen.
Fortunately for the credit of the nation, the command of this
exceedingly compact force was taken by the principal grandee in the
neighbourhood. He turned out to be a man of considerable cunning,
as well as a man of high rank; and he was known by the style and
title of the Earl of Cawdor.
The one cheering circumstance in connection with the heavy
responsibility which now rested on the shoulders of the Earl,
consisted in this: that he had apparently no cause to dread internal
treason as well as foreign invasion. The remarkably inconvenient
spot which the French had selected for their landing, showed, not
only that they themselves knew nothing of the coast, but that none
of the inhabitants, who might have led them to an easier place of
disembarkation, were privy to their purpose. So far so good. But still,
the great difficulty remained of facing the French with an equality of
numbers, and with the appearance, at least, of an equality of
discipline. The first of these requisites it was easy to fulfil. There
were hosts of colliers and other labourers in the neighbourhood,—
big, bold, lusty fellows enough; but so far as the art of marching and
using weapons was concerned, as helpless as a pack of children.
The question was, how to make good use of these men for show-
purposes, without allowing them fatally to embarrass the
proceedings of their trained and disciplined companions. In this
emergency, Lord Cawdor hit on a grand Idea. He boldly mixed the
women up in the business—and it is unnecessary to add, that the
business began to prosper from that lucky moment.
In those days, the wives of the Welsh labourers wore, what the
wives of all classes of the community have been wearing since—red
petticoats. It was Lord Cawdor's happy idea to call on these patriot-
matrons to sink the question of skirts; to forego the luxurious
consideration of warmth; and to turn the colliers into military men
(so far as external appearances, viewed at a distance, were
concerned), by taking off the wives' red petticoats and putting them
over the husbands' shoulders. Where patriot-matrons are concerned,
no national appeal is made in vain, and no personal sacrifice is
refused. All the women seized their strings, and stepped out of their
petticoats on the spot. What man in that make-shift military but
must think of "home and beauty," now that he had the tenderest
memento of both to grace his shoulders and jog his memory? In an
inconceivably short space of time every woman was shivering, and
every collier was turned into a soldier.
VI. Of how it all ended.
Thus recruited, Lord Cawdor marched off to the scene of action; and
the patriot women, deprived of their husbands and their petticoats,
retired, it is to be hoped and presumed, to the friendly shelter of
bed. It was then close on nightfall, if not actually night; and the
disorderly marching of the transformed colliers could not be
perceived. But, when the British army took up its position, then was
the time when the excellent stratagem of Lord Cawdor told at its
true worth. By the uncertain light of fires and torches, the French
scouts, let them venture as near as they might, could see nothing in
detail. A man in a scarlet petticoat looked as soldier-like as a man in
a scarlet coat, under those dusky circumstances. All that the enemy
could now see were lines on lines of men in red, the famous uniform
of the English army.
The council of the French braves must have been a perturbed
assembly on that memorable night. Behind them, was the empty bay
—for the four ships, after landing the invaders, had set sail again for
France, sublimely indifferent to the fate of the fourteen hundred.
Before them, there waited in battle array an apparently formidable
force of British soldiers. Under them was the hostile English ground
on which they were trespassers caught in the fact. Girt about by
these serious perils, the discreet commander of the Invasion fell
back on those safeguards of caution and deliberation of which he
had already given proofs on approaching the English shore. He had
doubted at Ilfracombe; he had doubted again in Cardigan Bay; and
now, on the eve of the first battle, he doubted for the third time—
doubted, and gave in. If History declines to receive the French
commander as a hero, Philosophy opens her peaceful doors to him,
and welcomes him in the character of a wise man.
At ten o'clock that night, a flag of truce appeared in the English
camp, and a letter was delivered to Lord Cawdor from the prudent
chief of the invaders. The letter set forth, with amazing gravity and
dignity, that the circumstances under which the French troops had
landed, having rendered it "unnecessary" to attempt any military
operations, the commanding officer did not object to come forward
generously and propose terms of capitulation. Such a message as
this was little calculated to impose on any man—far less on the artful
nobleman who had invented the stratagem of the red petticoats.
Taking a slightly different view of the circumstances, and declining
altogether to believe that the French Directory had sent fourteen
hundred men over to England to divert the inhabitants by the
spectacle of a capitulation, Lord Cawdor returned for answer that he
did not feel himself at liberty to treat with the French commander,
except on the condition of his men surrendering as prisoners of war.
On receiving this reply, the Frenchman gave an additional proof of
that philosophical turn of mind which has been already claimed for
him as one of his merits, by politely adopting the course which Lord
Cawdor suggested. By noon the next day, the French troops were all
marched off, prisoners of war—the patriot-matrons had resumed
their petticoats—and the short terror of the invasion had happily
passed away.
The first question that occurred to everybody, as soon as the alarm
had been dissipated, was, what this extraordinary burlesque of an
invasion could possibly mean. It was asserted, in some quarters,
that the fourteen hundred Frenchmen had been recruited from those
insurgents of La Vendée who had enlisted in the service of the
Republic, who could not be trusted at home, and who were
therefore despatched on the first desperate service that might offer
itself abroad. Others represented the invading army as a mere gang
of galley-slaves and criminals in general, who had been landed on
our shores with the double purpose of annoying England and ridding
France of a pack of rascals. The commander of the expedition,
however, disposed of this latter theory by declaring that six hundred
of his men were picked veterans from the French army, and by
referring, for corroboration of this statement, to his large supplies of
powder, ball, and hand-grenades, which would certainly not have
been wasted, at a time when military stores were especially
precious, on a gang of galley-slaves.
The truth seems to be, that the French (who were even more
densely ignorant of England and English institutions at that time
than they are at this) had been so entirely deceived by false reports
of the temper and sentiments of our people, as to believe that the
mere appearance of the troops of the Republic on these Monarchical
shores, would be the signal for a revolutionary rising of all the
disaffected classes from one end of Great Britain to the other.
Viewed merely as materials for kindling the insurrectionary spark,
the fourteen hundred Frenchmen might certainly be considered
sufficient for the purpose—providing the Directory of the Republic
could only have made sure beforehand that the English tinder might
be depended on to catch light!
One last event must be recorded before this History can be
considered complete. The disasters of the invading army, on shore,
were matched, at sea, by the disasters of the vessels that had
carried them. Of the four ships which had alarmed the English coast,
the two largest (the frigates) were both captured, as they were
standing in for Brest Harbour, by Sir Harry Neale. This smart and
final correction of the fractious little French invasion was
administered on the ninth of March, seventeen hundred and ninety-
seven.
Moral.
This is the history of the Great (Forgotten) Invasion. It is short, it is
not impressive, it is unquestionably deficient in serious interest. But
there is a Moral to be drawn from it, nevertheless. If we are invaded
again, and on a rather larger scale, let us not be so ill-prepared, this
next time, as to be obliged to take refuge in our wives' red
petticoats.
CURIOSITIES OF LITERATURE.—I.
THE UNKNOWN PUBLIC.

Do the customers at publishing-houses, the members of book-clubs


and circulating libraries, and the purchasers and borrowers of
newspapers and reviews, compose altogether the great bulk of the
reading public of England? There was a time when, if anybody had
put this question to me, I, for one, should certainly have answered,
Yes.
I know better now. So far from composing the bulk of English
readers, the public just mentioned represents nothing more than the
minority.
This startling discovery dawned upon me gradually. I made my first
approaches towards it, in walking about London, more especially in
the second and third rate neighbourhoods. At such times, whenever
I passed a small stationer's or small tobacconist's shop, I became
mechanically conscious of certain publications which invariably
occupied the windows. These publications all appeared to be of the
same small quarto size; they seemed to consist merely of a few
unbound pages; each one of them had a picture on the upper half of
the front leaf, and a quantity of small print on the under. I noticed
just as much as this, for some time, and no more. None of the
gentlemen who profess to guide my taste in literary matters, had
ever directed my attention towards these mysterious publications.
My favourite Review is, as I firmly believe, at this very day,
unconscious of their existence. My enterprising librarian—who forces
all sorts of books on my attention that I don't want to read, because
he has bought whole editions of them a great bargain—has never
yet tried me with the limp unbound picture-quarto of the small
shops. Day after day, and week after week, the mysterious
publications haunted my walks, go where I might; and, still, I was
too careless to stop and notice them in detail. I left London and
travelled about England. The neglected publications followed me.
There they were in every town, large or small. I saw them in fruit-
shops, in oyster-shops, in cigar-shops, in lozenge-shops. Villages
even—picturesque, strong-smelling villages—were not free from
them. Wherever the speculative daring of one man could open a
shop, and the human appetites and necessities of his fellow-mortals
could keep it from shutting up again—there, as it appeared to me,
the unbound picture-quarto instantly entered, set itself up
obtrusively in the window, and insisted on being looked at by
everybody. "Buy me, borrow me, stare at me, steal me. Oh,
inattentive stranger, do anything but pass me by!"
Under this sort of compulsion, it was not long before I began to stop
at shop-windows and look attentively at these all-pervading
specimens of what was to me a new species of literary production. I
made acquaintance with one of them among the deserts of West
Cornwall; with another in a populous thoroughfare of Whitechapel;
with a third in a dreary little lost town at the north of Scotland. I
went into a lovely county of South Wales; the modest railway had
not penetrated to it, but the audacious picture-quarto had found it
out. Who could resist this perpetual, this inevitable, this
magnificently unlimited appeal to notice and patronage? From
looking in at the windows of the shops, I got on to entering the
shops themselves—to buying specimens of this locust-flight of small
publications—to making strict examination of them from the first
page to the last—and finally, to instituting inquiries about them in all
sorts of well-informed quarters. The result has been the discovery of
an Unknown Public; a public to be counted by millions; the
mysterious, the unfathomable, the universal public of the penny-
novel-Journals.[2]
I have five of these journals now before me, represented by one
sample copy, bought hap-hazard, of each. There are many more;
but these five represent the successful and well-established
members of the literary family. The eldest of them is a stout lad of
fifteen years' standing. The youngest is an infant of three months
old. All five are sold at the same price of one penny; all five are
published regularly once a week; all five contain about the same
quantity of matter. The weekly circulation of the most successful of
the five, is now publicly advertised (and, as I am informed, without
exaggeration) at half a Million. Taking the other four as attaining
altogether to a circulation of another half million (which is probably
much under the right estimate) we have a sale of a Million weekly
for five penny journals. Reckoning only three readers to each copy
sold, the result is a public of three millions—a public unknown to the
literary world; unknown, as disciples, to the whole body of professed
critics; unknown, as customers, at the great libraries and the great
publishing-houses; unknown, as an audience, to the distinguished
English writers of our own time. A reading public of three millions
which lies right out of the pale of literary civilisation, is a
phenomenon worth examining—a mystery which the sharpest man
among us may not find it easy to solve.
In the first place, who are the three millions—the Unknown Public—
as I have ventured to call them?
The known reading public—the minority already referred to—are
easily discovered and classified. There is the religious public, with
booksellers and literature of its own, which includes reviews and
newspapers as well as books. There is the public which reads for
information, and devotes itself to Histories, Biographies, Essays,
Treatises, Voyages and Travels. There is the public which reads for
amusement, and patronises the Circulating Libraries and the railway
book-stalls. There is, lastly, the public which reads nothing but
newspapers. We all know where to lay our hands on the people who
represent these various classes. We see the books they like on their
tables. We meet them out at dinner, and hear them talk of their
favourite authors. We know, if we are at all conversant with literary
matters, even the very districts of London in which certain classes of
people live who are to be depended upon beforehand as the picked
readers for certain kinds of books. But what do we know of the
enormous outlawed majority—of the lost literary tribes—of the
prodigious, the overwhelming three millions? Absolutely nothing.
I myself—and I say it to my sorrow—have a very large circle of
acquaintance. Ever since I undertook the interesting task of
exploring the Unknown Public, I have been trying to discover among
my dear friends and my bitter enemies (both alike on my visiting
list), a subscriber to a penny-novel-journal—and I have never yet
succeeded in the attempt. I have heard theories started as to the
probable existence of penny-novel-journals in kitchen dressers, in
the back parlours of Easy Shaving Shops, in the greasy seclusion of
the boxes at the small Chop Houses. But I have never yet met with
any man, woman, or child who could answer the inquiry, "Do you
subscribe to a penny journal?" plainly in the affirmative, and who
could produce the periodical in question. I have learnt, years ago, to
despair of ever meeting with a single woman, after a certain age,
who has not had an offer of marriage. I have given up, long since,
all idea of ever discovering a man who has himself seen a ghost, as
distinguished from that other inevitable man who has had a bosom
friend who has unquestionably seen one. These are two among
many other aspirations of a wasted life which I have definitely
resigned. I have now to add one more to the number of my
vanished illusions.
In the absence, therefore, of any positive information on the subject,
it is only possible to pursue the present investigation by accepting
such negative evidence as may help us to guess with more or less
accuracy, at the social position, the habits, the tastes, and the
average intelligence of the Unknown Public. Arguing carefully by
inference, we may hope, in this matter, to arrive at something like a
safe, if not a satisfactory, conclusion.
To begin with, it may be fairly assumed—seeing that the staple
commodity of each one of the five journals before me, is composed
of Stories—that the Unknown Public reads for its amusement more
than for its information.
Judging by my own experience, I should be inclined to add, that the
Unknown Public looks to quantity rather than quality in spending its
penny a-week on literature. In buying my five specimen copies, at
five different shops, I purposely approached the individual behind
the counter, on each occasion, in the character of a member of the
Unknown Public—say, Number Three Million and One—who wished
to be guided in laying out a penny entirely by the recommendation
of the shopkeeper himself. I expected, by this course of proceeding,
to hear a little popular criticism, and to get at what the conditions of
success might be, in a branch of literature which was quite new to
me. No such result rewarded my efforts in any case. The dialogue
between buyer and seller always took some such practical turn as
this:
Reader, Number Three Million and One.—"I want to take in one of
the penny journals. Which do you recommend?"
Enterprising Publisher.—"Some likes one, and some likes another.
They're all good pennorths. Seen this one?"
"Yes."
"Seen that one?"
"No."
"Look what a pennorth!"
"Yes—but about the stories in this one? Are they as good, now, as
the stories in that one?"
"Well, you see, some likes one, and some likes another. Sometimes I
sells more of one, and sometimes I sells more of another. Take 'em
all the year round, and there ain't a pin, as I knows of, to choose
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!

ebookname.com

You might also like