?? ch01.htm
字號(hào):
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<!-- This document was created from RTF source by rtftohtml version 3.0.1 -->
<META NAME="GENERATOR" Content="Symantec Visual Page 1.0">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html;CHARSET=iso-8859-1">
<TITLE>Teach Yourself C++ in 21 Days</TITLE>
</HEAD>
<BODY TEXT="#000000" BGCOLOR="#FFFFFF">
<H1 ALIGN="CENTER"><A HREF="fm.htm" tppabs="http://petunia.atomki.hu/pio/Manuals/english/0-672/0-672-31070-8/htm/fm.htm"><IMG SRC="../buttons/BLANPREV.GIF" tppabs="http://petunia.atomki.hu/pio/Manuals/english/0-672/0-672-31070-8/buttons/BLANPREV.GIF"
WIDTH="37" HEIGHT="37" ALIGN="BOTTOM" BORDER="0"></A><A HREF="javascript:if(confirm('http://www.mcp.com/sams \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://www.mcp.com/sams'" tppabs="http://www.mcp.com/sams"><IMG
SRC="../buttons/BLANHOME.GIF" tppabs="http://petunia.atomki.hu/pio/Manuals/english/0-672/0-672-31070-8/buttons/BLANHOME.GIF" WIDTH="37" HEIGHT="37" ALIGN="BOTTOM"
BORDER="0"></A><A HREF="../index.htm" tppabs="http://petunia.atomki.hu/pio/Manuals/english/0-672/0-672-31070-8/index.htm"><IMG SRC="../buttons/BLANTOC.GIF" tppabs="http://petunia.atomki.hu/pio/Manuals/english/0-672/0-672-31070-8/buttons/BLANTOC.GIF"
WIDTH="37" HEIGHT="37" ALIGN="BOTTOM" BORDER="0"></A><A HREF="ch02.htm" tppabs="http://petunia.atomki.hu/pio/Manuals/english/0-672/0-672-31070-8/htm/ch02.htm"><IMG SRC="../buttons/BLANNEXT.GIF" tppabs="http://petunia.atomki.hu/pio/Manuals/english/0-672/0-672-31070-8/buttons/BLANNEXT.GIF"
WIDTH="37" HEIGHT="37" ALIGN="BOTTOM" BORDER="0"></A></H1>
<H1></H1>
<UL>
<LI><A HREF="#Heading1">Day 1</A>
<UL>
<LI><A HREF="#Heading2">Getting Started</A>
<UL>
<LI><A HREF="#Heading3">Introduction</A>
<LI><A HREF="#Heading4">A Brief History of C++</A>
<LI><A HREF="#Heading5">Programs</A>
<LI><A HREF="#Heading6">Solving Problems</A>
<UL>
<LI><A HREF="#Heading7">Procedural, Structured, and Object-Oriented Programming</A>
<LI><A HREF="#Heading8">C++ and Object-Oriented Programming</A>
</UL>
<LI><A HREF="#Heading9">How C++ Evolved</A>
<LI><A HREF="#Heading10">The ANSI Standard</A>
<LI><A HREF="#Heading11">Should I Learn C First?</A>
<LI><A HREF="#Heading12">Preparing to Program</A>
<LI><A HREF="#Heading13">Your Development Environment</A>
<LI><A HREF="#Heading14">Compiling the Source Code</A>
<LI><A HREF="#Heading15">Creating an Executable File with the Linker</A>
<LI><A HREF="#Heading17">The Development Cycle</A>
<UL>
<LI><A HREF="#Heading18">Figure 1.1.</A>
</UL>
<LI><A HREF="#Heading19">HELLO.CPPYour First C++ Program</A>
<LI><A HREF="#Heading20">Listing 1.1. HELLO.CPP, the Hello World program.</A>
<LI><A HREF="#Heading21">Compile Errors</A>
<LI><A HREF="#Heading22">Listing 1.2. Demonstration of</A>
<LI><A HREF="#Heading23">compiler error.</A>
<LI><A HREF="#Heading24">Summary</A>
<LI><A HREF="#Heading25">Q&A</A>
<LI><A HREF="#Heading26">Workshop</A>
<UL>
<LI><A HREF="#Heading27">Quiz</A>
<LI><A HREF="#Heading28">Exercises</A>
</UL>
</UL>
</UL>
</UL>
<P>
<HR SIZE="4">
<H2 ALIGN="CENTER"><BR>
<A NAME="Heading1"></A><FONT COLOR="#000077">Day 1</FONT></H2>
<H2 ALIGN="CENTER"><A NAME="Getting STarted"></A><FONT COLOR="#000077">Getting Started</FONT></H2>
<P>
<H3 ALIGN="CENTER"><A NAME="Heading3"></A><FONT COLOR="#000077">Introduction</FONT></H3>
<P>Welcome to Teach Yourself C++ in 21 Days! Today you will get started on your way
to becoming a proficient C++ programmer. You'll learn
<UL>
<LI>Why C++ is the emerging standard in software development.
<P>
<LI>The steps to develop a C++ program.
<P>
<LI>How to enter, compile, and link your first working C++ program.
</UL>
<H3 ALIGN="CENTER"><A NAME="Heading4"></A><FONT COLOR="#000077">A Brief History of
C++</FONT></H3>
<P>Computer languages have undergone dramatic evolution since the first electronic
computers were built to assist in telemetry calculations during World War II. Early
on, programmers worked with the most primitive computer instructions: machine language.
These instructions were represented by long strings of ones and zeroes. Soon, assemblers
were invented to map machine instructions to human-readable and -manageable mnemonics,
such as <TT>ADD</TT> and <TT>MOV</TT>.</P>
<P>In time, higher-level languages evolved, such as BASIC and COBOL. These languages
let people work with something approximating words and sentences, such as <TT>Let
I = 100</TT>. These instructions were translated back into machine language by interpreters
and compilers. An interpreter translates a program as it reads it, turning the program
instructions, or code, directly into actions. A compiler translates the code into
an intermediary form. This step is called compiling, and produces an object file.
The compiler then invokes a linker, which turns the object file into an executable
program.</P>
<P>Because interpreters read the code as it is written and execute the code on the
spot, interpreters are easy for the programmer to work with. Compilers, however,
introduce the extra steps of compiling and linking the code, which is inconvenient.
Compilers produce a program that is very fast each time it is run. However, the time-consuming
task of translating the source code into machine language has already been accomplished.</P>
<P>Another advantage of many compiled languages like C++ is that you can distribute
the executable program to people who don't have the compiler. With an interpretive
language, you must have the language to run the program.</P>
<P>For many years, the principle goal of computer programmers was to write short
pieces of code that would execute quickly. The program needed to be small, because
memory was expensive, and it needed to be fast, because processing power was also
expensive. As computers have become smaller, cheaper, and faster, and as the cost
of memory has fallen, these priorities have changed. Today the cost of a programmer's
time far outweighs the cost of most of the computers in use by businesses. Well-written,
easy-to-maintain code is at a premium. Easy- to-maintain means that as business requirements
change, the program can be extended and enhanced without great expense.
<H3 ALIGN="CENTER"><A NAME="Heading5"></A><FONT COLOR="#000077">Programs</FONT></H3>
<P>The word program is used in two ways: to describe individual instructions, or
source code, created by the programmer, and to describe an entire piece of executable
software. This distinction can cause enormous confusion, so we will try to distinguish
between the source code on one hand, and the executable on the other.</P>
<DL>
<DD>
<HR>
<FONT COLOR="#000077"><B>New Term:</B></FONT><B> </B>A <I>program</I> can be defined
as either a set of written instructions created by a programmer or an executable
piece of software.
<HR>
</DL>
<P>Source code can be turned into an executable program in two ways: Interpreters
translate the source code into computer instructions, and the computer acts on those
instructions immediately. Alternatively, compilers translate source code into a program,
which you can run at a later time. While interpreters are easier to work with, most
serious programming is done with compilers because compiled code runs much faster.
C++ is a compiled language.
<H3 ALIGN="CENTER"><A NAME="Heading6"></A><FONT COLOR="#000077">Solving Problems</FONT></H3>
<P>The problems programmers are asked to solve have been changing. Twenty years ago,
programs were created to manage large amounts of raw data. The people writing the
code and the people using the program were all computer professionals. Today, computers
are in use by far more people, and most know very little about how computers and
programs work. Computers are tools used by people who are more interested in solving
their business problems than struggling with the computer.</P>
<P>Ironically, in order to become easier to use for this new audience, programs have
become far more sophisticated. Gone are the days when users typed in cryptic commands
at esoteric prompts, only to see a stream of raw data. Today's programs use sophisticated
"user-friendly interfaces," involving multiple windows, menus, dialog boxes,
and the myriad of metaphors with which we've all become familiar. The programs written
to support this new approach are far more complex than those written just ten years
ago.</P>
<P>As programming requirements have changed, both languages and the techniques used
for writing programs have evolved. While the complete history is fascinating, this
book will focus on the transformation from procedural programming to object-oriented
programming.
<H4 ALIGN="CENTER"><A NAME="Heading7"></A><FONT COLOR="#000077">Procedural, Structured,
and Object-Oriented Programming</FONT></H4>
<P>Until recently, programs were thought of as a series of procedures that acted
upon data. A procedure, or function, is a set of specific instructions executed one
after the other. The data was quite separate from the procedures, and the trick in
programming was to keep track of which functions called which other functions, and
what data was changed. To make sense of this potentially confusing situation, structured
programming was created.</P>
<P>The principle idea behind structured programming is as simple as the idea of divide
and conquer. A computer program can be thought of as consisting of a set of tasks.
Any task that is too complex to be described simply would be broken down into a set
of smaller component tasks, until the tasks were sufficiently small and self-contained
enough that they were easily understood.</P>
<P>As an example, computing the average salary of every employee of a company is
a rather complex task. You can, however, break it down into these subtasks:
<DL>
<DD><B>1.</B> Find out what each person earns.<BR>
<BR>
<B>2.</B> Count how many people you have.<BR>
<BR>
<B>3.</B> Total all the salaries.<BR>
<BR>
<B>4.</B> Divide the total by the number of people you have.
</DL>
<P>Totaling the salaries can be broken down into
<DL>
<DD><B>1.</B> Get each employee's record.<BR>
<B><BR>
2.</B> Access the salary.<BR>
<B><BR>
3.</B> Add the salary to the running total.<BR>
<B><BR>
4.</B> Get the next employee's record.
</DL>
<P>In turn, obtaining each employee's record can be broken down into
<DL>
<DD><B>1.</B> Open the file of employees.<BR>
<B><BR>
2.</B> Go to the correct record.<BR>
<B><BR>
3.</B> Read the data from disk.
</DL>
<P>Structured programming remains an enormously successful approach for dealing with
complex problems. By the late 1980s, however, some of the deficiencies of structured
programing had became all too clear.</P>
<P>First, it is natural to think of your data (employee records, for example) and
what you can do with your data (sort, edit, and so on) as related ideas.</P>
<P>Second, programmers found themselves constantly reinventing new solutions to old
problems. This is often called "reinventing the wheel," and is the opposite
of reusability. The idea behind reusability is to build components that have known
properties, and then to be able to plug them into your program as you need them.
This is modeled after the hardware world--when an engineer needs a new transistor,
she doesn't usually invent one, she goes to the big bin of transistors and finds
one that works the way she needs it to, or perhaps modifies it. There was no similar
option for a software engineer.</P>
<DL>
<DD>
<HR>
<FONT COLOR="#000077"><B>New Term:</B></FONT><B> </B>The way we are now using computers--with
menus and buttons and windows--fosters a more interactive, event-driven approach
to computer programming. <I>Event-driven</I> means that an event happens--the user
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -