Accelerated C++
Practical Programming by Example
by Andrew Koenig and Barbara E. Moo
Addison-Wesley, 2000
ISBN 0-201-70353-X
Pages 336
Second Printing
Table of Contents
Contents
Chapter 0 Getting started
0.1 Comments
0.2 #include
0.3 The main function
0.4 Curly braces
0.5 Using the standard library for output
0.6 The return statement
0.7 A slightly deeper look
0.8 Details
Chapter 1 Working with strings
1.1 Input
1.2 Framing a name
1.3 Details
Chapter 2 Looping and counting
2.1 The problem
2.2 Overall structure
2.3 Writing an unknown number of rows
2.4 Writing a row
2.5 The complete framing program
2.6 Counting
2.7 Details
Chapter 3 Working with batches of data
3.1 Computing student grades
3.2 Using medians instead of averages
3.3 Details
Chapter 4 Organizing programs and data
4.1 Organizing computations
4.2 Organizing data
4.3 Putting it all together
4.4 Partitioning the grading program
4.5 The revised grading program
4.6 Details
Chapter 5 Using sequential containers and analyzing strings
5.1 Separating students into categories
5.2 Iterators
5.3 Using iterators instead of indices
5.4 Rethinking our data structure for better performance
5.5 The list type
5.6 Taking strings apart
5.7 Testing our split function
5.8 Putting strings together
5.9 Details
Chapter 6 Using library algorithms
6.1 Analyzing strings
6.2 Comparing grading schemes
6.3 Classifying students, revisited
6.4 Algorithms, containers, and iterators
6.5 Details
Chapter 7 Using associative containers
7.1 Containers that support efficient look-up
7.2 Counting words
7.3 Generating a cross-reference table
7.4 Generating sentences
7.5 A note on performance
7.6 Details
Chapter 8 Writing generic functions
8.1 What is a generic function?
8.2 Data-structure independence
8.3 Input and output iterators
8.4 Using iterators for flexibility
8.5 Details
Chapter 9 Defining new types
9.1 Student_info revisited
9.2 Class types
9.3 Protection
9.4 The Student_info class
9.5 Constructors
9.6 Using the Student_info class
9.7 Details
Chapter 10 Managing memory and low-level data structures
10.1 Pointers and arrays
10.2 String literals revisited
10.3 Initializing arrays of character pointers
10.4 Arguments to main
10.5 Reading and writing files
10.6 Three kinds of memory management
10.7 Details
Chapter 11 Defining abstract data types
11.1 The Vec class
11.2 Implementing the Vec class
11.3 Copy control
11.4 Dynamic Vecs
11.5 Flexible memory management
11.6 Details
Chapter 12 Making class objects act like values
12.1 A simple string class
12.2 Automatic conversions
12.3 Str operations
12.4 Some conversions are hazardous
12.5 Conversion operators
12.6 Conversions and memory management
12.7 Details
Chapter 13 Using inheritance and dynamic binding
13.1 Inheritance
13.2 Polymorphism and virtual functions
13.3 Using inheritance to solve our problem
13.4 A simple handle class
13.5 Using the handle class
13.6 Subtleties
13.7 Details
Chapter 14 Managing memory (almost) automatically
14.1 Handles that copy their objects
14.2 Reference-counted handles
14.3 Handles that let you decide when to share data
14.4 An improvement on controllable handles
14.5 Details
Chapter 15 Revisiting character pictures
15.1 Design
15.2 Implementation
15.3 Details
Chapter 16 Where do we go from here?
16.1 Use the abstractions you have
16.2 Learn more
Appendix A Language details
A.1 Declarations
A.2 Types
A.3 Expressions
A.4 Statements
Appendix B Library summary
B.1 Input-output
B.2 Containers and iterators
B.3 Algorithms
static const char* const letters[] = { /* ... */ };
because there is no intent ever to change its elements.
Page 195: The call to split(words) in the last line of the first code example should be
split(line).
Page 199: The name blanks should be spaces.
Page 200: The two references to words in the first complete paragraph (the second of
which is in a code example) should refer to line.
Page 220: In the last example on the page, the variables temp and s should be temp1
and greeting, respectively.
Page 221: In the second paragraph of section 12.4, we should be talking about Vec,
not vector. Moreover, in the hypothetical case, p would contain 42 empty rows, not 42
rows of single null characters.
Page 249: Just before the last example, the phrase "version of final in Core" should
be "version of regrade in Core."
Page 250: Near the end of the third line, final should be regrade.
Page 264: In the first example, the last comment should say "changes only s2 and not
s1" instead of "changes only s1 and not s2." In the following example, the call
make_unique(); should be cp.make_unique(); Page 281: in the last line before section
15.2.2, operator>> should be operator<<.
Page 282: In the last example, the last two parameters should be named beg and
end, respectively.
Page 287: In the discussion near the bottom of the page, protected allows access to
the base-class part of any object of the appropriate derived class, not just the
base-class part of the current object. What it does not allow is access to members of
freestanding base-class objects.
Page 292: Just before the sample output, the text describes the grade histogram as
containing asterisks, when it actually contains = symbols.
Clarifications in the first printing
Page 28: The description of the for statement should make it clear that the
init-statement is required to be either a definition or an expression statement.
Page 191: In the first complete paragraph, the two uses of size_t are easier to
understand if they refer to size_type instead, to match the code. The two names refer
to the same type, so the uses are technically correct, but it's easier to understand if
they're changed.
Page 193: The discussion of the size function at the bottom of the page makes it
appear that the type of the difference between two pointers is more important than it
really is. The real point is that although the value of limit - data has type ptrdiff_t,
returning that value from size converts it to size's return type.
Typographical details in the first printing
If a page has any constant-width text in the heading at the top of the page (which can
happen only for odd-numbered pages), the page number is very slightly smaller than
it should be. The affected page numbers are 3, 85, 87, 89, 91, 93, 95, 103, 105, 107,
109, 163, 179, 189, 191, 193, 215, 217, 219, 233, and 235.
Page xii: "language" should be "language" near the end of the third paragraph.
Page 24: Shortly before 2.4.1.2, change "such the ones" to "such as the ones."
Page 30: Change string::size_type to int in the two for statements at the bottom of the
page.
Page 34: The program in exercise 2-10 should have a return 0; statement at the end.
Page 45: Near the bottom, change "it should easy" to "it should be easy."
Page 72: The comments in the last example on the page have their beginning slashes
in italic font rather than constant-width font.
Page 158: The word "have" appears twice in a row in the first paragraph after the
numbered list near the top of the page.
Page 162: The word "the" appears twice in a row in the first complete paragraph on
this page.
Page 164: The word "be" appears twice in a row in paragraph 5, line 3.
Page 167: In the second line of the paragraph beginning "Protection labels,"
"accessible" should be "accessible."
Page 178: In the second complete paragraph from the end of the page, "determine
the its type" should be "determine its type."
Page 199: Immediately before the example, "in of an expression" should be "in an
expression." In the last complete paragraph, the word "the" appears twice in a row.
Page 203: On the first line of the page, "such this one" should be "such as this one."
Page 224: Near the middle of the page, "does not to prevent" should be "does not
prevent."
Page 253: Near the end of the second paragraph, "use the a single" should be "use a
single."
Page 260: In the first line of the first complete paragraph, "we would like be able"
should be "we would like to be able."
Page 262: In the second paragraph from the end, ``such Student_info'' should be
``such as Student_info.''
Page 283: In the first complete paragraph, "an ordinary member functions" should be
"an ordinary member function."
Page 289: In the fourth line, "parameter, type" should be "parameter type."
Page 307: The table extends beyond the nominal right margin.