Wednesday 19 June 2013

Introduction To C++ Programming Language

C++ is object oriented programming language . But in this we can do Structured Programming also. Initially named "C with Classes" . C++ was developed By Bjarne Stroustrup at Bell-Laboratories in 1980s . Stroustrup take the best feature of simula 67 and C, and designed a language which support object oriented programming feature.
Therefore we can say C++ is extension of C language since the class was a major addition to original C language stroustrup called the new language "C with Classes" . However in 1983 the name was changes to C++. The idea of C++ comes from C increment operator ++ . Therefore as C++ is next version of C as +1 So it is named as C++ .

C++ is actually upper version or superset of C programming language . So amost all the Syntax or variable declaration, loops , conditional statements , Switching Statements etc are same .

C++ allows programmers to build large and complex applications in useful and efficient way . It enables programmers to improve the quality of code produced , thus making code easier to write . 


Features Of Object Oriented Programming

1. Classes And Objects

Classes

A class is collection heterogeneous collection of data. The word "heterogeneous" means class consist of data of different data-types binded together in single entity.


A class is a user defined data type which holds both the data and function. The data inside the class are called member data and the functions are called member function . 

Objects

An Object is an entity that has state, behavior and identity. Objects are used to model real world entities that we find in everyday life . Some common examples of objects are book, clock, apple, car etc .

Every Object will have data structures called attributes and behaviour called operations . Here, behaviour are functions defined in classes of which object is made . These functions defined the code to be executed or task to be performed.


EXAMPLE :-


Class My-Class

{

public :
char name [ 20 ];
int age ;
int salary ;

public :
void getdata ( ) ;
void showdata ( );
};

void main ( ) 
{
My-Class My-obj ;               // Creation of object of class My-Class
getch ( ) ; 
}





2. Encapsulation 


Data Encapsulation is a mechanism that binds together data and functions in single entity. OOPS provide this feature this was not availaible in C programming language . Data Encapsulation generally provide the feature to contains both data members and member functions in single entity called class. 

Class My-Class
{
public :
char name [ 20 ];                  // Data Members 
int age ;
int salary ;                                       
                                                          + public :
void getdata ( ) ;                  // Member Functions
void showdata ( );
};


3. Data Hiding


Data Hiding can be defined as mechanism of hiding the data of class from outside world means from other classes or ouside class so that any access to class intentionally or unintentionally cannot access the data . The data can only be accessed only through the object of the class.

Data Hiding is mainly implemented by using Access specifiers . The main access-specifiers used in  
C++ are :-

* Private :- If a variable is declared with access-specifier then It is private data member of that class  and it cannot be accessed outside class directly . For Accessing Private data member outside class we have to use these Private data member in public Member function and then by calling these member function with help of object we can in this way inderectly access Private members



* Public :- Public Data-Members and Member-Function have Lifetime access through the program Execution . The variable that are declared as public can be directly accessed outside the class they belong to . They can be used outside class by calling them through object of that class .Public data members have less security as compared to Private as these can be accessed outside class .

* Protected :- Protected Data members and Member-Functions are used mainly in case of Inheritance. In inheritance if data-member is declared as Protected then it can be accessed through public Member function in Derived class and If this class is inherited by another class then that derived class can also used this protected member


4. Inheritance 

Inheritance is most powerful feature of Object Oriented Programming after the concept of Classes and objects . Inheritance is the process of creating a new class, called derived class from existing class called Base class The Derived class inherits some or all the traits from base class and also add new features to derived class . The base class is class is remained unchanged during this process . 

Inheritance Consist of Following Types :-

* Single Inheritance
* Multiple Inheritance
* Multilevel Inheritance
* Hierarchical Inheritance
* Hybrid Inheritance




5. Polymorphism 

Polymorphism is a very powerful concept that is used for allowing designing of complex applications . The word Polymorphism is composed of two words "poly" + "morphism" . The word "Poly" means many and "morphism" means forms . So, Polymorphism means the ability to take many forms but technically different tasks . In other words, Polymorphism can also be defined as one interface that can be used to perform related but different tasks . 

Polymorphism has two types :-

1. Compile Time Polymorphism :- It can be done by :-

* Function Overloading :- The function overloading is the concept of using no of functions that perform different types of tasks But using same name for all functions . The same function can be used for all functions But they should be defferenciate by passing arguments of different data-types in each function.



* Function overloading :- It is process of performing general or comples Arithmetic or other operations on Data of Non-Basic Data-Types like addition of objects of class etc

2. Runtime Time Polymorphism :- 


* Virtual Function :- Virtual Functions are defined in base class in public section and they provide mechanism by which the derived class can override it . These functions are bound dynamically . 

Share this

0 Comment to "Introduction To C++ Programming Language"

Post a Comment