Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
C++ For Dummies (2004) [eng].pdf
Скачиваний:
84
Добавлен:
16.08.2013
Размер:
8.09 Mб
Скачать

Introduction

Welcome to C++ For Dummies, 5th Edition. Think of this book as C++: Reader’s Digest Edition, bringing you everything you need to know

without the boring stuff.

What’s in This Book

C++ For Dummies is an introduction to the C++ language. C++ For Dummies starts from the beginning (where else?) and works its way from early concepts and through more sophisticated techniques. It doesn’t assume that you have any prior knowledge, at least, not of programming.

C++ For Dummies is rife with examples. Every concept is documented in numer­ ous snippets and several complete programs.

Unlike other C++ programming books, C++ For Dummies considers the “why” just as important as the “how.” The features of C++ are like pieces of a jigsaw puzzle. Rather than just present the features, I think it’s important that you understand how they fit together.

If you don’t understand why a particular feature is in the language, you won’t truly understand how it works. After you finish this book, you’ll be able to write a reasonable C++ program, and, just as important, you’ll understand why and how it works.

C++ For Dummies can also be used as a reference: If you want to understand what’s going on with all the template stuff, just flip to Chapter 27, and you’re there. Each chapter contains necessary references to other earlier chapters in case you don’t read the chapters in sequence.

C++ For Dummies is not operatingor system-specific. It is just as useful to Unix or Linux programmers as it is to Windows-based developers. C++ For Dummies doesn’t cover Windows or .NET programming. You have to master C++ before you can move on to Windows and .NET programming.

2C++ For Dummies, 5th Edition

What’s on the CD

The CD-ROM included with C++ For Dummies contains the source code for the examples in this book. This can spare you considerable typing.

Your computer can’t execute these or any other C++ program directly. You have to run your C++ programs through a C++ development environment, which spits out an executable program. (Don’t worry, this procedure is explained in Chapter 1.)

The programs in C++ For Dummies are compatible with any standard C++ envi­ ronment, but don’t worry if you don’t already own one. A full-featured C++ envi­ ronment known as Dev-C++ is contained on the enclosed CD-ROM. You can use this tool to write your own C++ programs as well as explore the programs from the book.

No worries if you already own Visual Studio.NET. Some people need an intro­ duction to C++ before going into the many features offered by .NET. C++ For Dummies is just as happy with Visual Studio as it is with its own Dev-C++. C++ For Dummies does not contain Visual Studio.NET. However, the programs in the book have been tested for compatibility with the industry standard “unman­ aged C++” portion of Visual Studio.NET.

What Is C++?

C++ is an object-oriented, low-level ANSI and ISO standard programming lan­ guage. As a low-level language similar to and compatible with its predecessor C, C++ can generate very efficient, very fast programs.

As an object-oriented language, C++ has the power and extensibility to write large-scale programs. C++ is one of the most popular programming languages for all types of programs. Most of the programs you use on your PC every day are written in C++.

C++ has been certified as a 99.9 percent pure standard. This makes it a portable language. There is a C++ compiler for every major operating system, and they all support the same C++ language. (Some operating systems support exten­ sions to the basic language, but all support the C++ core.)

Conventions Used in This Book

When I describe a message or information that you see onscreen, it appears like this:

Introduction 3

Hi mom!

In addition, code listings appear as follows:

// some program void main()

{

...

}

If you are entering these programs by hand, you must enter the text exactly as shown with one exception: The number of spaces is not critical, so don’t worry if you enter one too many or one too few spaces.

C++ words are usually based on English words with similar meanings. This can make reading a sentence containing both English and C++ difficult to make out without a little help. To help out, C++ commands and function names appear in a different font like this. In addition, function names are always followed by an open and closed parenthesis like myFavoriteFunction(). The argu­ ments to the function are left off except when there’s a specific need to make them easier to read. It’s a lot easier to say: “this is myFavoriteFunction()” than “this is myFavoriteFunction(int, float).”

Sometimes, the book directs you to use specific keyboard commands. For exam­ ple, when the text instructs you to press Ctrl+C, it means that you should hold down the Ctrl key while pressing the C key and then release both together.

Don’t type the plus sign.

Sometimes, I’ll tell you to use menu commands, such as File Open. This nota­ tion means to use the keyboard or mouse to open the File menu and then choose the Open option. Finally, both Dev-C++ and Visual Studio.NET define function keys for certain common operations — unfortunately, they don’t use the same function keys. To avoid confusion, I rarely use function keys in the book — I couldn’t have kept the two straight anyway.

How This Book Is Organized

Each new feature is introduced by answering the following three questions:

What is this new feature?

Why was it introduced into the language?

How does it work?

4C++ For Dummies, 5th Edition

Small pieces of code are sprinkled liberally throughout the chapters. Each demonstrates some newly introduced feature or highlights some brilliant point I’m making. These snippets may not be complete and certainly don’t do any­ thing meaningful. However, every concept is demonstrated in at least one functional program.

Note: A good programmer doesn’t let lines of code extend too far because it makes them hard to read. I have inserted newlines appropriately to limit my programs to the width of the book page.

And There’s More

A real-world program can take up lots of pages. However, seeing such a pro­ gram is an important didactic tool for any reader. I have included a series of programs along with an explanation of how these programs work on the enclosed CD-ROM.

I use one simple example program that I call BUDGET. This program starts life as a simple, functionally-oriented BUDGET1. This program maintains a set of simple checking and savings accounts. The reader is encouraged to review this program at the end of Part II. The subsequent version, BUDGET2, adds the object-oriented concepts presented in Part III. The examples work their way using ever more features of the language, culminating with BUDGET5, which you should review after you master all the chapters in the book. The BUDGET programs can be found on the book’s CD-ROM. For a complete overview of the CD-ROM’s contents, see this book’s Appendix.

Part I: Introduction to C++ Programming

Part I starts you on your journey. You begin by examining what it means to write a computer program. From there, you step through the syntax of the language (the meaning of the C++ commands).

Part II: Becoming a Functional

C++ Programmer

In this part, you expand upon your newly gained knowledge of the basic com­ mands of C++ by adding the capability to bundle sections of C++ code into mod­ ules and reusing these modules in programs.