Object Oriented Programming
C++ is called object oriented programming (OOP) language because C++ language views a problem in terms of objects involved rather than the procedure for doing it.
Objects
An object is an identifiable entity with some characteristics and behaviors.
While programming using object oriented approach, the characteristics of an object are represented by its data and its behavior is represented by its functions/operators associated. Therefore, in object oriented programming object represent an entity that can store data and has its interface through functions.
Advantages
Advantages of OOP Programming are that it makes the program less complex, enhances readability. Components are reusable and extendible. Object oriented programming is always good for writing large business logics and large applications or games. Several components of a large program can be easily extended by introducing new classes or introducing new function/operators. OOPs is also very much desired for maintenance and long term support.
Disadvantages
It may not be well suit for small functional problems like adding two numbers or calculating factorial. All the member functions of an object may not be used thus it introduce code overhead.
Source code Example
Below is an example takes two input from user and calculates sum and then prints in console. First block contains source code written in structured programming language i.e. in C. Next to this is the same example written in object oriented way i.e. written in C++. Here we have introduced a class called calculator and implemented its addition operation. We have extended this class to support other operations like subtract, multiply and division.
Structured Programming code Example
Object Oriented Programming code Example
Output
Calculator demo First Operand: 1 Second Operand: 2 1 + 2 = 3
About our authors: Team EQA
You have viewed 1 page out of 62. Your C++ learning is 0.00% complete. Login to check your learning progress.