100% found this document useful (4 votes)
245 views

An Introduction to Programming with C 8th Edition Diane Zak all chapter instant download

Introduction

Uploaded by

ezinsahar
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 (4 votes)
245 views

An Introduction to Programming with C 8th Edition Diane Zak all chapter instant download

Introduction

Uploaded by

ezinsahar
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/ 46

Download Full ebookname - Read Now at ebookname.

com

An Introduction to Programming with C 8th Edition


Diane Zak

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

OR CLICK BUTTON

DOWLOAD EBOOK

Discover More Ebook - Explore Now at 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/

ebookname.com

CGI Perl Web Warrior Series 1st Edition Diane Zak

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

ebookname.com

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/

ebookname.com

Injunctive Relief and International Arbitration 1st


Edition Hakeem Seriki

https://ebookname.com/product/injunctive-relief-and-international-
arbitration-1st-edition-hakeem-seriki/

ebookname.com
Neural progenitor cells methods and protocols Second
Edition Loic P. Deleyrolle (Editor)

https://ebookname.com/product/neural-progenitor-cells-methods-and-
protocols-second-edition-loic-p-deleyrolle-editor/

ebookname.com

Windows XP Zambak 1st Edition Osman Ay

https://ebookname.com/product/windows-xp-zambak-1st-edition-osman-ay/

ebookname.com

Metrology of Pedestrian Locomotion and Slip Resistance


ASTM Special Technical Publication 1424 Mark I. Marpet

https://ebookname.com/product/metrology-of-pedestrian-locomotion-and-
slip-resistance-astm-special-technical-publication-1424-mark-i-marpet/

ebookname.com

Encyclopedia of e commerce e government and mobile


commerce Mehdi Khosrow-Pour

https://ebookname.com/product/encyclopedia-of-e-commerce-e-government-
and-mobile-commerce-mehdi-khosrow-pour/

ebookname.com

Making Pictures of War Realia et Imaginaria in the


Iconology of the Ancient near East 1st Edition Laura
Battini
https://ebookname.com/product/making-pictures-of-war-realia-et-
imaginaria-in-the-iconology-of-the-ancient-near-east-1st-edition-
laura-battini/
ebookname.com
The Monroe Doctrine in a Contemporary Perspective 1st
Edition Denneth M. Modeste

https://ebookname.com/product/the-monroe-doctrine-in-a-contemporary-
perspective-1st-edition-denneth-m-modeste/

ebookname.com
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
[email protected]
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.
Random documents with unrelated
content Scribd suggests to you:
TABLE DES MATIÈRES

A M. le vicomte de Grouchy I

Préface III

LIVRE PREMIER
LA CHANOINESSE

CHAPITRE PREMIER
ENFANCE DE SOPHIE DE GROUCHY

Le château de Villette. — Les Grouchy. — Le marquis et sa


femme. — Vie patriarcale à la campagne. — Les hôtes littéraires à
Paris. — Rue Gaillon et rue Royale. — Les Fréteau, Dupaty et
d’Arbouville. — Enfance de Sophie. — Son frère Emmanuel. — Sa
sœur Charlotte. — Le chevalier de Grouchy. — Grave maladie en
1775. — Lectures et travaux de Sophie. 1

CHAPITRE II
LA CHANOINESSE DE NEUVILLE

Les chapitres nobles de Dames. — Le prieuré de Neuville-en-


Bresse. — Sophie y est envoyée. — Ses occupations. — Sa
correspondance. — Sophie reçoit la visite du président Dupaty. —
Son retour à Paris et à Villette. — On cherche à la marier. —
Rencontre du marquis de Condorcet, chez Dupaty. 27

LIVRE II
LE SALON DE L’HÔTEL DES MONNAIES

CHAPITRE PREMIER
PREMIÈRES ANNÉES DU MARIAGE DE CONDORCET
Le mariage. — Les calomnies de Lamartine et de Michelet. —
Installation à l’Hôtel des Monnaies. — Revenus de Condorcet. —
Les hôtes du Salon. — Mort de Dupaty. — Le Président laisse ses
papiers à Sophie. — Fondation du Lycée. — Condorcet y professe
les mathématiques. — Sophie assiste aux leçons. — La maison de
Mme Helvétius à Auteuil. 65

CHAPITRE II
LE SALON DE SOPHIE AU DÉBUT DE LA RÉVOLUTION

