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