Home > Store > Programming > C/C++

Sams Teach Yourself C++ in 21 Days, 5th Edition

Register your product to gain access to bonus material or receive a coupon.

Sams Teach Yourself C++ in 21 Days, 5th Edition

eBook (Adobe DRM)

  • Your Price: $28.79
  • List Price: $35.99
  • About Adobe DRM eBooks
  • This eBook requires the free Adobe® Digital Editions software.

    Before downloading this DRM-encrypted PDF, be sure to:


    • Install the free Adobe Digital Editions software on your machine. Adobe Digital Editions only works on Macintosh and Windows, and requires the Adobe Flash Player. Please see the official system requirements.
    • Authorize your copy of Adobe Digital Editions using your Adobe ID (select AdobeID as the eBook vendor). If you don't already have an Adobe ID, you can create one here.

Description

  • Copyright 2005
  • Pages: 936
  • Edition: 5th
  • eBook (Adobe DRM)
  • ISBN-10: 0-7686-6600-7
  • ISBN-13: 978-0-7686-6600-7

A new edition of this title is available, ISBN-10:  0672329417 ISBN-13: 9780672329418

Join the leagues of thousands of programmers and learn C++ from some of the best. The fifth edition of the best seller Sams Teach Yourself C++ in 21 Days, written by Jesse Liberty, a well-known C++ and C# programming manual author and Bradley L. Jones, manager for a number of high profiler developer websites, has been updated to the new ANSI/ISO C++ Standard. This is an excellent hands-on guide for the beginning programmer. Packed with examples of syntax and detailed analysis of code, fundamentals such as managing I/O, loops, arrays and creating C++ applications are all covered in the 21 easy-to-follow lessons. You will also be given access to a website that will provide you will all the source code examples developed in the book as a practice tool. C++ is the preferred language for millions of developers-make Sams Teach Yourself the preferred way to learn it!

 

Sample Content

Table of Contents

Introduction.

    Who Should Read This Book

    Conventions Used in This Book

    Sample Code for This Book

    Week 1 At a Glance

    A Note to C Programmers

    Where You Are Going

1. Getting Started.

      A Brief History of C++

      The Need for Solving Problems

      Procedural, Structured, and Object-Oriented Programming

      Object-Oriented Programming (OOP)

      C++ and Object-Oriented Programming

    How C++ Evolved

    Should I Learn C First?

    C++, Java, and C#

    Microsoft's Managed Extensions to C++

    The ANSI Standard

    Preparing to Program

    Your Development Environment

      The Process of Creating the Program

      Creating an Object File with the Compiler

      Creating an Executable File with the Linker

    The Development Cycle

    HELLO.cpp-Your First C++ Program

    Getting Started with Your Compiler

      Building the Hello World Project

    Compile Errors

    Summary

    Q&A

    Workshop

      Quiz

      Exercises

2. The Anatomy of a C++ Program.

    A Simple Program

    A Brief Look at cout

    Using the Standard Namespace

    Commenting Your Programs

      Types of Comments

      Using Comments

      A Final Word of Caution About Comments

    Functions

      Using Functions

      Methods Versus Functions

    Summary

    Q&A

    Workshop

      Quiz

      Exercises

3. Working with Variables and Constants.

    What Is a Variable?

      Storing Data in Memory

      Setting Aside Memory

      Size of Integers

      signed and unsigned

      Fundamental Variable Types

    Defining a Variable

      Case Sensitivity

      Naming Conventions

      Keywords

    Creating More Than One Variable at a Time

    Assigning Values to Your Variables

    Creating Aliases with typedef

    When to Use short and When to Use long

      Wrapping Around an unsigned Integer

      Wrapping Around a signed Integer

    Working with Characters

      Characters and Numbers

      Special Printing Characters

    Constants

      Literal Constants

      Symbolic Constants

    Enumerated Constants

    Summary

    Q&A

    Workshop

      Quiz

      Exercises

4. Creating Expressions and Statements.

    Starting with Statements

      Using Whitespace

      Blocks and Compound Statements

    Expressions

    Working with Operators

      Assignment Operators

      Mathematical Operators

    Combining the Assignment and Mathematical Operators

    Incrementing and Decrementing

      Prefixing Versus Postfixing

    Understanding Operator Precedence

    Nesting Parentheses

    The Nature of Truth

      Evaluating with the Relational Operators

    The if Statement

      Indentation Styles

      The else Statement

      Advanced if Statements

    Using Braces in Nested if Statements

    Using the Logical Operators

      The Logical AND Operator

      The Logical OR Operator

      The Logical NOT Operator

    Short Circuit Evaluation

    Relational Precedence

    More About Truth and Falsehood

    The Conditional (Ternary) Operator

    Summary

    Q&A

    Workshop

      Quiz

      Exercises

