16-10-2012, 12:06 PM
C++ development environment
C++ development.pdf (Size: 41.55 KB / Downloads: 27)
An IDE packages all the components noted above and makes them available
through some simple to use visual interface.
On a Intel 486-, or Pentium- based PC system, you will be using either
Borland's C++ environment or Microsoft's C++. On a Macintosh system, you will
probably be using Symantec C++. These systems are fairly similar.
They employ a variety of different windows on the screen to present
information about a program (usually termed a "project") that you are developing.
At least one of these windows will be an editing window where you can change the
text of the source code of the program. Another window will display some kind of
summary that specifies which files (and, possibly, libraries) are used to form a
program. Figure 5.1 illustrates the arrangement with Symantec 8 for the Power PC.
The editing window is on the left, the project window is to the right.
C++ INPUT AND OUTPUT
Because any interesting program is going to have to have at least some output (and
usually some input), you have to learn a little about the input and output facilities
before you can do anything.
In some languages (FORTRAN, Pascal, etc), the input and output routines are
fixed in the language definition. C and C++ are more flexible. These languages
assume only that the operating system can provide some primitive 'read' and 'write'
functions that may be used to get bytes of data into or out from a program. More
useful sets of i/o routines are then provided by libraries. Routines in these libraries
will call the 'read' and 'write' routines but they will do a lot of additional work (e.g.
converting sequences of digits into the appropriate bit pattern to represent a
number).
Most C programs use an i/o library called stdio (for standard i/o). This library
can be used in C++; but more often, C++ programs make use of an alternative
library called iostream (i/o stream library).
The i/o stream library (iostream) makes use of some of the "object oriented"
features of C++. It uses "stream objects" to handle i/o.
Now in general an object is something that "owns a resource and provides
services related to that resource". A "stream object" owns a "stream", either an
output stream or an input stream. An output stream is something that takes
character data and gets them to an output device. An input stream gets data bytes
from some input device and routes them to a program. (A good way of thinking of
them is as kinds of software analogues of hardware peripheral device controllers.)
A SIMPLE EXAMPLE PROGRAM IN C++
This example is intended to illustrate the processes involved in entering a program,
getting it checked, correcting typing errors, compiling the program and running it.
The program is very simple; it reads two integer values and prints the quotient and
remainder. The coding will be treated pretty informally, we won't bother with all
the rules that specify what names are allowed for variables, where variables get
defined, what forms of punctuation are needed in statements. These issues are
explored after this fairly informal example.
Running the program
You can simply "Run" your program or you can run it under control from the IDE's
debugger. If you just run the program, it will open a new window for input and
output. You enter your data and get your results. When the program terminates it
will display some message (e.g. via an "Alert" dialog); when you clear ("OK") the
dialog you are returned to the main part of the development environment with its
editor and project windows.
Running under the control of a debugger takes a little more setting up.
Eventually, the IDE will open a window showing the code of your main program
with an arrow marker at the first statement.