Читать книгу Beginning Programming with C++ For Dummies - Davis Stephen R. - Страница 2

Introduction

Оглавление

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.

About This Book

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:

✔ Install the Code::Blocks C++ compiler and use it to build a program.

✔ Create and evaluate expressions.

✔ Direct the flow of control through your program.

✔ Create data structures that better model the real world.

✔ Define and use C++ pointers.

✔ Manipulate character strings to generate output the way you want to see it.

✔ Write to and read from files.

Foolish Assumptions

I try to make very few assumptions in this book about the reader, but I do assume the following:

You have a computer. Most readers will have computers that run Windows; however, the programs in this book run equally well on Windows, Macintosh, Linux, and Unix. In fact, because C++ is a standardized language, these programs should run on any computer that has a C++ compiler.

You know the basics of how to use your computer. For example, I assume that you know how to run a program, copy a file, create a folder, and so on.

You know how to navigate through menus. I include lots of instructions such as “Click File and then click Open.” If you can follow that instruction, then you’re good to go.

You are new to programming. I don’t assume that you know anything about programming. Heck, I don’t even assume that you know what programming is.

To help you navigate this book as efficiently as possible, I use a few conventions:

✔ C++ terms and other such items you see in computer code are in monofont typeface, like this.

✔ New terms are emphasized with italics (and defined).

✔ Numbered steps that you need to follow and characters you need to type are set in bold.

✔ The programmer in this book is always female and the user is always male. When I say “she types in …” you know I mean the author of the program and when I say “he types in …” you know I mean the user of the program.

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:

✔ If you already know what programming is but nothing about C++, you can skip Chapter 1.

✔ I recommend that you use the Code::Blocks compiler that comes with the book, even if you want to use a different C++ compiler after you finish the book. However, if you insist that you don’t want to use Code::Blocks, you can skip Chapter 2.

✔ Skim through Chapter 3 if you’ve already done a little computer programming.

✔ Start concentrating at Chapter 4, even if you have experience with other languages such as BASIC.

✔ You can stop reading after Chapter 20 if you’re starting to feel saturated. Chapter 21 opens up the new topic of object-oriented programming – you don’t want to take that on until you feel really comfortable with what you’ve learned so far.

✔ You can skip any of the TechnicalStuff icons.

How This Book Is Organized

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.

Part I: Getting Started with C++ Programming

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.

Part II: Writing a Program: Decisions, Decisions

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.

Part III: Becoming a Procedural Programmer

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.

Part IV: Data Structures

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.

Part V: Object-Oriented Programming

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.

Part VI: Advanced Strokes

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.

Part VII: The Part of Tens

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++.

Icons Used in This Book

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.

The Tip icon points out helpful information that is likely to make your job easier.

This icon marks a generally interesting and useful fact – something that you might want to remember for later use. I also use this icon to remind you of some fact that you may have skipped over in an earlier chapter.

The Warning icon highlights lurking danger. With this icon, I’m telling you to pay attention and proceed with caution.

When you see this icon, you know that there’s techie stuff nearby. If you’re not feeling very techie, you can skip this info.

Beyond the Book

Beginning Programming with C++ For Dummies, Second Edition includes the following goodies online for easy download:

✔ The source code for all of the examples in the book can be downloaded from www.dummies.com/extras/beginningprogrammingcplusplus. The programs are organized by chapter number. I’ve included a project file for Code::Blocks (more about Code::Blocks in the next bullet point, and I explain project files in Chapter 2).

✔ This book uses the free, open source Code::Blocks environment and GCC C++ compiler. The version of Code::Blocks used in writing this book (Version13.12) is available for download at www.dummies.com/extras/beginningprogrammingcplusplus. I have included versions for Windows (2000 and later) and for Macintosh (10.6 and later). Chapter 2 includes instructions for how to download and install Code::Blocks. You can find newer versions of Code::Blocks and versions for different versions of Linux at www.codeblocks.org/downloads/binaries.

If you do go to www.codeblocks.org, be sure to download a version that includes the gcc compiler.

✔ Updates to this book, if I have any, are also available at www.dummies.com/extras/beginningprogrammingcplusplus.

✔ A cheat sheet that provides some useful programming aids is available at www.dummies.com/cheatsheet/beginningprogrammingcplusplus.

Where to Go from Here

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!

Beginning Programming with C++ For Dummies

Подняться наверх