Select from the choices above.

Please send all questions & assignments to:
dsolarek@eng.utoledo.edu

Introduction to C++

What is C++?

To describe the C++ programming language we must begin by talking about C. The C language is a general-purpose programming language that was originally designed in 1972 by Dennis Ritchie of Bell Laboratories in Murray Hill, New Jersey and implemented there on a DEC1 PDP-11 minicomputer. It was first used as the language for rewriting the newly created UNIX operating system.

Although it is an excellent general-purpose programming language, C is not a good language for beginning programmers because it is somewhat cryptic in nature. However, it does allow the more experienced programmer a wide range of operations from high level down to a very low level, approaching the level of assembly language. There seems to be no limit to the flexibility available. Because of this flexibility, C is often characterized (somewhat confusingly) by different authors as a high-level, medium-level, or even a low-level language.

In 1985 Bell Labs employee Bjarne Stroustrop created an object-oriented programming2 language called C++ that is a superset of C. Because C++ retains C as a subset, it gains many of the attractive features of the C language, such as efficiency, closeness to the machine, and a variety of built-in data types4. A number of new features were added to C++ to make the language even more robust, many of which are not used by novice programmers. C++ is actually a hybrid language, as you can use it in a procedural5 manner and/or an object oriented manner.

History of C and C++

C came into being in the years 1969-1973, in parallel with the early development of the Unix operating system; the most creative period occurred during 1972. The developer of UNIX, Ken Thompson, had been using both assembler and a language named B to produce initial versions of UNIX in 1970. Ken Thompson had created the B language in 1969-70; it was derived directly from Martin Richards's BCPL. The invention of C came about to overcome the limitations of B. Dennis Ritchie turned B into C during 1971-73, keeping most of B's syntax while adding types and many other changes, and writing the first compiler. B was a programming language based on BCPL. BCPL was developed as a typeless systems programming language, by Martin Richards. BCPL basic data type was the machine word, and it made heavy use of pointers and address arithmetic. C evolved from B and BCPL and incorporated typing.

Another spate of changes peaked between 1977 and 1979, when portability of the Unix system was being demonstrated. In the middle of this second period, the first widely available description of the language appeared: The C Programming Language, often called the 'white book' or 'K&R'. Finally, in the middle 1980s, the language was officially standardized by the ANSI X3J11 committee, which made further changes. Until the early 1980s, although compilers existed for a variety of machine architectures and operating systems, the language was almost exclusively associated with Unix; more recently, its use has spread much more widely, and today it is among the languages most commonly used throughout the computer industry.

Ritchie, Alan Snyder, Steven C. Johnson, Michael Lesk, and Thompson contributed language ideas during 1972-1977, and Johnson's portable compiler remains widely used. During this period, the collection of library routines grew considerably, thanks to these people and many others at Bell Laboratories. In 1978, Brian Kernighan and Ritchie wrote the book that became the language definition for several years. Beginning in 1983, the ANSI X3J11 committee standardized the language. Especially notable in keeping its efforts on track were its officers Jim Brodie, Tom Plum, and P. J. Plauger, and the successive draft redactors, Larry Rosler and Dave Prosser.

In the beginning, Stroustrop merely viewed his work as an extension of C, calling it C with Classes. This version was released around 1982. In 1983/84 C with Classes was revised and renamed C++. It was summarized in the book, "The C++ Programming Language" by Stroupstrop, Addison Wesley, 1985. In the 1990's, C++ has become the most widely used object-oriented language, with a good publicly available compiler (g++ from the Free Software Foundation) and high-quality commercial compilers and development environments available for the Macintosh, PC, and Unix-based workstations.

What is Object-Oriented Programming?

