Thursday, February 10, 2011

Introduction of C++


Basic Notes on C++:

Ø  It was developed by Bjarne Stroustrup at AT&T Lab in the early 1980’s.

Ø  Initially, it was called “C with classes”. After 1983, it was being called as C++ (C=C+1 or C+=1) i.e. incremented version of C.

Ø  C++ is superset of C. All C programs are also C++ programs but not vice versa.

Ø  C++ supports Object Oriented Programming (OOP).

1.1 Procedural Programming Paradigm

The programming paradigm is:
      Decide which procedures you want;
    use the best algorithms you can find.
The traditional programming languages like C, Fortran, Pascal, and Basic are Procedural Programming Languages. A procedural program is written as a list of instructions, telling the computer, step-by-step, what to do: Get two numbers, add them and display the sum. The problem is divided into a number of functions. The primary focus of programmer is on creating functions. While developing functions, very little attention is given to data that are being used by various functions.
                       Procedural programming is fine for small projects. It does not model real world problems well. This is because functions are action oriented and does not really correspond to the elements of the problems.

 Basic Characteristics:
Ø  Emphasis in on algorithm (step by step description of problem solving) to solve a problem. Each step of algorithm is converted into corresponding instruction or code in language.
Ø  Large program is divided into a number of functions, with each function having a clearly defined purpose and a clearly defined interface to other functions in the program. The integration of these functions constitutes a whole program.
Ø  Uses top-down approach in program design. In top-down programming, we conceive of the program as a whole as a process to be discovered. We think of the problem as a whole as a process to be decomposed. We decompose the problem into sub-problems with the following three characteristics:
                                i.      The sub-problem stands alone as a problem in its own right
                              ii.      The sub-problem appears to be solvable, though we may not have an immediate solution, and
                            iii.      If all of the sub-problems in the decomposition are solvable, then we know a composition that will put the solutions of the sub-problems together as a solution of the original
Ø  In multi-function program, some important and used by more functions data items are placed as global so that they may be accessed by all the functions. Global data are more vulnerable. Each function may have its local data.
Ø  Data move openly around the system from function to function. Information is passed between functions using parameters or arguments.

Object-Oriented Programming Paradigm

In Object-Oriented Programming, a program is decomposed into a number of entities called objects. Data and the functions that operate on that data are combined into that object. OOP mainly focus on data rather than procedure. It considers data as critical element in the program development and does not allow it to flow freely around the system. It ties data more closely to the functions that operate on it and protects it from accidental modification from outside the functions.

Basic Characteristics:
Ø  Emphasis is on the data rather than procedure. It focuses on security of data from unauthorized modification in the program.
Ø  A program is divided into a number of objects. Each object has its own data and functions. These functions are called member functions and data are known as member data.
Ø  Data is hidden and can no be accessed by external functions.
Ø  Follows bottom-up approach in program design. The methodology for constructing an object-oriented program is to discover the related objects at first. Then, appropriate class is formed for similar objects. The different classes and their objects constitute a program.
Ø  Object may communicate with each other through functions.
Ø  New data and functions can be easily added whenever necessary.
   Ø  Once a class has been written, created and debugged, it can be used in a number of programs    without modification i.e. a same code can be reused. It is similar to the way a library functions in a procedural  language.   

No comments:

Post a Comment