C++ is an Object
Oriented Programming Languages (OOPL). It was developed by Mr.Bjarne Stroustrup
in 1980 at Bell Laboratories. It is an extension of C-Language. It was
initially named as ‘C with Classes’.
NEED
FOR OOP APPROACH:
Object Oriented Programming is an approach to program
organization and development that attempts to eliminate the pitfalls of
Procedure Oriented Programming
With advent of languages such as C became
very popular and it was the main technic 0f 1980’s.
Structured Programming was a popular tool for
developing moderately complex programs
As the size and complexity of program
increase the structured programming approach failed in developing big tree
programs that are easy to maintain and reusable.
Once the program exceeds 20,000 lines of code
it become very difficult to group the essence of the program in totality.
Out of the total cost of software around 90%
is spent on debugging and maintenance
Only 2% of software objects undertaken by U.S.
Defence Department in 1970’s worked successfully.
This increasing complexity of programs as necessitated for
the development of new programming approach of OOP. It is such an approach that
eliminates the drawback of Structured Programming Approach.
MAIN
ADVANTAGE OF OOP OVER SOP
In
SOP, most of the data is created as global; hence all the functions in
the program can access the data. If there are 100 of functions if any function
mismanipulates the data by mistake it will be very difficulty to check the code
of all these functions to find out the error. As the complexity of the program
increases it will become almost impossible to find out the bugs.
Procedure Oriented Approach
In OOP, most of the data will be
private only a few functions, can manipulate the data. The data and functions
that operate on the data will be encapsulated as a single unit and such a unit
is called as Object. If any outside function want to access the data it
has to make use of the few functions, which can access the data i.e., the
outside functions cannot directly access the data. In this approach, if data is
mismanipulated by mistake we need to check the code of only a few functions.
Therefore, the debugging process is considerably reduced.
Object Oriented Approach
DIFFERENCES BETWEEN POP AND
OOP
Procedure Oriented Programming
|
Object Oriented Programming
|
Emphasis is on doing things
|
Emphasis is on data rather than procedures
|
Programs are divided into small things
known as functions
|
Programs are divided into what are known as
Objects
|
Data move openly around the system from
function to function
|
Data is hidden and cannot be accessed by
external functions
|
Debugging Process is very difficult
|
Debugging Process is very easy
|
Follows top-down approach in program design
|
Follows bottom-up approach in program
design
|
Most of the functions share global data
|
The data of an object can be accessed only
by the functions that are associated with it
|
Reference
Variable: It Provides an alias for previously defined
variable.
Ex:- int total=500;
Int &sum=total;
Syn: datatype
&ref_name=var_name;
Both variables refer
to the same data in the memory. If a change made to 1 variable will effect
another variable.
Operators in
C++:
>>->Extraction
<<->Insertion
:: ->scope resolution
.
:->Inheritance
Operator
&->Reference
Operator
new
delete
->*àPointer to
member
INTRODUCTION TO
C++
C++ is an OOP language developed by Bjarne Stroustrup of
Denmark at AT & T Bell Laboratories in New Jersey, USA in 1982.Stroustrup,
an admirer of simula67 & a strong supporter
of C wanted to combine the
best of both languages & create a more powerful language that support
Object – Oriented Programming features.
DIFFERENCES BETWEEN C AND C++
C
|
C++
|
In
C, main function return a value of void type
|
In
C++, it returns a value of integer type
|
Prototyping
for functions and procedures are optional
|
It
is an strictly typed language which makes compulsory for specifying prototype
and procedures
|
C
doesn’t give importance to data
|
It
uses the concept of data hiding which restricts data to move away from the
entity definition
|
C
doesn’t support declaration of variables inline
|
It
allows inline declaration wherever the user wants
|
Extension
of source file is .c
|
Extension
of source file is .cpp
|
The
basic building block is a function
|
The
basic building block is an object
|
C
does not support future extension
|
It
supports the concept of Inheritance through which new features can be added
without redeclaring the existing one
|
C
doesn’t support multiple definition for the same name which is basically
overloading
|
C++
supports overloading both for a function and operators.
|
FEATURES OF OBJECT ORIENTED
LANGUAGE- Emphasis is on data rather than procedure.
- Programs are divided into what are known as
objects.
- Data structures are designed such that they
characterize the objects.
- Functions that operate on the data of an
object are tied together in the data structure.
- Data is hidden and cannot be accessed by
external functions.
- Objects may communicate with each other
through functions.
- New data and functions can be easily added
whenever necessary.
- Follows bottom-up approach in program design.
BENEFITS
OF OBJECT ORIENTED PROGRAMMING (OOP)
- 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.
- Since a class defines only the data it needs to
be concerned with, when an instance of that class (an object) is run, the code
will not be able to accidentally access other program data. This characteristic
of data hiding provides greater system security and avoids unintended data
corruption.
- The
definition of a class is reusable 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 any new data type that is
not already defined in the language itself.
- We can
build programs from the standard working modules that communicate with one
another, rather than having to start writing the code from scratch. This leads
to saving of development time and higher productivity.
- It is
easy to partition the work in a project based on objects.
- Object-Oriented
systems can be easily upgraded from small to large systems.
- Message
passing techniques for communication between objects makes the interface
descriptions with external systems much simpler.
- The
principle of data hiding helps the programmer to build secure programs that
cannot be invaded by code in other parts of the program.
- Software
complexity can be easily managed.
APPLICATIONS OF OOPS
- Real – time Systems
- Simulation and modeling
- Object – Oriented databases
- Hypertext, hypermedia and expertext
- Artificial Intelligence
- Neural works
- CIM/CAM/CAD systems
- Office automation systems
- Decision support
- Parallel Programming