Book description
The Deitels' groundbreaking How to Program series offers unparalleled breadth and depth of object-oriented programming concepts and intermediate-level topics for further study. Using the Deitels’ signature “Live-Code™ Approach,” this complete, authoritative introduction to C programming offers strong treatment of structured algorithm and program development in ANSI/ISO C with 150 working C programs. Includes rich, 300-page treatment of object-oriented programming in C++ that helps students interpret the code more effectively.
Table of contents
- Copyright
- Deitel® Series Page
-
Preface
- Before You Begin
- Features of C How to Program, Fifth Edition
-
Teaching Approach
- Live-Code Approach
- World Wide Web Access
- Objectives
- Quotations
- Outline
- Sections
- Thousands of Lines of Syntax-Highlighted Code in Hundreds of Example Programs (with Outputs)
- Illustrations/Figures
- Programming Tips
- Summary Bullets
- Terminology
- Self-Review Exercises and Answers
- Exercises
- Thousands of Index Entries
- “Double Indexing” of C Live-Code Examples
- Software Included with C How to Program, 5/e
- Teaching Resources for C How to Program, 5/e
- Deitel® Buzz Online Free E-mail Newsletter
- What’s New at Deitel
- Acknowledgments
- About the Authors
- About Deitel & Associates, Inc.
-
1. Introduction to Computers, the Internet and the 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. Machine Languages, Assembly Languages and High-Level Languages
- 1.7. Fortran, COBOL, Pascal and Ada
- 1.8. History of C
- 1.9. C Standard Library
- 1.10. C++
- 1.11. Java
- 1.12. BASIC, Visual Basic, Visual C++, Visual C# and .NET
- 1.13. Key Software Trend: Object Technology
- 1.14. Typical C Program Development Environment
- 1.15. Hardware Trends
- 1.16. History of the Internet
- 1.17. History of the World Wide Web
- 1.18. Notes About C and This Book
- 1.19. 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 Machine Languages, Assembly Languages and High-Level Languages
- Section 1.7 Fortran, COBOL, Pascal and Ada
- Section 1.8 History of C
- Section 1.9 C Standard Library
- Section 1.10 C++
- Section 1.11 Java
- Section 1.12 BASIC, Visual Basic, Visual C++, Visual C# and .NET
- Section 1.13 Key Software Trend: Object Technology
- Section 1.14 Typical C Program Development Environment
- Section 1.15 Hardware Trends
- Section 1.16 History of the Internet
- Section 1.17 History of the World Wide Web
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
2. Introduction to C Programming
- 2.1. Introduction
- 2.2. A Simple C Program: Printing a Line of Text
- 2.3. Another Simple C Program: Adding Two Integers
- 2.4. Memory Concepts
- 2.5. Arithmetic in C
- 2.6. Decision Making: Equality and Relational Operators
- Summary
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
3. Structured Program Development in C
- 3.1. Introduction
- 3.2. Algorithms
- 3.3. Pseudocode
- 3.4. Control Structures
- 3.5. The if Selection Statement
- 3.6. The if...else Selection Statement
- 3.7. The while Repetition Statement
- 3.8. Formulating Algorithms Case Study 1: Counter-Controlled Repetition
- 3.9. Formulating Algorithms with Top-Down, Stepwise Refinement Case Study 2: Sentinel-Controlled Repetition
- 3.10. Formulating Algorithms with Top-Down, Stepwise Refinement Case Study 3: Nested Control Structures
- 3.11. Assignment Operators
- 3.12. Increment and Decrement Operators
-
Summary
- Section 3.1 Introduction
- Section 3.2 Algorithms
- Section 3.3 Pseudocode
- Section 3.4 Control Structures
- Section 3.5 The if Selection Statement
- Section 3.6 The if...else Selection Statement
- Section 3.7 The while Repetition Statement
- Section 3.8 Formulating Algorithms Case Study 1: Counter-Controlled Repetition
- Section 3.9 Formulating Algorithms with Top-Down, Stepwise Refinement Case Study 2: Sentinel-Controlled Repetition
- Section 3.11 Assignment Operators
- Section 3.12 Increment and Decrement Operators
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
4. C Program Control
- 4.1. Introduction
- 4.2. Repetition Essentials
- 4.3. Counter-Controlled Repetition
- 4.4. for Repetition Statement
- 4.5. for Statement: Notes and Observations
- 4.6. Examples Using the for Statement
- 4.7. switch Multiple-Selection Statement
- 4.8. do...while Repetition Statement
- 4.9. break and continue Statements
- 4.10. Logical Operators
- 4.11. Confusing Equality (==) and Assignment (=) Operators
- 4.12. Structured Programming Summary
-
Summary
- Section 4.2 Repetition Essentials
- Section 4.3 Counter-Controlled Repetition
- Section 4.4 for Repetition Statement
- Section 4.5 for Statement: Notes and Observations
- Section 4.6 Examples Using the for Statement
- Section 4.7 switch Multiple-Selection Statement
- Section 4.8 do...while Repetition Statement
- Section 4.9 break and continue Statements
- Section 4.10 Logical Operators
- Section 4.11 Confusing Equality (==) and Assignment (=) Operators
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
5. C Functions
- 5.1. Introduction
- 5.2. Program Modules in C
- 5.3. Math Library Functions
- 5.4. Functions
- 5.5. Function Definitions
- 5.6. Function Prototypes
- 5.7. Function Call Stack and Activation Records
- 5.8. Headers
- 5.9. Calling Functions: Call-by-Value and Call-by-Reference
- 5.10. Random Number Generation
- 5.11. Example: A Game of Chance
- 5.12. Storage Classes
- 5.13. Scope Rules
- 5.14. Recursion
- 5.15. Example Using Recursion: Fibonacci Series
- 5.16. Recursion vs. Iteration
-
Summary
- Section 5.1 Introduction
- Section 5.2 Program Modules in C
- Section 5.3 Math Library Functions
- Section 5.4 Functions
- Section 5.5 Function Definitions
- Section 5.6 Function Prototypes
- Section 5.7 Function Call Stack and Activation Records
- Section 5.8 Headers
- Section 5.9 Calling Functions: Call-by-Value and Call-by-Reference
- Section 5.10 Random Number Generation
- Section 5.11 Example: A Game of Chance
- Section 5.12 Storage Classes
- Section 5.13 Scope Rules
- Section 5.14 Recursion
- Section 5.16 Recursion vs. Iteration
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
6. C Arrays
- 6.1. Introduction
- 6.2. Arrays
- 6.3. Defining Arrays
-
6.4. Array Examples
- Defining an Array and Using a Loop to Initialize the Array’s Elements
- Initializing an Array in a Definition with an Initializer List
- Specifying an Array’s Size with a Symbolic Constant and Initializing Array Elements with Calculations
- Summing the Elements of an Array
- Using Arrays to Summarize Survey Results
- Graphing Array Element Values with Histograms
- Rolling a Die 6000 Times and Summarizing the Results in an Array
- Using Character Arrays to Store and Manipulate Strings
- Static Local Arrays and Automatic Local Arrays
- 6.5. Passing Arrays to Functions
- 6.6. Sorting Arrays
- 6.7. Case Study: Computing Mean, Median and Mode Using Arrays
- 6.8. Searching Arrays
- 6.9. Multiple-Subscripted Arrays
-
Summary
- Section 6.1 Introduction
- Section 6.2 Arrays
- Section 6.3 Defining Arrays
- Section 6.4 Array Examples
- Section 6.5 Passing Arrays to Functions
- Section 6.6 Sorting Arrays
- Section 6.7 Case Study: Computing Mean, Median and Mode Using Arrays
- Section 6.8 Searching Arrays
- Section 6.9 Multiple-Subscripted Arrays
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
- Recursion Exercises
- Special Section: Sudoku
-
7. C Pointers
- 7.1. Introduction
- 7.2. Pointer Variable Definitions and Initialization
- 7.3. Pointer Operators
- 7.4. Passing Arguments to Functions by Reference
- 7.5. Using the const Qualifier with Pointers
- 7.6. Bubble Sort Using Call-by-Reference
- 7.7. sizeof Operator
- 7.8. Pointer Expressions and Pointer Arithmetic
- 7.9. Relationship between Pointers and Arrays
- 7.10. Arrays of Pointers
- 7.11. Case Study: Card Shuffling and Dealing Simulation
- 7.12. Pointers to Functions
-
Summary
- Section 7.2 Pointer Variable Definitions and Initialization
- Section 7.3 Pointer Operators
- Section 7.4 Passing Arguments to Functions by Reference
- Section 7.5 Using the const Qualifier with Pointers
- Section 7.7 sizeof Operator
- Section 7.8 Pointer Expressions and Pointer Arithmetic
- Section 7.9 Relationship between Pointers and Arrays
- Section 7.10 Arrays of Pointers
- Section 7.12 Pointers to Functions
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
- Special Section: Building Your Own Computer
-
8. C Characters and Strings
- 8.1. Introduction
- 8.2. Fundamentals of Strings and Characters
- 8.3. Character-Handling Library
- 8.4. String-Conversion Functions
- 8.5. Standard Input/Output Library Functions
- 8.6. String-Manipulation Functions of the String-Handling Library
- 8.7. Comparison Functions of the String-Handling Library
- 8.8. Search Functions of the String-Handling Library
- 8.9. Memory Functions of the String-Handling Library
- 8.10. Other Functions of the String-Handling Library
-
Summary
- Section 8.2 Fundamentals of Strings and Characters
- Section 8.3 Character-Handling Library
- Section 8.4 String-Conversion Functions
- Section 8.5 Standard Input/Output Library Functions
- Section 8.6 String-Manipulation Functions of the String-Handling Library
- Section 8.7 Comparison Functions of the String-Handling Library
- Section 8.8 Search Functions of the String-Handling Library
- Section 8.9 Memory Functions of the String-Handling Library
- Section 8.10 Other Functions of the String-Handling Library
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
- Special Section: Advanced String-Manipulation Exercises
- A Challenging String-Manipulation Project
-
9. C Formatted Input/Output
- 9.1. Introduction
- 9.2. Streams
- 9.3. Formatting Output with printf
- 9.4. Printing Integers
- 9.5. Printing Floating-Point Numbers
- 9.6. Printing Strings and Characters
- 9.7. Other Conversion Specifiers
- 9.8. Printing with Field Widths and Precision
- 9.9. Using Flags in the printf Format Control String
- 9.10. Printing Literals and Escape Sequences
- 9.11. Reading Formatted Input with scanf
-
Summary
- Section 9.2 Streams
- Section 9.3 Formatting Output with printf
- Section 9.4 Printing Integers
- Section 9.5 Printing Floating-Point Numbers
- Section 9.6 Printing Strings and Characters
- Section 9.7 Other Conversion Specifiers
- Section 9.8 Printing with Field Widths and Precision
- Section 9.9 Using Flags in the printf Format Control String
- Section 9.10 Printing Literals and Escape Sequences
- Section 9.11 Formatting Input with scanf
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
10. C Structures, Unions, Bit Manipulations and Enumerations
- 10.1. Introduction
- 10.2. Structure Definitions
- 10.3. Initializing Structures
- 10.4. Accessing Members of Structures
- 10.5. Using Structures with Functions
- 10.6. typedef
- 10.7. Example: High-Performance Card Shuffling and Dealing Simulation
- 10.8. Unions
- 10.9. Bitwise Operators
- 10.10. Bit Fields
- 10.11. Enumeration Constants
-
Summary
- Section 10.1 Introduction
- Section 10.2 Structure Definitions
- Section 10.3 Initializing Structures
- Section 10.4 Accessing Members of Structures
- Section 10.5 Using Structures with Functions
- Section 10.6 typedef
- Section 10.8 Unions
- Section 10.9 Bitwise Operators
- Section 10.10 Bit Fields
- Section 10.11 Enumeration Constants
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
11. C File Processing
- 11.1. Introduction
- 11.2. Data Hierarchy
- 11.3. Files and Streams
- 11.4. Creating a Sequential-Access File
- 11.5. Reading Data from a Sequential-Access File
- 11.6. Random-Access Files
- 11.7. Creating a Random-Access File
- 11.8. Writing Data Randomly to a Random-Access File
- 11.9. Reading Data from a Random-Access File
- 11.10. Case Study: Transaction-Processing Program
-
Summary
- Section 11.1 Introduction
- Section 11.2 Data Hierarchy
- Section 11.3 Files and Streams
- Section 11.4 Creating a Sequential-Access File
- Section 11.5 Reading Data from a Sequential-Access File
- Section 11.6 Random-Access Files
- Section 11.7 Creating a Random-Access File
- Section 11.8 Writing Data Randomly to a Random-Access File
- Section 11.9 Reading Data from a Random-Access File
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
- 12. C Data Structures
-
13. C Preprocessor
- 13.1. Introduction
- 13.2. #include Preprocessor Directive
- 13.3. #define Preprocessor Directive: Symbolic Constants
- 13.4. #define Preprocessor Directive: Macros
- 13.5. Conditional Compilation
- 13.6. #error and #pragma Preprocessor Directives
- 13.7. # and ## Operators
- 13.8. Line Numbers
- 13.9. Predefined Symbolic Constants
- 13.10. Assertions
-
Summary
- Section 13.1 Introduction
- Section 13.2 #include Preprocessor Directive
- Section 13.3 #define Preprocessor Directive: Symbolic Constants
- Section 13.4 #define Preprocessor Directive: Macros
- Section 13.5 Conditional Compilation
- Section 13.6 #error and #pragma Preprocessor Directives
- Section 13.7 # and ## Operators
- Section 13.8 Line Numbers
- Section 13.9 Predefined Symbolic Constants
- Section 13.10 Assertions
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
14. Other C Topics
- 14.1. Introduction
- 14.2. Redirecting Input/Output on Linux/UNIX and Windows Systems
- 14.3. Variable-Length Argument Lists
- 14.4. Using Command-Line Arguments
- 14.5. Notes on Compiling Multiple-Source-File Programs
- 14.6. Program Termination with exit and atexit
- 14.7. volatile Type Qualifier
- 14.8. Suffixes for Integer and Floating-Point Constants
- 14.9. More on Files
- 14.10. Signal Handling
- 14.11. Dynamic Memory Allocation: Functions calloc and realloc
- 14.12. Unconditional Branching with goto
-
Summary
- Section 14.2 Redirecting Input/Output on Linux/UNIX and Windows Systems
- Section 14.3 Variable-Length Argument Lists
- Section 14.4 Using Command-Line Arguments
- Section 14.5 Notes on Compiling Multiple-Source-File Programs
- Section 14.6 Program Termination with exit and atexit
- Section 14.7 volatile Type Qualifier
- Section 14.8 Suffixes for Integer and Floating-Point Constants
- Section 14.9 More on Files
- Section 14.10 Signal Handling
- Section 14.11 Dynamic Memory Allocation: Functions calloc and realloc
- Section 14.12 Unconditional Branching with goto
- Terminology
- Self-Review Exercise
- Answers to Self-Review Exercise
- Exercises
-
15. Game Programming with the Allegro C Library
- 15.1. Introduction
- 15.2. Installing Allegro
- 15.3. A Simple Allegro Program
- 15.4. Simple Graphics: Importing Bitmaps and Blitting
- 15.5. Animation with Double Buffering
- 15.6. Importing and Playing Sounds
- 15.7. Keyboard Input
- 15.8. Fonts and Displaying Text
- 15.9. Implementing the Game of Pong
- 15.10. Timers in Allegro
- 15.11. The Grabber and Allegro Datafiles
- 15.12. Other Allegro Capabilities
- 15.13. Allegro Internet and Web Resources
-
Summary
- Section 15.3 A Simple Allegro Program
- Section 15.4 Simple Graphics: Importing Bitmaps and Blitting
- Section 15.5 Animation with Double Buffering
- Section 15.6 Importing and Playing Sounds
- Section 15.7 Keyboard Input
- Section 15.8 Fonts and Displaying Text
- Section 15.10 Timers in Allegro
- Section 15.11 The Grabber and Allegro Datafiles
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
- 16. Sorting: A Deeper Look
-
17. Introduction to C99
- 17.1. Introduction
- 17.2. Support for C99
- 17.3. New C99 Headers
- 17.4. // Comments
- 17.5. Mixing Declarations and Executable Code
- 17.6. Declaring a Variable in a for Statement Header
- 17.7. Designated Initializers and Compound Literals
- 17.8. Type bool
- 17.9. Implicit int in Function Declarations
- 17.10. Complex Numbers
- 17.11. Variable-Length Arrays
- 17.12. Other C99 Features
- 17.13. Internet and Web Resources
-
Summary
- Section 17.1 Introduction
- Section 17.2 Support for C99
- Section 17.4 // Comments
- Section 17.5 Mixing Declarations and Executable Code
- Section 17.6 Declaring a Variable in a for Statement Header
- Section 17.7 Designated Initializers and Compound Literals
- Section 17.8 Type bool
- Section 17.9 Implicit int Function Declarations
- Section 17.10 Complex Numbers
- Section 17.11 Variable-Length Arrays
- Section 17.12 Other C99 Features
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
18. C++ as a Better C; Introducing Object Technology
- 18.1. Introduction
- 18.2. C++
- 18.3. A Simple Program: Adding Two Integers
- 18.4. C++ Standard Library
- 18.5. Header Files
- 18.6. Inline Functions
- 18.7. References and Reference Parameters
- 18.8. Empty Parameter Lists
- 18.9. Default Arguments
- 18.10. Unary Scope Resolution Operator
- 18.11. Function Overloading
- 18.12. Function Templates
- 18.13. Introduction to Object Technology and the UML
- 18.14. Wrap-Up
-
Summary
- Section 18.2 C++
- Section 18.3 A Simple Program: Adding Two Integers
- Section 18.4 C++ Standard Library
- Section 18.5 Header Files
- Section 18.6 Inline Functions
- Section 18.7 References and Reference Parameters
- Section 18.8 Empty Parameter Lists
- Section 18.9 Default Arguments
- Section 18.10 Unary Scope Resolution Operator
- Section 18.11 Function Overloading
- Section 18.12 Function Templates
- Section 18.13 Introduction to Object Technology and the UML
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
19. Introduction to Classes and Objects
- 19.1. Introduction
- 19.2. Classes, Objects, Member Functions and Data Members
- 19.3. Overview of the Chapter Examples
- 19.4. Defining a Class with a Member Function
- 19.5. Defining a Member Function with a Parameter
-
19.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
- 19.7. Initializing Objects with Constructors
- 19.8. Placing a Class in a Separate File for Reusability
- 19.9. Separating Interface from Implementation
- 19.10. Validating Data with set Functions
- 19.11. Wrap-Up
-
Summary
- Section 19.2 Classes, Objects, Member Functions and Data Members
- Section 19.4 Defining a Class with a Member Function
- Section 19.5 Defining a Member Function with a Parameter
- Section 19.6 Data Members, set Functions and get Functions
- Section 19.7 Initializing Objects with Constructors
- Section 19.8 Placing a Class in a Separate File for Reusability
- Section 19.9 Separating Interface from Implementation
- Section 19.10 Validating Data with set Functions
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
20. Classes: A Deeper Look, Part 1
- 20.1. Introduction
- 20.2. Time Class Case Study
- 20.3. Class Scope and Accessing Class Members
- 20.4. Separating Interface from Implementation
- 20.5. Access Functions and Utility Functions
- 20.6. Time Class Case Study: Constructors with Default Arguments
- 20.7. Destructors
- 20.8. When Constructors and Destructors Are Called
- 20.9. Time Class Case Study: A Subtle Trap—Returning a Reference to a private Data Member
- 20.10. Default Memberwise Assignment
- 20.11. Software Reusability
- 20.12. Wrap-Up
-
Summary
- Section 20.2 Time Class Case Study
- Section 20.3 Class Scope and Accessing Class Members
- Section 20.4 Separating Interface from Implementation
- Section 20.5 Access Functions and Utility Functions
- Section 20.6 Time Class Case Study: Constructors with Default Arguments
- Section 20.7 Destructors
- Section 20.8 When Constructors and Destructors Are Called
- Section 20.9 Time Class Case Study: A Subtle Trap—Returning a Reference to a private Data Member
- Section 20.8 When Constructors and Destructors Are Called
- Section 20.11 Software Reusability
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
21. Classes: A Deeper Look, Part 2
- 21.1. Introduction
- 21.2. const (Constant) Objects and const Member Functions
- 21.3. Composition: Objects as Members of Classes
- 21.4. friend Functions and friend Classes
- 21.5. Using the this Pointer
- 21.6. Dynamic Memory Management with Operators new and delete
- 21.7. static Class Members
- 21.8. Data Abstraction and Information Hiding
- 21.9. Container Classes and Iterators
- 21.10. Proxy Classes
- 21.11. Wrap-Up
-
Summary
- Section 21.2 const (Constant) Objects and const Member Functions
- Section 21.3 Composition: Objects as Members of Classes
- Section 21.4 friend Functions and friend Classes
- Section 21.5 Using the this Pointer
- Section 21.6 Dynamic Memory Management with Operators new and delete
- Section 21.7 static Class Members
- Section 21.8 Data Abstraction and Information Hiding
- Section 21.9 Container Classes and Iterators
- Section 21.10 Proxy Classes
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
22. Operator Overloading
- 22.1. Introduction
- 22.2. Fundamentals of Operator Overloading
- 22.3. Restrictions on Operator Overloading
- 22.4. Operator Functions as Class Members vs. Global Functions
- 22.5. Overloading Stream Insertion and Stream Extraction Operators
- 22.6. Overloading Unary Operators
- 22.7. Overloading Binary Operators
-
22.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
- 22.9. Converting between Types
- 22.10. Overloading ++ and −−
- 22.11. explicit Constructors
- 22.12. Wrap-Up
-
Summary
- Section 22.2 Fundamentals of Operator Overloading
- Section 22.3 Restrictions on Operator Overloading
- Section 22.4 Operator Functions as Class Members vs. Global Functions
- Section 22.5 Overloading Stream Insertion and Stream Extraction Operators
- Section 22.6 Overloading Unary Operators
- Section 22.7 Overloading Binary Operators
- Section 22.8 Case Study: Array Class
- Section 22.9 Converting between Types
- Section 22.10 Overloading ++ and −−
- Section 22.11 explicit Constructors
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
23. Object-Oriented Programming: Inheritance
- 23.1. Introduction
- 23.2. Base Classes and Derived Classes
- 23.3. protected Members
-
23.4. Relationship between Base Classes and Derived Classes
- 23.4.1. Creating and Using a CommissionEmployee Class
- 23.4.2. Creating a BasePlusCommissionEmployee Class Without Using Inheritance
- 23.4.3. Creating a CommissionEmployee–BasePlusCommissionEmployee Inheritance Hierarchy
- 23.4.4. CommissionEmployee–BasePlusCommissionEmployee Inheritance Hierarchy Using protected Data
- 23.4.5. CommissionEmployee–BasePlusCommissionEmployee Inheritance Hierarchy Using private Data
- 23.5. Constructors and Destructors in Derived Classes
- 23.6. public, protected and private Inheritance
- 23.7. Software Engineering with Inheritance
- 23.8. Wrap-Up
- Summary
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
24. Object-Oriented Programming: Polymorphism
- 24.1. Introduction
- 24.2. Polymorphism Examples
-
24.3. Relationships Among Objects in an Inheritance Hierarchy
- 24.3.1. Invoking Base-Class Functions from Derived-Class Objects
- 24.3.2. Aiming Derived-Class Pointers at Base-Class Objects
- 24.3.3. Derived-Class Member-Function Calls via Base-Class Pointers
- 24.3.4. Virtual Functions
- 24.3.5. Summary of the Allowed Assignments Between Base-Class and Derived-Class Objects and Pointers
- 24.4. Type Fields and switch Statements
- 24.5. Abstract Classes and Pure virtual Functions
-
24.6. Case Study: Payroll System Using Polymorphism
- 24.6.1. Creating Abstract Base Class Employee
- 24.6.2. Creating Concrete Derived Class SalariedEmployee
- 24.6.3. Creating Concrete Derived Class HourlyEmployee
- 24.6.4. Creating Concrete Derived Class CommissionEmployee
- 24.6.5. Creating Indirect Concrete Derived Class BasePlusCommissionEmployee
- 24.6.6. Demonstrating Polymorphic Processing
- 24.7. (Optional) Polymorphism, Virtual Functions and Dynamic Binding “Under the Hood”
- 24.8. Case Study: Payroll System Using Polymorphism and Runtime Type Information with Downcasting, dynamic_cast, typeid and type_info
- 24.9. Virtual Destructors
- 24.10. Wrap-Up
-
Summary
- Section 24.1 Introduction
- Section 24.3 Relationships Among Objects in an Inheritance Hierarchy
- Section 24.5 Abstract Classes and Pure virtual Functions
- Section 24.7 (Optional) Polymorphism, Virtual Functions and Dynamic Binding “Under the Hood”
- Section 24.8 Case Study: Payroll System Using Polymorphism and Runtime Type Information with Downcasting, dynamic_cast, typeid and type_info
- Section 24.9 Virtual Destructors
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
25. Templates
- 25.1. Introduction
- 25.2. Function Templates
- 25.3. Overloading Function Templates
- 25.4. Class Templates
- 25.5. Nontype Parameters and Default Types for Class Templates
- 25.6. Notes on Templates and Inheritance
- 25.7. Notes on Templates and Friends
- 25.8. Notes on Templates and static Members
- 25.9. Wrap-Up
-
Summary
- Section 25.1 Introduction
- Section 25.2 Function Templates
- Section 25.3 Overloading Function Templates
- Section 25.4 Class Templates
- Section 25.5 Nontype Parameters and Default Types for Class Templates
- Section 25.6 Notes on Templates and Inheritance
- Section 25.7 Notes on Templates and Friends
- Section 25.8 Notes on Templates and static Members
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
26. Stream Input/Output
- 26.1. Introduction
- 26.2. Streams
- 26.3. Stream Output
- 26.4. Stream Input
- 26.5. Unformatted I/O Using read, write and gcount
- 26.6. Introduction to Stream Manipulators
-
26.7. Stream Format States and Stream Manipulators
- 26.7.1. Trailing Zeros and Decimal Points (showpoint)
- 26.7.2. Justification (left, right and internal)
- 26.7.3. Padding (fill, setfill)
- 26.7.4. Integral Stream Base (dec, oct, hex, showbase)
- 26.7.5. Floating-Point Numbers; Scientific and Fixed Notation (scientific, fixed)
- 26.7.6. Uppercase/Lowercase Control (uppercase)
- 26.7.7. Specifying Boolean Format (boolalpha)
- 26.7.8. Setting and Resetting the Format State via Member Function flags
- 26.8. Stream Error States
- 26.9. Tying an Output Stream to an Input Stream
- 26.10. Wrap-Up
-
Summary
- Section 26.1 Introduction
- Section 26.2 Streams
- Section 26.3 Stream Output
- Section 26.4 Stream Input
- Section 26.5 Unformatted I/O Using read, write and gcount
- Section 26.6 Introduction to Stream Manipulators
- Section 26.7 Stream Format States and Stream Manipulators
- Section 26.8 Stream Error States
- Section 26.9 Tying an Output Stream to an Input Stream
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
27. Exception Handling
- 27.1. Introduction
- 27.2. Exception-Handling Overview
-
27.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
- 27.4. When to Use Exception Handling
- 27.5. Rethrowing an Exception
- 27.6. Exception Specifications
- 27.7. Processing Unexpected Exceptions
- 27.8. Stack Unwinding
- 27.9. Constructors, Destructors and Exception Handling
- 27.10. Exceptions and Inheritance
- 27.11. Processing new Failures
- 27.12. Class auto_ptr and Dynamic Memory Allocation
- 27.13. Standard Library Exception Hierarchy
- 27.14. Other Error-Handling Techniques
- 27.15. Wrap-Up
-
Summary
- Section 27.1 Introduction
- Section 27.2 Exception-Handling Overview
- Section 27.3 Example: Handling an Attempt to Divide by Zero
- Section 27.4 When to Use Exception Handling
- Section 27.5 Rethrowing an Exception
- Section 27.6 Exception Specifications
- Section 27.7 Processing Unexpected Exceptions
- Section 27.8 Stack Unwinding
- Section 27.9 Constructors, Destructors and Exception Handling
- Section 27.10 Exceptions and Inheritance
- Section 27.11 Processing new Failures
- Section 27.12 Class auto_ptr and Dynamic Memory Allocation
- Section 27.13 Standard Library Exception Hierarchy
- Terminology
- Self-Review Exercises
- Answers to Self-Review Exercises
- Exercises
-
A. Internet and Web Resources
- A.1. Free C/C++ Compilers and Development Tools
- A.2. C Resource Sites
- A.3. C99
- A.4. C Projects, Freeware and Shareware
- A.5. C Source Code
- A.6. C Articles and Whitepapers
- A.7. C Tutorials and Webcasts
- A.8. GNOME and GLib
- A.9. SWIG
- A.10. Objective-C
- A.11. C Sample Chapters and eBooks
- A.12. C Wikis
- A.13. C FAQs
- A.14. C Newsgroups
- A.15. C Blogs
- A.16. C Downloads from Download.com
- A.17. C Game Programming
- A.18. Allegro Game Programming Resources
- A.19. Jobs for C Programmers
- A.20. Deitel C Training
- B. Operator Precedence Charts
- C. ASCII Character Set
-
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. Game Programming: Solving Sudoku
Product information
- Title: C How to Program, Fifth Edition
- Author(s):
- Release date: August 2006
- Publisher(s): Pearson
- ISBN: 9780136085881
You might also like
book
Programming in C, Fourth Edition
will teach you how to write programs in the C programming language. Whether you’re a novice …
book
C Programming Language, 2nd Edition
This book is meant to help the reader learn how to program in C. It is …
video
Programming in C - The Complete Course
A vast majority of modern programming languages and popular libraries are based on C, making C …
book
Learn C Programming - Second Edition
Get started with writing simple programs in C while learning core programming concepts Key Features Learn …