C++ From the Ground Up

Free Download

Authors:

Edition: 3

ISBN: 9780072228977, 0-07-222897-0

Size: 2 MB (2454431 bytes)

Pages: 625/625

File format:

Language:

Publishing Year:

Category: Tags: , ,

Herbert Schildt9780072228977, 0-07-222897-0

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 2
About the Author……Page 3
Contents……Page 6
Preface……Page 18
For Further Study……Page 20
1 The Story of C++……Page 22
The Creation of C……Page 23
Understanding the Need for C++……Page 25
C++ Is Born……Page 26
What Is Object- Oriented Programming?……Page 27
Polymorphism……Page 28
How C++ Relates to Java and C#……Page 29
2 An Overview of C++……Page 32
Entering the Program……Page 33
Compiling the Program……Page 34
A Line- by- Line Explanation……Page 35
Handling Syntax Errors……Page 37
A Second Simple Program……Page 38
A More Practical Example……Page 39
A New Data Type……Page 40
Functions……Page 41
A Program with Two Functions……Page 42
Function Arguments……Page 43
Functions Returning Values……Page 45
The main( ) Function……Page 46
Some Output Options……Page 47
The if Statement……Page 48
The for Loop……Page 49
Blocks of Code……Page 50
Semicolons and Positioning……Page 51
C++ Keywords……Page 52
The Standard C++ Library……Page 53
3 The Basic Data Types……Page 54
Local Variables……Page 56
Formal Parameters……Page 57
Global Variables……Page 58
Some Type Modifiers……Page 59
Literals……Page 62
String Literals……Page 64
Character Escape Sequences……Page 65
Variable Initializations……Page 66
Arithmetic Operators……Page 67
Increment and Decrement……Page 69
How C++ Got Its Name……Page 70
Relational and Logical Operators……Page 71
Converting to and from bool……Page 74
Casts……Page 75
Spacing and Parentheses……Page 76
4 Program Control Statements……Page 78
The if Statement……Page 79
The Conditional Expression……Page 80
Nested ifs……Page 81
The if- else- if Ladder……Page 82
The for Loop……Page 83
Some Variations on the for Loop……Page 85
The Infinite Loop……Page 87
The switch Statement……Page 88
The while Loop……Page 92
The do- while Loop……Page 94
Using continue……Page 95
Using break to Exit Loops……Page 96
Nested Loops……Page 97
Using the goto Statement……Page 98
Putting Together the Pieces……Page 99
5 Arrays and Strings……Page 102
One- Dimensional Arrays……Page 103
No Bounds Checking……Page 105
Sorting an Array……Page 106
Strings……Page 107
Reading a String from the Keyboard……Page 108
strcat……Page 110
strcmp……Page 111
strlen……Page 112
Using the Null Terminator……Page 114
Two- Dimensional Arrays……Page 115
Array Initialization……Page 117
Unsized Array Initializations……Page 121
Arrays of Strings……Page 122
An Example Using String Arrays……Page 123
6 Pointers……Page 126
What Are Pointers?……Page 127
The Pointer Operators……Page 128
The Base Type Is Important……Page 129
Pointer Expressions……Page 131
Pointer Arithmetic……Page 132
Pointers and Arrays……Page 133
Indexing a Pointer……Page 136
Are Pointers and Arrays Interchangeable?……Page 137
A Comparison Example……Page 138
Arrays of Pointers……Page 139
The Null Pointer Convention……Page 142
Pointers and 16- bit Environments……Page 143
Invalid Pointer Comparisons……Page 145
Forgetting to Reset a Pointer……Page 146
7 Functions, Part One: The Fundamentals……Page 148
Local Variables……Page 149
Global Variables……Page 155
Calling Functions with Pointers……Page 157
Calling Functions with Arrays……Page 158
Passing Strings……Page 161
argc and argv: Arguments to main( )……Page 162
Passing Numeric Command Line Arguments……Page 165
The return Statement……Page 166
Returning from a Function……Page 167
Returning Values……Page 168
Functions That Return Pointers……Page 170
Function Prototypes……Page 172
Headers: A Closer Look……Page 173
Recursion……Page 174
8 Functions, Part Two: References, Overloading,
and Default Arguments……Page 178
How C++ Passes Arguments……Page 179
Using a Pointer to Create a Call- by- Reference……Page 180
Reference Parameters……Page 181
Declaring Reference Parameters 8……Page 184
Returning References……Page 185
Creating a Bounded Array……Page 188
Independent References……Page 189
A Few Restrictions When Using References……Page 190
Function Overloading……Page 191
Default Function Arguments……Page 194
Default Arguments versus Overloading……Page 196
Function Overloading and Ambiguity……Page 198
9 More Data Types and Operators……Page 202
const……Page 203
volatile……Page 205
auto……Page 206
extern……Page 207
static Variables……Page 208
Register Variables……Page 212
The Origins of the register Modifier……Page 213
Enumerations……Page 214
Bitwise Operators……Page 218
AND, OR, XOR, and NOT……Page 219
The Shift Operators……Page 223
The ? Operator……Page 224
The Comma Operator……Page 226
Using sizeof……Page 227
Dynamic Allocation Using new and delete……Page 228
Allocating Arrays……Page 231
C¡¯s Approach to Dynamic Allocation:malloc( ) and free( )……Page 232
Precedence Summary……Page 234
10 Structures and Unions……Page 236
Structures……Page 237
Accessing Structure Members……Page 239
A Simple Inventory Example……Page 240
Passing Structures to Functions……Page 247
Assigning Structures……Page 248
Pointers to Structures and the Arrow Operator……Page 249
References to Structures……Page 253
Arrays and Structures Within Structures……Page 254
C Structure Versus C++ Structures……Page 255
Bit- Fields……Page 256
Unions……Page 258
Anonymous Unions……Page 263
Moving On to Object- Oriented Programming……Page 264
11 Introducing the Class……Page 266
Class Fundamentals……Page 267
A Closer Look at Class Member Access……Page 271
Constructors and Destructors……Page 273
Parameterized Constructors……Page 276
An Initialization Alternative……Page 280
Classes and Structures Are Related……Page 281
Structures versus Classes……Page 283
Unions and Classes Are Related……Page 284
Inline Functions……Page 285
Creating Inline Functions Inside a Class……Page 286
Arrays of Objects……Page 288
Initializing Object Arrays……Page 289
Pointers to Objects……Page 291
Object References……Page 293
12 A Closer Look at Classes……Page 294
Friend Functions……Page 295
Overloading Constructors……Page 299
Applying Dynamic Initialization to Constructors……Page 301
Assigning Objects……Page 303
Passing Objects to Functions……Page 304
Constructors, Destructors, and Passing Objects……Page 305
A Potential Problem When Passing Objects……Page 306
Returning Objects……Page 309
A Potential Problem When Returning Objects……Page 310
Creating and Using a Copy Constructor……Page 312
Copy Constructors and Parameters……Page 313
Copy Constructors and Initializations……Page 315
Using Copy Constructors When an Object Is Returned……Page 316
Copy Constructors ¡ª Is There a Simpler Way?……Page 317
The this Keyword……Page 318
13 Operator Overloading……Page 320
Operator Overloading Using Member Functions……Page 321
Using Member Functions to Overload Unary Operators……Page 324
Operator Overloading Tips and Restrictions……Page 329
Order Matters……Page 330
Using a Friend to Overload a Unary Operator……Page 334
Overloading the Relational and Logical Operators……Page 337
A Closer Look at the Assignment Operator……Page 338
Overloading [ ]……Page 341
Overloading ( )……Page 345
Another Example of Operator Overloading……Page 346
14 Inheritance……Page 352
Introducing Inheritance……Page 353
Base Class Access Control……Page 356
Using protected Members……Page 358
Using protected for Inheritance of a Base Class……Page 361
Inheriting Multiple Base Classes……Page 363
When Constructors and Destructors Are Executed……Page 364
Passing Parameters to Base Class Constructors……Page 367
Granting Access……Page 371
Virtual Base Classes……Page 373
15 Virtual Functions and Polymorphism……Page 378
Pointers to Derived Types……Page 379
Virtual Functions……Page 381
Virtual Functions Are Inherited……Page 384
Why Virtual Functions?……Page 386
A Simple Application of Virtual Functions……Page 387
Pure Virtual Functions and Abstract Classes……Page 391
Early versus Late Binding……Page 393
Polymorphism and the Purist……Page 394
16 Templates……Page 396
Generic Functions……Page 397
A Function with Two Generic Types……Page 399
Explicitly Overloading a Generic Function……Page 400
Overloading a Function Template……Page 402
Using Standard Parameters with Template Functions……Page 403
Creating a Generic abs( ) Function……Page 404
Generic Classes……Page 405
An Example with Two Generic Data Types……Page 408
Creating a Generic Array Class……Page 409
Using Non- Type Arguments with Generic Classes……Page 410
Using Default Arguments with Template Classes……Page 412
Explicit Class Specializations……Page 414
17 Exception Handling……Page 416
Exception Handling Fundamentals……Page 417
exit( ) and abort( )……Page 419
Catching Class Types……Page 422
Using Multiple catch Statements……Page 423
Catching All Exceptions……Page 425
Restricting Exceptions Thrown by a Function……Page 427
Rethrowing an Exception……Page 429
Handling Exceptions Thrown by new……Page 430
The nothrow Alternative……Page 431
Overloading new and delete……Page 432
Overloading the nothrow Version of new……Page 436
18 The C++ I/O System……Page 438
C++ Streams……Page 439
The C++ Stream Classes……Page 440
Overloading the I/ O Operators……Page 441
Creating Inserters……Page 442
Using Friend Functions to Overload Inserters……Page 444
Overloading Extractors……Page 445
Formatting with the ios Member Functions……Page 447
Using I/ O Manipulators……Page 452
Creating Your Own Manipulator Functions……Page 454
Opening and Closing a File……Page 456
Reading and Writing Text Files……Page 459
Unformatted Binary I/ O……Page 460
Reading and Writing Blocks of Data……Page 462
Detecting EOF……Page 463
A File Comparison Example……Page 464
More Binary I/ O Functions……Page 465
Random Access……Page 467
Checking I/ O Status……Page 469
Customized I/ O and Files……Page 470
19 Run-Time Type ID and the Casting Operators……Page 472
Run- Time Type Identification ( RTTI)……Page 473
A Simple Application of Run- Time Type ID……Page 477
typeid Can Be Applied to Template Classes……Page 479
dynamic_ cast……Page 483
const_ cast……Page 488
static_ cast……Page 489
reinterpret_ cast……Page 490
The Traditional Cast Versus the Four Casting Operators……Page 491
20 Namespaces and Other Advanced Topics……Page 492
Namespace Fundamentals……Page 493
using……Page 496
Unnamed Namespaces……Page 498
The std Namespace……Page 499
Pointers to Functions……Page 501
Finding the Address of an Overloaded Function……Page 504
Static Class Members……Page 505
const Member Functions and mutable……Page 507
Explicit Constructors……Page 509
The Member Initialization Syntax……Page 511
Linkage Specification……Page 514
The .* and ¨C>* Pointer- to- Member Operators……Page 516
Creating Conversion Functions……Page 518
21 Introducing the Standard Template Library……Page 520
An Overview of the STL……Page 521
The Container Classes……Page 523
Vectors……Page 525
Accessing a Vector Through an Iterator……Page 529
Inserting and Deleting Elements in a Vector……Page 530
Storing Class Objects in a Vector……Page 531
The Power of Iterators……Page 534
Lists……Page 535
Sort a List……Page 540
Merging One List with Another……Page 541
Storing Class Objects in a List……Page 542
Maps……Page 544
Storing Class Objects in a Map……Page 549
Algorithms……Page 550
Counting……Page 553
Removing and Replacing Elements……Page 554
Transforming a Sequence……Page 556
The string Class 21……Page 558
Some string Member Functions……Page 562
Final Thoughts on the STL……Page 566
22 The C++ Preprocessor……Page 568
# define……Page 569
Function- Like Macros……Page 571
# include……Page 573
# if, # else, # elif, and # endif……Page 574
# ifdef and # ifndef……Page 576
# undef……Page 577
The Diminishing Role of the Preprocessor……Page 578
# line……Page 579
The # and ## Preprocessor Operators……Page 580
Predefined Macro Names……Page 581
Final Thoughts……Page 582
A C-Based I/Oased I/ O……Page 584
C I/ O Uses Streams……Page 585
printf( )……Page 586
scanf( )……Page 588
The C File System……Page 593
fopen( )……Page 594
fgetc( )……Page 595
Using fopen( ), fgetc( ), fputc( ), and fclose( )……Page 596
ferror( ) and rewind( )……Page 597
fread( ) and fwrite( )……Page 598
fseek( ) and Random- Access I/ O……Page 599
fprintf( ) and fscanf( )……Page 600
Erasing Files……Page 601
B Working with an Older C++ Compiler……Page 602
BookmarkTitle:……Page 0
Two Simple Changes……Page 604
C The .NET Managed Extensions to C++……Page 606
_ _ abstract……Page 607
_ _ nogc……Page 608
Preprocessor Extensions……Page 609
Compiling Managed C++……Page 610
Index……Page 612

Reviews

There are no reviews yet.

Be the first to review “C++ From the Ground Up”
Shopping Cart
Scroll to Top