home *** CD-ROM | disk | FTP | other *** search
-
-
-
- Introduction
- WHAT IS C++
-
- THE ORIGIN OF C++
- -----------------------------------------------------------------
- The C programming language was developed at AT&T for the purpose
- of writing the operating system for the PDP-11 series of
- computers which ultimately became the unix operating system.
- C was developed with the primary goal of operating efficiency.
- Bjarne Stroustrup, also of AT&T, developed C++ in order to add
- object oriented constructs to the C language. Because object
- oriented technology was new at the time and all existing
- implementations of object oriented languages were very slow and
- inefficient, the primary goal of C++ was to maintain the
- efficiency of C.
-
- C++ can be viewed as a traditional procedural language with some
- additional constructs. Beginning with C, some constructs are
- added for object oriented programming and some for improved
- procedural syntax. A well written C++ program will reflect
- elements of both object oriented programming style and classic
- procedural programming. C++ is actually an extendible language
- since we can define new types in such a way that they act just
- like the predefined types which are part of the standard
- language. C++ is designed for large scale software development.
-
-
- HOW TO GET STARTED IN C++
- -----------------------------------------------------------------
- The C programming language was originally defined by the classic
- text authored by Kernigan and Ritchie, "The C Programming
- language", and was the standard used by all C programmers until a
- few years ago. The ANSI standard for C was finally approved in
- December of 1989 and has become the official standard for
- programming in C. The ANSI standard adds many things to the
- language which were not a part of the Kernigan and Ritchie
- definition, and changes a few. The two definitions are not
- absolutely compatible and some experienced C programmers may not
- have studied the newer constructs added to the language by the
- ANSI-C standard.
-
- This tutorial will assume a thorough knowledge of the C
- programming language and little time will be spent on the
- fundamental aspects of the language. However, as a aid to those
- programmers that have learned the dialect of C as defined by
- Kernigan & Ritchie, some sections will be devoted to explaining
- the newer additions included in the ANSI-C standard. As the
- ANSI-C standard was in development, many of the newer constructs
- from C++ were included as parts of C itself, so even though C++
- is a derivation and extension of C, it would be fair to say that
- ANSI-C has some of its roots in C++. An example is prototyping
- which was developed for C++ and later added to C.
-
- Page I-1
-
- Introduction - What is C++
-
- The best way to learn C++ is by using it. Almost any valid C
- program is also a valid C++ program and, in fact, the addition
- of about 12 keywords is the only reason that some C programs will
- not compile and execute as a C++ program. There are a few other
- subtle differences, but we will save the discussion of them until
- later. Since this is true, the best way to learn C++ is to
- simply add to your present knowledge and use a few new constructs
- as you need them for each new project. It would be a tremendous
- mistake to try to use all of the new constructs in your first C++
- program. You would probably end up with an incomprehensive
- mixture of code that would be more inefficient than the same
- program written purely in C. It would be far better to add a few
- new constructs to your toolkit occasionally, and use them as
- needed while you gain experience with their use.
-
- As an illustration of the portability of C to C++, all of the
- example programs included in the Coronado Enterprises C tutorial
- compile and execute correctly when compiled as C++ programs with
- no changes. None of the C++ programs will compile and execute
- correctly with any C compiler however, if for no other reason
- than the use of the new style of C++ comments.
-
-
- HOW TO USE THIS TUTORIAL
- -----------------------------------------------------------------
- This tutorial is best used while sitting in front of your
- computer. It is designed to help you gain experience with your
- own C++ compiler in addition to teaching you the proper use of
- C++. Display an example program on the monitor, using whatever
- text editor you usually use, and read the accompanying text
- which will describe each new construct introduced in the example
- program. After you study the program, and understand the new
- constructs, compile and execute the program with your C++
- compiler.
-
- After you successfully compile and execute the example program,
- introduce a few errors into the program to see what kind of error
- messages are issued. If you have done much programming, you will
- not be surprised if your compiler gives you an error message that
- seems to have nothing to do with the error introduced. This is
- because error message analysis is a very difficult problem with
- any modern programming language. The most important result of
- these error introduction exercises is the experience you will
- gain using your compiler and understanding its nuances. You
- should then attempt to extend the program using the techniques
- introduced with the program to gain experience.
-
- The way this tutorial is written, you will not find it necessary
- to compile and execute every program. At the end of each
- example program, listed in comments, you will find the result of
- execution of that program. Some of the constructs are simple
- and easy for you to understand, so you may choose to ignore
- compilation and execution of that example program, depending
-
- Page I-2
-
- Introduction - What is C++
-
- upon the result of execution to give you the output. Some
- students have used these results of execution to study several
- chapters of this tutorial on an airplane by referring to a
- hardcopy of the example programs.
-
- In the text of this tutorial, keywords, variable names, and
- function names will be written in bold type as an aid when you
- are studying the example programs.
-
-
- DIFFERENT C++ IMPLEMENTATIONS
- -----------------------------------------------------------------
- There are primarily two standards for naming C++ files, one using
- the extension CPP and the other using the extension CXX. All
- files in this tutorial use the CPP extension for naming files.
- If your compiler requires the CXX extension it will be up to you
- to rename the files. When C++ was in its infancy, header files
- generally used the extension .HPP, but there is a definite trend
- to use .H for all header files. For that reason all header files
- in this tutorial will use that convention.
-
- Even though we have tried to use the most generic form of all
- constructs, it is possible that some constructs will not actually
- compile and run with some C++ compilers. As we find new
- implementations of C++, and acquire copies of them, we will
- compile and execute all files in an attempt to make all example
- programs as universal as possible.
-
- The C++ language is very new and is changing rapidly. The
- developer of the language, AT&T, has changed the formal
- definition several times in the last few years and the compiler
- writers are staying busy trying to keep up with them. It would
- be best for you to search the more popular programming magazines
- for evaluations and comparisons of compilers. New C++
- implementations are being introduced at such a rapid rate, that
- we cannot make a compiler recommendation here.
-
- A committee is currently meeting to produce an ANSI-C++ standard,
- but the standard is not expected to be available for general use
- until sometime in 1996. Until then we must expect a few changes
- to the language.
-
-
- PRINTING THE EXAMPLE PROGRAMS
- -----------------------------------------------------------------
- Some students prefer to work from a hardcopy of the example
- programs. If you desire to print out the example programs, there
- is a batch file on the distribution disk to help you do this.
- Make the distribution disk the default drive and type PRINTALL at
- the user prompt. The system will print out about 140 pages of
- C++ programs, all of the example programs in this tutorial.
-
-
-
- Page I-3
-
- Introduction - What is C++
-
- The PRINTALL batch file calls the program named LIST.EXE once
- for each example program on the distribution disk.
-
-
- PROGRAMMING EXERCISES
- -----------------------------------------------------------------
- There are programming exercises given at the end of each chapter
- to enable you to try a few of the constructs given in the
- chapter. These are for your benefit and you will benefit greatly
- if you attempt to solve each programming problem. If you merely
- read this entire tutorial, you will have a good working knowledge
- of C++, but you will only become a C++ programmer if you write
- C++ programs. The programming exercises are given as suggestions
- to get you started programming.
-
- An answer for each programming exercise is given in the ANSWERS
- directory on the distribution disk. The answers are all given
- in compilable C++ source files named in the format CHnn_m.CPP,
- where nn is the chapter number and m is the exercise number. If
- more than one answer is required, an A, B, or C, is included
- following the exercise number.
-
-
- RECOMMENDED ADDITIONAL READING
- -----------------------------------------------------------------
-
- Brad Cox. "Object Oriented Programming, An Evolutionary
- Approach". Addison-Wesley, 1986. This book is excellent
- for a study of object oriented programming and what it is,
- but since it is based on Objective-C, it covers nothing of
- the C++ language or how to use it.
-
- Margaret Ellis & Bjarne Stroustrup. "The Annotated C++ Reference
- Manual". Addison-Wesley, 1990. This is the base document
- for the ANSI-C++ standard. Even though it is the definitive
- book on C++, it would be difficult for a beginner to learn
- the language from this book alone.
-
- Scott Meyers. "Effective C++, 50 Specific Ways to Improve Your
- Programs and Designs". Addison-Wesley, 1992. This book
- is excellent for the advanced C++ programmer, but it is
- definitely not for the beginner.
-
- Note that the C++ culture is in rapid change and by the time you
- read this, there will be additional well written texts available
- as aids to your learning the syntax and proper use of the C++
- programming language.
-
-
-
-
-
-
-
- Page I-4
-