5. Organizing into Functions.

    What Is a Function?

    Return Values, Parameters, and Arguments

    Declaring and Defining Functions

      Function Prototypes

      Defining the Function

    Execution of Functions

    Determining Variable Scope

      Local Variables

      Local Variables Within Blocks

    Parameters Are Local Variables

      Global Variables

      Global Variables: A Word of Caution

    Considerations for Creating Function Statements

    More About Function Arguments

    More About Return Values

    Default Parameters

    Overloading Functions

    Special Topics About Functions

      Inline Functions

      Recursion

    How Functions Work-A Peek Under the Hood

      Levels of Abstraction

    Summary

    Q&A

    Workshop

      Quiz

      Exercises

6. Understanding Object-Oriented Programming.

    Is C++ Object-Oriented?

    Creating New Types

    Introducing Classes and Members

      Declaring a Class

      A Word on Naming Conventions

      Defining an Object

      Classes Versus Objects

    Accessing Class Members

      Assigning to Objects, Not to Classes

      If You Don't Declare It, Your Class Won't Have It

    Private Versus Public Access

      Making Member Data Private

    Implementing Class Methods

    Adding Constructors and Destructors

    Getting a Default Constructor and Destructor

    Using the Default Constructor

    Including const Member Functions

    Interface Versus Implementation

    Where to Put Class Declarations and Method Definitions

    Inline Implementation

    Classes with Other Classes as Member Data

    Exploring Structures

    Summary

    Q&A

    Workshop

      Quiz

      Exercises

7. More on Program Flow.

    Looping

      The Roots of Looping: goto

      Why goto Is Shunned

    Using while Loops

      Exploring More Complicated while Statements

      Introducing continue and break

      Examining while (true) Loops

    Implementing do...while Loops

    Using do...while

    Looping with the for Statement

      Advanced for Loops

      Empty for Loops

      Nesting Loops

      Scoping in for Loops

    Summing Up Loops

    Controlling Flow with switch Statements

      Using a switch Statement with a Menu

    Summary

    Q&A

    Workshop

      Quiz

      Exercises

    Week 1 In Review

    Week 2 At a Glance

      Where You Are Going

8. Understanding Pointers.

    What Is a Pointer?

      A Bit About Memory

      Getting a Variable's Memory Address

      Storing a Variable's Address in a Pointer

      Pointer Names

      Getting the Value from a Variable

      Dereferencing with the Indirection Operator

      Pointers, Addresses, and Variables

      Manipulating Data by Using Pointers

      Examining the Address

    Why Would You Use Pointers?

    The Stack and the Free Store (Heap)

      Allocating Space with the new Keyword

      Putting Memory Back: The delete Keyword

    Another Look at Memory Leaks

    Creating Objects on the Free Store

    Deleting Objects from the Free Store

    Accessing Data Members

    Creating Member Data on the Free Store

    The this Pointer

    Stray, Wild, or Dangling Pointers

    Using const Pointers

      const Pointers and const Member Functions

      Using a const this Pointers

    Summary

    Q&A

    Workshop

      Quiz

      Exercises

9. Exploiting References.

    What Is a Reference?

    Using the Address-Of Operator (&) on References

      Attempting to Reassign References (Not!)

    Referencing Objects

    Null Pointers and Null References

    Passing Function Arguments by Reference

      Making swap() Work with Pointers

      Implementing swap() with References

    Understanding Function Headers and Prototypes

    Returning Multiple Values

      Returning Values by Reference

    Passing by Reference for Efficiency

Passing a const Pointer

References as an Alternative

    Knowing When to Use References Versus Pointers

    Mixing References and Pointers

    Returning Out-of-Scope Object References

      Returning a Reference to an Object on the Heap

    Pointer, Pointer, Who Has the Pointer?

    Summary

    Q&A

    Workshop

      Quiz

      Exercises

10. Working with Advanced Functions.

    Overloaded Member Functions

    Using Default Values

    Choosing Between Default Values and Overloaded Functions

    The Default Constructor

    Overloading Constructors

    Initializing Objects

    The Copy Constructor

    Operator Overloading

      Writing an Increment Function

      Overloading the Prefix Operator

      Returning Types in Overloaded Operator Functions

      Returning Nameless Temporaries

      Using the this Pointer

      Overloading the Postfix Operator

      Difference Between Prefix and Postfix

      Overloading Binary Mathematical Operators

      Issues in Operator Overloading

      Limitations on Operator Overloading

      What to Overload

      The Assignment Operator

    Handling Data Type Conversion

    Conversion Operators

    Summary

    Q&A

      Workshop

      Quiz

      Exercises

