Accelerated C++
Practical Programming
by Example
Andrew Koenig
Barbara E. Moo
AAddison-Wesley
Boston • San Francisco • New York • Toronto • Montreal
London • Munich • Paris • Madrid
Capetown • Sydney • Tokyo • Singapore • Mexico City
Contents
Preface
Chapter 0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
Chapter 1
1.1
1.2
1.3
Chapter 2
2.1
2.2
2.3
2.4
2.5
2.6
2.7
•
Getting started
Comments
# i n c l u d e
The main function
Curly braces
Using the standard library for output
The r e t u r n statement
A slightly deeper look
Details
Working with strings
Input
Framing a name
Details
Looping and counting
The problem
Overall structure
Writing an unknown number of
Writing a row
The complete framing program
Counting
Details
rows
•
xi
1
1
2
2
2
3
3
4
5
9
9
11
14
17
17
18
18
22
27
30
31
VII
VÜi Contents
Chapter 3 Working with batches of data 35
3.1 Computing student grades 35
3.2 Using medians instead of averages 41
3.3 Details 48
Chapter 4 Organizing programs and data 51
4.1 Organizing computations 51
4.2 Organizing data 61
4.3 Putting it all together 65
4.4 Partitioning the grading program 68
4.5 The revised grading program 70
4.6 Details 71
Chapter 5 Using sequential containers and analyzing strings 75
5.1 Separating students into categories 75
5.2 Iterators 79
5.3 Using iterators instead of indices . 82
5.4 Rethinking our data structure for better performance 84
5.5 The l i s t type 85
5.6 Taking s t r i n g s apart 87
5.7 Testing our s p l i t function 90
5.8 Putting s t r i n g s together 91
5.9 Details 96
Chapter 6 Using library algorithms 101
6.1 Analyzing s t r i n g s 101
6.2 Comparing grading schemes 110
6.3 Classifying students, revisited 116
6.4 Algorithms, containers, and iterators 120
6.5 Details 121
Chapter 7 Using associative containers 123
7.1 Containers that support efficient look-up 123
7.2 Counting words ' 124
7.3 Generating a cross-reference table 126
7.4 Generating sentences 129
7.5 A note on performance 136
7.6 Details 137
Chapter 8 Writing generic functions 139
8.1 What is a generic function? • 139
8.2 Data-structure independence 143
8.3 Input and output iterators 150
8.4 Using iterators for flexibility 152
8.5 Details 153
Contents ix
Chapter 9 Defining new types 155
9.1 S t u d e n t _ i n f о revisited 155
9.2 Class types 156
9.3 Protection 160
9.4 The S t u d e n t _ i n f о class 163
9.5 Constructors 164
9.6 Using the S t u d e n t _ i n f о class 166
9.7 Details 167
Chapter 10 Managing memory and low-level data structures 169
10.1 Pointers and arrays 169
10.2 String literals revisited 176
10.3 Initializing arrays of character pointers 177
10.4 Arguments to main 179
10.5 Reading and writing files 180
10.6 Three kinds of memory management 182
10.7 Details 185
Chapter 11 Defining abstract data types 187
11.1 The Vec class 187
11.2 Implementing the Vec class 188
11.3 Copy control 195
11.4 Dynamic Vecs 202
11.5 Flexible memory management 203
11.6 Details 209
Chapter 12 Making class objects act like values 211
12.1 A simple string class 212
12.2 Automatic conversions 213
12.3 S t r operations 214
12.4 Some conversions are hazardous 221
12.5 Conversion operators 222
12.6 Conversions and memory management 223
12.7 Details 225
Chapter 13 Using inheritance and dynamic binding 227
13.1 Inheritance 227
13.2 Polymorphism and v i r t u a l functions 232
13.3 Using inheritance to solve our problem 237
13.4 A simple handle class 243
13.5 Using the handle class 247
13.6 Subtleties , 248
13.7 Details 250
X Contents
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
253
254
260
263
264
268
Chapter 15 Revisiting character pictures
15.1 Design
15.2 Implementation
15.3 Details
269
269
278
288
Chapter 16 Where do we go from here?
16.1 Use the abstractions you have
16.2 Learn more
Appendix A Language details
A.l Declarations
A.2 Types
A.3 Expressions
A.4 Statements
Appendix В Library summary
B.l Input-output
B.2 Containers and iterators
B.3 Algorithms
Index
291
291
293
295
295
299
305
308
311
311
314
322
325
本文档为【Accelerated C++】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑,
图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。