Read an Excerpt
Hour 1: Getting StartedWelcome to Teach Yourself C++ in 24 Hours! In this very first hour you will learn:
- How to set up and use the features of your compiler
- The steps to develop a C++ program
- How to enter, compile, and link your first working C++ program
Preparing to ProgramC++, perhaps more than other languages, demands that the programmer design the program before writing it. Trivial problems, such as the ones discussed in the first few chapters of this book, don't require much design. Complex problems, however, such as the ones professional programmers are challenged with every day, do require design. The more thorough the design, the more likely it is that the program will solve the problems it is designed to solve, on time and on budget. A good design also makes for a program that is relatively bug free and easy to maintain. It has been estimated that fully 90 percent of the cost of software is the combined cost of debugging and maintenance. To the extent that good design can reduce those costs, it can have a significant impact on the bottom-line cost of the project.
The first question you need to ask when preparing to design any program is, "What is the problem I'm trying to solve?" Every program should have a clear, well-articulated goal; and you'll find that even the simplest programs in this book have one.
The second question every good programmer asks is, "Can this be accomplished without resorting to writing custom software?" Reusing an old program, using pen and paper, or buying software off the shelf are often better solutions to a problem than writing something new. The programmer who can offer these alternatives will never suffer from lack of work; finding less expensive solutions to today's problems will always generate new opportunities later.
Assuming you understand the problem and it requires writing a new program, you are ready to begin your design.
C++, ANSI C++, ISO C++, Windows, and Other Areas of ConfusionC++ is a language. DOS, Windows, UNIX, and MacOS are operating systems. When you learn C++, you'll want to learn it as a portable language without regard to which machine and operating system you'll run your programs on.
Teach Yourself C++ in 24 Hours makes no assumptions about your operating system. This book teaches ANSI/ISO C++. ANSI/ISO C++ is just another way of saying "standard" C++-the internationally agreedupon version that is portable to any platform and any development environment. The code presented throughout the book is standard ANSI/ISO and should run on almost any compiler. Therefore, you will see few references to windows, list boxes, graphics, and so forth. All that is operating system-dependent.
You'll see output accomplished through standard output. To make this work, you might need to tell your compiler to create a console application. This is the case with the Bloodshed Dev-C++ compiler. Some compilers, written to be used with Windows or the Mac or another windowing environment, call this a quick window, or a simple window, or perhaps a console window.
A compiler is the software you will be using throughout this book. It translates a program from humanreadable form into machine code, producing an object file that will later be linked and run. A linker is a program that builds an executable (runnable) file from the object code files produced by the compiler.
There are two compilers included on the CD-ROM with this book. The next section walks you through the set-up and installation process for the Dev-C++ Bloodshed compiler. It is designed to run in a windows-based operating environment and provides an integrated development environment (IDE) that permits you to edit, compile, debug, and more from a graphical interface. Eventually you might want to consider using another compiler that is not dependent on a Windows environment, but that is a matter of personal choice.
Installing and Setting Up the CompilerTo use the Dev-C++ Integrated Development Environment (IDE) supplied with this book, you need to use a Microsoft Windows operating system. If you are not going to be working in this environment, this section will not apply to you. You will need to find a compiler for your operating system. If you are working in Windows, then proceed with the installation of the Bloodshed C++ compiler, which is the graphical interface you will use for the remainder of the book. You might also see this graphical interface referred to as the Bloodshed Compiler, Bloodshed Dev-C++, Dev-C++, or Dev-C++ IDE. They are all the same.
Insert the CD and it should run automatically. If not, you can start it manually by running start.exe from the CD. Click Compiler Center, then click Launch Dev-C++ Installer. You will use the default settings, so click Yes, then Next, then you must wait until you get the Setup Complete window. When you see the Setup Complete window, click Finish. This brings you back to the original screen. Click Exit. You have now installed the Dev-C++ IDE, but need to configure it in order to make it easier to use. If you don't already have compression software installed on your computer, install the WinZip software from the CD-ROM. To start the installation process, you will follow similar steps to those outlined for the compiler installation.
Unzip the file from the CD, extracting it into the \Dev-C++ directory (or, if you did not use the default directory, the directory where you installed the compiler). Click Yes any time you get a Confirm File Overwrite window. This process will upgrade your Dev-C++ IDE from version 4.0 to version 4.01. After you complete the installation of the compiler and the upgrade, install the debugger. It is also located on the CD-ROM and can easily be installed by following the prompts. It is the Cygnus Insight debugger, version 5. The Dev-C++ compiler comes with a standard command line debugger. The Cygnus Insight debugger is graphical and easier to use....