Table of Contents


C++ Premier Plus

1 C++ Basics

1.1 Variables, Operators and Expressions

  1. naming
  2. logic operation
    • –i and i–.
    • logical and arithmetic shift.
  3. scientific output expression
    • use “%10.1f” as format specifier.

2 GETTING STARTED

2.1 Learning C++: What Lies Before You

2.2 The Origins of C++: A Little History

2.3 Portability and Standards

2.4 The Mechanics of Creating a Program

3 SETTING OUT TO C++

3.1 C++ Initiation

3.2 C++ Statements

  1. Comments
    • //
    • * *

3.3 More C++ Statements

3.4 Functions

4 DEALING WITH DATA

4.1 Simple Variables

  1. Variables:
    • common variables names
      int price_count_reader;    // No abbreviation.
      int num_errors;            // "num" is a widespread convention.
      int num_dns_connections;   // Most people know what "DNS" stands for.
      
    • Class Data Members

      Data members of classes, both static and non-static, are named like ordinary nonmember variables, but with a trailing underscore.

      class TableInfo {
        ...
       private:
        string table_name_;  // OK - underscore at end.
        string tablename_;   // OK.
        static Pool<TableInfo>* pool_;  // OK.
      };
      
  2. Constant Names

    Variables declared constexpr or const, and whose value is fixed for the duration of the program, are named with a leading "k" followed by mixed case. For example:

    const int kDaysInAWeek = 7;
    
  3. Function Names
    AddTableEntry()
    DeleteUrl()
    OpenFileOrDie()
    
  4. File Names
    • my_useful_class.cc
    • my-useful-class.cc
    • myusefulclass.cc
    • myusefulclass_test.cc // _unittest and _regtest are deprecated.

4.2 The const Qualifier

4.3 Floating-Point Numbers

4.4 C++ Arithmetic Operators

5 COMPOUND TYPES

5.1 Introducing Arrays

5.2 Strings

5.3 Introducing the string Class

5.4 Introducing Structures

5.5 Unions

5.6 Enumerations

5.7 Pointers and the Free Store

5.8 Pointers, Arrays, and Pointer Arithmetic

  1. swap value of two variables using pointers
    #include <stdio.h>
    
    void Swap(int* a, int* b)
    {
      int temp;   //use the variable temp to store one value.
      temp = (*b);  //temp equals to content of pointer b
      (*b) = (*a);  //pointer b equals to content of pointer a
      (*a) = temp;  //content of pointer a equals to temp
    
    }
    int main()
    {
      int i = 123, j = 456;
      int* x = &i;  //x points to i
      int* y = &j;  //y points to j
      printf("Before swapping: i = %d, j = %d\n",i , j);
    
      Swap(x, y);
      printf("After swapping: i = %d, j = %d\n",i , j);
    return 0;
    }
    

6 LOOPS AND RELATIONAL EXPRESSIONS

6.1 Introducing for Loops

6.2 Relational Expressions

6.3 The while Loop

6.4 The do while Loop

6.5 Loops and Text Input

6.6 Nested Loops and Two-Dimensional Arrays

7 BRANCHING STATEMENTS AND LOGICAL OPERATORS

7.1 The if Statement

7.2 Logical Expressions

7.3 The cctype Library of Character Functions

7.4 The ?: Operator

7.5 The switch Statement

7.6 The break and continue Statements

7.7 Number-Reading Loops

7.8 Simple File Input/Output

8 FUNCTIONS: C++’S PROGRAMMING MODULES

8.1 Function Review

8.2 Function Arguments and Passing by Value

8.3 Functions and Arrays

8.4 Functions and Two-Dimensional Arrays

8.5 Functions and C-Style Strings

8.6 Functions and Structures

8.7 Functions and string Class Objects

8.8 Recursion

8.9 Pointers to Functions

9 ADVENTURES IN FUNCTIONS

9.1 C++ Inline Functions

9.2 Reference Variables

9.3 Default Arguments

9.4 Function Overloading

9.5 Function Templates

10 MEMORY MODELS AND NAMESPACES

10.1 Separate Compilation

10.2 Storage Duration, Scope, and Linkage

10.3 The Placement new Operator

10.4 Namespaces

11 OBJECTS AND CLASSES

11.1 Procedural and Object-Oriented Programming

11.2 Abstraction and Classes

11.3 Class Constructors and Destructors

11.4 Knowing Your Objects: The this Pointer

11.5 An Array of Objects

11.6 The Interface and Implementation Revisited

11.7 Class Scope

11.8 Abstract Data Types

12 WORKING WITH CLASSES

12.1 Operator Overloading

12.2 Time on Our Hands: Developing an Operator Overloading Example

12.3 Introducing Friends

12.4 Overloaded Operators: Member Versus Nonmember Functions

12.5 More Overloading: A Vector Class

12.6 Automatic Conversions and Type Casts for Classes

13 CLASSES AND DYNAMIC MEMORY ALLOCATION

13.1 Dynamic Memory and Classes

13.2 A Queue Simulation

14 CLASS INHERITANCE

14.1 Beginning with a Simple Base Class

14.2 Inheritance: An Is-a Relationship

14.3 Polymorphic Public Inheritance

14.4 Access Control: protected

14.5 Abstract Base Classes

14.6 Inheritance and Dynamic Memory Allocation

14.7 Class Design Review

15 REUSING CODE IN C++

15.1 Classes with Object Members

15.2 Private Inheritance

15.3 Multiple Inheritance

15.4 Class Templates

16 FRIENDS, EXCEPTIONS, AND MORE

16.1 Friends

16.2 Nested Classes

16.3 Exceptions

16.4 RTTI

16.5 Type Cast Operators

17 THE string CLASS AND THE STANDARD TEMPLATE LIBRARY

17.1 The string Class

17.2 The auto_ptr Class

17.3 The STL

17.4 Generic Programming

17.5 Function Objects (aka Functors)

17.6 Algorithms

17.7 Other Libraries

18 INPUT, OUTPUT, AND FILES

18.1 An Overview of C++ Input and Output

18.2 Output with cout

18.3 Input with cin

18.4 File Input and Output

18.5 Incore Formatting

18.6 What Now?