Welcome to Beginning Programming with C++ For Dummies, Second Edition. This book is intended for the reader who wants to learn to program.
Somehow over the years, programming has become associated with mathematics and logic calculus and other complicated things. I never quite understood that. Programming is a skill like writing advertising or drawing or photography. It does require the ability to think a problem through, but I’ve known some really good programmers who had zero math skills. Some people are naturally good at it and pick it up quickly, others not so good and not so quick. Nevertheless, anyone with enough patience and “stick-to-itiveness” can learn to program a computer. Even me.
Learning to program necessarily means learning a programming language. This book is based upon the C++ programming language. Versions of the suggested compiler for Windows and Macintosh are included with the online materials accompanying this book. Linux versions are available for download at www.codeblocks.org. (Don’t worry: I include step-by-step instructions for installing the package and building your first program in the book.)
The goal of this book is to teach you the basics of programming in C++, not to inundate you with every detail of the C++ programming language. At the end of this book, you’ll be able to write a reasonably sophisticated program in C++. You’ll also be in a position to quickly grasp a number of other similar languages, such as Java and C#.NET.
In this book, you discover what a program is, how it works, plus how to do the following:
I try to make very few assumptions in this book about the reader, but I do assume the following:
To help you navigate this book as efficiently as possible, I use a few conventions:
I encourage you to read one part of the book; then put the book away and play with C++ for awhile before moving to the next part. The book is organized so that by the end of each part, you’ve mastered enough new material to go out and write programs.
I’d like to add the following advice:
Beginning Programming with C++ For Dummies is split into seven parts. You don’t have to read it sequentially, and you don’t even have to read all the sections in any particular chapter. You can use the Table of Contents and the Index to find the information you need and quickly get your answer. In this section, I briefly describe what you’ll find in each part.
This part describes what programs are and how they work. Using a fictitious tire-changing computer, I take you through several algorithms for removing a tire from a car to give you a feel for how programs work. You also get Code::Blocks up and running on your computer before leaving this part.
This part introduces you to the basics of programming with C++. You find out how to declare integer variables and how to write simple expressions. You’ll even discover how to make decisions within a program — a small step closer to expertise — by the time you finish this part.
Here you learn how to direct the flow of control within your programs. You’ll find out how to loop, how to break your code into modules (and why), and how to build these separate modules back into a single program. At the end of this part, you’ll be able to write real programs that actually solve problems.
This part expands your knowledge of data types. Earlier sections of the book are limited to integers; in this part, you work with characters, decimals, and arrays; and you even get to define your own types. Finally, this is the part where you master the most-dreaded topic, the C++ pointer.
This is where you expand your knowledge into object-oriented techniques, the stuff that differentiates C++ from its predecessors, most notably C. (Don’t worry if you don’t know what object-oriented programming is — you’ll get there.) You’ll want to be comfortable with the material in Parts I through IV before jumping into this part, but you’ll be a much stronger programmer by the time you finish it.
This is a collection of topics that are important but didn’t fit in the earlier parts. For example, here’s where I discuss how to create, read to, and write from files.
This part includes lists of what to do (and what not to do) when programming to avoid creating bugs needlessly. In addition, this part includes some advice about what topics to study next, should you decide to expand your knowledge of C++.
What’s a For Dummies book without icons pointing you in the direction of really great information that’s sure to help you along your way? In this section, I briefly describe each icon I use in this book.
Beginning Programming with C++ For Dummies, Second Edition includes the following goodies online for easy download:
If you do go to www.codeblocks.org, be sure to download a version that includes the gcc compiler.
You can find a set of errata and Frequently Asked Questions for this and all my books at www.stephendavis.com. You will also find a link to my email address there. Feel free to send me your questions and comments (that’s how I learn). It’s through reader input that these books can improve.
Now you’ve stalled long enough, it’s time to turn to Chapter 1 and start discovering how to program!
3.16.218.221