Book description
For Introduction to Programming (CS1) and other more
intermediate courses covering programming in C++. Also appropriate
as a supplement for upper-level courses where the instructor uses a
book as a reference for the C++ language.
This best-selling comprehensive text is aimed at readers with
little or no programming experience. It teaches programming by
presenting the concepts in the context of full working programs and
takes and early objects approach. The text has an emphasis on
achieving program clarity through structured and object-oriented
programming, software reuse and component-oriented software
construction. The Sixth Edition reflects the suggested improvements
of a distinguished team of industry professionals and
academics.
Table of contents
- Copyright
- Deitel® Series Page
- Deitel Resource Centers
-
Preface
- New and Updated Features
- Teaching Approach
- Tour of the Book
- Object-Oriented Design of an ATM with the UML: A Tour of the Optional Software Engineering Case Study
- Acknowledgments
- About the Authors
- Before You Begin
-
1. Introduction to Computers, the Internet and the World Wide Web
- 1.1. Introduction
- 1.2. What Is a Computer?
- 1.3. Computer Organization
- 1.4. Early Operating Systems
- 1.5. Personal, Distributed and Client/Server Computing
- 1.6. The Internet and the World Wide Web
- 1.7. Web 2.0
- 1.8. Machine Languages, Assembly Languages and High-Level Languages
- 1.9. History of C and C++
- 1.10. C++ Standard Library
- 1.11. History of Java
- 1.12. Fortran, COBOL, Pascal and Ada
- 1.13. BASIC, Visual Basic, Visual C++, C# and .NET
- 1.14. Key Software Trend: Object Technology
- 1.15. Typical C++ Development Environment
- 1.16. Notes About C++ and C++ How to Program, 6/e
- 1.17. Test-Driving a C++ Application
- 1.18. Software Technologies
- 1.19. Game Programming with the Ogre Libraries
- 1.20. Future of C++: Open Source Boost Libraries, TR1 and C++0x
- 1.21. Software Engineering Case Study: Introduction to Object Technology and the UML
- 1.22. Wrap-Up
- 1.23. Web Resources
-
Summary
- Section 1.1 Introduction
- Section 1.2 What Is a Computer?
- Section 1.3 Computer Organization
- Section 1.4 Early Operating Systems
- Section 1.5 Personal, Distributed and Client/Server Computing
- Section 1.6 The Internet and the World Wide Web
- Section 1.7 Web 2.0
- Section 1.8 Machine Languages, Assembly Languages and High-Level Languages
- Section 1.9 History of C and C++
- Section 1.10 C++ Standard Library
- Section 1.11 History of Java
- Section 1.12 Fortran, COBOL, Pascal and Ada
- Section 1.13 BASIC, Visual Basic, Visual C++, C# and .NET
- Section 1.14 Key Software Trend: Object Technology
- Section 1.15 Typical C++ Development Environment
- Section 1.18 Software Technologies
- Section 1.19 Game Programming with the Ogre Libraries
- Section 1.20 Future of C++: Open Source Boost Libraries, TR1 and C++0x
- Section 1.21 Software Engineering Case Study: Introduction to Object Technology and the UML
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
2. Introduction to C++ Programming
- 2.1. Introduction
- 2.2. First Program in C++: Printing a Line of Text
- 2.3. Modifying Our First C++ Program
- 2.4. Another C++ Program: Adding Integers
- 2.5. Memory Concepts
- 2.6. Arithmetic
- 2.7. Decision Making: Equality and Relational Operators
- 2.8. (Optional) Software Engineering Case Study: Examining the ATM Requirements Specification
- 2.9. Wrap-Up
- Summary
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
3. Introduction to Classes and Objects
- 3.1. Introduction
- 3.2. Classes, Objects, Member Functions and Data Members
- 3.3. Overview of the Chapter Examples
- 3.4. Defining a Class with a Member Function
- 3.5. Defining a Member Function with a Parameter
-
3.6. Data Members, set Functions and get Functions
- GradeBook Class with a Data Member, a set Function and a get Function
- Access Specifiers public and private
- Member Functions setCourseName and getCourseName
- Member Function displayMessage
- Testing Class GradeBook
- Software Engineering with Set and Get Functions
- GradeBook’s UML Class Diagram with a Data Member and set and get Functions
- 3.7. Initializing Objects with Constructors
- 3.8. Placing a Class in a Separate File for Reusability
- 3.9. Separating Interface from Implementation
- 3.10. Validating Data with set Functions
- 3.11. (Optional) Software Engineering Case Study: Identifying the Classes in the ATM Requirements Specification
- 3.12. Wrap-Up
-
Summary
- Section 3.2 Classes, Objects, Member Functions and Data Members
- Section 3.4 Defining a Class with a Member Function
- Section 3.5 Defining a Member Function with a Parameter
- Section 3.6 Data Members, set Functions and get Functions
- Section 3.7 Initializing Objects with Constructors
- Section 3.8 Placing a Class in a Separate File for Reusability
- Section 3.9 Separating Interface from Implementation
- Section 3.10 Validating Data with set Functions
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
4. Control Statements: Part 1
- 4.1. Introduction
- 4.2. Algorithms
- 4.3. Pseudocode
- 4.4. Control Structures
- 4.5. if Selection Statement
- 4.6. if...else Double-Selection Statement
- 4.7. while Repetition Statement
- 4.8. Formulating Algorithms: Counter-Controlled Repetition
-
4.9. Formulating Algorithms: Sentinel-Controlled Repetition
- Developing the Pseudocode Algorithm with Top-Down, Stepwise Refinement: The Top and First Refinement
- Proceeding to the Second Refinement
- Implementing Sentinel-Controlled Repetition in Class GradeBook
- Program Logic for Sentinel-Controlled Repetition vs. Counter-Controlled Repetition
- Floating-Point Number Precision and Memory Requirements
- Converting Between Fundamental Types Explicitly and Implicitly
- Formatting for Floating-Point Numbers
- 4.10. Formulating Algorithms: Nested Control Statements
- 4.11. Assignment Operators
- 4.12. Increment and Decrement Operators
- 4.13. (Optional) Software Engineering Case Study: Identifying Class Attributes in the ATM System
- 4.14. Wrap-Up
-
Summary
- Section 4.2 Algorithms
- Section 4.3 Pseudocode
- Section 4.4 Control Structures
- Section 4.5 if Selection Statement
- Section 4.6 if...else Double-Selection Statement
- Section 4.7 while Repetition Statement
- Section 4.8 Formulating Algorithms: Counter-Controlled Repetition
- Section 4.9 Formulating Algorithms: Sentinel-Controlled Repetition
- Section 4.10 Formulating Algorithms: Nested Control Statements
- Section 4.11 Assignment Operators
- Section 4.12 Increment and Decrement Operators
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
5. Control Statements: Part 2
- 5.1. Introduction
- 5.2. Essentials of Counter-Controlled Repetition
- 5.3. for Repetition Statement
- 5.4. Examples Using the for Statement
- 5.5. do...while Repetition Statement
- 5.6. switch Multiple-Selection Statement
- 5.7. break and continue Statements
- 5.8. Logical Operators
- 5.9. Confusing the Equality (==) and Assignment (=) Operators
- 5.10. Structured Programming Summary
- 5.11. (Optional) Software Engineering Case Study: Identifying Objects’ States and Activities in the ATM System
- 5.12. Wrap-Up
-
Summary
- Section 5.2 Essentials of Counter-Controlled Repetition
- Section 5.3 for Repetition Statement
- Section 5.4 Examples Using the for Statement
- Section 5.5 do...while Repetition Statement
- Section 5.6 switch Multiple-Selection Statement
- Section 5.7 break and continue Statements
- Section 5.8 Logical Operators
- Section 5.9 Confusing the Equality (==) and Assignment (=) Operators
- Section 5.10 Structured Programming Summary
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
6. Functions and an Introduction to Recursion
- 6.1. Introduction
- 6.2. Program Components in C++
- 6.3. Math Library Functions
- 6.4. Function Definitions with Multiple Parameters
- 6.5. Function Prototypes and Argument Coercion
- 6.6. C++ Standard Library Header Files
- 6.7. Case Study: Random Number Generation
- 6.8. Case Study: Game of Chance; Introducing enum
- 6.9. Storage Classes
- 6.10. Scope Rules
- 6.11. Function Call Stack and Activation Records
- 6.12. Functions with Empty Parameter Lists
- 6.13. Inline Functions
- 6.14. References and Reference Parameters
- 6.15. Default Arguments
- 6.16. Unary Scope Resolution Operator
- 6.17. Function Overloading
- 6.18. Function Templates
- 6.19. Recursion
- 6.20. Example Using Recursion: Fibonacci Series
- 6.21. Recursion vs. Iteration
-
6.22. (Optional) Software Engineering Case Study: Identifying Class Operations in the ATM System
- Identifying Operations
- Modeling Operations
- Operations of Class BankDatabase and Class Account
- Operations of Class Screen
- Operations of Class Keypad
- Operations of Class CashDispenser and Class DepositSlot
- Operations of Class ATM
- Identifying and Modeling Operation Parameters
- Software Engineering Case Study Self-Review Exercises
- Answers to Software Engineering Case Study Self-Review Exercises
- 6.23. Wrap-Up
-
Summary
- Section 6.1 Introduction
- Section 6.2 Program Components in C++
- Section 6.3 Math Library Functions
- Section 6.4 Function Definitions with Multiple Parameters
- Section 6.5 Function Prototypes and Argument Coercion
- Section 6.6 C++ Standard Library Header Files
- Section 6.7 Case Study: Random Number Generation
- Section 6.8 Case Study: Game of Chance; Introducing enum
- Section 6.9 Storage Classes
- Section 6.10 Scope Rules
- Section 6.11 Function Call Stack and Activation Records
- Section 6.12 Functions with Empty Parameter Lists
- Section 6.13 Inline Functions
- Section 6.14 References and Reference Parameters
- Section 6.15 Default Arguments
- Section 6.16 Unary Scope Resolution Operator
- Section 6.17 Function Overloading
- Section 6.18 Function Templates
- Section 6.19 Recursion
- Section 6.20 Example Using Recursion: Fibonacci Series
- Section 6.21 Recursion vs. Iteration
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
7. Arrays and Vectors
- 7.1. Introduction
- 7.2. Arrays
- 7.3. Declaring Arrays
-
7.4. Examples Using Arrays
- 7.4.1. Declaring an Array and Using a Loop to Initialize the Array’s Elements
- 7.4.2. Initializing an Array in a Declaration with an Initializer List
- 7.4.3. Specifying an Array’s Size with a Constant Variable and Setting Array Elements with Calculations
- 7.4.4. Summing the Elements of an Array
- 7.4.5. Using Bar Charts to Display Array Data Graphically
- 7.4.6. Using the Elements of an Array as Counters
- 7.4.7. Using Arrays to Summarize Survey Results
- 7.4.8. Using Character Arrays to Store and Manipulate Strings
- 7.4.9. Static Local Arrays and Automatic Local Arrays
- 7.5. Passing Arrays to Functions
- 7.6. Case Study: Class GradeBook Using an Array to Store Grades
- 7.7. Searching Arrays with Linear Search
- 7.8. Sorting Arrays with Insertion Sort
- 7.9. Multidimensional Arrays
- 7.10. Case Study: Class GradeBook Using a Two-Dimensional Array
- 7.11. Introduction to C++ Standard Library Class Template vector
- 7.12. (Optional) Software Engineering Case Study: Collaboration Among Objects in the ATM System
- 7.13. Wrap-Up
-
Summary
- Section 7.1 Introduction
- Section 7.2 Arrays
- Section 7.3 Declaring Arrays
- Section 7.4 Examples Using Arrays
- Section 7.5 Passing Arrays to Functions
- Section 7.6 Case Study: Class GradeBook Using an Array to Store Grades
- Section 7.7 Searching Arrays with Linear Search
- Section 7.8 Sorting Arrays with Insertion Sort
- Section 7.9 Multidimensional Arrays
- Section 7.11 Introduction to C++ Standard Library Class Template vector
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
- Recursion Exercises
- vector Exercises
-
8. Pointers and Pointer-Based Strings
- 8.1. Introduction
- 8.2. Pointer Variable Declarations and Initialization
- 8.3. Pointer Operators
- 8.4. Passing Arguments to Functions by Reference with Pointers
- 8.5. Using const with Pointers
- 8.6. Selection Sort Using Pass-by-Reference
- 8.7. sizeof Operator
- 8.8. Pointer Expressions and Pointer Arithmetic
- 8.9. Relationship Between Pointers and Arrays
- 8.10. Arrays of Pointers
- 8.11. Case Study: Card Shuffling and Dealing Simulation
- 8.12. Function Pointers
- 8.13. Introduction to Pointer-Based String Processing
- 8.14. Wrap-Up
-
Summary
- Section 8.2 Pointer Variable Declarations and Initialization
- Section 8.3 Pointer Operators
- Section 8.4 Passing Arguments to Functions by Reference with Pointers
- Section 8.5 Using const with Pointers
- Section 8.6 Selection Sort Using Pass-by-Reference
- Section 8.7 sizeof Operator
- Section 8.8 Pointer Expressions and Pointer Arithmetic
- Section 8.9 Relationship Between Pointers and Arrays
- Section 8.10 Arrays of Pointers
- Section 8.11 Case Study: Card Shuffling and Dealing Simulation
- Section 8.12 Function Pointers
- Section 8.13 Introduction to Pointer-Based String Processing
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
- Special Section: Building Your Own Computer
- More Pointer Exercises
- String-Manipulation Exercises
- Special Section: Advanced String-Manipulation Exercises
- A Challenging String-Manipulation Project
-
9. Classes: A Deeper Look, Part 1
- 9.1. Introduction
- 9.2. Time Class Case Study
- 9.3. Class Scope and Accessing Class Members
- 9.4. Separating Interface from Implementation
- 9.5. Access Functions and Utility Functions
- 9.6. Time Class Case Study: Constructors with Default Arguments
- 9.7. Destructors
- 9.8. When Constructors and Destructors Are Called
- 9.9. Time Class Case Study: A Subtle Trap—Returning a Reference to a private Data Member
- 9.10. Default Memberwise Assignment
- 9.11. (Optional) Software Engineering Case Study: Starting to Program the Classes of the ATM System
- 9.12. Wrap-Up
-
Summary
- Section 9.2 Time Class Case Study
- Section 9.3 Class Scope and Accessing Class Members
- Section 9.4 Separating Interface from Implementation
- Section 9.5 Access Functions and Utility Functions
- Section 9.6 Time Class Case Study: Constructors with Default Arguments
- Section 9.7 Destructors
- Section 9.8 When Constructors and Destructors Are Called
- Section 9.9 Time Class Case Study: A Subtle Trap—Returning a Reference to a private Data Member
- Section 9.10 Default Memberwise Assignment
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
10. Classes: A Deeper Look, Part 2
- 10.1. Introduction
- 10.2. const (Constant) Objects and const Member Functions
- 10.3. Composition: Objects as Members of Classes
- 10.4. friend Functions and friend Classes
- 10.5. Using the this Pointer
- 10.6. Dynamic Memory Management with Operators new and delete
- 10.7. static Class Members
- 10.8. Data Abstraction and Information Hiding
- 10.9. Container Classes and Iterators
- 10.10. Proxy Classes
- 10.11. Wrap-Up
-
Summary
- Section 10.2 const (Constant) Objects and const Member Functions
- Section 10.3 Composition: Objects as Members of Classes
- Section 10.4 friend Functions and friend Classes
- Section 10.5 Using the this Pointer
- Section 10.6 Dynamic Memory Management with Operators new and delete
- Section 10.7 static Class Members
- Section 10.8 Data Abstraction and Information Hiding
- Section 10.9 Container Classes and Iterators
- Section 10.10 Proxy Classes
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
11. Operator Overloading; String and Array Objects
- 11.1. Introduction
- 11.2. Fundamentals of Operator Overloading
- 11.3. Restrictions on Operator Overloading
- 11.4. Operator Functions as Class Members vs. Global Functions
- 11.5. Overloading Stream Insertion and Stream Extraction Operators
- 11.6. Overloading Unary Operators
- 11.7. Overloading Binary Operators
-
11.8. Case Study: Array Class
- Creating Arrays, Outputting Their Size and Displaying Their Contents
- Using the Overloaded Stream Insertion Operator to Fill an Array
- Using the Overloaded Inequality Operator
- Initializing a New Array with a Copy of an Existing Array’s Contents
- Using the Overloaded Assignment Operator
- Using the Overloaded Equality Operator
- Using the Overloaded Subscript Operator
- Array Class Definition
- Overloading the Stream Insertion and Stream Extraction Operators as friends
- Array Default Constructor
- Array Copy Constructor
- Array Destructor
- getSize Member Function
- Overloaded Assignment Operator
- Overloaded Equality and Inequality Operators
- Overloaded Subscript Operators
- 11.9. Converting between Types
-
11.10. Case Study: String Class
- String Class Definition
- Overloading the Stream Insertion and Stream Extraction Operators as friends
- String Conversion Constructor
- String Copy Constructor
- String Destructor
- Overloaded Assignment Operator
- Overloaded Addition Assignment Operator
- Overloaded Negation Operator
- Overloaded Equality and Relational Operators
- Overloaded Subscript Operators
- Overloaded Function Call Operator
- String Member Function getLength
- Notes on Our String Class
- 11.11. Overloading ++ and --
- 11.12. Case Study: A Date Class
- 11.13. Standard Library Class string
- 11.14. explicit Constructors
- 11.15. Wrap-Up
-
Summary
- Section 11.1 Introduction
- Section 11.2 Fundamentals of Operator Overloading
- Section 11.3 Restrictions on Operator Overloading
- Section 11.4 Operator Functions as Class Members vs. Global Functions
- Section 11.5 Overloading Stream Insertion and Stream Extraction Operators
- Section 11.6 Overloading Unary Operators
- Section 11.7 Overloading Binary Operators
- Section 11.8 Case Study: Array Class
- Section 11.9 Converting between Types
- Section 11.10 Case Study: String Class
- Section 11.11 Overloading ++ and --
- Section 11.13 Standard Library Class string
- Section 11.14 explicit Constructors
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
12. Object-Oriented Programming: Inheritance
- 12.1. Introduction
- 12.2. Base Classes and Derived Classes
- 12.3. protected Members
-
12.4. Relationship between Base Classes and Derived Classes
- 12.4.1. Creating and Using a CommissionEmployee Class
- 12.4.2. Creating a BasePlusCommissionEmployee Class Without Using Inheritance
- 12.4.3. Creating a CommissionEmployee–BasePlusCommissionEmployee Inheritance Hierarchy
- 12.4.4. CommissionEmployee–BasePlusCommissionEmployee Inheritance Hierarchy Using protected Data
- 12.4.5. CommissionEmployee–BasePlusCommissionEmployee Inheritance Hierarchy Using private Data
- 12.5. Constructors and Destructors in Derived Classes
- 12.6. public, protected and private Inheritance
- 12.7. Software Engineering with Inheritance
- 12.8. Wrap-Up
- Summary
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
13. Object-Oriented Programming: Polymorphism
- 13.1. Introduction
- 13.2. Polymorphism Examples
-
13.3. Relationships Among Objects in an Inheritance Hierarchy
- 13.3.1. Invoking Base-Class Functions from Derived-Class Objects
- 13.3.2. Aiming Derived-Class Pointers at Base-Class Objects
- 13.3.3. Derived-Class Member-Function Calls via Base-Class Pointers
- 13.3.4. Virtual Functions
- 13.3.5. Summary of the Allowed Assignments Between Base-Class and Derived-Class Objects and Pointers
- 13.4. Type Fields and switch Statements
- 13.5. Abstract Classes and Pure virtual Functions
-
13.6. Case Study: Payroll System Using Polymorphism
- 13.6.1. Creating Abstract Base Class Employee
- 13.6.2. Creating Concrete Derived Class SalariedEmployee
- 13.6.3. Creating Concrete Derived Class HourlyEmployee
- 13.6.4. Creating Concrete Derived Class CommissionEmployee
- 13.6.5. Creating Indirect Concrete Derived Class BasePlusCommissionEmployee
- 13.6.6. Demonstrating Polymorphic Processing
- 13.7. (Optional) Polymorphism, Virtual Functions and Dynamic Binding “Under the Hood”
- 13.8. Case Study: Payroll System Using Polymorphism and Runtime Type Information with Downcasting, dynamic_cast, typeid and type_info
- 13.9. Virtual Destructors
- 13.10. (Optional) Software Engineering Case Study: Incorporating Inheritance into the ATM System
- 13.11. Wrap-Up
-
Summary
- Section 13.1 Introduction
- Section 13.2 Polymorphism Examples
- Section 13.3 Relationships Among Objects in an Inheritance Hierarchy
- Section 13.4 Type Fields and switch Statements
- Section 13.5 Abstract Classes and Pure virtual Functions
- Section 13.7 (Optional) Polymorphism, Virtual Functions and Dynamic Binding “Under the Hood”
- Section 13.8 Case Study: Payroll System Using Polymorphism and Runtime Type Information with Downcasting, dynamic_cast, typeid and type_info
- Section 13.9 Virtual Destructors
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
14. Templates
- 14.1. Introduction
- 14.2. Function Templates
- 14.3. Overloading Function Templates
- 14.4. Class Templates
- 14.5. Nontype Parameters and Default Types for Class Templates
- 14.6. Notes on Templates and Inheritance
- 14.7. Notes on Templates and Friends
- 14.8. Notes on Templates and static Members
- 14.9. Wrap-Up
-
Summary
- Section 14.1 Introduction
- Section 14.2 Function Templates
- Section 14.3 Overloading Function Templates
- Section 14.4 Class Templates
- Section 14.5 Nontype Parameters and Default Types for Class Templates
- Section 14.6 Notes on Templates and Inheritance
- Section 14.7 Notes on Templates and Friends
- Section 14.8 Notes on Templates and static Members
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
15. Stream Input/Output
- 15.1. Introduction
- 15.2. Streams
- 15.3. Stream Output
- 15.4. Stream Input
- 15.5. Unformatted I/O Using read, write and gcount
- 15.6. Introduction to Stream Manipulators
-
15.7. Stream Format States and Stream Manipulators
- 15.7.1. Trailing Zeros and Decimal Points (showpoint)
- 15.7.2. Justification (left, right and internal)
- 15.7.3. Padding (fill, setfill)
- 15.7.4. Integral Stream Base (dec, oct, hex, showbase)
- 15.7.5. Floating-Point Numbers; Scientific and Fixed Notation (scientific, fixed)
- 15.7.6. Uppercase/Lowercase Control (uppercase)
- 15.7.7. Specifying Boolean Format (boolalpha)
- 15.7.8. Setting and Resetting the Format State via Member Function flags
- 15.8. Stream Error States
- 15.9. Tying an Output Stream to an Input Stream
- 15.10. Wrap-Up
-
Summary
- Section 15.1 Introduction
- Section 15.2 Streams
- Section 15.3 Stream Output
- Section 15.4 Stream Input
- Section 15.5 Unformatted I/O Using read, write and gcount
- Section 15.6 Introduction to Stream Manipulators
- Section 15.7 Stream Format States and Stream Manipulators
- Section 15.8 Stream Error States
- Section 15.9 Tying an Output Stream to an Input Stream
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
16. Exception Handling
- 16.1. Introduction
- 16.2. Exception-Handling Overview
-
16.3. Example: Handling an Attempt to Divide by Zero
- Defining an Exception Class to Represent the Type of Problem That Might Occur
- Demonstrating Exception Handling
- Enclosing Code in a try Block
- Defining a catch Handler to Process a DivideByZeroException
- Termination Model of Exception Handling
- Flow of Program Control When the User Enters a Nonzero Denominator
- Flow of Program Control When the User Enters a Denominator of Zero
- 16.4. When to Use Exception Handling
- 16.5. Rethrowing an Exception
- 16.6. Exception Specifications
- 16.7. Processing Unexpected Exceptions
- 16.8. Stack Unwinding
- 16.9. Constructors, Destructors and Exception Handling
- 16.10. Exceptions and Inheritance
- 16.11. Processing new Failures
- 16.12. Class auto_ptr and Dynamic Memory Allocation
- 16.13. Standard Library Exception Hierarchy
- 16.14. Other Error-Handling Techniques
- 16.15. Wrap-Up
-
Summary
- Section 16.1 Introduction
- Section 16.2 Exception-Handling Overview
- Section 16.3 Example: Handling an Attempt to Divide by Zero
- Section 16.4 When to Use Exception Handling
- Section 16.5 Rethrowing an Exception
- Section 16.6 Exception Specifications
- Section 16.7 Processing Unexpected Exceptions
- Section 16.8 Stack Unwinding
- Section 16.9 Constructors, Destructors and Exception Handling
- Section 16.10 Exceptions and Inheritance
- Section 16.11 Processing new Failures
- Section 16.12 Class auto_ptr and Dynamic Memory Allocation
- Section 16.13 Standard Library Exception Hierarchy
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
17. File Processing
- 17.1. Introduction
- 17.2. Data Hierarchy
- 17.3. Files and Streams
- 17.4. Creating a Sequential File
- 17.5. Reading Data from a Sequential File
- 17.6. Updating Sequential Files
- 17.7. Random-Access Files
- 17.8. Creating a Random-Access File
- 17.9. Writing Data Randomly to a Random-Access File
- 17.10. Reading from a Random-Access File Sequentially
- 17.11. Case Study: A Transaction-Processing Program
- 17.12. Overview of Object Serialization
- 17.13. Wrap-Up
-
Summary
- Section 17.1 Introduction
- Section 17.2 Data Hierarchy
- Section 17.3 Files and Streams
- Section 17.4 Creating a Sequential File
- Section 17.5 Reading Data from a Sequential File
- Section 17.6 Updating Sequential Files
- Section 17.7 Random-Access Files
- Section 17.8 Creating a Random-Access File
- Section 17.9 Writing Data Randomly to a Random-Access File
- Section 17.10 Reading from a Random-Access File Sequentially
- Section 17.12 Overview of Object Serialization
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
18. Class string and String Stream Processing
- 18.1. Introduction
- 18.2. string Assignment and Concatenation
- 18.3. Comparing strings
- 18.4. Substrings
- 18.5. Swapping strings
- 18.6. string Characteristics
- 18.7. Finding Substrings and Characters in a string
- 18.8. Replacing Characters in a string
- 18.9. Inserting Characters into a string
- 18.10. Conversion to C-Style Pointer-Based char * Strings
- 18.11. Iterators
- 18.12. String Stream Processing
- 18.13. Wrap-Up
-
Summary
- Section 18.1 Introduction
- Section 18.2 string Assignment and Concatenation
- Section 18.3 Comparing strings
- Section 18.4 Substrings
- Section 18.5 Swapping strings
- Section 18.6 string Characteristics
- Section 18.7 Finding Substrings and Characters in a string
- Section 18.8 Replacing Characters in a string
- Section 18.9 Inserting Characters into a string
- Section 18.10 Conversion to C-Style Pointer-Based char * Strings
- Section 18.11 Iterators
- Section 18.12 String Stream Processing
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
- 19. Searching and Sorting
-
20. Data Structures
- 20.1. Introduction
- 20.2. Self-Referential Classes
- 20.3. Dynamic Memory Allocation and Data Structures
- 20.4. Linked Lists
- 20.5. Stacks
- 20.6. Queues
- 20.7. Trees
- 20.8. Wrap-Up
- Summary
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
- Special Section: Building Your Own Compiler
-
21. Bits, Characters, C Strings and structs
- 21.1. Introduction
- 21.2. Structure Definitions
- 21.3. Initializing Structures
- 21.4. Using Structures with Functions
- 21.5. typedef
- 21.6. Example: High-Performance Card Shuffling and Dealing Simulation
- 21.7. Bitwise Operators
- 21.8. Bit Fields
- 21.9. Character-Handling Library
- 21.10. Pointer-Based String-Conversion Functions
- 21.11. Search Functions of the Pointer-Based String-Handling Library
- 21.12. Memory Functions of the Pointer-Based String-Handling Library
- 21.13. Wrap-Up
-
Summary
- Section 21.2 Structure Definitions
- Section 21.3 Initializing Structures
- Section 21.4 Using Structures with Functions
- Section 21.5 typedef
- Section 21.7 Bitwise Operators
- Section 21.8 Bit Fields
- Section 21.9 Character-Handling Library
- Section 21.10 Pointer-Based String-Conversion Functions
- Section 21.11 Search Functions of the Pointer-Based String-Handling Library
- Section 21.12 Memory Functions of the Pointer-Based String-Handling Library
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
22. Standard Template Library (STL)
- 22.1. Introduction to the Standard Template Library (STL)
- 22.2. Sequence Containers
- 22.3. Associative Containers
- 22.4. Container Adapters
-
22.5. Algorithms
- 22.5.1. fill, fill_n, generate and generate_n
- 22.5.2. equal, mismatch and lexicographical_compare
- 22.5.3. remove, remove_if, remove_copy and remove_copy_if
- 22.5.4. replace, replace_if, replace_copy and replace_copy_if
- 22.5.5. Mathematical Algorithms
- 22.5.6. Basic Searching and Sorting Algorithms
- 22.5.7. swap, iter_swap and swap_ranges
- 22.5.8. copy_backward, merge, unique and reverse
- 22.5.9. inplace_merge, unique_copy and reverse_copy
- 22.5.10. Set Operations
- 22.5.11. lower_bound, upper_bound and equal_range
- 22.5.12. Heapsort
- 22.5.13. min and max
- 22.5.14. STL Algorithms Not Covered in This Chapter
- 22.6. Class bitset
- 22.7. Function Objects
- 22.8. Wrap-Up
- 22.9. STL Web Resources
-
Summary
- Section 22.1 Introduction to the Standard Template Library (STL)
- Section 22.1.1 Introduction to Containers
- Section 22.1.2 Introduction to Iterators
- Section 22.1.3 Introduction to Algorithms
- Section 22.2 Sequence Containers
- Section 22.2.1 vector Sequence Container
- Section 22.2.2 list Sequence Container
- Section 22.2.3 deque Sequence Container
- Section 22.3 Associative Containers
- Section 22.3.1 multiset Associative Container
- Section 22.3.2 set Associative Container
- Section 22.3.3 multimap Associative Container
- Section 22.3.4 map Associative Container
- Section 22.4 Container Adapters
- Section 22.4.1 stack Adapter
- Section 22.4.2 queue Adapter
- Section 22.4.3 priority_queue Adapter
- Section 22.5.1 fill, fill_n, generate and generate_n
- Section 22.5.2 equal, mismatch and lexicographical_compare
- Section 22.5.3 remove, remove_if, remove_copy and remove_copy_if
- Section 22.5.4 replace, replace_if, replace_copy and replace_copy_if
- Section 22.5.5 Mathematical Algorithms
- Section 22.5.6 Basic Searching and Sorting Algorithms
- Section 22.5.7 swap, iter_swap and swap_ranges
- Section 22.5.8 copy_backward, merge, unique and reverse
- Section 22.5.9 inplace_merge, unique_copy and reverse_copy
- Section 22.5.10 Set Operations
- Section 22.5.11 lower_bound, upper_bound and equal_range
- Section 22.5.12 Heapsort
- Section 22.5.13 min and max
- Section 22.6 Class bitset
- Section 22.7 Function Objects
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
- Recommended Reading
-
23. Game Programming with Ogre
- 23.1. Introduction
- 23.2. Installing Ogre, OgreAL and OpenAL
- 23.3. Basics of Game Programming
- 23.4. The Game of Pong: Code Walkthrough
- 23.5. Wrap-Up
- 23.6. Ogre Web Resources
-
Summary
- Section 23.3 Basics of Game Programming
- Section 23.4.1 Ogre Initialization
- Section 23.4.2 Creating a Scene
- Section 23.4.3 Adding to the Scene
- Section 23.4.4 Animation and Timers
- Section 23.4.5 User Input
- Section 23.4.6 Collision Detection
- Section 23.4.7 Sound
- Section 23.4.8 Resources
- Section 23.4.9 Pong Driver
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
24. Boost Libraries, Technical Report 1 and C++0x
- 24.1. Introduction
- 24.2. Deitel Online C++ and Related Resource Centers
- 24.3. Boost Libraries
- 24.4. Adding a New Library to Boost
- 24.5. Installing the Boost Libraries
- 24.6. Boost Libraries in Technical Report 1 (TR1)
- 24.7. Regular Expressions with the Boost.Regex Library
- 24.8. Smart Pointers with Boost.Smart_ptr
- 24.9. Technical Report 1
- 24.10. C++0x
-
24.11. Core Language Changes
- Rvalue Reference
- Clarification of Initialization of Class Objects by rvalues
- static_assert
- extern template
- Extended friend Declarations
- Synchronizing the C++ Preprocessor with C99
- Conditionally Supported Behavior
- Changing Undefined Behavior into Diagnosable Errors
- Adding the long long Type to C++
- Adding Extended Integer Types to C++
- Delegating Constructors
- Right Angle Brackets
- Deducing the Type of Variable from Its Initializer
- Variadic Templates
- Template Aliases
- New Character Types
- Extending sizeof
- Alternative to Sequence Points
- 24.12. Wrap-Up
-
Summary
- Section 24.2 Deitel Online C++ and Related Resource Centers
- Section 24.3 Boost Libraries
- Section 24.4 Adding a New Library to Boost
- Section 24.5 Installing the Boost Libraries
- Section 24.6 Boost Libraries in Technical Report 1 (TR1)
- Section 24.7 Regular Expressions with the Boost.Regex Library
- Section 24.7.1 Regular Expression Example
- Section 24.7.2 Validating User Input with Regular Expressions
- Section 24.7.3 Replacing and Splitting Strings
- Section 24.8 Smart Pointers with Boost.Smart_ptr
- Section 24.8.1 Reference Counted shared_ptr
- Section 24.8.2 weak_ptr:shared_ptr Observer
- Section 24.9 Technical Report 1
- Section 24.10 C++0x
- Section 24.11 Core Language Changes
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
25. Other Topics
- 25.1. Introduction
- 25.2. const_cast Operator
- 25.3. namespaces
- 25.4. Operator Keywords
- 25.5. mutable Class Members
- 25.6. Pointers to Class Members (.* and ->*)
- 25.7. Multiple Inheritance
- 25.8. Multiple Inheritance and virtual Base Classes
- 25.9. Wrap-Up
- Summary
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
- A. Operator Precedence and Associativity Chart
- B. ASCII Character Set
- C. Fundamental Types
-
D. Number Systems
- D.1. Introduction
- D.2. Abbreviating Binary Numbers as Octal and Hexadecimal Numbers
- D.3. Converting Octal and Hexadecimal Numbers to Binary Numbers
- D.4. Converting from Binary, Octal or Hexadecimal to Decimal
- D.5. Converting from Decimal to Binary, Octal or Hexadecimal
- D.6. Negative Binary Numbers: Two’s Complement Notation
- Summary
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
E. C Legacy Code Topics
- E.1. Introduction
- E.2. Redirecting Input/Output on UNIX/Linux/Mac OS X and Windows Systems
- E.3. Variable-Length Argument Lists
- E.4. Using Command-Line Arguments
- E.5. Notes on Compiling Multiple-Source-File Programs
- E.6. Program Termination with exit and atexit
- E.7. Type Qualifier volatile
- E.8. Suffixes for Integer and Floating-Point Constants
- E.9. Signal Handling
- E.10. Dynamic Memory Allocation with calloc and realloc
- E.11. Unconditional Branch: goto
- E.12. Unions
- E.13. Linkage Specifications
- E.14. Wrap-Up
-
Summary
- Section E.2 Redirecting Input/Output on UNIX/Linux/Mac OS X and Windows Systems
- Section E.3 Variable-Length Argument Lists
- Section E.4 Using Command-Line Arguments
- Section E.5 Notes on Compiling Multiple-Source-File Programs
- Section E.6 Program Termination with exit and atexit
- Section E.7 Type Qualifier volatile
- Section E.8 Suffixes for Integer and Floating-Point Constants
- Section E.9 Signal Handling
- Section E.10 Dynamic Memory Allocation with calloc and realloc
- Section E.11 Unconditional Branch: goto
- Section E.12 Unions
- Section E.13 Linkage Specifications
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
F. Preprocessor
- F.1. Introduction
- F.2. The #include Preprocessor Directive
- F.3. The #define Preprocessor Directive: Symbolic Constants
- F.4. The #define Preprocessor Directive: Macros
- F.5. Conditional Compilation
- F.6. The #error and #pragma Preprocessor Directives
- F.7. Operators # and ##
- F.8. Predefined Symbolic Constants
- F.9. Assertions
- F.10. Wrap-Up
-
Summary
- Section F.2 The #include Preprocessor Directive
- Section F.3 The #define Preprocessor Directive: Symbolic Constants
- Section F.4 The #define Preprocessor Directive: Macros
- Section F.5 Conditional Compilation
- Section F.6 The #error and #pragma Preprocessor Directives
- Section F.7 Operators # and ##
- Section F.8 Predefined Symbolic Constants
- Section F.9 Assertions
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
G. ATM Case Study Code
- G.1. ATM Case Study Implementation
- G.2. Class ATM
- G.3. Class Screen
- G.4. Class Keypad
- G.5. Class CashDispenser
- G.6. Class DepositSlot
- G.7. Class Account
- G.8. Class BankDatabase
- G.9. Class Transaction
- G.10. Class BalanceInquiry
- G.11. Class Withdrawal
- G.12. Class Deposit
- G.13. Test Program ATMCaseStudy.cpp
- G.14. Wrap-Up
- H. UML 2: Additional Diagram Types
- I. Using the Visual Studio Debugger
- J. Using the GNU C++ Debugger
-
Bibliography
Product information
- Title: C++ How to Program, Sixth Edition
- Author(s):
- Release date: July 2007
- Publisher(s): Pearson
- ISBN: 9780136085669
You might also like
book
C++ How to Program, Ninth Edition
For Introduction to Programming (CS1) and other more intermediate courses covering programming in C++. Also appropriate …
book
C++ How to Program, 10/e
C++ How to Program presents leading-edge computing technologies in a friendly manner appropriate for introductory college …
book
The C++ Programming Language, 4th Edition
The new C++11 standard allows programmers to express ideas more clearly, simply, and directly, and to …
book
Programming: Principles and Practice Using C++, 2nd Edition
An Introduction to Programming by the Inventor of C++ Preparation for Programming in the Real World …