Register your product to gain access to bonus material or receive a coupon.
Starter Kit
Includes C++ compiler and IDE for Windows, Mac & Linux
In just 24 lessons of one hour or less, you can learn the basics of programming with C++–one of the most popular and powerful programming languages ever created.
Using a straightforward, step-by-step approach, this fast and friendly tutorial teaches you everything you need to know, from installing and using a compiler, to debugging the programs you’ve created, to what’s coming in C++0x, the next version of C++.
Each lesson builds on what you’ve already learned, giving you a solid understanding of the basics of C++ programming concepts and techniques.
Step-by-step instructions carefully walk you through the most common C++ programming tasks
Quizzes and Exercises at the end of each chapter help you test yourself to make sure you’re ready to go on
Starter Kit software provides everything you need to create and compile C++ programs on any platform–Windows, Mac or Linux
Learn how to…
Jesse Liberty is the author of numerous books on software development, including best selling titles on C++ and .NET. He is the president of Liberty Associates, Inc. where he provides custom programming, consulting, and training.
Rogers Cadenhead is a web application developer who has written many books on Internet-related topics, including Teach Yourself Java in 24 Hours. He maintains this book’s official website at http://cplusplus.cadenhead.org.
CD-ROM Includes
C++ compiler
Visual development environment for Windows, Mac and Linux
Source code for the book’s examples
Register your book at informit.com/register for convenient access to updates and corrections as they become available.
Creating Variables and Constants in C++
Download the sample pages (includes Chapter 3 and Index)
Introduction 1
Part I: Beginning C++
HOUR 1: Writing Your First Program 5
Using C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Finding a Compiler. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Compiling and Linking the Source Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Creating Your First Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
HOUR 2: Organizing the Parts of a Program 15
Reasons to Use C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
The Parts of a Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Comments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
HOUR 3: Creating Variables and Constants 29
What Is a Variable?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Defining a Variable. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. . . . . . . . . . . . . 33
Assigning Values to Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Using Type Definitions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
HOUR 4: Using Expressions, Statements, and Operators 43
Statements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
If-Else Conditional Statements . . . . . . . . . . . .