Le foyer de la République. — Condorcet et sa femme se


séparent de leurs anciens amis. — Naissance d’une fille. —
Pamphlets contre le marquis et sa femme. — Les Girondins chez
Condorcet et chez Julie Talma. — Etablissement à Auteuil avec
Jean Debry auprès de Cabanis. — Lettres sur la sympathie. —
Mort de la marquise de Grouchy chez Condorcet. — Mise en
arrestation de Condorcet. 99

LIVRE III
LES ANNÉES DOULOUREUSES

CHAPITRE PREMIER
PROSCRIPTION ET MORT DE CONDORCET. — RUINE DE SOPHIE

La maison de la rue Servandoni. — Mme Vernet. — Derniers


jours de Condorcet. — Visites de Sophie au proscrit. — Testament
du philosophe et conseils à sa fille. — Mort de Condorcet. —
Sophie fait des portraits et vend de la lingerie. — Ses biens
confisqués. — Elle élève sa fille et soutient sa sœur. — Belle lettre
à propos de la mort de Fréteau. — Sophie traduit la théorie des
sentiments moraux d’Adam Smith et publie ses lettres sur la
sympathie ainsi que les œuvres de son mari. — Union de
Charlotte de Grouchy avec Cabanis. 133

CHAPITRE II
LA MAISONNETTE ET PARIS. — MORT DE LA MARQUISE DE CONDORCET
173
Mme de Condorcet recouvre ses biens. — Le muséum. —
Rencontre de Fauriel. — La Maisonnette. — Le Consulat et
l’Empire. — L’opposition se donne rendez-vous chez Mme de
Condorcet. — Mariage d’Elisa de Condorcet avec le général
O’Connor. — Mort de Cabanis. — Les hôtes de la Maisonnette:
Benjamin Constant, Manzoni, Ginguené, Guizot. — Le procès du
maréchal de Grouchy en 1816: rôle de sa sœur. — La marquise de
Condorcet se retire du monde. — Rentrée à Paris. — Ses bonnes
œuvres. — Sa mort.
Pièces annexes. 237
Index alphabétique. 245

ÉVREUX, IMPRIMERIE DE CHARLES HÉRISSEY

Au lecteur.
L'orthographe d'origine a été conservée et n'a pas été
harmonisée, mais quelques erreurs clairement introduites par le
typographe ou à l'impression ont été corrigées. Ces corrections
sont soulignées en pointillés dans le texte. Placez le curseur sur le
mot pour voir l'orthographe originale.
La ponctuation a été tacitement corrigée à quelques endroits.
*** END OF THE PROJECT GUTENBERG EBOOK LA MARQUISE DE
CONDORCET: SA FAMILLE, SON SALON, SES AMIS, 1764-1822 ***

Updated editions will replace the previous one—the old editions


will be renamed.

Creating the works from print editions not protected by U.S.


copyright law means that no one owns a United States
copyright in these works, so the Foundation (and you!) can copy
and distribute it in the United States without permission and
without paying copyright royalties. Special rules, set forth in the
General Terms of Use part of this license, apply to copying and
distributing Project Gutenberg™ electronic works to protect the
PROJECT GUTENBERG™ concept and trademark. Project
Gutenberg is a registered trademark, and may not be used if
you charge for an eBook, except by following the terms of the
trademark license, including paying royalties for use of the
Project Gutenberg trademark. If you do not charge anything for
copies of this eBook, complying with the trademark license is
very easy. You may use this eBook for nearly any purpose such
as creation of derivative works, reports, performances and
research. Project Gutenberg eBooks may be modified and
printed and given away—you may do practically ANYTHING in
the United States with eBooks not protected by U.S. copyright
law. Redistribution is subject to the trademark license, especially
commercial redistribution.

START: FULL LICENSE


THE FULL PROJECT GUTENBERG
LICENSE
PLEASE READ THIS BEFORE YOU DISTRIBUTE OR USE THIS WORK

To protect the Project Gutenberg™ mission of promoting the


free distribution of electronic works, by using or distributing this
work (or any other work associated in any way with the phrase
“Project Gutenberg”), you agree to comply with all the terms of
the Full Project Gutenberg™ License available with this file or
online at www.gutenberg.org/license.

Section 1. General Terms of Use and


