1. Introducing C++
Programming is a core activity in the process of performing tasks or solving problems with the aid of a computer. An idealised picture is:
[problem or task specification] – COMPUTER – [solution or completed task]
Unfortunately things are not (yet) that simple. In particular, the “specification” cannot be given to the computer using natural language. Moreover, it cannot (yet) just be a description of the problem or task, but has to contain information about how the problem is to be solved or the task is to be executed. Hence we need programming languages. Click here for a more detailed view of the problem solving pipeline.
There are many different programming languages, and many ways to classify them. For example, “high-level” programming languages are languages whose syntax is relatively close to natural language, whereas the syntax of “low-level” languages includes many technical references to the nuts and bolts (0’s and 1’s, etc.) of the computer. “Declarative” languages (as opposed to “imperative” or “procedural” languages) enable the programmer to minimise his or her account of how the computer is to solve a problem or produce a particular output. “Object-oriented languages” reflect a particular way of thinking about problems and tasks in terms of identifying and describing the behaviour of the relevant “objects”. Smalltalk is an example of a pure object-oriented language. C++ includes facilities for object-oriented programming, as well as for more conventional procedural programming.
Proponents of different languages and styles of languages sometimes make extravagant claims. For example, it is sometimes claimed that (well written) object-oriented programs reflect the way in which humans think about solving problems. Judge for yourselves!
C++ was developed by Bjarne Stroustrup of AT&T Bell Laboratories in the early 1980’s, and is based on the C language. The name is a pun – “++” is a syntactic construct used in C (to increment a variable), and C++ is intended as an incremental improvement of C. Most of C is a subset of C++, so that most C programs can be compiled (i.e. converted into a series of low-level instructions that the computer can execute directly) using a C++ compiler.
C is in many ways hard to categorise. Compared to assembly language it is high-level, but it nevertheless includes many low-level facilities to directly manipulate the computer’s memory. It is therefore an excellent language for writing efficient “systems” programs. But for other types of programs, C code can be hard to understand, and C programs can therefore be particularly prone to certain types of error. The extra object-oriented facilities in C++ are partly included to overcome these shortcomings.
The American National Standards Institution (ANSI) provides “official” and generally accepted standard definitions of many programming languages, including C and C++. Such standards are important. A program written only in ANSI C++ is guaranteed to run on any computer whose supporting software conforms to the ANSI standard. In other words, the standard guarantees that ANSI C++ programs are portable. In practice most versions of C++ include ANSI C++ as a core language, but also include extra machine-dependent features to allow smooth interaction with different computers’ operating systems. These machine dependent features should be used sparingly. Moreover, when parts of a C++ program use non-ANSI components of the language, these should be clearly marked, and as far a possible separated from the rest of the program, so as to make modification of the program for different machines and operating systems as easy as possible.
The best way to learn a programming language is to try writing programs and test them on a computer! To do this, we need several pieces of software:
- An editor with which to write and modify the C++ program components or source code,
- A compiler with which to convert the source code into machine instructions which can be executed by the computer directly,
- A linking program with which to link the compiled program components with each other and with a selection of routines from existing libraries of computer code, in order to form the complete machine-executable object program,
- A debugger to help diagnose problems, either in compiling programs in the first place, or if the object program runs but gives unintended results.
There are several editors available for UNIX-based systems. Two of the most popular editors are emacs and vi. For the compiler and linker, we will be using the GNU g++ compiler/linker, and for the debugger we will be using the GNU debugger gdb. For those that prefer an integrated development environment (IDE) that combines an editor, a compiler, a linking program and a debugger in a single programming environment (in a similar way to Microsoft Developer Studio under Windows NT), there are also IDEs available for UNIX (e.g. Eclipse, xcode, kdevelop etc.)
I do include this books to increase your learning experience in c++ or you can download them from the books page
Download other books from the Books Page by just clicking on the title