Full download Programming Principles and Practice Using C 3rd Edition Stroustrup pdf docx
Full download Programming Principles and Practice Using C 3rd Edition Stroustrup pdf docx
com
https://textbookfull.com/product/programming-principles-and-
practice-using-c-3rd-edition-stroustrup/
OR CLICK BUTTON
DOWNLOAD NOW
https://textbookfull.com/product/programming-principles-and-practice-
using-c-second-edition-stroustrup/
textboxfull.com
https://textbookfull.com/product/programming-principles-and-practice-
using-c-third-edition-bjarne-stroustrup/
textboxfull.com
https://textbookfull.com/product/a-tour-of-c-3rd-edition-stroustrup-b/
textboxfull.com
https://textbookfull.com/product/tour-of-c-a-c-in-depth-series-3rd-
edition-stroustrup/
textboxfull.com
A Tour of C++ Stroustrup
https://textbookfull.com/product/a-tour-of-c-stroustrup/
textboxfull.com
https://textbookfull.com/product/a-tour-of-c-stroustrup-2/
textboxfull.com
https://textbookfull.com/product/introduction-to-computation-and-
programming-using-python-3rd-edition-john-v-guttag/
textboxfull.com
https://textbookfull.com/product/introduction-to-computation-and-
programming-using-python-3rd-edition-john-v-guttag-2/
textboxfull.com
https://textbookfull.com/product/principles-and-practice-of-radiation-
oncology-7th-edition-edward-c-halperin/
textboxfull.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
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
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
The use of CC, AA, and XX, rather than a single token in different colors, is to
help where colors are not easy to distinguish.
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.
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)
Memory management
Design and programming ideals
The C++ standard library
Software development strategies
To keep the book lighter than the small laptop on which it is written, some
supplementary topics from the second edition are placed on the Web (§0.4.1):
Working our way through the chapters, we cover the programming techniques
called procedural programming (as with the C programming language), data
abstraction, object-oriented programming, and generic programming. The
main topic of this book is programming, that is, the ideals, techniques, and
tools of expressing ideas in code. The C++ programming language is our main
tool, so we describe many of C++’s facilities in some detail. But please
remember that C++ is just a tool, rather than the main topic of this book. This
is “programming using C++,” not “C++ with a bit of programming theory.”
Each topic we address serves at least two purposes: it presents a technique,
concept, or principle and also a practical language or library feature. For
example, we use the interface to a two-dimensional graphics system to
illustrate the use of classes and inheritance. This allows us to be economical
with space (and your time) and also to emphasize that programming is more
than simply slinging code together to get a result as quickly as possible. The
C++ standard library is a major source of such “double duty” examples –
many even do triple duty. For example, we introduce the standard-library
vector, use it to illustrate widely useful design techniques, and show many of
the programming techniques used to implement it. One of our aims is to show
you how major library facilities are implemented and how they map to
hardware. We insist that craftsmen must understand their tools, not just
consider them “magical.”
Some topics will be of greater interest to some programmers than to others.
However, we encourage you not to prejudge your needs (how would you know
what you’ll need in the future?) and at least look at every chapter. If you read
this book as part of a course, your teacher will guide your selection.
CC
We characterize our approach as “depth-first.” It is also “concrete-first” and
“concept-based.” First, we quickly (well, relatively quickly, Chapter 1 to
Chapter 9) assemble a set of skills needed for writing small practical programs.
In doing so, we present a lot of tools and techniques in minimal detail. We
focus on simple concrete code examples because people grasp the concrete
faster than the abstract. That’s simply the way most humans learn. At this
initial stage, you should not expect to understand every little detail. In
particular, you’ll find that trying something slightly different from what just
worked can have “mysterious” effects. Do try, though! Please do the drills and
exercises we provide. Just remember that early on you just don’t have the
concepts and skills to accurately estimate what’s simple and what’s
complicated; expect surprises and learn from them.
AA
We move fast in this initial phase – we want to get you to the point where
you can write interesting programs as fast as possible. Someone will argue,
“We must move slowly and carefully; we must walk before we can run!” But
have you ever watched a baby learning to walk? Babies really do run by
themselves before they learn the finer skills of slow, controlled walking.
Similarly, you will dash ahead, occasionally stumbling, to get a feel of
programming before slowing down to gain the necessary finer control and
understanding. You must run before you can walk!
XX
It is essential that you don’t get stuck in an attempt to learn “everything”
about some language detail or technique. For example, you could memorize all
of C++’s built-in types and all the rules for their use. Of course you could, and
doing so might make you feel knowledgeable. However, it would not make you
a programmer. Skipping details will get you “burned” occasionally for lack of
knowledge, but it is the fastest way to gain the perspective needed to write
good programs. Note that our approach is essentially the one used by children
learning their native language and also the most effective approach used to
learn a foreign language. We encourage you to seek help from teachers,
friends, colleagues, Mentors, etc. on the inevitable occasions when you are
stuck. Be assured that nothing in these early chapters is fundamentally
difficult. However, much will be unfamiliar and might therefore feel difficult at
first.
Later, we build on your initial skills to broaden your base of knowledge. We
use examples and exercises to solidify your understanding, and to provide a
conceptual base for programming.
AA
We place a heavy emphasis on ideals and reasons. You need ideals to guide
you when you look for practical solutions – to know when a solution is good
and principled. You need to understand the reasons behind those ideals to
understand why they should be your ideals, why aiming for them will help you
and the users of your code. Nobody should be satisfied with “because that’s
the way it is” as an explanation. More importantly, an understanding of ideals
and reasons allows you to generalize from what you know to new situations
and to combine ideas and tools in novel ways to address new problems.
Knowing “why” is an essential part of acquiring programming skills.
Conversely, just memorizing lots of poorly understood rules is limiting, a
source of errors, and a massive waste of time. We consider your time precious
and try not to waste it.
Many C++ language-technical details are banished to other sources, mostly
on the Web (§0.4.1). We assume that you have the initiative to search out
information when needed. Use the index and the table of contents. Don’t
forget the online help facilities of your compiler. Remember, though, to
consider every Web resource highly suspect until you have reason to believe
better of it. Many an authoritative-looking Web site is put up by a
programming novice or someone with something to sell. Others are simply
outdated. We provide a collection of links and information on our support Web
site: www.stroustrup.com/programming.xhtml.
Please don’t be too impatient for “realistic” examples. Our ideal example is
the shortest and simplest code that directly illustrates a language facility, a
concept, or a technique. Most real-world examples are far messier than ours,
yet do not consist of more than a combination of what we demonstrate.
Successful commercial programs with hundreds of thousands of lines of code
are based on techniques that we illustrate in a dozen 50-line programs. The
fastest way to understand real-world code is through a good understanding of
the fundamentals.
We do not use “cute examples involving cuddly animals” to illustrate our
points. We assume that you aim to write real programs to be used by real
people, so every example that is not presented as specifically language-
technical is taken from a real-world use. Our basic tone is that of professionals
addressing (future) professionals.
C++ rests on two pillars:
0.3.1 Portability
CC
It is common to write C++ to run on a variety of machines. Major C++
applications run on machines we haven’t ever heard of! We consider the use of
C++ on a variety of machine architectures and operating systems most
important. Essentially every example in this book is not only ISO Standard
C++, but also portable. By portable, we mean that we make no assumptions
about the computer, the operating system, and the compiler beyond that an
up-to-date standard-conforming C++ implementation is available. Unless
specifically stated, the code we present should work on every C++
Random documents with unrelated
content Scribd suggests to you:
1810
CHAPTER IV
INTRODUCTION
The beginning of the year 1810 saw the army of Lord Wellington
withdrawn from Spain, and awaiting in Portugal the attack of the
French, which seemed the inevitable. It was destined to wait many
months before the blow fell. King Joseph and his advisers committed
the error of invading Andalusia, the subjugation of which, and the
siege of Cadiz, involved the employment of the larger portion of the
forces at their disposal. Before they could invade Portugal, it was
necessary for them to give time for reinforcements to arrive from
France. The Emperor, having concluded peace with Austria, was
now able to spare some of his legions for the complete conquest of
the Peninsula. But the time of waiting was long. Astorga in the north
did not fall till 22nd April; Ciudad Rodrigo was not taken till 9th July.
In July the opposing forces were brought into contact on the 24th
in the Combat of the Coa, in which, owing to the obstinacy of
General Crawfurd, the Light Division was severely handled by very
superior numbers and nearly cut off. Followed the advance of the
French army and the siege of Almeida, which was taken on 27th
August.
Meanwhile, during these weary months of waiting, the Portuguese
army was growing in numbers and steadily improving in efficiency
and discipline. The language used concerning it in the letters is full of
confidence, and offers a contrast to the rather despondent tone of
the references to it at the beginning of the previous year.
Major Warre, after a very busy time in August, seems to have
been attacked by his old malady and to have been sent to Lisbon.
He thus, much to his chagrin, missed Bussaco and the retreat to the
lines of Torres Vedras. Early in October he had recovered sufficiently
to rejoin the Marshal at his Headquarters within the lines. But the
hard life and exposure resulted in a very serious relapse, which
brought him to death’s door, and the Medical Board determined that
he must be sent home. He arrived at Falmouth, after a bad voyage
of ten days, early in November, and the last two letters of this year’s
series, from Falmouth and Honiton respectively, indicate a very
tedious journey and a precarious state of health.
LETTERS
Lisbon, Feb. 6, 1810.
My Dear Kind Mother,
I was made quite happy, on my arrival three days since at this
place, by receiving your affectionate letter of 29th Decr. and 1st
Jany. (I have also received yours of Dec. 12th)....
I own I think you very much more gloomy than necessary as to
public affairs, and do not agree with you as to Ministers, as I approve
much of many of their measures. Our misfortunes in Spain they
neither could foresee or prevent. Who could imagine the Spaniards
would betray those who went to their assistance? Cowards they are
not—that is the soldier. He is capable of being equal to any in the
world. But without Officers, or of course confidence, without
discipline and betrayed by their Government, what could they do?
Our last accounts, and their enemy being before Cadiz, was as
unexpected as an earthquake, and quite as unaccountable, as that
Spain has no army. They [the French] will find it very difficult to
conquer this country, and though things in Spain are certainly very
dispiriting, the game is not lost. Nothing, however, but a revolution
(horrid as the idea is to humanity) can save it, and that is already
begun, I suspect, and I hope the traitors will fall. I am quite of the
opinion that Public safety is the Supreme Law, and the cant of
humanity, when the country is to be saved, I consider as weak and
unmanly. They have paid dearly for a bigoted adherence to old
absurd forms and prejudices. I do not mean that a revolution and
popular Government will now save them. But I am sure that it is the
only thing that can. They are very enthusiastical and violent, and
they abhor the French, against whom their fury will be directed as
well as against their Government and traitors; and in this tumult
some great characters may start up.
As to Flushing, our expedition there was disastrous, but well
meant. Who could foresee that Austria would so soon make peace?
And the diversion, had it continued the war, would have been of
great consequence. Besides, as a soldier, I think we make too much
fuss about the loss of men where a great object is to be obtained.
Victorious or beaten we must lose men, but while we regret their loss
individually, we should not as a public one, in so glorious and just a
cause, that of our political existence as a nation.
I write to Tom some account of our tour, which was very pleasant,
though rapid. We travelled near 200 leagues in less than two
months. Nothing can exceed the beauty of part of the country we
went through, and we had only one day rain, and our inspection of
the progress of the discipline of the Portuguese troops was as
pleasant as our most sanguine wishes could expect.
I am very sorry you had not received the letters I wrote from this in
answer to that you wrote in company from Hendon, which I
answered, each individually. I wrote also to my father and Emily in
December, which letters I hope you have since received, and I only
did not write from Porto, as I intended, from really not having time
hardly to sleep or eat, what between duty and grand ceremonies and
rejoicings. Nothing can have been more honourable or flattering to
the Marshal than his reception in that City, and indeed in every place
we have been in throughout the country, and he deserves it for his
unremitted exertions, and Herculean labour. There exists not a more
honourable firm man or a more zealous Patriot. His failings are mere
foibles of a temper naturally warm and hasty, and great zeal to have
everything right, without much patience. Those who accuse him of
severity are either those who have felt it because they deserved it,
their friends, or people wilfully ignorant of the state in which he found
the army. And of how much he has foreborne, as to myself, I declare
I do not know one instance of severity, and [do know] numberless
ones of his mercy, and goodness of heart, where others would have
been less lenient. You see I insensibly fall into politics, or the shop,
so called, but one naturally writes about what one’s mind is
constantly occupied with, and as the subject is not uninteresting I
hope you will not be angry at my writing to a lady on such grave
matters as Politics and Tactics, or rather more properly speaking, on
public concerns.
I was three days at Arouca with dear Clara, who is a most amiable
sensible woman. Her manners and sense are really quite
astonishing for one so constantly secluded from the world. She was
quite well. We put the convent in a terrible fuss by the Marshal’s
arrival to breakfast there, on his way to Vizeu. It was very kind of him
to go to pay her a visit, and he was very much pleased with her.
I have got an order from the Nuncio to remove her where I please,
in case of danger, but it is not quite what I wanted, and I shall try to
get a more general one, and bring her to Lisbon, when necessary,
where my friends the Louriçals will be glad to receive her. The
Marchioness has just lost her sister the Duchess of Laffões, and has
the care and guardianship of the young Duchess and her sister,
nieces to the Prince, a dismal prospect for her, poor thing, in the
present state of public affairs, but notwithstanding she will not allow
me to place Clara anywhere else, and she cannot be with more
amiable charming people. Adieu, as I write to Tom and know that he
will see this letter, and you his, shall say no more, but beg you will
give kindest love to my dear father, with thanks for his letter, from
your sincerely affectionate Son,
Wm. Warre.
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.
textbookfull.com