C++ Programmer's Notebook, 2/e

Jim Keogh, James Edward Keogh, John Shapley Gray

  • 出版商: Prentice Hall
  • 出版日期: 2001-08-16
  • 售價: $1,340
  • 貴賓價: 9.5$1,273
  • 語言: 英文
  • 頁數: 508
  • 裝訂: Paperback
  • ISBN: 0130887013
  • ISBN-13: 9780130887016
  • 相關分類: C++ 程式語言
  • 海外代購書籍(需單獨結帳)



  • Learn C++ fast! Real code, thoroughly explained-and ready to use!
  • Completely updated with over 200 new examples
  • All the fundamentals: variables, operators, arrays, functions, program control, I/O, files, streams, memory management, sorts, searches, and more
  • Advanced topics: data structures, templates, string classes, and exception handling
  • See the code and put it to work—fast, easy, and hands on

C++ Programmer's Notebook, Second Edition teaches C++ the way you want to learn it: with real code! This quick, visual tutorial presents hundreds of annotated "snapshots" of working code, covering all the C++ concepts and techniques you need—and delivering specific solutions you can use right now!

Practical, comprehensive coverage includes:

  • Variables, operators, expressions, arrays, and C-style strings
  • Structures, functions, and program control
  • Objects, classes, overloading, inheritance, and pointers
  • Virtual and friend functions
  • I/O, files, streams, and memory management
  • Sorts and searches
  • Data structures and templates
  • String classes and exception handling
  • Quality checklists for building robust, high-performance code!

Completely updated with over 200 new examples, C++ Programmer's Notebook, Second Edition is the perfect starting point for new C++ developers-and the perfect reference for experienced C++ developers looking for quick solutions!

Table of Contents

1. Working with Variables.

Naming Variables. Using Variables. Boolean Variables. Integer Variables. Character Variables. Escape Sequences. Floating Point Variables. Inside Exponential Notation. Data Type Conversion. Assigning Values to Variables. Constants. Scope. Local Variables versus Global Variables. File and Class Scope. Storage Specifiers. Static. Register. Auto. Storage Specifier Rules.

2. Working with Operators and Expressions.

Expressions. Arithmetic Operators. The +=, -=, *=, /= Operators. The ++, -- Operators. Relational Operators. The == and != Operators. Logical Operators. Bitwise Operators. Bitwise AND. Bitwise OR. Bitwise XOR (exclusive OR). Bitwise NOT. The Shift Left Operator. The Shift Right Operator. ?-The Conditional Operator. An Introduction to Indirection. The Precedence Table. Working with Expressions.

3. Working with Arrays and C-Style Strings.

Arrays and Strings. Assigning Values to an Array. Multidimensional Arrays. Assigning Values to a Multidimensional Array. Allocating Arrays Using the new Operator. Allocating Multidimensional Arrays Using the new Operator. C-Style Strings. Copying One C-Style String to Another Using strcpy( ) and strncpy( ). Reading in a C-Style String Using gets( )and fgets( ). Reading a C-Style String from the Keyboard Using scanf( ). Reading a C-Style String from the Keyboard with the Extraction Operator. Reading a C-Style String from the Keyboard with get( ) and getline( ). Comparing Two C-Style Strings. Displaying a C-Style String with printf( ). Displaying a C-Style String with puts( ). Displaying a String with the Insertion Operator. Concatenating C-Style Strings with strcat( ) and strncat( ). Determining the Length of a C-Style String with strlen( ). Determining the Length of a Substring with strcspn( ). Determining the Length of a Substring with strspn( ). Locating a Character within a C-Style String Using strpbrk( ). Locating the First Occurrence of a Substring in a C-Style String with strstr( ). Dividing a C-Style String into Several Substrings Using strtok( ). C-Style Strings versus the String Types of the C++ Standard Library.

4. Working with Structures.

Structures. A Structure at Work. Running the Sample Program. Other Ways to Declare an Instance of a Structure. Assigning Values to Structure Members. Multiple Instances of Structures. Assigning Values to Multiple Instances. Structures within Structures. Passing Members of a Structure to a Function. Passing Members by Address. Passing a Structure to a Function. Passing a Structure to a Function by Reference. Functions Returning Structures. Unions. Enumerations. The typedef Declaration.

5. Working with Functions.

Anatomy of a C++ Program. The main( ) Function. How to Use a Function. Passing Arguments by Value. Passing Multiple Arguments. Passing Arguments Using Reference Variables. Passing Arguments to the main( ) Function. Returning Values. Building a Program Using Functions. Additional Function Facts. Program Statements. White Space Characters. Preprocessor Directives. More Preprocessor Directives. #define with Arguments. inline Function. #if, #else, #elif, #endif. #ifdef, #ifndef, #undef. Using Include Once Header Files. #line, #error, and #pragma.