Object-oriented programming (OOP) is a revolutionary new way of looking at computer programming. Historically, programs have been viewed as procedures (or we may think of these as "verbs") that operate on data. OOP takes the view that programs should start by thinking about the data (or "nouns") first. After all, the primary purpose of computing is the result ... not the computing procedure itself. By using data modeling concepts and techniques, a programmer can identify data objects and their relationships. A generalization of a data object along with its possible data variables and methods (what to do with the variables) is a class of data objects. A real instance of a class is an object. (It's what you run in the computer.)

Some of the ideas and advantages of OOP include:

  • The concept of a data class makes it possible to define subclasses of data objects that share some or all of the main class characteristics. Called inheritance, this property of OOP forces a more thorough data analysis, reduces development time, and ensures more accurate coding.
  • Data hiding is possible because an object and its methods will know only about the data they need to know about. Because other objects and methods in the application program cannot be accessed without rewriting the object, the possiblities of accidental or unintended data corruption that are possible in procedural programs are not possible with OOP.
  • The definition of a class is reuseable not only by the program for which it is initially created but also by other object-oriented programs (and, for this reason, can be more easily distributed for use in networks).
  • The concept of data classes allows a programmer to create new data types that are not defined in the language itself.
C++ is the most popular object-oriented language today. A subset of C++, the Java programming language is designed especially for distributing program objects in client/server systems such as the World Wide Web.

What is a Method?

In object-oriented programming, a method is a programmed procedure that is defined as part of a class and included in any object of that class. A class (and thus an object) can have more than one method. A method in an object can only have access to the data known to that object, which ensures data integrity among the set of objects in an application. A method can be re-used in multiple objects.

What is an Object?

Objects are entities stored in the computer's memory. The terms object and variable are sometimes used interchangeably. In object-oriented programming, each object contains the data variables of the class it is an instance of. The object's methods are designed to handle the actual values that are supplied to the object when the object is being used.

In object-oriented programming, objects are the things you think about first in designing a program and they are also the units of code that are eventually derived from the process. In between, each object is made into a generic class of object and even more generic classes are defined so that objects can share models and reuse the class definitions in their code. Each object is an instance of a particular class or subclass with the class' own methods or procedures and data variables. An object is what actually runs in the computer.

Every object has attributes and exhibits a specific behavior which are defined by its:

  • name
  • state (values of its attributes stored in the computer's memory)
  • set of operations (e.g., addition, subtraction, multiplication, input and output)
The state of an object changes according to the methods which are applied to it. We refer to these possible sequence of state changes as the behaviour of the object. The behavior of an object is defined by the set of methods which can be applied on it.

What is a Class?

A class is the implementation of an abstract data type. It defines attributes and methods which implement the data structure and operations of the abstract data type, respectively. Instances of classes are called objects. Consequently, classes define properties and behaviour of sets of objects.

In object-oriented programming, a class is a user-defined type. The terms type and class are sometimes used inter changeably. A class is a template definition of the methods and variables in a particular kind of object. Thus, an object is a specific instance of a class; it contains real values instead of variables.

The class is one of the defining ideas of object-oriented programming. Among the important ideas about classes are:

  • A class can have subclasses that can inherit all or some of the characteristics of the class. In relation to each subclass, the class becomes the superclass.
  • Subclasses can also define their own methods and variables that are not part of their superclass.
  • The structure of a class and its subclasses is called the class hierarchy.


Footnotes:

1.
DEC (Digital Equipment Corporation) a large company that popularized the idea of a minicomputer (something smaller, less expensive, and more fun than a mainframe) before there were PCs. Their PDP (Personal Digital Processor) and VAX (Virtual Address Extension) minicomputers became the standard for real-time, scientific, and UNIX computing. Industry-wide benchmarks are still based on DEC's VAX-11/780, which was introduced in 1977.
2.
Object-oriented programming (or OOP) is organized around objects rather than actions, data rather than logic. Object-oriented programming takes the view that what we really care about are the objects we want to manipulate rather than the logic required to manipulate them.
3.
A first-generation language (1GL) is machine language or the level of instructions and data that the processor is actually given to work on (which in conventional computers is a string of 0s and 1s). A second-generation language (2GL) is assembler (sometimes called "assembly") language. An assembler converts the assembler language statements into machine language. A third-generation language (3GL) is a "high-level" programming language, such as PL/I, C, or Java. A compiler converts the statements of a specific high-level programming language into machine language. A 3GL language requires a considerable amount of programming knowledge. A fourth-generation language (4GL) is designed to be closer to natural language than a 3GL language. Languages for accessing databases are often described as 4GLs. A fifth-generation language (5GL) is programming that uses a visual or graphical development interface to create source language that is usually compiled with a 3GL or 4GL language compiler.
4.
A data type in a programming language is a set of data with values having predefined characteristics. Examples of data types include: integer, floating point number, character, string, and pointer. Usually, a limited number of such data types come built into a programming language. The language specifies the range of values for a given data type, how the values are to be processed by the computer, and how they are stored.
5.
In procedural programming, the main program coordinates calls to procedures and passes appropriate data to these procedures as parameters. In this approach, a program can be viewed as a sequence of procedure calls. A procedure call from the main program is used to invoke the procedure. After the sequence of instructions is processed within the procedure, control passes back to the main (calling) program right after the instruction where the procedure call was made.

 

There have been visitors since 11/26/2003

Added to the Web: September 7, 1998.
Last updated: January 21, 1999.
Web page design by Dan Solarek.

http://cset.sp.utoledo.edu/