Practical C Programming 2nd Edition Steve Oualline instant download
Practical C Programming 2nd Edition Steve Oualline instant download
https://ebookname.com/product/practical-c-programming-2nd-
edition-steve-oualline/
https://ebookname.com/product/practical-uml-statecharts-in-c-c-
event-driven-programming-for-embedded-systems-2nd-edition-miro-
samek/
https://ebookname.com/product/thinking-in-c-volume-2-practical-
programming-bruce-eckel/
https://ebookname.com/product/how-not-to-program-in-c-111-broken-
programs-and-3-working-ones-or-why-does-2-2-5986-1st-edition-
steve-oualline/
https://ebookname.com/product/the-image-of-a-country-created-by-
international-media-1st-edition-elena-tarasheva/
Broadbandits Inside the 750 Billion Telecom Heist 1st
Edition Om Malik
https://ebookname.com/product/broadbandits-inside-
the-750-billion-telecom-heist-1st-edition-om-malik/
https://ebookname.com/product/the-struggle-for-democracy-9th-
edition-edward-s-greenberg/
https://ebookname.com/product/canine-and-feline-nephrology-and-
urology-second-edition-dennis-j-chew-dvm-dacvim/
https://ebookname.com/product/canadian-painters-in-a-modern-
world-1925-1955-writings-and-reconsiderations-2nd-edition-lora-
senechal-carney/
https://ebookname.com/product/nanodevices-for-the-life-sciences-
nanotechnologies-for-the-life-sciences-volume-4-1st-edition-
challa-s-s-r-kumar/
Earthquake Resistant Design of Buildings 1st Edition
Muhammad Hadi (Author)
https://ebookname.com/product/earthquake-resistant-design-of-
buildings-1st-edition-muhammad-hadi-author/
• Table of C ontents
• Index
• Reviews
• Examples
• Reader Reviews
• Errata
Publisher : O'Reilly
Pub Date : December 2002
ISBN : 0-596-00419-2
Pages : 574
Publisher : O'Reilly
Pub Date : December 2002
ISBN : 0-596-00419-2
Pages : 574
C opyright
Preface
Scope of This Handbook
How This Book Is Organized
How to Read This Book If You Already Know C
Font C onventions
How to C ontact Us
Acknowledgments for the First Edition
Acknowledgments for the Second Edition
C hapter 3. Style
Section 3.1. C omments
C olophon
Index
Copyright
Copyright © 2003, 1995 O'Reilly & Associates, Inc.
Nutshell Handbook, the Nutshell Handbook logo, and the O'Reilly logo are
registered trademarks of O'Reilly & Associates, Inc. Many of the designations
used by manufacturers and sellers to distinguish their products are claimed as
trademarks. Where those designations appear in this book, and O'Reilly &
Associates, Inc. was aware of a trademark claim, the designations have been
printed in caps or initial caps. The association between the image of an Eastern
chipmunk and the topic of C++ programming is a trademark of O'Reilly &
Associates, Inc.
While every precaution has been taken in the preparation of this book, the
publisher and authors assume no responsibility for errors or omissions, or for
damages resulting from the use of the information contained herein.
Preface
This book is devoted to practical C++ programming. It teaches you not only
the mechanics of the language, but also style and debugging. The entire life
cycle of a program is discussed, including conception, design, writing,
debugging, release, documentation, maintenance, and revision.
Style is emphasized. Creating a good program involves more than just typing
code. It is an art in which writing and programming skills blend to form a
masterpiece. A well-written program not only functions correctly, but also is
simple and easy to understand. Comments allow programmers to include
descriptive text in their programs. Clearly written, well-commented programs
are highly prized.
Consider two programs. One was written by a clever programmer, using all the
tricks. The program contains no comments, but it works. The other is nicely
commented and well structured, but doesn't work. Which program is more
useful? In the long run, the "broken" one is more useful because it can be
fixed and maintained easily. Although the clever one works now, sooner or
later it will have to be modified. The hardest work you will ever have to do is
modifying a cleverly written program.
Scope of This Handbook
The GNU C++ compiler, named g++ (available for most Unix systems[1])
As far as standard C++ is concerned, there are only minor differences among
the various compilers. This book clearly indicates where compiler differences
can affect the programmer. Specific instructions are given for producing and
running programs using each of these compilers. The book also gives examples
of using the programming utility make for automated program production.
How This Book Is Organized
You must crawl before you walk. In Part I, you learn how to crawl. These
chapters teach you enough to write very simple programs. You start with the
mechanics of programming and programming style. Next, you learn how to use
variables and very simple decision and control statements.
At this point you will have learned enough to create very simple programs;
therefore, in Chapter 7, you embark on a complete tour of the programming
process that shows you how real programs are created.
Chapter 1 gives you an overview of C++, describes its history and uses,
and explains how the language is organized.
Chapter 2 explains the basic programming process and gives you enough
information to write a very simple program.
Chapter 6 explains simple decision statements including if, else, and for.
The problem of == versus = is discussed.
Chapter 7 takes you through the steps required for creating a simple
program, from specification through release. Fast prototyping and
debugging are discussed.
Part II describes all the other simple statements and operators that are used in
programming. You also learn how to organize these statements into simple
functions.
In Part III you learn how basic declarations and statements can be used in the
construction of advanced types such as structures, unions, and classes. You
also learn about the concept of pointers.
Advanced programming techniques are explored in Part IV. In this section, you
explore a number of C++ features that let you create complex, yet easy-to-
use objects or classes.
Chapter 23 shows how to split a program into several files and use
modular programming techniques. The make utility is explained in more
detail.
Chapter 25 describes the template library that comes with C++. This
library consists of a number of "container templates" and related data
structures which let you create very complex and robust data structures
with very little work.
Chapter 28 describes how to turn C code into C++ code and addresses
many of the traps lurking in C code that bite the C++ programmer.
Chapter 30 lists programming adages that will help you construct good
C++ programs.
Appendix C lists the rules that determine the order in which operators are
evaluated.
Appendix D contains a program that shows how the computer can compute
the value of the sine function.
C++ is built on the C language. If you know C, you will find much of the
material presented in Chapter 2 through Chapter 12 familiar.
An entirely new I/O system. (The basics are described in Chapter 4. The
new file system is discussed in detail in Chapter 16.)
So you can use C++ as a better C. But C++ has added some entirely new
features such as objects, templates, and exceptions. So starting with Chapter
13, you will begin to learn entirely new concepts.
Font Conventions
Italic
Used for directories and to emphasize new terms and concepts when they
are introduced. Italic is also used to highlight comments in examples.
Bold
Constant width
Used for programs and the elements of a program and in examples to show
the contents of files or the output from commands. A reference in text to a
word or item used in an example or code fragment is also shown in
constant width font.
Constant bold
Constant italic
"Quotes"
...
Stands for text (usually computer output) that's been omitted for clarity or
to save space.
There is a web page for this book, which lists errata, examples, or any
additional information. You can access this page at:
http://www.oreilly.com/catalog/cplus2
To comment or ask technical questions about this book, send email to:
bookquestions@oreilly.com
For more information about books, conferences, Resource Centers, and the
O'Reilly Network, see the O'Reilly web site at:
http://www.oreilly.com/
Acknowledgments for the First Edition
Thanks to Peg Kovar for her proofreading and editing help. Special thanks to
Dale Dougherty for ripping apart my first book and forcing me to put it
together correctly. I greatly appreciate the hard work put in by Phil Straite and
Gregory Satir. I especially thank all those people who reviewed and edited my
book. My thanks also go to the production group at O'Reilly & AssociatesNicole
Gipson, project manager and production editor; John Files, Juliette Muellner,
and Jane Ellin, production assistants; and Mike Sierra, book design
implementor. Finally, special thanks go to all the hard-working programmers
out there whose code has taught me so much.
Acknowledgments for the Second Edition
For the second edition I wish to thank my editor, Robert J. Denn, for his
patience and hard work in getting the book done. Thanks to Ray Lischner for
his technical insight. Al Stevens deserves special recognition for his extensive
knowledge of C++ and his exacting standards. His efforts helped me to tighten
the terminology and refine the examples in the book, resulting in a much more
precise manuscript. Any errors in this book are my own and are not the fault
of the reviewers or of the staff at O'Reilly.
Also I wish to give credit to all the sales and marketing people at O'Reilly who
work so hard to sell my book.
Other documents randomly have
different content
Finally, one face on each of the six pieces was pronounced finished,
and the next step was to "joint" or "dress down" one edge straight,
smooth and square with the working face—the first planed surface.
This seemed easier after the experience of making the bench hook,
and Harry knew how to test for squareness with the try square.
Working on the two long pieces for the body, both edges of each
were squared up, a 10-inch piece was marked off on one end of
each with pencil and try square, and sawed off with cross cut saw.
It was decided to leave the inner faces rough, as they would be
inside the trestle, and out of sight. These four pieces forming the
body were now nailed together with 21⁄2-inch wire nails, as shown in
a.
The four pieces for the legs were dressed on all four sides, and it
only remained to cut the angle at top and bottom.
This brought into use a new tool, the bevel. The angle x was found
by laying the bevel on the mechanical drawing, and fixing it at the
angle by tightening the set screw provided for the purpose. The line
was carried across the face by means of the try square, and the
bevel used on the farther edge. When this laying out was finished,
the piece looked like c, the triangular piece y being removed by
sawing directly on the pencil lines.
After the four legs were laid out in this manner and cut, they were
nailed to the body with 3-inch wire nails.
The saw horse was now complete with the exception of the two
braces, and the final truing up.
The braces were made by holding a piece of stock 4 inches × 7⁄8
inch in position and marking the slope with a pencil, sawing to pencil
lines and nailing in position d.
The final process of truing up was an interesting one to Harry, and
he used it many times afterward in finishing pieces of furniture, such
as tables, tabourettes, etc.
The horse was placed on the bench, and a pair of dividers set as
shown at e.
A line was scribed on each leg wherever the compasses point
touched it, holding the latter upright and going around all four sides
of each leg. By sawing to the lines made in this way, the trestle was
found to stand on the floor perfectly true. This is a method much
used in truing up articles that rest on three or more legs, and it
overcomes any inaccuracies that may have arisen in the process of
assembling; but it is very important that the surface on which this
truing up is done shall itself be perfectly true. The bench used in this
case was new and had not yet warped at all, but an old bench might
not have been suitable. This can be ascertained by testing the
surface in several directions with a long straight edge.
The facts of warping and shrinkage in wood must always be taken
into consideration.
The saw horse is an important part of every shop equipment, and
the boys now relegated the clumsy chairs to the kitchen, where they
belonged, and were prepared to saw out stock from their longest
boards.
XVI
Ralph had painted two signs and fastened them in prominent places
on the wall. One read: "One thing at a time"; the other, "A place for
everything, and everything in its place."
"Those are very old-fashioned," he said, "but they are none the less
absolutely true. Many boys fail to accomplish anything in tool work
because they do not heed the first, and more time is wasted than
we ever realize, particularly among mechanics, by failing to observe
the second. It often seems a waste of time to put a tool or piece of
stock away in a definite place, but, on the other hand, one often
spends ten times as many minutes in looking for a thing as he would
putting it in its place where it could be found instantly."
"What's the answer?" said Harry absent-mindedly.
"The answer is that we will make a rack for our lumber before we do
anything else.
"It need not be very fine work, but it will make our shop much
neater, if the surfaces of the wood are planed instead of being left
rough, and to give you practice in planing and to develop your
muscles, I am going to let you do most of the planing, while I lay
out the work."
The rack as finally constructed is shown in Fig. 93. The shop was not
sheathed on the inside, the framework or studding being exposed.
The short cross pieces were nailed to the studding with ten-penny
wire nails, but where they joined the uprights they were let into the
latter to a depth of 1⁄2 inch before being nailed. Harry wanted to
know what this was for, and Ralph explained that if the cross pieces
were simply nailed to the uprights, all the weight would be carried
by the nails. By letting or "gaining" them part way into the uprights,
the weight was carried by the latter without so much strain on the
nails.
"Then why don't you let them into the wall studs too?" asked Harry.
"Because the studs are in position and we couldn't saw them out
without breaking through the outside of the building; therefore we
are obliged simply to nail them on."
Fig. 93. The lumber rack
Four of the uprights were spaced three feet apart, and held in place
at top and bottom by blocks nailed to the ceiling and floor. A
carpenter would have simply "toe-nailed" them by driving nails at an
angle through the ends of the uprights into the floor, but the boys
were not yet skilled in carpenters' methods. An ideal lumber rack is
made of galvanized iron pipe. It is indestructible, fire-proof, rather
expensive, and the joints are regular pipe fitter's joints, elbows, tees,
crosses, and floor plates.
This was beyond our boys' pocket-book, as it would have required
the services of a pipe fitter.
One of the uprights laid out and partly cut is shown at a, the
openings having been taken out with cross cut saw and chisel.
On one of the upper tiers the cross pieces were made eight inches
longer than the others, and where they extended beyond the front
of the rack pieces of pine 6 × 2 × 7⁄8 inches were nailed to the
ends, making a convenient hook for hanging hand screws, which are
always in the way on the floor. It also made a very convenient shelf
for storing narrow waste strips of lumber, which should not be
destroyed, as one can never tell when they will be needed.
In the case of a rack made of iron pipe, the ends of these long cross
pieces need be only ordinary pipe elbows.
The labour of building a lumber rack was much heavier than
anything the boys had done before, but it brought the larger
muscles into play, seemed like real carpenter work, and was an
excellent preparation for the finer tool work to follow. A boy who has
never carried out a piece of large work successfully cannot realize
the satisfaction of looking at a really good piece of construction and
being able to say, "I made that all myself!"
Fig. 94. First wind vane
Ralph suggested that one or two things more were needed to make
their equipment ship-shape—one was a tool cabinet, and another
was some arrangement for storing small pieces of stock; but as both
of these required considerable tool practice, they were recorded in a
notebook as among the things to be done later on.
It was agreed that the shop needed a vane to show the direction of
the wind, and the boys' design for this is shown at Fig. 94. It
included a weather vane and windmill.
The whole combination required five pieces of wood. The two short
pieces, 7 inches long by 1 inch square, were first dressed to size, cut
out and halved together as shown. They were then taken apart and
cut to the lines shown, with a knife, making propeller blades similar
to those made for the aeroplane. When both were finished, they
were again put together, and a hole drilled through the centre a trifle
larger than a flat-head wire nail 21⁄2 inches long. This nail is to hold
the mill to the horizontal piece. The nail is to be tight in this
horizontal piece, but the windmill must revolve freely about the nail.
It is for this reason that the hole in the mill must be slightly larger
than the diameter of the nail.
The horizontal piece is bevelled on one end with the knife and has a
1⁄4-inch slot sawed out at the other. The slot is to receive the wind
vane. The vane was sawed out of 1⁄4-inch wood, fitted into the slot
and nailed with brads.
When all these parts were assembled, it was necessary to find the
centre of gravity of the whole combination, as it is important that it
be perfectly balanced.
To find the correct point, a light string was slipped under the
horizontal piece and moved back and forth until the vane hung
horizontally. The spot where the string touched the wood was
marked with a pencil and a 1⁄4-inch hole drilled at this point for the
pivot. A corresponding hole was drilled 3 inches deep into the
bevelled end of the standard.
A piece of 1⁄4-inch maple dowel was used as a pivot, the upper end
being sand-papered until the vane swung freely. The boys found that
by placing a metal washer between the vane and its standard, much
of the friction was removed. A wire nail driven into the standard
through a hole drilled in the horizontal piece would have answered
the same purpose as the dowel. When the centre of gravity is not
found for the pivot, the vane is apt to tilt forward or backward and
not only look badly, but bring considerable friction on one end, so
that it will not revolve freely with the wind.
XVII
In the meantime, Harry had found out to his own satisfaction that
his water-wheel windmill would not work.
"What have you curved those ends out for?" he exclaimed on
catching a sight of Ralph's vane.
"Why, to make it more sensitive to the slightest breeze. Those
curves catch the wind quicker than flat surfaces; have you never
noticed that on the weather bureau vanes they are always curved
out like that?"
"No," said Harry. "By the way, do you know why my mill doesn't
work?"
"I have told you about six times that a water-wheel receives the
water on one side only, while your mill receives the same pressure
on both sides of the centre. The two forces balance, so your mill
can't very well turn. If you could cut off the wind from one side, it
would go all right."
"Well, why can't I box in one side?"
"You can, but then you will have to shift it every time the wind
changes. You could construct a combination mill and vane, and
arrange it so that the box would be shifted by the vane, but
honestly, I don't think it worth the trouble. It would be clumsy, top-
heavy, and hard to balance. I have a scheme for a horizontal mill,
but we will take it up later. In the meantime, let's make a happy jack
windmill!"
"Happy jack?"
"That's what they call them, but we will try to be original and I
propose an Indian with war clubs."
"Whew! That sounds interesting!"
Ralph's sketch of the Indian is shown in Fig. 96. The figure was
sawed out of 1⁄2-inch pine, a 3⁄8-inch hole bored for the arms, and a
1⁄4-inch hole bored for the dowel pivot at the feet. The arms were
made of a piece of dowel, six inches long, with 3⁄16-inch holes bored
near the ends to receive the "clubs." These were whittled out of
pine, each club being a propeller blade. When fastened into the
dowel they formed a complete two-bladed propeller, but this was not
done until the dowel had been inserted through the Indian's
shoulders, and a brad driven through on each side of the body to
keep the arms in place.
Harry was so anxious to see it work
that he came near spoiling it, and had
to be restrained by the older boy, as in
making these toys a well balanced
figure is very important. When it was
finally finished, and placed out in the
wind, the antics of the Indian made
Harry laugh till the tears ran down his
cheeks.
"That's the finest thing we ever made,"
he said. Ralph smiled. It seemed that
he had heard something like that
several times before.
An athlete was suggested, and a bold
figure with outstretched arms was
sketched, as shown in Fig. 97.
Fig. 96. Happy jack The Indian clubs he is supposed to be
swinging were propeller blades, and to
give them more uniform motion than in the case of the Indian, the
hands were drilled and a piece of 1⁄4-inch dowel inserted. At each
end of the dowel was fastened a blade which had been drilled to fit.
Brads were driven through the dowel on each side of the hand to
keep the clubs swinging freely.
The body and arms were cut from a
piece of 1⁄2-inch pine and halved
together across the chest, and after
the joint was made the form of the
body and the arms whittled out with a
knife. The two parts were then
fastened together with brads.
It was important that this figure face
the wind, so into the space between
the ankles was fitted the small end of
a wind vane and the figure securely
fastened to it with brads. The centre of
gravity was then found and the whole
combination pivoted on a generous
piece of 1⁄4-inch dowel.
A hole was drilled through the centre of each propeller and another
in the flat stern of each air-ship. The pivots for the propellers were
flat-head wire nails small enough for the blades to revolve freely, but
driven securely into the air-ships.
These were now fastened at the ends of the arms of the
anemometer by attaching two strips of basswood to each ship by
wires. The strips were to hold the ships in the proper position facing
in the direction of motion, which was always the same, no matter in
which direction the wind was blowing.
The upper ends of these strips were brought together, and securely
fastened under one of the bolts by wires.
As the anemometer revolved, centrifugal force sent the air-ships out
as far as the basswood strips would allow.
It was a very interesting fair weather
toy, but the first gale, while having no
effect on the anemometer other than
to make it spin around at terrific
speed, nearly wrecked the ships by
slamming them against the standard. Fig. 99. The Zeppelin
So the boys always took the ships off wind vane
at night, and put them on again when
they wanted to give an exhibition.
The propellers were gilded and the ships painted in bright colours.
A very simple vane may be made to represent a Zeppelin air-ship
(Fig. 99) by cutting out a piece of white pine 2 feet long and 21⁄2
inches wide with the ends pointed to the shape of a Gothic arch. The
hole for the pivot should be bored 2 inches deep and be placed well
forward of the centre. To make the vane balance, the rear portion
from the pivot to the stern should be planed thin and rounded with
the spokeshave.
Fig. 100. A six-bladed mill
TOOLS: SAWS
One end of the turning saw can be released from the frame by
removing a pin, passed through a small hole. This is fastened in the
frame again and made to follow a curved line like a fret or coping
saw.
The number of teeth to the inch varies, and saws are rated as four-
point, five-point, etc., according to the number of points or spaces to
the inch. For very hard woods, a saw with small teeth, i. e., with
more points than ordinary to the inch, should be used; but a boy
who possesses one saw of each kind—a rip, a cross cut, a back saw,
and a turning saw—has all that will be required for ordinary
woodwork.
TOOLS: PLANES
A boy buying his tool outfit is often bewildered by the array in the
hardware store. He is further confused by the advice of the
salesman, and his own little store of money.
In selecting planes, only three are really necessary for ordinary
work, and this number may even be reduced to two.
Wooden planes are still the favourite tools of some woodworkers,
but iron planes have largely superseded them. A 15-inch iron jack
plane, a 9-inch smoothing plane, and a block plane make a very
good combination for a beginning.
Special planes can be added later, as the finances will allow.
The iron plane with its various parts is shown in Fig. 111. These
refer to either the jack or the smooth plane.
In the block plane there is no cap iron, the cutter or plane iron being
placed with the bevelled side up. There is frequently found on this
tool an adjustment for changing the amount of opening in the mouth
for hard or soft woods.
The plane iron and cap are fastened together with a set screw, and
the cap is removed when it is being ground or sharpened on an
oilstone.
This set screw, which is loosened with a screw-driver, or the edge of
the clamp used as a screw-driver, also allows the distance from the
cutting edge to the cap to be changed for soft or hard woods. These
two irons are fastened into the throat of the plane by the clamp.
The
lever (1)
is for
straighte
ning the
plane
iron, and
the
Fig. 111b. The screw s
smoothing plane is for Fig. 111. The smoothing
adjusting plane
the depth of the cut.
The difference between the jack and smooth planes, aside from the
size, is in the shape of the "cutter" or "bit." In the jack plane, the bit
is ground with a slightly curved cutting edge. This enables the tool
to remove coarse shavings, but leaves a slightly corrugated surface
which must be smoothed with the smoothing plane.
The jack plane also tends to straighten the work, owing to its
greater length. The greater the length, the more does it straighten.
The old-fashioned jointers were made several feet long for this very
purpose.
If a boy can afford only one plane, it should be a jack plane, but the
cutter should be ground straight to act as a smooth plane.
The block plane can be dispensed with better than any of the others,
because the smooth plane can be used on a shooting board for
truing up end grain, the original purpose of the block plane.
The latter plane has no cap, as it works on the ends of the wood
fibres with a shearing or paring action. This is helped by holding the
tool at an angle with the wood, a position not advisable with the
other two tools.
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.
ebookname.com