11. Object-Oriented Analysis and Design.

    Building Models

    Software Design: The Modeling Language

    Software Design: The Process

      Waterfall Versus Iterative Development

      The Process of Iterative Development

    Step 1: The Conceptualization Phase: Starting with The Vision

    Step 2: The Analysis Phase: Gathering Requirements

      Use Cases

      Application Analysis

      Systems Analysis

      Planning Documents

      Visualizations

      Artifacts

    Step 3: The Design Phase

      What Are the Classes?

      Transformations

      Other Transformations

      Building the Static Model

      Dynamic Model

    Steps 4-6: Implementation, Testing, and Rollout?

    Iterations

    Summary

    Q&A

    Workshop

      Quiz

      Exercises

12. Implementing Inheritance.

    What Is Inheritance?

      Inheritance and Derivation

      The Animal Kingdom

      The Syntax of Derivation

    Private Versus Protected

    Inheritance with Constructors and Destructors

      Passing Arguments to Base Constructors

    Overriding Base Class Functions

      Hiding the Base Class Method

      Calling the Base Method

    Virtual Methods

      How Virtual Functions Work

      Trying to Access Methods from a Base Class

      Slicing

      Creating Virtual Destructors

      Virtual Copy Constructors

      The Cost of Virtual Methods

    Summary

    Q&A

    Workshop

      Quiz

      Exercises

13. Managing Arrays and Strings.

    What Is an Array?

      Accessing Array Elements

      Writing Past the End of an Array

      Fence Post Errors

      Initializing Arrays

      Declaring Arrays

    Using Arrays of Objects

      Declaring Multidimensional Arrays

      Initializing Multidimensional Arrays

    Building Arrays of Pointers

    A Look at Pointer Arithmetic-An Advanced Topic

    Declaring Arrays on the Free Store

      A Pointer to an Array Versus an Array of Pointers

      Pointers and Array Names

      Deleting Arrays on the Free Store

      Resizing Arrays at Runtime

    char Arrays and Strings

    Using the strcpy() and strncpy() Methods

    String Classes

    Linked Lists and Other Structures

    Creating Array Classes

    Summary

    Q&A

    Workshop

      Quiz

      Exercises

14. Polymorphism.

    Problems with Single Inheritance

      Percolating Upward

      Casting Down

      Adding to Two Lists

    Multiple Inheritance

      The Parts of a Multiply Inherited Object

      Constructors in Multiply Inherited Objects

      Ambiguity Resolution

      Inheriting from Shared Base Class

      Virtual Inheritance

      Problems with Multiple Inheritance

      Mixins and Capabilities Classes

    Abstract Data Types

      Pure Virtual Functions

      Implementing Pure Virtual Functions

      Complex Hierarchies of Abstraction

      Which Classes Are Abstract?

    Summary

    Q&A

    Workshop

      Quiz

      Exercises

    Week 2 In Review

    Week 3 At a Glance

      Where You Are Going

15. Special Classes and Functions.

    Sharing Data Among Objects of the Same Type: Static Member Data

    Using Static Member Functions

    Pointers to Functions

      Why Use Function Pointers?

      Arrays of Pointers to Functions

      Passing Pointers to Functions to Other Functions

      Using typedef with Pointers to Functions

    Pointers to Member Functions

      Arrays of Pointers to Member Functions

    Summary

    Q&A

    Workshop

      Quiz

      Exercises

16. Advanced Inheritance.

    Aggregation

      Accessing Members of the Aggregated Class

      Controlling Access to Aggregated Members

      Cost of Aggregation

      Copying by Value

    Implementation in Terms of Inheritance Versus Aggregation/Delegation

      Using Delegation

    Private Inheritance

    Adding Friend Classes

    Friend Functions

    Friend Functions and Operator Overloading

    Overloading the Insertion Operator

    Summary

    Q&A

    Workshop

      Quiz

      Exercises

17. Working with Streams.

    Overview of Streams

      Encapsulation of Data Flow

      Understanding Buffering

    Streams and Buffers

    Standard I/O Objects

    Redirection of the Standard Streams

    Input Using cin

      Inputting Strings

      String Problems

      The cin Return Value

    Other Member Functions of cin

      Single Character Input

      Getting Strings from Standard Input

      Using cin.ignore()

      Peeking at and Returning Characters: peek() and putback()

    Outputting with cout

      Flushing the Output

      Functions for Doing Output

      Manipulators, Flags, and Formatting Instructions

    Streams Versus the printf() Function

    File Input and Output

    Using the ofstream

      Condition States

      Opening Files for Input and Output

      Changing the Default Behavior of ofstream on Open

    Binary Versus Text Files

    Command-line Processing

    Summary

    Q&A

    Workshop

      Quiz

      Exercises