Redistributing Project Gutenberg™
electronic works
1.A. By reading or using any part of this Project Gutenberg™
electronic work, you indicate that you have read, understand,
agree to and accept all the terms of this license and intellectual
property (trademark/copyright) agreement. If you do not agree
to abide by all the terms of this agreement, you must cease
using and return or destroy all copies of Project Gutenberg™
electronic works in your possession. If you paid a fee for
obtaining a copy of or access to a Project Gutenberg™
electronic work and you do not agree to be bound by the terms
of this agreement, you may obtain a refund from the person or
entity to whom you paid the fee as set forth in paragraph 1.E.8.

1.B. “Project Gutenberg” is a registered trademark. It may only


be used on or associated in any way with an electronic work by
people who agree to be bound by the terms of this agreement.
There are a few things that you can do with most Project
Gutenberg™ electronic works even without complying with the
full terms of this agreement. See paragraph 1.C below. There
are a lot of things you can do with Project Gutenberg™
electronic works if you follow the terms of this agreement and
help preserve free future access to Project Gutenberg™
electronic works. See paragraph 1.E below.
1.C. The Project Gutenberg Literary Archive Foundation (“the
Foundation” or PGLAF), owns a compilation copyright in the
collection of Project Gutenberg™ electronic works. Nearly all the
individual works in the collection are in the public domain in the
United States. If an individual work is unprotected by copyright
law in the United States and you are located in the United
States, we do not claim a right to prevent you from copying,
distributing, performing, displaying or creating derivative works
based on the work as long as all references to Project
Gutenberg are removed. Of course, we hope that you will
support the Project Gutenberg™ mission of promoting free
access to electronic works by freely sharing Project Gutenberg™
works in compliance with the terms of this agreement for
keeping the Project Gutenberg™ name associated with the
work. You can easily comply with the terms of this agreement
by keeping this work in the same format with its attached full
Project Gutenberg™ License when you share it without charge
with others.

1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside
the United States, check the laws of your country in addition to
the terms of this agreement before downloading, copying,
displaying, performing, distributing or creating derivative works
based on this work or any other Project Gutenberg™ work. The
Foundation makes no representations concerning the copyright
status of any work in any country other than the United States.

1.E. Unless you have removed all references to Project


Gutenberg:

1.E.1. The following sentence, with active links to, or other


immediate access to, the full Project Gutenberg™ License must
appear prominently whenever any copy of a Project
Gutenberg™ work (any work on which the phrase “Project
Gutenberg” appears, or with which the phrase “Project
Gutenberg” is associated) is accessed, displayed, performed,
viewed, copied or distributed:

This eBook is for the use of anyone anywhere in the United


States and most other parts of the world at no cost and
with almost no restrictions whatsoever. You may copy it,
give it away or re-use it under the terms of the Project
Gutenberg License included with this eBook or online at
www.gutenberg.org. If you are not located in the United
States, you will have to check the laws of the country
where you are located before using this eBook.

1.E.2. If an individual Project Gutenberg™ electronic work is


derived from texts not protected by U.S. copyright law (does not
contain a notice indicating that it is posted with permission of
the copyright holder), the work can be copied and distributed to
anyone in the United States without paying any fees or charges.
If you are redistributing or providing access to a work with the
phrase “Project Gutenberg” associated with or appearing on the
work, you must comply either with the requirements of
paragraphs 1.E.1 through 1.E.7 or obtain permission for the use
of the work and the Project Gutenberg™ trademark as set forth
in paragraphs 1.E.8 or 1.E.9.

1.E.3. If an individual Project Gutenberg™ electronic work is


posted with the permission of the copyright holder, your use and
distribution must comply with both paragraphs 1.E.1 through
1.E.7 and any additional terms imposed by the copyright holder.
Additional terms will be linked to the Project Gutenberg™
License for all works posted with the permission of the copyright
holder found at the beginning of this work.

1.E.4. Do not unlink or detach or remove the full Project


Gutenberg™ License terms from this work, or any files
containing a part of this work or any other work associated with
Project Gutenberg™.

1.E.5. Do not copy, display, perform, distribute or redistribute


this electronic work, or any part of this electronic work, without
prominently displaying the sentence set forth in paragraph 1.E.1
with active links or immediate access to the full terms of the
Project Gutenberg™ License.

1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if
you provide access to or distribute copies of a Project
Gutenberg™ work in a format other than “Plain Vanilla ASCII” or
other format used in the official version posted on the official
Project Gutenberg™ website (www.gutenberg.org), you must,
at no additional cost, fee or expense to the user, provide a copy,
a means of exporting a copy, or a means of obtaining a copy
upon request, of the work in its original “Plain Vanilla ASCII” or
other form. Any alternate format must include the full Project
Gutenberg™ License as specified in paragraph 1.E.1.

1.E.7. Do not charge a fee for access to, viewing, displaying,


performing, copying or distributing any Project Gutenberg™
works unless you comply with paragraph 1.E.8 or 1.E.9.

1.E.8. You may charge a reasonable fee for copies of or


providing access to or distributing Project Gutenberg™
electronic works provided that:

• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”

• You provide a full refund of any money paid by a user who


notifies you in writing (or by e-mail) within 30 days of receipt
that s/he does not agree to the terms of the full Project
Gutenberg™ License. You must require such a user to return or
destroy all copies of the works possessed in a physical medium
and discontinue all use of and all access to other copies of
Project Gutenberg™ works.

• You provide, in accordance with paragraph 1.F.3, a full refund of


any money paid for a work or a replacement copy, if a defect in
the electronic work is discovered and reported to you within 90
days of receipt of the work.

• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.

1.E.9. If you wish to charge a fee or distribute a Project


Gutenberg™ electronic work or group of works on different
terms than are set forth in this agreement, you must obtain
permission in writing from the Project Gutenberg Literary
Archive Foundation, the manager of the Project Gutenberg™
trademark. Contact the Foundation as set forth in Section 3
below.

1.F.

1.F.1. Project Gutenberg volunteers and employees expend


considerable effort to identify, do copyright research on,
transcribe and proofread works not protected by U.S. copyright
law in creating the Project Gutenberg™ collection. Despite these
efforts, Project Gutenberg™ electronic works, and the medium
on which they may be stored, may contain “Defects,” such as,
but not limited to, incomplete, inaccurate or corrupt data,
transcription errors, a copyright or other intellectual property
infringement, a defective or damaged disk or other medium, a
computer virus, or computer codes that damage or cannot be
read by your equipment.

1.F.2. LIMITED WARRANTY, DISCLAIMER OF DAMAGES - Except


for the “Right of Replacement or Refund” described in
paragraph 1.F.3, the Project Gutenberg Literary Archive
Foundation, the owner of the Project Gutenberg™ trademark,
and any other party distributing a Project Gutenberg™ electronic
work under this agreement, disclaim all liability to you for
damages, costs and expenses, including legal fees. YOU AGREE
THAT YOU HAVE NO REMEDIES FOR NEGLIGENCE, STRICT
LIABILITY, BREACH OF WARRANTY OR BREACH OF CONTRACT
EXCEPT THOSE PROVIDED IN PARAGRAPH 1.F.3. YOU AGREE
THAT THE FOUNDATION, THE TRADEMARK OWNER, AND ANY
DISTRIBUTOR UNDER THIS AGREEMENT WILL NOT BE LIABLE
TO YOU FOR ACTUAL, DIRECT, INDIRECT, CONSEQUENTIAL,
PUNITIVE OR INCIDENTAL DAMAGES EVEN IF YOU GIVE
NOTICE OF THE POSSIBILITY OF SUCH DAMAGE.

1.F.3. LIMITED RIGHT OF REPLACEMENT OR REFUND - If you


discover a defect in this electronic work within 90 days of
receiving it, you can receive a refund of the money (if any) you
paid for it by sending a written explanation to the person you
received the work from. If you received the work on a physical
medium, you must return the medium with your written
explanation. The person or entity that provided you with the
defective work may elect to provide a replacement copy in lieu
of a refund. If you received the work electronically, the person
or entity providing it to you may choose to give you a second
opportunity to receive the work electronically in lieu of a refund.
If the second copy is also defective, you may demand a refund
in writing without further opportunities to fix the problem.

1.F.4. Except for the limited right of replacement or refund set


forth in paragraph 1.F.3, this work is provided to you ‘AS-IS’,
WITH NO OTHER WARRANTIES OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.

1.F.5. Some states do not allow disclaimers of certain implied


warranties or the exclusion or limitation of certain types of
damages. If any disclaimer or limitation set forth in this
agreement violates the law of the state applicable to this
agreement, the agreement shall be interpreted to make the
maximum disclaimer or limitation permitted by the applicable
state law. The invalidity or unenforceability of any provision of
this agreement shall not void the remaining provisions.

1.F.6. INDEMNITY - You agree to indemnify and hold the


Foundation, the trademark owner, any agent or employee of the
Foundation, anyone providing copies of Project Gutenberg™
electronic works in accordance with this agreement, and any
volunteers associated with the production, promotion and
distribution of Project Gutenberg™ electronic works, harmless
from all liability, costs and expenses, including legal fees, that
arise directly or indirectly from any of the following which you
do or cause to occur: (a) distribution of this or any Project
Gutenberg™ work, (b) alteration, modification, or additions or
deletions to any Project Gutenberg™ work, and (c) any Defect
you cause.

Section 2. Information about the Mission


of Project Gutenberg™
Project Gutenberg™ is synonymous with the free distribution of
electronic works in formats readable by the widest variety of
computers including obsolete, old, middle-aged and new
computers. It exists because of the efforts of hundreds of
volunteers and donations from people in all walks of life.

Volunteers and financial support to provide volunteers with the


assistance they need are critical to reaching Project
Gutenberg™’s goals and ensuring that the Project Gutenberg™
collection will remain freely available for generations to come. In
2001, the Project Gutenberg Literary Archive Foundation was
created to provide a secure and permanent future for Project
Gutenberg™ and future generations. To learn more about the
Project Gutenberg Literary Archive Foundation and how your
efforts and donations can help, see Sections 3 and 4 and the
Foundation information page at www.gutenberg.org.

Section 3. Information about the Project


Gutenberg Literary Archive Foundation
The Project Gutenberg Literary Archive Foundation is a non-
profit 501(c)(3) educational corporation organized under the
laws of the state of Mississippi and granted tax exempt status
by the Internal Revenue Service. The Foundation’s EIN or
federal tax identification number is 64-6221541. Contributions
to the Project Gutenberg Literary Archive Foundation are tax
deductible to the full extent permitted by U.S. federal laws and
your state’s laws.

The Foundation’s business office is located at 809 North 1500


West, Salt Lake City, UT 84116, (801) 596-1887. Email contact
links and up to date contact information can be found at the
Foundation’s website and official page at
www.gutenberg.org/contact
Section 4. Information about Donations to
the Project Gutenberg Literary Archive
Foundation
Project Gutenberg™ depends upon and cannot survive without
widespread public support and donations to carry out its mission
of increasing the number of public domain and licensed works
that can be freely distributed in machine-readable form
accessible by the widest array of equipment including outdated
equipment. Many small donations ($1 to $5,000) are particularly
important to maintaining tax exempt status with the IRS.

The Foundation is committed to complying with the laws


regulating charities and charitable donations in all 50 states of
the United States. Compliance requirements are not uniform
and it takes a considerable effort, much paperwork and many
fees to meet and keep up with these requirements. We do not
solicit donations in locations where we have not received written
confirmation of compliance. To SEND DONATIONS or determine
the status of compliance for any particular state visit
www.gutenberg.org/donate.

While we cannot and do not solicit contributions from states


where we have not met the solicitation requirements, we know
of no prohibition against accepting unsolicited donations from
donors in such states who approach us with offers to donate.

International donations are gratefully accepted, but we cannot


make any statements concerning tax treatment of donations
received from outside the United States. U.S. laws alone swamp
our small staff.

Please check the Project Gutenberg web pages for current


donation methods and addresses. Donations are accepted in a
number of other ways including checks, online payments and
credit card donations. To donate, please visit:
www.gutenberg.org/donate.

Section 5. General Information About


Project Gutenberg™ electronic works
Professor Michael S. Hart was the originator of the Project
Gutenberg™ concept of a library of electronic works that could
be freely shared with anyone. For forty years, he produced and
distributed Project Gutenberg™ eBooks with only a loose
network of volunteer support.

Project Gutenberg™ eBooks are often created from several


printed editions, all of which are confirmed as not protected by
copyright in the U.S. unless a copyright notice is included. Thus,
we do not necessarily keep eBooks in compliance with any
particular paper edition.

Most people start at our website which has the main PG search
facility: www.gutenberg.org.

This website includes information about Project Gutenberg™,


including how to make donations to the Project Gutenberg
Literary Archive Foundation, how to help produce our new
eBooks, and how to subscribe to our email newsletter to hear
about new eBooks.
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