C++ How to Program

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

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 an early-objects approach. The authors emphasize achieving program clarity through structured and object-oriented programming, software reuse and component-oriented software construction. The Eighth Edition encourages students to connect computers to the community, using the Internet to solve problems and make a difference in our world. All content has been carefully fine-tuned in response to a team of distinguished academic and industry reviewers.

Author(s): Paul Deitel; Harvey Deitel
Edition: 8
Year: 2011

Language: English

Cover
Title Page
Copyright Page
Contents
Preface
1 Introduction to Computers and C++
1.1 Introduction
1.2 Computers: Hardware and Software
1.3 Data Hierarchy
1.4 Computer Organization
1.5 Machine Languages, Assembly Languages and High-Level Languages
1.6 Introduction to Object Technology
1.7 Operating Systems
1.8 Programming Languages
1.9 C++ and a Typical C++ Development Environment
1.10 Test-Driving a C++ Application
1.11 Web 2.0: Going Social
1.12 Software Technologies
1.13 Future of C++: TR1, the New C++ Standard and the Open Source Boost Libraries
1.14 Keeping Up-to-Date with Information Technologies
1.15 Wrap-Up
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 Wrap-Up
3 Introduction to Classes, Objects and Strings
3.1 Introduction
3.2 Defining a Class with a Member Function
3.3 Defining a Member Function with a Parameter
3.4 Data Members, set Functions and get Functions
3.5 Initializing Objects with Constructors
3.6 Placing a Class in a Separate File for Reusability
3.7 Separating Interface from Implementation
3.8 Validating Data with set Functions
3.9 Wrap-Up
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
4.10 Formulating Algorithms: Nested Control Statements
4.11 Assignment Operators
4.12 Increment and Decrement Operators
4.13 Wrap-Up
5 Control Statements: Part2
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 Wrap-Up
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 Headers
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 Wrap-Up
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 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 Wrap-Up
8 Pointers
8.1 Introduction
8.2 Pointer Variable Declarations and Initialization
8.3 Pointer Operators
8.4 Pass-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 Pointer-Based String Processing
8.11 Arrays of Pointers
8.12 Function Pointers
8.13 Wrap-Up
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 Wrap-Up
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 static Class Members
10.7 Proxy Classes
10.8 Wrap-Up
11 Operator Overloading; Class string
11.1 Introduction
11.2 Using the Overloaded Operators of Standard Library Class string
11.3 Fundamentals of Operator Overloading
11.4 Overloading Binary Operators
11.5 Overloading the Binary Stream Insertion and Stream Extraction Operators
11.6 Overloading Unary Operators
11.7 Overloading the Unary Prefix and Postfix ++ and -- Operators
11.8 Case Study: A Date Class
11.9 Dynamic Memory Management
11.10 Case Study: Array Class
11.10.1 Using the Array Class
11.10.2 Array Class Definition
11.11 Operators as Member Functions vs. Non-Member Functions
11.12 Converting between Types
11.13 explicit Constructors
11.14 Building a String Class
11.15 Wrap-Up
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
13 Object-Oriented Programming: Polymorphism
13.1 Introduction
13.2 Introduction to Polymorphism: Polymorphic Video Game
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.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 CommissionEmployee
13.6.4 Creating Indirect Concrete Derived Class BasePlusCommissionEmployee
13.6.5 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 Wrap-Up
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 Wrap-Up
15 Stream Input/Output
15.1 Introduction
15.2 Streams
15.2.1 Classic Streams vs. Standard Streams
15.2.2 iostream Library Headers
15.2.3 Stream Input/Output Classes and Objects
15.3 Stream Output
15.3.1 Output of char * Variables
15.3.2 Character Output Using Member Function put
15.4 Stream Input
15.4.1 get and getline Member Functions
15.4.2 istream Member Functions peek, putback and ignore
15.4.3 Type-Safe I/O
15.5 Unformatted I/O Using read, write and gcount
15.6 Introduction to Stream Manipulators
15.6.1 Integral Stream Base: dec, oct, hex and setbase
15.6.2 Floating-Point Precision (precision, setprecision)
15.6.3 Field Width (width, setw)
15.6.4 User-Defined Output 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
16 Exception Handling: A Deeper Look
16.1 Introduction
16.2 Example: Handling an Attempt to Divide by Zero
16.3 When to Use Exception Handling
16.4 Rethrowing an Exception
16.5 Exception Specifications
16.6 Processing Unexpected Exceptions
16.7 Stack Unwinding
16.8 Constructors, Destructors and Exception Handling
16.9 Exceptions and Inheritance
16.10 Processing new Failures
16.11 Class unique_ptr and Dynamic Memory Allocation
16.12 Standard Library Exception Hierarchy
16.13 Wrap-Up
17 File Processing
17.1 Introduction
17.2 Files and Streams
17.3 Creating a Sequential File
17.4 Reading Data from a Sequential File
17.5 Updating Sequential Files
17.6 Random-Access Files
17.7 Creating a Random-Access File
17.8 Writing Data Randomly to a Random-Access File
17.9 Reading from a Random-Access File Sequentially
17.10 Case Study: A Transaction-Processing Program
17.11 Object Serialization
17.12 Wrap-Up
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
19 Searching and Sorting
19.1 Introduction
19.2 Searching Algorithms
19.2.1 Efficiency of Linear Search
19.2.2 Binary Search
19.3 Sorting Algorithms
19.3.1 Efficiency of Selection Sort
19.3.2 Efficiency of Insertion Sort
19.3.3 Merge Sort (A Recursive Implementation)
19.4 Wrap-Up
20 Custom Templatized 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
21 Bits, Characters, C Strings and structs
21.1 Introduction
21.2 Structure Definitions
21.3 typedef
21.4 Example: Card Shuffling and Dealing Simulation
21.5 Bitwise Operators
21.6 Bit Fields
21.7 Character-Handling Library
21.8 Pointer-Based String Manipulation Functions
21.9 Pointer-Based String-Conversion Functions
21.10 Search Functions of the Pointer-Based String-Handling Library
21.11 Memory Functions of the Pointer-Based String-Handling Library
21.12 Wrap-Up
22 Standard Template Library (STL)
22.1 Introduction to the Standard Template Library (STL)
22.2 Introduction to Containers
22.3 Introduction to Iterators
22.4 Introduction to Algorithms
22.5 Sequence Containers
22.5.1 vector Sequence Container
22.5.2 list Sequence Container
22.5.3 deque Sequence Container
22.6 Associative Containers
22.6.1 multiset Associative Container
22.6.2 set Associative Container
22.6.3 multimap Associative Container
22.6.4 map Associative Container
22.7 Container Adapters
22.7.1 stack Adapter
22.7.2 queue Adapter
22.7.3 priority_queue Adapter
22.8 Algorithms
22.8.1 fill, fill_n, generate and generate_n
22.8.2 equal, mismatch and lexicographical_compare
22.8.3 remove, remove_if, remove_copy and remove_copy_if
22.8.4 replace, replace_if, replace_copy and replace_copy_if
22.8.5 Mathematical Algorithms
22.8.6 Basic Searching and Sorting Algorithms
22.8.7 swap, iter_swap and swap_ranges
22.8.8 copy_backward, merge, unique and reverse
22.8.9 inplace_merge, unique_copy and reverse_copy
22.8.10 Set Operations
22.8.11 lower_bound, upper_bound and equal_range
22.8.12 Heapsort
22.8.13 min and max
22.8.14 STL Algorithms Not Covered in This Chapter
22.9 Class bitset
22.10 Function Objects
22.11 Wrap-Up
23 Boost Libraries, Technical Report 1 and C++0x
23.1 Introduction
23.2 Deitel Online C++ and Related Resource Centers
23.3 Boost Libraries
23.4 Boost Libraries Overview
23.5 Regular Expressions with the regex Library
23.5.1 Regular Expression Example
23.5.2 Validating User Input with Regular Expressions
23.5.3 Replacing and Splitting Strings
23.6 Smart Pointers
23.6.1 Reference Counted shared_ptr
23.6.2 weak_ptr: shared_ptr Observer
23.7 Technical Report 1
23.8 C++0x
23.9 Core Language Changes
23.10 Wrap-Up
24 Other Topics
24.1 Introduction
24.2 const_cast Operator
24.3 mutable Class Members
24.4 namespaces
24.5 Operator Keywords
24.6 Pointers to Class Members (.* and ->*)
24.7 Multiple Inheritance
24.8 Multiple Inheritance and virtual Base Classes
24.9 Wrap-Up
Chapters on the Web
A: Operator Precedence and Associativity
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
E: Preprocessor
E.1 Introduction
E.2 #include Preprocessor Directive
E.3 #define Preprocessor Directive: Symbolic Constants
E.4 #define Preprocessor Directive: Macros
E.5 Conditional Compilation
E.6 #error and #pragma Preprocessor Directives
E.7 Operators # and ##
E.8 Predefined Symbolic Constants
E.9 Assertions
E.10 Wrap-Up
Appendices on the Web
Index
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
25 ATM Case Study, Part 1: Object-Oriented Design with the UML
25.1 Introduction
25.2 Introduction to Object-Oriented Analysis and Design
25.3 Examining the ATM Requirements Document
25.4 Identifying the Classes in the ATM Requirements Document
25.5 Identifying Class Attributes
25.6 Identifying Objects' States and Activities
25.7 Identifying Class Operations
25.8 Indicating Collaboration Among Objects
25.9 Wrap-Up
26 ATM Case Study, Part 2: Implementing an Object-Oriented Design
26.1 Introduction
26.2 Starting to Program the Classes of the ATM System
26.3 Incorporating Inheritance into the ATM System
26.4 ATM Case Study Implementation
26.4.1 Class ATM
26.4.2 Class Screen
26.4.3 Class Keypad
26.4.4 Class CashDispenser
26.4.5 Class DepositSlot
26.4.6 Class Account
26.4.7 Class BankDatabase
26.4.8 Class Transaction
26.4.9 Class BalanceInquiry
26.4.10 Class Withdrawal
26.4.11 Class Deposit
26.4.12 Test Program ATMCaseStudy.cpp
26.5 Wrap-Up
F: C Legacy Code Topics
F.1 Introduction
F.2 Redirecting Input/Output on UNIX/Linux/Mac OS X and Windows Systems
F.3 Variable-Length Argument Lists
F.4 Using Command-Line Arguments
F.5 Notes on Compiling Multiple-Source-File Programs
F.6 Program Termination with exit and atexit
F.7 Type Qualifier volatile
F.8 Suffixes for Integer and Floating-Point Constants
F.9 Signal Handling
F.10 Dynamic Memory Allocation with calloc and realloc
F.11 Unconditional Branch: goto
F.12 Unions
F.13 Linkage Specifications
F.14 Wrap-Up
G: UML 2: Additional Diagram Types
G.1 Introduction
G.2 Additional Diagram Types
H: Using the Visual Studio Debugger
H.1 Introduction
H.2 Breakpoints and the Continue Command
H.3 Locals and Watch Windows
H.4 Controlling Execution Using the Step Into, Step Over, Step Out and Continue Commands
H.5 Autos Window
H.6 Wrap-Up
I: Using the GNU C++ Debugger
I.1 Introduction
I.2 Breakpoints and the run, stop, continue and print Commands
I.3 print and set Commands
I.4 Controlling Execution Using the step, finish and next Commands
I.5 watch Command
I.6 Wrap-Up