The Power Of 'C++'
The history: C++
C++ language was originally a ‘pre-compiler’, similar to the processor of C, which converted special construction in its source code to pain C. This code was then compiled by a normal C compiler. The pre-code was read by the C++ pre compiler, was usually located in a file with the extension .cpp, .cc, or .c. This file would then be converted to a C source with the extension .c, which was complied and linked.
C is supposed to be the root of C++. Dr. Bjarne Stroustrup at AT&T’s BELL Labs in early 1980’s added object oriented features to C and a new language was made known as C++.
Explaining C++ concepts:
The C++ is a language that has used the art of compromise, a compromise between the roots of C language and implementing the Object Oriented programming approach.
While object oriented programs can be written in languages such as C or BASIC, these languages lack certain features. For example, C provides no mechanism to hide variables from unauthorized access. C also does not allow one class to declare as a subclass of another. C++ symbol can be viewed as “Keep the features of C” and add (‘++’) new features to it.
What is Object Oriented Programming?
Object-oriented programming propagates a slightly different approach to programming problems than the strategy, which is usually used in C. The Object Oriented paradigm is the latest in the software development and the most adopted in the developing projects of today.
Procedural programming:
The c-way is known as a ‘procedural approach’: a problem is decomposed into sub problems and this process is repeated until the subtasks can be coded. In procedural paradigm, the emphasis is on doing things.
OOP Programming:
In contrast to the procedural programming approach, OOP enables you to model more closely whatever real-world problem the program is written to solve. OOP treats data as an important and critical element in the program development. It ties data more closely to the functions that operates on it and thus avoids global access. It then builds data and functions around these objects. Thus, an object is an identifiable entity with some characteristics and behavior.
For instance if we take an example of Aston martin which is a class having characteristics like wheels, steering, brakes and their behavior is mobility. But Aston martin belongs to a class ‘car’. ‘Car’ itself is a subclass of another class ‘automobiles’.
Hence, we can say that a class is a group of objects that share common properties and relationships.
For example we can say that ‘fish’ is the class but ‘dolphin’ is an object
Organization of data and functions in OOP
Some terminology and features:
Data Abstraction
Data Encapsulation
Inheritance
Polymorphism
Dynamic Binding
Message passing
DATA ABSTRACTION
Abstraction is the process of simplifying the real world concept into its essential elements. Abstraction refers to the act of representing essential features without including the background details or explanations. For example if we consider the example of keyboard. You only press certain key according to your requirement. What is happening inside, how is it happening etc. you needn’t know. This is abstraction; you only know the essential things to operate on keyboard without knowing the background details of keyboard.
DATA ENCAPSULATION
Data encapsulation is the way of combining both data and the functions that operate on that data under a single unit. The wrapping up of data and functions (that operate on data) into a single unit (called class) is known as Encapsulation. Here the data is not accessible to outside world, and only those functions, which are wrapped in the class, can be access it. This insulation of data from direct access by the program is called data hiding or information hiding.
INHERITANCE
Inheritance is the capability of one class of things to inherit capabilities or properties from another class. For instance, we are humans. We inherit from the class ‘humans’ certain properties such as ability to see, listen, and eat etc. but these properties are not unique to humans. The class ‘humans’ inherits these properties from the class ‘mammal’, which again inherit some characteristics from the class ‘animals’.
Role of inheritance in OOP
Its capability to express the inheritance relationship, which makes it, ensures the closeness with the real world models.
The idea of reusability is preserved. Inheritance allows addition of special features to an existing class.
Inheritance bears a transitive nature. If a class A inherits properties from class B, then all subclasses of A will automatically inherit the properties of B.
POLYMORPHISM
Polymorphism is the ability for a message or data to be processed in more than one form. It is the property by which the same message can be sent to objects of several different classes, and each object can respond in a different way depending on its class. In OOP, this one thing, which may take several distinct forms, may be an operator or a function. This provides the facility of sending the same message to objects of parent class and objects of the class/subclass to which it belongs. This allows objects having different internal structures (of derived class) to share the same external interface.
DYNAMIC BINDING
Binding refers to the linking of a procedure call to be executed in response to the call. Dynamic binding (also known as late binding) means that the code associated with a given procedure call is not known until the time of the call at run time. It is associated with polymorphism and inheritance.
MESSAGE PASSING
In OOP objects communicate with one another by sending and receiving information much the same way as people pass message to one another. The concept of message passing makes it easier to talk about building systems that directly model or simulate their real-world counterparts. A message for an object is a request for execution of a procedure, and therefore will invoke a function in the receiving object that generates the desired results. Message passing involves specifying the name of the object, the name of the function and the information to be sent.
Advantages and pretensions of C++
Often it is said that programming in C++ leads to `better' programs. Some of the claimed advantages of C++ are:
1)New programs would be developed in less time because old code can be reused.
2)Creating and using new data types would be easier than in C.
3)The memory management under C++ would be easier and more transparent.
4)Programs would be less bug-prone, as C++ uses a stricter syntax and type checking.
5)`Data hiding', the usage of data by one program part while other program parts cannot access the data, would be easier to implement with C++.
A FIRST IMPRESSION OF C++
Introduction
C++ is the superset of the C programming language that supports object oriented programming (OOP). Hence we can say that C++ cannot be separated from C. C++ is an object oriented programming language and was developed by Bajarne Stoustrup at AT&T Bell Laboratories in early 1980’s. Stroustrup an admirer of Simula67 and a strong supporter of C, wanted to combine the best of both the languages and create a more powerful language that could support object oriented programming and still retain the elegance of C. In 1983, the name was changed to C++ with the idea of attaching an increment operator, thereby suggesting that C++ is an augmented (incremented) version of C++.
Applications of C++
C++ is a versatile language for handling very large programs. It is suitable for virtually any programming tasks
1)Since C++ allows us to create hierarchy-related objects, we can build special object oriented libraries, which can be used later by many programmers.
2)While C++ is able to map the real world problem properly, the C part of C++ gives the language the ability to get close to the machine level details.
3)C++ programs are easily maintainable and expandable.
Getting started
C++ character sets:
C++ uses the characters set as given below as the building block to form the basic programming elements as identifiers, variable, array etc
Letters: Upper case A-Z
Lower case a-z
Digits 0…9
Special characters: / * + “ < # ) ( = | { > % ~ ; } / ^ [ - : ‘ ? & _ ] ` .
White spaces blank space, horizontal tab(à), carriage return( ), newline, form feed.
Keywords
Keywords are some reserved words in C++ which have predefined meaning to compiler. We cannot use keywords as variable name. Some commonly used keywords are:
Auto extern sizeof break float
Static case for struct char
Goto switch const if typedef
Continue do short while register
Double return else long void