6. Working with Program Control.

Program Control Statements. The if Statement. The if...else Statement. The ? Operator. Nested if. Multiple Conditions. The switch...case Statement. Tricks of the Trade. for Loop. More on for Loops. while Loop. do...while Loop. break. Continue. exit( ). goto.

7. Working with Objects and Classes.

Classes. Declaring an Instance of a Class. Hiding Data Using the Access Control Specifier. The Constructor. More on Initialization. The Destructor. The Copy Constructor. Defining a Function Member outside the Class Declaration.

8. Working with Overloading.

Overloading. Overloading a Unary Operator. Overloading a Binary Operator. Overloading the Input and Output Operators. Operators that Can and Cannot Be Overloaded.

9. Working with Inheritance.

Inheritance. Access Specifiers. More about Inheritance. Multiple Inheritance. Ambiguity in Multiple Inheritance. Containership Class. Levels of Inheritance.

10. Working with Pointers.

Pointers and References. More on Using Pointers. Incrementing Pointers. Decrementing Pointers. Pointer Math. An Array of Pointers. Pointer-to-a-Pointer. Pointer-to-a-Function. Tricks of the Trade.

11. Working with Virtual and Friend Functions.

Creating a Virtual Function. Virtual Destructors. Creating a Pure Virtual Function. More about Virtual Functions. Friend Functions. Creating a Friend Function from a Function Member Forward Reference of a Class. Friend Classes.

12. Working with Keyboard Input and Screen Output.

C-Style Keyboard Input and Screen Output. Reading a Character from the Keyboard without Echo Using getch( )and _getch( ). Displaying a Character on the Screen with putchar( ). Reading a String from the Keyboard with Less Overhead Using gets( ). Reading Input with Greater Control Using scanf( ). Reading Data with scanf( ). Limiting the Number of Characters Read. Specifying Input String Contents. Creating Your Own Separator. Displaying a String with Less Overhead Using puts( ). Displaying a String with Greater Control Using printf( ). Displaying a String with printf( ). Displaying an Integer with printf( ).

13. Working with Files and Streams.

File Input/Output and Opening and Closing a File. Mode Specifiers for the fopen( ) Function. Writing a Character to a File Using putc( )and fputc( ). Reading a Character from a File Using getc( ). Tricks of the Trade. Writing a String to a File Using fputs( ). Reading a String from a File Using fgets( ). Writing an Integer to a File Using putw( ). Reading an Integer from a File Using getw( ). Writing a Block of Data to a File Using fwrite( ). Reading a Block of Data from a File Using fread( ). Creating a Database File. Reading a Record. Writing Various Data Types to a File or a String Using fprintf( ) and sprintf( ). Reading Various Data Types from a File or a String Using fscanf( ) and sscanf( ). Moving to Specific Locations in a File Using fseek( ). Other File Manipulation Functions. Using a File in C++. Writing Information to a File Using C++. Reading a String from a File Using C++. Reading and Writing a Single Character to a File Using C++. Reading and Writing an Object to a File. Specify the File Mode in C++. Moving to Specific Locations in an Input Using File Using seekg( )and tellg( ). Moving to Specific Locations in an Output File Using seekp( ) and tellp( ). Reading and Writing to the Same File.

14. Working with Memory Management.

Computer Memory. Data in the Program Process Space. Storing Data on the Heap. Storing an Array of Objects on the Heap. Reallocating Heap Memory. Storing Data on the Heap Using the new Operator. Using a Dynamic Array. More on Dynamic Arrays.

15. Working with Sorting and Searching Data.

The Bubble Sort. Inside the Bubble Sort. The Selection Sort. Inside the Selection Sort. The Quick Sort. Inside the Quick Sort. The Sequential (Linear) Search. The Binary Search. A Closer Look at the Binary Search Routine. Using bsearch( ).

16. Working with Data Structures.

Linked Lists. Adding a Node to the End of a Linked List. Adding a Node to Maintain Sorted Order. Removing a Node from a Linked List. Linked List Operators. More on Linked List Operators. Stacks. Implementing a Stack as an Array. Implementing a Stack as a Linked List. Using a Linked List Stack. Queues. Implementing a Queue as an Array. Implementing a Queue as a Linked List. Using a Linked List Queue.

17. Working with Templates.

Templates. Using Template Functions with a Defined Type. Templates with Multiple Parameters. Class Templates. Template Class Friendships.

18. Working with Assertions and Exceptions.

Assertions. try, catch, and throw. More about try, catch, and throw. Functions that Throw Exceptions. Throwing Objects.

Appendix A: A User-Defined String Class.
Appendix B: Keeping Current.
Appendix C: Programmer's Checklist.
Appendix D: ASCII Codes.






1. 使用變數
2. 使用運算符和運算式
3. 使用陣列和C風格字串