Ammeraal, L. (1995) C++ for Programmers, Chichester: John Wiley

Contents

Preface ix

Chapter 1 Introduction 1
1.1 About C++ and Other Languages 1
1.2 Our First C++ Program 3
1.3 Memory Organization and Binary Numbers 7
1.4 Identifiers and Keywords 9
1.5 Constants 10
1.6 Comment 14
Exercises 15

Chapter 2 Expressions and Statements 17
2.1 Arithmetic Operations 17
2.2 Types, Variables, and Assignments 20
2.3 Comparison and Logical Operators 27
2.4 Compound and Conditional Statements 29
2.5 Iteration Statements 34
2.6 Break, Continue, Goto, Switch 39
Exercises 43

Chapter 3 More Operators 45
3.1 Conditional Expressions 45
3.2 The Comma-operator 47
3.3 Bit Manipulation 52
3.4 Simple Arrays 56
3.5 Associativity 58
3.6 Precedence of Operators 61
3.7 Arithmetic Conversions and the Cast-operator 65
3.8 Lvalues 70
Exercises 72

Chapter 4 Functions and Program Structure 75
4.1 Definition and Declarations of Functions 75
4.2 The void Keyword; Global Variables 79
4.3 Altering Variables via Parameters 83
4.4 Types of Arguments and Return Values 86
4.5 Initialization 88
4.6 Separate Compilation 91
4.7 Some Mathematical Standard Functions 94
4.8 Function Overloading 95
4.9 References as Return Values 99
4.10 Inline Functions and Macros 100
4.11 Other Preprocessor Facilities 105
Exercises 111

Chapter 5 Arrays, Pointers, and Strings 115
5.1 Address Arithmetic 115
5.2 Function Arguments and Arrays 117
5.3 Pointers 119
5.4 Strings 125
5.5 String Operations 128
5.6 Dynamic Memory Allocation 136
5.7 Input and Output of Strings 142
5.8 Strings as Arguments and as Return Values 145
5.9 Multi-dimensional Arrays 148
5.10 Program Parameters 153
5.11 The Functions sscanf and sprintf 155
5.12 Pointers to Functions 156
Exercises 158

Chapter 6 Classes and Objects 161
6.1 Classes and Structures 161
6.2 Classes as Arguments and as Return Values 167
6.3 Unions 171
6.4 Bit Fields 172
6.5 Member Functions and Encapsulation 172
6.6 Member Access Control 175
6.7 Constructors and Destructors 177
6.8 Operator Overloading and Friend Functions 184
6.9 Type Conversion for Classes 192
6.10 Copying a Class Object 195
Exercises 201

Chapter 7 Object-oriented Programming 203
7.1 Interface, Implementation, and Application Files 203
7.2 A Class for Sets 204
7.3 Derived Classes and Inheritance 210
7.4 Virtual Functions and Late Binding 216
7.5 Static Class Members 223
7.6 Pointers to Members 224
7.7 Polymorphism and Reusability 228
7.8 Iterators 232
7.9 A Calculator for Rational Arithmetic 236
Exercises 244

Chapter 8 Standard I/O 247
8.1 Introduction 247
8.2 The Function printf 249
8.3 The Function scanf 252
8.4 Files 257
8.5 'Binary Files' 265
8.6 Random Access 268
Exercises 273

Chapter 9 Stream I/O 275
9.1 Streams 275
9.2 Output 276
9.3 Input 285
9.4 File I/O 289
9.5 Random Access; Error States 292
9.6 In-memory Format Conversion 296
Exercises 297

Chapter 10 Standard Library Functions 299
10.1 Diagnostics: <assert.h> 300
10.2 Character Classification: <ctype.h> 300
10.3 Error Numbers: <errno.h> 301
10.4 Floating-point Precision: <float.h> 301
10.5 Maximum Integer, etc.: <limits.h> 303
10.6 Mathematical Functions: <math.h> 303
10.7 Non-local Jumps: <setjmp.h> 305
10.8 Special Situations: <signal.h> 306
10.9 Variable-length Argument Lists: <stdarg.h> 307
10.10 Special Types: <stddef.h> 308
10.11 Input and Output: <stdio.h> 309
10.12 Miscellaneous: <stdlib.h> 313
10.13 String Functions: <string.h> 317
10.14 Time and Date: <time.h> 320

Chapter 11 Templates 323
11.1 Introduction 323
11.2 Function Templates 323
11.3 Class Templates 327
11.4 A Quicksort Template 331

Chapter 12 Exception Handling 335
12.1 Errors and Exceptions 335
12.2 Using the Keywords try, catch and throw 337
12.3 Error Handling with new 341
12.4 The set_terminate Function 343
12.5 Exception Specifications and set_unexpected 344

Appendix A: More Exercises 347

Appendix B: ASCII Table 365

Appendix C: More About Manipulators 367
C.1 Manipulators without Parameters 367
C.2 Defining Manipulators with Parameters 369

Bibliography 373

Index 375

Back to list of recent books by the same author
Publisher's web page