Copy Link
Add to Bookmark
Report

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 procedural language with some additional constructs, some of which 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. Since 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, because we realize that many programmers have learned the dialect of C as defined by Kernigan & Ritchie, some sections will be devoted to explaining the newer additions as provided by 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.

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 program. 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 each day, 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.

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.

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 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.

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 languages 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.

PRINTING OUT 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 and the system will print out about 170 pages of C++ programs, all of the example programs in this tutorial.

The PRINTALL batch file calls the program named LIST.EXE once for each example program on the distribution disk. LIST.EXE was written in TURBO Pascal and compiled for your use in listing any program with line numbers and the date and time the program was last modified. TURBO Pascal was used because Borland does not require a licensing fee for distributing copies of the resulting run time files, and this file is included with all Coronado Enterprises tutorials.


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

Richard S. Wiener & Lewis J. Pinson. "An Introduction to Object-Oriented Programming and C++". Addison-Wesley, 1988. This is the first book recommended since it covers both object oriented programming and C++ in depth. It is clearly written and well organized.

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.

Stephen Dewhurst & Kathy Stark. Programming in C++". Prentice Hall, 1989. This book covers the fundamentals of the language well and covers the proper application of object oriented programming techniques.

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.

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.


A SPECIAL NOTE FOR THE SHAREWARE VERSION

It is impossible to include the graphics diagrams in chapters 5 and 7 in a pure ASCII text. They are therefore omitted from this version of the tutorial. If you need these diagrams, they can be purchased directly from Coronado Enterprises along with your registration. See the READ.ME file on either diskette for more information.

← previous
next →
loading
sending ...
New to Neperos ? Sign Up for free
download Neperos App from Google Play
install Neperos as PWA

Let's discover also

Recent Articles

Recent Comments

Neperos cookies
This website uses cookies to store your preferences and improve the service. Cookies authorization will allow me and / or my partners to process personal data such as browsing behaviour.

By pressing OK you agree to the Terms of Service and acknowledge the Privacy Policy

By pressing REJECT you will be able to continue to use Neperos (like read articles or write comments) but some important cookies will not be set. This may affect certain features and functions of the platform.
OK
REJECT