Monday, 29 September 2014

1. Introduction to C++

Chapter : 1
Introduction to C++

  1.            What is programming language?
  2.             Structured programming language
  3.            Object Oriented Programming Language
  4.             Difference between structured and Object Oriented Programming Language

What is Programming Language ? :
               Programming language is the language to communicate with the machine, particularly with computers. Programming languages can be used to write programs to control behavior of machine or to express algorithms.
Examples : C, C++, Java, C#, VB, etc.
There are two types of programming language
1.      Structured programming language                        and
2.      Object oriented programming language

Structured Programming Language :
               Structured programming (sometimes known as modular programming) is a subset of procedural programming that enforces a logical structure on the program being written to make it more efficient and easier to understand and modify.
Example : C, Ada, Pascal, etc.
Object Oriented Programming Language :
 Object-oriented programming (OOP) is a programming paradigm that represents the concept of "objects" that have attributes that describe the objects characteristics and related methods (Functionality). Objects, which are usually instance of classes, are used to interact with one another to design applications and computer programs
   Definition :    Languages (Programming Language) which follows object oriented programming (OOP) paradigm are known as Object Oriented Programming Languages.
   Examples : C++, Java, C#, Ruby, Python, etc.
               In object oriented programming language model organized around object and data rather than procedures and logic.

            When we consider a C++ program, it can be defined as a collection of objects that communicate via invoking each other's methods. Let us now briefly look into what do class, object, methods and instant variables mean.

·         Object        :        Object is an instance of class, having its own set of attributes (or characteristics or data members or member variable or instant variable ) and behavior (or functionality or member functions or methods)
·         Class         :        Class can be defined as a template/blueprint that describes the attributes and behavior.  Class is combination of attributes and behavior.

·         Attributes      :       Each class has set of attributes (or characteristics or data member or instant variable). Each object has its own unique set of attributes. An object's state is created by the values assigned to these instant variables.


·         Method (Or Function or Behavior)         :          A class can contain many methods. Objects are communicates throw methods. It is in methods where the logics are written, data is manipulated and all the actions are executed.
Class and Object

Characteristics of Object Oriented Programming Language – 
              
                 there are following characteristics of programming language
·         Encapsulation :                                                                                                                                                                                 Encapsulation is binding of attributes (Characteristics) and behavior (functions) and keeping data safe from outside.         
                                                           Data encapsulation is the mechanism to bundling the attributes and behavior in a single capsule that is class and keeping them safely and securely from outside interfaces. Data hiding is the mechanism to hide internal object details (data members) safely and securely from outside interfaces.
·          Abstraction :  
                                   Data abstraction refers to, providing only essential information to the outside world and hiding their background details, i.e., to represent the needed information in program without presenting the details.
                                   Data abstraction is mechanism of exposing only the interfaces and hiding the implementation details from the user. The ability to represent data at a very conceptual level without any details is known as data abstraction.
      (Note - Any C++ program where you implement a class with public and private members are an example of data encapsulation and data abstraction.)
·         Inheritance :
                                    This is the process by which a class can be derived from a base class with all features of base class and some of its own. This increases code re-usability.
                                      Inheritance allows us to define a class which is derived from another class, which makes it easier to create and maintain an application. This also provides an opportunity to reuse the code functionality and fast implementation time. We can inherit/derived one or more classes from one/more base classes.
Base Class : Base class is also known as parent class, the class from which we derive/inherit a child                   class
Derive Class : Derive class is also known as child class, the class which we derive from base class/                      parent class.

Types of Inheritance :  In C++, there are five types of inheritance

1.      Single Inheritance
2.      Multiple Inheritance
3.      Multi Level Inheritance
4.      Hierarchical Inheritance
5.      Hybrid Inheritance


Single Inheritance : In single inheritance we derived single class from single base class
Single Inheritance
        In above example we derive a child class student from base class person

        Multiple Inheritance : In multiple inheritance we derived single class from more than one base class.
Multiple Inheritance
         In above example we derive a class Researcher From two base classes Student and Employee. 

         Multilevel Inheritance :  In multilevel inheritance we derived a class from base class which is derived 
         from another base class.
Multilevel Inheritance
         In above example we derive BCA_Student Class from Student class, but student class itself is a derived 
         class which is derives from person class.
         Hierarchical Inheritance  :  In hierarchical Inheritance we derived multiple classes from a single base 
         class.
Hierarchical Inheritance

        Hybrid Inheritance : Hybrid Inheritance is combination of one or more type of inheritance. 


·         Polymorphism : 
                                     Ability to take more than one form. (example – function overloading, operator overloading, etc.)
                                                               The word polymorphism means many forms. In object oriented programming language the ability to take more than one form is known as polymorphism. Performing different functionality/operations using same function/operator.
       
      Example : 


  •        Operator overloading (We use same operator to perform different operations)- we can use + operator to add two int numbers, two float numbers and we can also add objects of same  class.
  •        Function overloading (We use same function to perform different functionality) - we can  use area() function to calculate area of circle as well as area of rectangle.

           
Difference between Structured and Object Oriented Programming Language :
The difference between Structured Programming language and Object Oriented Programming language are:-
Structured Programming Language 
1.      Follow top-down approach to program design.
2.      Data and Functions don’t tide with each other.
3.      Large programs are divided into smaller self-contained program segment known as functions.
4.      Data moves openly around the system from function to function.
5.      Functions are dependent so re-usability is not possible

Object Oriented Programming Language
            1.      Follow bottom-up approach in program design.
            2.        Functions and data are tied together.
            3.       Programs are divided into entity called Objects.
            4.     Data is hidden and can’t be accessed by the external world
5.       Functions are not dependent so reusability is possible

      Object Oriented Programming is more powerful than Structured Programming, as we can see         above, we can re-use the code, Data is safe as it is hidden etc. in Object Oriented Programming.

          C ++ Programming Language :

             C++ is a middle level programming language, developed by Bjarne Strostrup, starting in 1979 at     AT & T’s Bell Lab in Murray Hill, New Jersey.
C++ is super-set of C language, with the Object Oriented feathers of Simula-67, originally named as C with Classes but later it was renamed as C++ in 1993.
C++ is a statistically typed, compiled, general-purpose, case sensitive, free-form programming language that supports procedural, object oriented and generic programming. (Note : A programming language is said to use static typing when type checking is performed during compile-time)
C++ is known as middle level language, because it is shows comprise a combination of both high-level and low-level languages.
C++ fully supports object-oriented programming, including four pillars of object-oriented development – Encapsulation, Inheritance, Polymorphism, and Abstraction.




4 comments: