Programming Principles and Practice Using C Third Edition Bjarne Stroustrup 2024 Scribd Download
Programming Principles and Practice Using C Third Edition Bjarne Stroustrup 2024 Scribd Download
com
https://textbookfull.com/product/programming-
principles-and-practice-using-c-third-edition-
bjarne-stroustrup/
https://textbookfull.com/product/programming-principles-and-practice-
using-c-second-edition-stroustrup/
textbookfull.com
https://textbookfull.com/product/programming-principles-and-practice-
using-c-3rd-edition-stroustrup/
textbookfull.com
https://textbookfull.com/product/computer-graphics-programming-in-
opengl-using-c-third-edition-gordon-phd/
textbookfull.com
https://textbookfull.com/product/modern-acting-the-lost-chapter-of-
american-film-and-theatre-1st-edition-cynthia-baron-auth/
textbookfull.com
The Practice of Spatial Analysis Helen Briassoulis
https://textbookfull.com/product/the-practice-of-spatial-analysis-
helen-briassoulis/
textbookfull.com
https://textbookfull.com/product/disentangling-the-philosophy-of-
economics-1st-edition-mariusz-maziarz/
textbookfull.com
https://textbookfull.com/product/system-dynamics-4th-edition-william-
j-palm/
textbookfull.com
https://textbookfull.com/product/leftovers-a-history-of-food-waste-
preservation-1st-edition-eleanor-barnett/
textbookfull.com
https://textbookfull.com/product/quantum-technologies-and-military-
strategy-1st-edition-ajey-lele-2/
textbookfull.com
Rethinking Talent Decisions A Tale of Complexity
Technology and Subjectivity 1st Edition Wiblen
https://textbookfull.com/product/rethinking-talent-decisions-a-tale-
of-complexity-technology-and-subjectivity-1st-edition-wiblen/
textbookfull.com
About This eBook
ePUB is an open, industry-standard format for eBooks. However,
support of ePUB and its many features varies across reading devices
and applications. Use your device or app settings to customize the
presentation to your liking. Settings that you can customize often
include font, font size, single or double column, landscape or portrait
mode, and figures that you can click or tap to enlarge. For additional
information about the settings and features on your reading device
or app, visit the device manufacturer’s Web site.
Many titles include programming code or configuration examples.
To optimize the presentation of these elements, view the eBook in
single-column, landscape mode and adjust the font size to the
smallest setting. In addition to presenting code and configurations in
the reflowable text format, we have included images of the code
that mimic the presentation found in the print book; therefore,
where the reflowable format may compromise the presentation of
the code listing, you will see a “Click here to view code image” link.
Click the link to view the print-fidelity code image. To return to the
previous page viewed, click the Back button on your device or app.
Programming: Principles and
Practice Using C++
Third Edition
Bjarne Stroustrup
The author and publisher have taken care in the preparation of this
book, but make no expressed or implied warranty of any kind and
assume no responsibility for errors or omissions. No liability is
assumed for incidental or consequential damages in connection with
or arising out of the use of the information or programs contained
herein.
ISBN-13: 978-0-13-830868-1
ISBN-10: 0-13-83086-3
First printing, May 2024
$PrintCode
Contents
Preface
1 Hello, World!
1.1 Programs
1.2 The classic first program
1.3 Compilation
1.4 Linking
1.5 Programming environments
3 Computation
3.1 Computation
3.2 Objectives and tools
3.3 Expressions
3.4 Statements
3.5 Functions
3.6 vector
3.7 Language features
4 Errors!
4.1 Introduction
4.2 Sources of errors
4.3 Compile-time errors
4.4 Link-time errors
4.5 Run-time errors
4.6 Exceptions
4.7 Avoiding and finding errors
5 Writing a Program
5.1 A problem
5.2 Thinking about the problem
5.3 Back to the calculator!
5.4 Back to the drawing board
5.5 Turning a grammar into code
5.6 Trying the first version
5.7 Trying the second version
5.8 Token streams
5.9 Program structure
6 Completing a Program
6.1 Introduction
6.2 Input and output
6.3 Error handling
6.4 Negative numbers
6.5 Remainder: %
6.6 Cleaning up the code
6.7 Recovering from errors
6.8 Variables
10 A Display Model
10.1 Why graphics?
10.2 A display model
10.3 A first example
10.4 Using a GUI library
10.5 Coordinates
10.6 Shapes
10.7 Using Shape primitives
10.8 Getting the first example to run
11 Graphics Classes
11.1 Overview of graphics classes
11.2 Point and Line
11.3 Lines
11.4 Color
11.5 Line_style
11.6 Polylines
11.7 Closed shapes
11.8 Text
11.9 Mark
11.10 Image
12 Class Design
12.1 Design principles
12.2 Shape
12.3 Base and derived classes
12.4 Other Shape functions
12.5 Benefits of object-oriented programming
17 Essential Operations
17.1 Introduction
17.2 Access to elements
17.3 List initialization
17.4 Copying and moving
17.5 Essential operations
17.6 Other useful operations
17.7 Remaining Vector problems
17.8 Changing size
17.9 Our Vector so far
18 Templates and Exceptions
18.1 Templates
18.2 Generalizing Vector
18.3 Range checking and exceptions
18.4 Resources and exceptions
18.5 Resource-management pointers
21 Algorithms
21.1 Standard-library algorithms
21.2 Function objects
21.3 Numerical algorithms
21.4 Copying
21.5 Sorting and searching
Index
Preface
Damn the
torpedoes!
Full speed ahead.
– Admiral
Farragut
Previous Editions
The third edition of Programming: Principles and Practice Using C++
is about half the size of the second edition. Students having to carry
the book will appreciate the lighter weight. The reason for the
reduced size is simply that more information about C++ and its
standard library is available on the Web. The essence of the book
that is generally used in a course in programming is in this third
edition (“PPP3”), updated to C++20 plus a bit of C++23. The fourth
part of the previous edition (“PPP2”) was designed to provide extra
information for students to look up when needed and is available on
the Web:
Acknowledgments
Special thanks to the people who reviewed drafts of this book and
suggested many improvements: Clovis L. Tondo, Jose Daniel Garcia
Sanchez, J.C. van Winkel, and Ville Voutilainen. Also, Ville Voutilainen
did the non-trivial mapping of the GUI/Graphics interface library to
Qt, making it portable to an amazing range of systems.
Also, thanks to the many people who contributed to the first and
second editions of this book. Many of their comments are reflected
in this third edition.
0
eiπ + 1
– Leonhard Euler
CC
To ease review and to help you if you miss a key point during a first reading
where you have yet to discover which kind of information is crucial, we place three
kinds of “alert markers” in the margin:
AA
This book is designed to be read chapter by chapter from the beginning to the
end. Often, you’ll want to go back to look at something a second or a third time. In
fact, that’s the only sensible approach, as you’ll always dash past some details that
you don’t yet see the point in. In such cases, you’ll eventually go back again.
Despite the index and the cross-references, this is not a book that you can open to
any page and start reading with any expectation of success. Each section and each
chapter assume understanding of what came before.
Each chapter is a reasonably self-contained unit, meant to be read in “one
sitting” (logically, if not always feasible on a student’s tight schedule). That’s one
major criterion for separating the text into chapters. Other criteria include that a
chapter is a suitable unit for drills and exercises and that each chapter presents
some specific concept, idea, or technique. This plurality of criteria has left a few
chapters uncomfortably long, so please don’t take “in one sitting” too literally. In
particular, once you have thought about the review questions, done the drill, and
worked on a few exercises, you’ll often find that you have to go back to reread a
few sections.
A common praise for a textbook is “It answered all my questions just as I
thought of them!” That’s an ideal for minor technical questions, and early readers
have observed the phenomenon with this book. However, that cannot be the whole
ideal. We raise questions that a novice would probably not think of. We aim to ask
and answer questions that you need to consider when writing quality software for
the use of others. Learning to ask the right (often hard) questions is an essential
part of learning to think as a programmer. Asking only the easy and obvious
questions would make you feel good, but it wouldn’t help make you a programmer.
We try to respect your intelligence and to be considerate about your time. In our
presentation, we aim for professionalism rather than cuteness, and we’d rather
understate a point than hype it. We try not to exaggerate the importance of a
programming technique or a language feature, but please don’t underestimate a
simple statement like “This is often useful.” If we quietly emphasize that something
is important, we mean that you’ll sooner or later waste days if you don’t master it.
Our use of humor is more limited than we would have preferred, but experience
shows that people’s ideas of what is funny differ dramatically and that a failed
attempt at humor can be confusing.
CC
We do not pretend that our ideas or the tools offered are perfect. No tool, library,
language, or technique is “the solution” to all of the many challenges facing a
programmer. At best, a language can help you to develop and express your solution.
We try hard to avoid “white lies”; that is, we refrain from oversimplified
explanations that are clear and easy to understand, but not true in the context of
real languages and real problems.
In addition, at the end of each chapter we offer some help to solidify what’s
learned:
Review: At the end of each chapter, you’ll find a set of review questions. They
are intended to point you to the key ideas explained in the chapter. One way to
look at the review questions is as a complement to the exercises: the exercises
focus on the practical aspects of programming, whereas the review questions
try to help you articulate the ideas and concepts. In that, they resemble good
interview questions.
Terms: A section at the end of each chapter presents the basic vocabulary of
programming and of C++. If you want to understand what people say about
programming topics and to articulate your own ideas, you should know what
each term means.
Postscript: A paragraph intended to provide some perspective for the material
presented.
In addition, we recommend that you take part in a small project (and more if time
allows for it). A project is intended to produce a complete useful program. Ideally, a
project is done by a small group of people (e.g., three people) working together
(e.g., while progressing through the later chapters of the book). Most people find
such projects the most fun and that they tie everything together.
CC
Learning involves repetition. Our ideal is to make every important point at least
twice and to reinforce it with exercises.
AA
Eventually, you should learn another programming language. We don’t consider
it possible to be a professional in the realm of software – even if you are not
primarily a programmer – without knowing more than one language. Why? No large
program is written in a single language. Also, different languages typically differ in
the way code is thought about and programs are constructed. Design techniques,
availability of libraries, and the way programs are built differ, sometimes
dramatically. Even when the syntaxes of two languages are similar, the similarity is
typically only skin deep. Performance, detection of errors, and constraints on what
can be expressed typically differ. This is similar to the ways natural languages and
cultures differ. Knowing only a single language and a single culture implies the
danger of thinking that “the way we do things” is the only way or the only good
way. That way opportunities are missed, and sub-optimal programs are produced.
One of the best ways to avoid such problems is to know several languages
(programming languages and natural languages).
Program organization
Debugging and testing
Class design
Computation
Function and algorithm design
Graphics (two-dimensional only)
Graphical user interfaces (GUIs)
Files and stream input and output (I/O)
Random documents with unrelated
content Scribd suggests to you:
Stand unserer heutigen Kunde gebracht, ist erfreulicherweise
nunmehr, wenigstens vorläufig zum Theil, in Aussicht gestellt. [14]
Anmerkung
[Inhalt]
Maasse:
Kopf 18 mm
Körper 41
,,
Ohr 14 ×
10 ,,
Vorderer Ohrrand 8.5
,,
Tragus (Länge von der tiefstenStelle der Basis bis zur 5×2
Spitze) ,,
Humerus 24
,,
Vorderarm 36
,,
Dig. 1 mit Kralle 6.3
,,
2 (33.5 + 5.5) 39
,, ,,
3 (35 + 11.5 + 9 + 3) 58.5
,, ,,
4 (33 + 11 + 5) 49
,, ,,
5 (29 + 5.5 + 4.7) 39.2
,, ,,
Femur 12
,,
Unterschenkel 15.5
,,
Fuss mit Krallen 10
,,
Sporn c. 13
,,
Schwanz c. 37
,,
Penis 9
,,
[Inhalt]
11 Exemplare,
a–l. in Spiritus, 3 mares (36–37.5 mm), 7 fem.
(36–38), 1 fem. juv. (24); Kema (4. VIII 93), Tomohon (4.
IX 94) etc., Minahassa, Nord Celébes.
1 mas,
m. in Spiritus, Loka, Pik von Bonthain, c. 1200 m,
Süd Celébes, X 95 (33 mm). Dieses Exemplar ist klein,
aber adult.
Die Art, die von Vorderindien bis zu den Molukken nachgewiesen ist,
wurde auch schon speciell von Nord Celébes registrirt (D o b s o n
Cat. 1878, 317 und J e n t i n k Cat. MPB. XII, 190 1888), während
der S a r a s i n sche Fundort von Süd Celébes neu ist. Dresden
besitzt sie auch von NW Neu Guinea (36 mm).
1 Bezeichnungen nach H e n s e l . ↑
2 D o b s o n (Cat. 1878, 227) sagt von V. abramus, dass er relativ einen
grösseren Penis habe als alle anderen Fledermäuse, J e n t i n k (Webers Zool.
Erg. I, 128 1890) führt ein j u n g e s Exemplar von Sumatra auf (Vorderarm nur
14.5 mm), dessen Penis 4.5 mm lang ist. ↑
3 Diese Maasse stimmen nicht genau mit denen der Abbildung Tafel IV, Figur 3,
da diese perspectivisch gezeichnet ist. ↑
[Inhalt]
Emballonuridae
Molossi
[Inhalt]
Tafel IV Fig. 4–6, Tafel X Fig. 3, 4 und 28, und Tafel XI Fig. 2 und 2 a
[17]
Maasse:
Kopf 25 mm
Körper 45
,,
Ohr 21 × 15
,,
Tragus (Länge von der Zacke an gemessen) 2 × 1.2
,,
Humerus 29
,,
Vorderarm 40
,,
Dig. 1 mit Kralle 8.5
,,
42
2 (40 + 2)
,, ,,
3 (39 + 18 + 15 + 7.5) 79.5
,, ,,
4 (37.5 + 14 + 10 + 1.7) 63.2
,, ,,
40.6
5 (23.5 + 11.5 + 4 + 1.6)
,, ,,
Femur 16
,,
Unterschenkel 14.5
,,
Fuss mit Krallen 13
,,
Sporn 8
,,
Schwanz (davon frei 23 mm) 34
,,
Auf Tafel IV Fig. 4 ist eine dorsale Ansicht des ganzen Thieres in
natürlicher, Fig. 5 die des Kopfes von der Seite in doppelter, Fig. 6
die des Tragus in vierfacher Grösse.
Anmerkung
Keine Kehlgrube.
Maasse:
Kopf 25 mm
Körper 41
,,
Ohr 15 × 16
,,
Tragus 2 × 1.6
,,
Humerus 26
,,
Vorderarm 36
,,
Dig. 1 mit Kralle 7
,,
2 33
,, ,,
3 (35 + 14 + 12.5 + 6) 67.5
,, ,,
54.5
4 (33 + 11 + 9 + 1.5)
,, ,,
35.5
5 (22 + 8 + 4 + 1.5)
,, ,,
Femur (?) 15
,,
Unterschenkel 13.5
,,
Fuss mit Krallen 9
,,
Sporn 11
,,
Schwanz (davon frei 15) 34
,,