Beginning Programming with C++ For Dummies, 2nd Edition

Book description

Learn to program with C++ quickly with this helpful For Dummies guide

Beginning Programming with C++ For Dummies, 2nd Edition gives you plain-English explanations of the fundamental principles of C++, arming you with the skills and know-how to expertly use one of the world's most popular programming languages. You'll explore what goes into creating a program, how to put the pieces together, learn how to deal with standard programming challenges, and much more.

Written by the bestselling author of C++ For Dummies, this updated guide explores the basic development concepts and techniques of C++ from a beginner's point of view, and helps make sense of the how and why of C++ programming from the ground up. Beginning with an introduction to how programming languages function, the book goes on to explore how to work with integer expressions and character expressions, keep errors out of your code, use loops and functions, divide your code into modules, and become a functional programmer.

  • Grasp C++ programming like a pro, even if you've never written a line of code

  • Master basic development concepts and techniques in C++

  • Get rid of bugs and write programs that work

  • Find all the code from the book and an updated C++ compiler on the companion website

  • If you're a student or first-time programmer looking to master this object-oriented programming language, Beginning Programming with C++ For Dummies, 2nd Edition has you covered.

    Table of contents

      1. Introduction
        1. About This Book
        2. Foolish Assumptions
        3. How This Book Is Organized
          1. Part I: Getting Started with C++ Programming
          2. Part II: Writing a Program: Decisions, Decisions
          3. Part III: Becoming a Procedural Programmer
          4. Part IV: Data Structures
          5. Part V: Object-Oriented Programming
          6. Part VI: Advanced Strokes
          7. Part VII: The Part of Tens
        4. Icons Used in This Book
        5. Beyond the Book
        6. Where to Go from Here
      2. Part I: Getting Started with C++ Programming
        1. Chapter 1: What Is a Program?
          1. How Does My Son Differ from a Computer?
          2. Programming a “Human Computer”
            1. Creating the algorithm
            2. Setting the tire-changing language
            3. Constructing the program
            4. Computer processors
          3. Computer Languages
            1. High-level languages
            2. The C++ language
        2. Chapter 2: Installing Code::Blocks
          1. Reviewing the Compilation Process
          2. Installing Code::Blocks
            1. Windows installation
            2. Ubuntu Linux installation
            3. Mac OS installation
            4. Setting up Code::Blocks
          3. Testing the Code::Blocks Installation
            1. Creating the project
            2. Testing your default project
        3. Chapter 3: Writing Your First Program
          1. Creating a New Project
            1. Filename extensions
          2. Entering Your Program
          3. Building the Program
          4. Finding What Could Go Wrong
            1. Misspelled commands
            2. Missing semicolon
          5. Using the Online Material
          6. Running the Program
          7. How the Program Works
            1. The template
            2. The Conversion program
      3. Part II: Writing a Program: Decisions, Decisions
        1. Chapter 4: Integer Expressions
          1. Declaring Variables
            1. Variable names
            2. Assigning a value to a variable
            3. Initializing a variable at declaration
          2. Integer Constants
          3. Expressions
            1. Binary operators
            2. Unraveling compound expressions
          4. Unary Operators
          5. The Special Assignment Operators
        2. Chapter 5: Character Expressions
          1. Defining Character Variables
            1. Encoding characters
            2. Example of character encoding
          2. Encoding Strings of Characters
          3. Special Character Constants
        3. Chapter 6: if I Could Make My Own Decisions
          1. The if Statement
            1. Comparison operators
            2. Say “No” to “No braces”
          2. What Else Is There?
          3. Nesting if Statements
          4. Compound Conditional Expressions
        4. Chapter 7: Switching Paths
          1. Controlling Flow with the switch Statement
          2. Control Fell Through: Did I break It?
          3. Implementing an Example Calculator with the switch Statement
        5. Chapter 8: Debugging Your Programs, Part I
          1. Identifying Types of Errors
          2. Avoiding Introducing Errors
            1. Coding with style
            2. Establishing variable naming conventions
          3. Finding the First Error with a Little Help
          4. Finding the Run-Time Error
            1. Formulating test data
            2. Executing the test cases
            3. Seeing what’s going on in your program
      4. Part III: Becoming a Procedural Programmer
        1. Chapter 9: while Running in Circles
          1. Creating a while Loop
          2. Breaking out of the Middle of a Loop
          3. Nested Loops
        2. Chapter 10: Looping for the Fun of It
          1. The for Parts of Every Loop
          2. Looking at an Example
          3. Getting More Done with the Comma Operator
        3. Chapter 11: Functions, I Declare!
          1. Breaking Your Problem Down into Functions
          2. Understanding How Functions Are Useful
          3. Writing and Using a Function
            1. Returning things
            2. Reviewing an example
          4. Passing Arguments to Functions
            1. Function with arguments
            2. Functions with multiple arguments
            3. Exposing main()
          5. Defining Function Prototype Declarations
        4. Chapter 12: Dividing Programs into Modules
          1. Breaking Programs Apart
          2. Breaking Up Isn’t That Hard to Do
            1. Creating Factorial.cpp
            2. Creating an #include file
            3. Including #include files
            4. Creating main.cpp
            5. Building the result
          3. Using the Standard C++ Library
          4. Variable Scope
        5. Chapter 13: Debugging Your Programs, Part 2
          1. Debugging a Dys-Functional Program
            1. Performing unit level testing
            2. Outfitting a function for testing
            3. Returning to unit test
      5. Part IV: Data Structures
        1. Chapter 14: Other Numerical Variable Types
          1. The Limitations of Integers in C++
            1. Integer round-off
            2. Limited range
          2. A Type That “doubles” as a Real Number
            1. Solving the truncation problem
            2. When an integer is not an integer
            3. Discovering the limits of double
          3. Variable Size — the “long” and “short” of It
            1. How far do numbers range?
          4. Types of Constants
          5. Passing Different Types to Functions
            1. Overloading function names
            2. Mixed-mode overloading
        2. Chapter 15: Arrays
          1. What Is an Array?
          2. Declaring an Array
          3. Indexing into an Array
          4. Looking at an Example
          5. Initializing an Array
        3. Chapter 16: Arrays with Character
          1. The ASCII-Zero Character Array
          2. Declaring and Initializing an ASCIIZ Array
          3. Looking at an Example
          4. Looking at a More Detailed Example
            1. Foiling hackers
            2. Do I Really Have to Do All That Work?
        4. Chapter 17: Pointing the Way to C++ Pointers
          1. What’s a Pointer?
          2. Declaring a Pointer
          3. Passing Arguments to a Function
            1. Passing arguments by value
            2. Passing arguments by reference
            3. Putting it together
            4. Reference argument types
          4. Playing with Heaps of Memory
            1. Do you really need a new keyword?
            2. Don’t forget to clean up after yourself
            3. Looking at an example
        5. Chapter 18: Taking a Second Look at C++ Pointers
          1. Pointers and Arrays
            1. Operations on pointers
            2. Pointer addition versus indexing into an array
            3. Using the pointer increment operator
            4. Why bother with array pointers?
          2. Operations on Different Pointer Types
          3. Constant Nags
          4. Differences Between Pointers and Arrays
          5. My main() Arguments
            1. Arrays of pointers
            2. Arrays of arguments
        6. Chapter 19: Programming with Class
          1. Grouping Data
          2. The Class
          3. The Object
          4. Arrays of Objects
          5. Looking at an Example
        7. Chapter 20: Debugging Your Programs, Part 3
          1. A New Approach to Debugging
            1. The solution
          2. Entomology for Dummies
            1. Starting the debugger
            2. Fixing the (first) bug
            3. Finding and fixing the second bug
      6. Part V: Object-Oriented Programming
        1. Chapter 21: What Is Object-Oriented Programming?
          1. Abstraction and Microwave Ovens
            1. Procedural nachos
            2. Object-oriented nachos
          2. Classification and Microwave Ovens
          3. Why Build Objects This Way?
          4. Self-Contained Classes
        2. Chapter 22: Structured Play: Making Classes Do Things
          1. Activating Our Objects
          2. Creating a Member Function
            1. Defining a member function
            2. Naming class members
            3. Calling a member function
            4. Accessing other members from within a member function
          3. Keeping a Member Function after Class
          4. Overloading Member Functions
        3. Chapter 23: Pointers to Objects
          1. Pointers to Objects
            1. Arrow syntax
            2. Calling all member functions
          2. Passing Objects to Functions
            1. Calling a function with an object value
            2. Calling a function with an object pointer
            3. Looking at an example
          3. Allocating Objects off the Heap
        4. Chapter 24: Do Not Disturb: Protected Members
          1. Protecting Members
            1. Why you need protected members
            2. Making members protected
            3. So what?
          2. Who Needs Friends, Anyway?
        5. Chapter 25: Getting Objects Off to a Good Start
          1. The Constructor
            1. Limitations on constructors
            2. Can I see an example?
            3. Constructing data members
          2. Destructors
            1. Looking at an example
            2. Destructing data members
        6. Chapter 26: Making Constructive Arguments
          1. Constructors with Arguments
            1. Looking at an example
          2. Overloading the Constructor
          3. The Default default Constructor
          4. Constructing Data Members
            1. Initializing data members with the default constructor
            2. Initializing data members with a different constructor
            3. Looking at an example
            4. New with C++ 2011
        7. Chapter 27: Coping with the Copy Constructor
          1. Copying an Object
            1. The default copy constructor
            2. Looking at an example
          2. Creating a Copy Constructor
          3. Avoiding Copies
      7. Part VI: Advanced Strokes
        1. Chapter 28: Inheriting a Class
          1. Advantages of Inheritance
            1. Learning the lingo
          2. Implementing Inheritance in C++
            1. Looking at an example
          3. Having a HAS_A Relationship
        2. Chapter 29: Are Virtual Functions for Real?
          1. Overriding Member Functions
            1. Early binding
            2. Ambiguous case
            3. Enter late binding
          2. When Is Virtual Not?
          3. Virtual Considerations
        3. Chapter 30: Overloading Assignment Operators
          1. Overloading an Operator
          2. Overloading the Assignment Operator Is Critical
          3. Looking at an Example
          4. Writing Your Own (or Not)
        4. Chapter 31: Performing Streaming I/O
          1. How Stream I/O Works
          2. Stream Input/Output
            1. Creating an input object
            2. Creating an output object
            3. Open modes
            4. What is binary mode?
            5. Hey, file, what state are you in?
          3. Other Member Functions of the fstream Classes
            1. Reading and writing streams directly
            2. Controlling format
            3. What’s up with endl?
          4. Manipulating Manipulators
          5. Using the stringstream Classes
        5. Chapter 32: I Take Exception!
          1. The Exception Mechanism
            1. Examining the exception mechanism in detail
            2. Special considerations for throwing
          2. Creating a Custom Exception Class
            1. Restrictions on exception classes
      8. Part VII: The Part of Tens
        1. Chapter 33: Ten Ways to Avoid Bugs
          1. Enable All Warnings and Error Messages
          2. Adopt a Clear and Consistent Coding Style
          3. Comment the Code While You Write It
          4. Single-Step Every Path in the Debugger at Least Once
          5. Limit the Visibility
          6. Keep Track of Heap Memory
          7. Zero Out Pointers after Deleting What They Point To
          8. Use Exceptions to Handle Errors
          9. Declare Destructors Virtual
          10. Provide a Copy Constructor and Overloaded Assignment Operator
        2. Chapter 34: Ten Features Not Covered in This Book
          1. The goto Command
          2. The Ternary Operator
          3. Binary Logic
          4. Enumerated Types
          5. Namespaces
          6. Pure Virtual Functions
          7. The string Class
          8. Multiple Inheritance
          9. Templates and the Standard Template Library
          10. Lambda Functions
      9. About the Author
      10. Cheat Sheet

    Product information

    • Title: Beginning Programming with C++ For Dummies, 2nd Edition
    • Author(s):
    • Release date: October 2014
    • Publisher(s): For Dummies
    • ISBN: 9781118823873