18. Creating and Using Namespaces.

    Getting Started

    Resolving Functions and Classes by Name

      Visibility of Variables

      Linkage

      Static Global Variables

    Creating a Namespace

      Declaring and Defining Types

      Defining Functions Outside a Namespace

      Adding New Members

      Nesting Namespaces

    Using a Namespace

    The using Keyword

      The using Directive

      The using Declaration

    The Namespace Alias

    The Unnamed Namespace

    The Standard Namespace std

    Summary

    Q&A

    Workshop

      Quiz

      Exercises

19. Templates.

    What Are Templates?

    Building a Template Definition

      Using the Name

      Implementing the Template

    Passing Instantiated Template Objects to Functions

    Templates and Friends

      Nontemplate Friend Classes and Functions

      General Template Friend Class or Function

    Using Template Items

      Using Specialized Functions

      Static Members and Templates

    The Standard Template Library

      Using Containers

      Understanding Sequence Containers

      Understanding Associative Containers

      Working with the Algorithm Classes

    Summary

    Q&A

    Workshop

      Quiz

      Exercises

20. Handling Errors and Exceptions.

    Bugs, Errors, Mistakes, and Code Rot

      Exceptional Circumstances

    The Idea Behind Exceptions

      The Parts of Exception Handling

      Causing Your Own Exceptions

      Creating an Exception Class

    Placing try Blocks and catch Blocks

    How Catching Exceptions Work

      Using More Than One catch Specification

      Exception Hierarchies

    Data in Exceptions and Naming Exception Objects

    Exceptions and Templates

    Exceptions Without Errors

    A Word About Code Rot

    Bugs and Debugging

      Breakpoints

      Watch Points

      Examining Memory

      Assembler

    Summary

    Q&A

    Workshop

      Quiz

      Exercises

21. What's Next.

    The Preprocessor and the Compiler

    The #define Preprocessor Directive

      Using #define for Constants

      Using #define for Tests

      The #else Precompiler Command

    Inclusion and Inclusion Guards

    Macro Functions

      Why All the Parentheses?

    String Manipulation

      Stringizing

      Concatenation

    Predefined Macros

    The assert() Macro

      Debugging with assert()

      Using assert() Versus Exceptions

      Side Effects

      Class Invariants

      Printing Interim Values

    Inline Functions

    Bit Twiddling

      Operator AND

      Operator OR

      Operator Exclusive OR

      The Complement Operator

      Setting Bits

      Clearing Bits

      Flipping Bits

      Bit Fields

    Programming Style

      Indenting

      Braces

      Long Lines and Function Length

      Structuring switch Statements

      Program Text

      Naming Identifiers

      Spelling and Capitalization of Names

      Comments

      Setting Up Access

      Class Definitions

      include Files

      Using assert()

      Making Items Constant with const

    Next Steps in Your C++ Development

      Where to Get Help and Advice

      Related C++ Topics: Managed C++, C#, and Microsoft's .NET

      Staying in Touch

    Summary

    Q&A

    Workshop

      Quiz

      Exercises

    Week 3 In Review

A. Working with Numbers: Binary and Hexadecimal.

    Using Other Bases

    Converting to Different Bases

      Binary

      Why Base 2?

      Bits, Bytes, and Nybbles

      What's a KB?

      Binary Numbers

    Hexadecimal

B. C++ Keywords.

C. Operator Precedence.

D. Answers.

    Day 1

      Quiz

      Exercises

    Day 2

      Quiz

      Exercises

    Day 3

      Quiz

      Exercises

    Day 4

      Quiz

      Exercises

    Day 5

      Quiz

      Exercises

    Day 6

      Quiz

      Exercises

    Day 7

      Quiz

      Exercises

    Day 8

      Quiz

      Exercises

    Day 9

      Quiz

      Exercises

    Day 10

      Quiz

      Exercises

    Day 11

      Quiz

      Exercises

    Day 12

      Quiz

      Exercises

    Day 13

      Quiz

      Exercises

    Day 14

      Quiz

      Exercises

    Day 15

      Quiz

      Exercises

    Day 16

      Quiz

      Exercises

    Day 17

      Quiz

      Exercises

    Day 18

      Quiz

      Exercises

    Day 19

      Quiz

      Exercises

    Day 20

      Quiz

      Exercises

    Day 21

      Quiz

      Exercises

E. A Look at Linked Lists.

    The Component Parts of Your Linked List

Index.

Updates

Submit Errata

More Information

Unlimited one-month access with your purchase
Free Safari Membership