C++ from the ground up

Free Download

Authors:

Edition: 3rd ed

ISBN: 9780072228977, 0072228970

Size: 5 MB (5723099 bytes)

Pages: 626/626

File format:

Language:

Publishing Year:

Category:

Herbert Schildt9780072228977, 0072228970

This excellent primer provides a plethora of C++ programming information for beginning to intermediate users on topics like classes, objects, expressions, arrays, pointers. Plus, it also covers advanced topics like inheritance, namespaces, STL, custom string class, and the Standard C++ Class Library. For users of all levels, this guide teaches with examples of source code and a thorough display of the results.

Table of contents :
C++
from the Ground Up……Page 3
About the Author……Page 4
Contents……Page 7
Preface……Page 19
For Further Study……Page 21
1 The Story of C++……Page 23
The Creation of C……Page 24
Understanding the Need for C++……Page 26
C++ Is Born……Page 27
What Is Object- Oriented Programming?……Page 28
Polymorphism……Page 29
How C++ Relates to Java and C#……Page 30
2 An Overview of C++……Page 33
Entering the Program……Page 34
Compiling the Program……Page 35
A Line- by- Line Explanation……Page 36
Handling Syntax Errors……Page 38
A Second Simple Program……Page 39
A More Practical Example……Page 40
A New Data Type……Page 41
Functions……Page 42
A Program with Two Functions……Page 43
Function Arguments……Page 44
Functions Returning Values……Page 46
The main( ) Function……Page 47
Some Output Options……Page 48
The if Statement……Page 49
The for Loop……Page 50
Blocks of Code……Page 51
Semicolons and Positioning……Page 52
C++ Keywords……Page 53
The Standard C++ Library……Page 54
3 The Basic Data Types……Page 55
Local Variables……Page 57
Formal Parameters……Page 58
Global Variables……Page 59
Some Type Modifiers……Page 60
Literals……Page 63
String Literals……Page 65
Character Escape Sequences……Page 66
Variable Initializations……Page 67
Arithmetic Operators……Page 68
Increment and Decrement……Page 70
How C++ Got Its Name……Page 71
Relational and Logical Operators……Page 72
Converting to and from bool……Page 75
Casts……Page 76
Spacing and Parentheses……Page 77
4 Program Control Statements……Page 79
The if Statement……Page 80
The Conditional Expression……Page 81
Nested ifs……Page 82
The if- else- if Ladder……Page 83
The for Loop……Page 84
Some Variations on the for Loop……Page 86
The Infinite Loop……Page 88
The switch Statement……Page 89
The while Loop……Page 93
The do- while Loop……Page 95
Using continue……Page 96
Using break to Exit Loops……Page 97
Nested Loops……Page 98
Using the goto Statement……Page 99
Putting Together the Pieces……Page 100
5 Arrays and Strings……Page 103
One- Dimensional Arrays……Page 104
No Bounds Checking……Page 106
Sorting an Array……Page 107
Strings……Page 108
Reading a String from the Keyboard……Page 109
strcat……Page 111
strcmp……Page 112
strlen……Page 113
Using the Null Terminator……Page 115
Two- Dimensional Arrays……Page 116
Array Initialization……Page 118
Unsized Array Initializations……Page 122
Arrays of Strings……Page 123
An Example Using String Arrays……Page 124
6 Pointers……Page 127
What Are Pointers?……Page 128
The Pointer Operators……Page 129
The Base Type Is Important……Page 130
Pointer Expressions……Page 132
Pointer Arithmetic……Page 133
Pointers and Arrays……Page 134
Indexing a Pointer……Page 137
Are Pointers and Arrays Interchangeable?……Page 138
A Comparison Example……Page 139
Arrays of Pointers……Page 140
The Null Pointer Convention……Page 143
Pointers and 16- bit Environments……Page 144
Invalid Pointer Comparisons……Page 146
Forgetting to Reset a Pointer……Page 147
7 Functions, Part One: The Fundamentals……Page 149
Local Variables……Page 150
Global Variables……Page 156
Calling Functions with Pointers……Page 158
Calling Functions with Arrays……Page 159
Passing Strings……Page 162
argc and argv: Arguments to main( )……Page 163
Passing Numeric Command Line Arguments……Page 166
The return Statement……Page 167
Returning from a Function……Page 168
Returning Values……Page 169
Functions That Return Pointers……Page 171
Function Prototypes……Page 173
Headers: A Closer Look……Page 174
Recursion……Page 175
8 Functions, Part Two: References, Overloading,
and Default Arguments……Page 179
How C++ Passes Arguments……Page 180
Using a Pointer to Create a Call- by- Reference……Page 181
Reference Parameters……Page 182
Declaring Reference Parameters 8……Page 185
Returning References……Page 186
Creating a Bounded Array……Page 189
Independent References……Page 190
A Few Restrictions When Using References……Page 191
Function Overloading……Page 192
Default Function Arguments……Page 195
Default Arguments versus Overloading……Page 197
Function Overloading and Ambiguity……Page 199
9 More Data Types and Operators……Page 203
const……Page 204
volatile……Page 206
auto……Page 207
extern……Page 208
static Variables……Page 209
Register Variables……Page 213
The Origins of the register Modifier……Page 214
Enumerations……Page 215
Bitwise Operators……Page 219
AND, OR, XOR, and NOT……Page 220
The Shift Operators……Page 224
The ? Operator……Page 225
The Comma Operator……Page 227
Using sizeof……Page 228
Dynamic Allocation Using new and delete……Page 229
Allocating Arrays……Page 232
C¡¯s Approach to Dynamic Allocation:malloc( ) and free( )……Page 233
Precedence Summary……Page 235
10 Structures and Unions……Page 237
Structures……Page 238
Accessing Structure Members……Page 240
A Simple Inventory Example……Page 241
Passing Structures to Functions……Page 248
Assigning Structures……Page 249
Pointers to Structures and the Arrow Operator……Page 250
References to Structures……Page 254
Arrays and Structures Within Structures……Page 255
C Structure Versus C++ Structures……Page 256
Bit- Fields……Page 257
Unions……Page 259
Anonymous Unions……Page 264
Moving On to Object- Oriented Programming……Page 265
11 Introducing the Class……Page 267
Class Fundamentals……Page 268
A Closer Look at Class Member Access……Page 272
Constructors and Destructors……Page 274
Parameterized Constructors……Page 277
An Initialization Alternative……Page 281
Classes and Structures Are Related……Page 282
Structures versus Classes……Page 284
Unions and Classes Are Related……Page 285
Inline Functions……Page 286
Creating Inline Functions Inside a Class……Page 287
Arrays of Objects……Page 289
Initializing Object Arrays……Page 290
Pointers to Objects……Page 292
Object References……Page 294
12 A Closer Look at Classes……Page 295
Friend Functions……Page 296
Overloading Constructors……Page 300
Applying Dynamic Initialization to Constructors……Page 302
Assigning Objects……Page 304
Passing Objects to Functions……Page 305
Constructors, Destructors, and Passing Objects……Page 306
A Potential Problem When Passing Objects……Page 307
Returning Objects……Page 310
A Potential Problem When Returning Objects……Page 311
Creating and Using a Copy Constructor……Page 313
Copy Constructors and Parameters……Page 314
Copy Constructors and Initializations……Page 316
Using Copy Constructors When an Object Is Returned……Page 317
Copy Constructors ¡ª Is There a Simpler Way?……Page 318
The this Keyword……Page 319
13 Operator Overloading……Page 321
Operator Overloading Using Member Functions……Page 322
Using Member Functions to Overload Unary Operators……Page 325
Operator Overloading Tips and Restrictions……Page 330
Order Matters……Page 331
Using a Friend to Overload a Unary Operator……Page 335
Overloading the Relational and Logical Operators……Page 338
A Closer Look at the Assignment Operator……Page 339
Overloading [ ]……Page 342
Overloading ( )……Page 346
Another Example of Operator Overloading……Page 347
14 Inheritance……Page 353
Introducing Inheritance……Page 354
Base Class Access Control……Page 357
Using protected Members……Page 359
Using protected for Inheritance of a Base Class……Page 362
Inheriting Multiple Base Classes……Page 364
When Constructors and Destructors Are Executed……Page 365
Passing Parameters to Base Class Constructors……Page 368
Granting Access……Page 372
Virtual Base Classes……Page 374
15 Virtual Functions and Polymorphism……Page 379
Pointers to Derived Types……Page 380
Virtual Functions……Page 382
Virtual Functions Are Inherited……Page 385
Why Virtual Functions?……Page 387
A Simple Application of Virtual Functions……Page 388
Pure Virtual Functions and Abstract Classes……Page 392
Early versus Late Binding……Page 394
Polymorphism and the Purist……Page 395
16 Templates……Page 397
Generic Functions……Page 398
A Function with Two Generic Types……Page 400
Explicitly Overloading a Generic Function……Page 401
Overloading a Function Template……Page 403
Using Standard Parameters with Template Functions……Page 404
Creating a Generic abs( ) Function……Page 405
Generic Classes……Page 406
An Example with Two Generic Data Types……Page 409
Creating a Generic Array Class……Page 410
Using Non- Type Arguments with Generic Classes……Page 411
Using Default Arguments with Template Classes……Page 413
Explicit Class Specializations……Page 415
17 Exception Handling……Page 417
Exception Handling Fundamentals……Page 418
exit( ) and abort( )……Page 420
Catching Class Types……Page 423
Using Multiple catch Statements……Page 424
Catching All Exceptions……Page 426
Restricting Exceptions Thrown by a Function……Page 428
Rethrowing an Exception……Page 430
Handling Exceptions Thrown by new……Page 431
The nothrow Alternative……Page 432
Overloading new and delete……Page 433
Overloading the nothrow Version of new……Page 437
18 The C++ I/O System……Page 439
C++ Streams……Page 440
The C++ Stream Classes……Page 441
Overloading the I/ O Operators……Page 442
Creating Inserters……Page 443
Using Friend Functions to Overload Inserters……Page 445
Overloading Extractors……Page 446
Formatting with the ios Member Functions……Page 448
Using I/ O Manipulators……Page 453
Creating Your Own Manipulator Functions……Page 455
Opening and Closing a File……Page 457
Reading and Writing Text Files……Page 460
Unformatted Binary I/ O……Page 461
Reading and Writing Blocks of Data……Page 463
Detecting EOF……Page 464
A File Comparison Example……Page 465
More Binary I/ O Functions……Page 466
Random Access……Page 468
Checking I/ O Status……Page 470
Customized I/ O and Files……Page 471
19 Run-Time Type ID and the Casting Operators……Page 473
Run- Time Type Identification ( RTTI)……Page 474
A Simple Application of Run- Time Type ID……Page 478
typeid Can Be Applied to Template Classes……Page 480
dynamic_ cast……Page 484
const_ cast……Page 489
static_ cast……Page 490
reinterpret_ cast……Page 491
The Traditional Cast Versus the Four Casting Operators……Page 492
20 Namespaces and Other Advanced Topics……Page 493
Namespace Fundamentals……Page 494
using……Page 497
Unnamed Namespaces……Page 499
The std Namespace……Page 500
Pointers to Functions……Page 502
Finding the Address of an Overloaded Function……Page 505
Static Class Members……Page 506
const Member Functions and mutable……Page 508
Explicit Constructors……Page 510
The Member Initialization Syntax……Page 512
Linkage Specification……Page 515
The .* and ¨C>* Pointer- to- Member Operators……Page 517
Creating Conversion Functions……Page 519
21 Introducing the Standard Template Library……Page 521
An Overview of the STL……Page 522
The Container Classes……Page 524
Vectors……Page 526
Accessing a Vector Through an Iterator……Page 530
Inserting and Deleting Elements in a Vector……Page 531
Storing Class Objects in a Vector……Page 532
The Power of Iterators……Page 535
Lists……Page 536
Sort a List……Page 541
Merging One List with Another……Page 542
Storing Class Objects in a List……Page 543
Maps……Page 545
Storing Class Objects in a Map……Page 550
Algorithms……Page 551
Counting……Page 554
Removing and Replacing Elements……Page 555
Transforming a Sequence……Page 557
The string Class 21……Page 559
Some string Member Functions……Page 563
Final Thoughts on the STL……Page 567
22 The C++ Preprocessor……Page 569
# define……Page 570
Function- Like Macros……Page 572
# include……Page 574
# if, # else, # elif, and # endif……Page 575
# ifdef and # ifndef……Page 577
# undef……Page 578
The Diminishing Role of the Preprocessor……Page 579
# line……Page 580
The # and ## Preprocessor Operators……Page 581
Predefined Macro Names……Page 582
Final Thoughts……Page 583
A C-Based I/Oased I/ O……Page 585
C I/ O Uses Streams……Page 586
printf( )……Page 587
scanf( )……Page 589
The C File System……Page 594
fopen( )……Page 595
fgetc( )……Page 596
Using fopen( ), fgetc( ), fputc( ), and fclose( )……Page 597
ferror( ) and rewind( )……Page 598
fread( ) and fwrite( )……Page 599
fseek( ) and Random- Access I/ O……Page 600
fprintf( ) and fscanf( )……Page 601
Erasing Files……Page 602
B Working with an Older C++ Compiler……Page 603
BookmarkTitle:……Page 0
Two Simple Changes……Page 605
C The .NET Managed Extensions to C++……Page 607
_ _ abstract……Page 608
_ _ nogc……Page 609
Preprocessor Extensions……Page 610
Compiling Managed C++……Page 611
Index……Page 613

Reviews

There are no reviews yet.

Be the first to review “C++ from the ground up”
Shopping Cart
Scroll to Top