Вы находитесь на странице: 1из 8

Report form 2019/2020

Student’s name: Ibrahim Hasan Tahir.


Subject: C++ OOP and Its Uses.
Course: 1st Course.
Stage: 2nd Stage.
Lecturer name: Osama Ali Salman.
C++ is an object-oriented language which is developed by Bjarne
Stroustrup. All the concepts of object-oriented approach are very
interesting. But sometimes we get the problem in understanding the
concept and many confusion occurs when we try to understand it. Let’s
see all of the object-oriented concepts introduced in C++ with real-
world examples which provide the ease to understand the concepts of
C++.

Object-oriented C++
C++ is not a pure object-oriented language because we can write the
code without the classes. It is object-oriented because it supports the
features provided by the object-oriented approach so it is a multi-
paradigm language.

Important Concepts of Object-oriented in C++


Classes
Objects
Inheritance
Encapsulation
Abstraction
Polymorphism
Interface etc.
Are above names looking like some medicines name? Are you
frightened after reading them? Don’t worry, I will be explaining them in
the easiest way. These are main concepts which are supported by C++
to implement Object Oriented approach. All the topics are with a
suitable example which is connected with real world.

Classes
A class is a user-defined data type which includes data members and
functions. It contains a similar type of objects. It is considered as a
blueprint of the object.

Example:
When we talk about birds then that is a class and when we talk about a
particular bird like sparrow then we are talking about the object.

Objects
These are the real world entities. Who exists in the real world that is
called objects like pen, pencil etc. And its class will be stationary.

Inheritance
Inheritance is the mechanism by which you can use the existing code. It
is used to decrease the program’s length. It means you can use all the
properties of a function or a complete class by inheriting it. It is based
on parent-child relationship. Existing class considered as Parent and the
new class is considered as child class. A child class can use the functions
and variables of the parent class.

Syntax to inherit the existing class:-


class classname: access_specifier classname
Different types of Inheritance:-
Single Inheritance
Multiple Inheritance
Hierarchical Inheritance
Multilevel Inheritance
Hybrid Inheritance
Example:
To understand the concept of inheritance, please look at the parent-
child relationship in the real world. As a child can use any of the
property of the parents, similarly a child class can use all the properties
of the parent class.

Encapsulation
Encapsulation is the important concept of OOP. It binds the functions
and data together. It can be achieved by using classes with different
access specifiers.

Example:
It is similar to a capsule. A capsule contains many of the ingredients and
contains them in a single unit. So encapsulation means wrapping of
data and functions in a single unit.

Abstraction
Abstraction is used to hide the information which helps in avoiding the
interference of any external. It hides the information which is not
necessary for the user, but it performs its function as well. It is called
data hiding.

Example:
For the concept Data hiding, you can look at the fan. You just know
about the fan that it revolves and gives you the cooling without the
knowledge of internal working or mechanism of the fan, it is data
hiding. It means when the user only wants functionality only and not
interested in mechanism or information is not necessary for the user
the data hiding comes in use.

Polymorphism
Polymorphism is a combination of two words i.e Poly and morphs. Poly
means many and morph means forms. It is achieved by overloading and
overriding either it is operator overloading/overriding or function
overloading/overriding.

Different types of Polymorphism


There are two types of Polymorphism in C++:

Compile-time Polymorphism (It is achieved by overloading)


Run-time Polymorphism (It is achieved by overriding)
Example:
You can understand this concept by Switchboard. There are many
buttons but each button performs different tasks.
You can say it polymorphism. All are the buttons but working is
different, similar A function or operator has the same name but
performs a different task.

That part was describing it in real life but the next little part is what the
areas of C++ OOP will work with

Applications of Object Oriented Programming


Main application areas of OOP are:

User interface design such as windows, menu.


Real Time Systems
Simulation and Modeling
Object oriented databases
AI and Expert System
Neural Networks and parallel programming
Decision support and office automation systems etc.

Benefits of OOP:
It is easy to model a real system as real objects are represented by
programming objects in OOP. The objects are processed by their
member data and functions. It is easy to analyze the user requirements.
With the help of inheritance, we can reuse the existing class to derive a
new class such that the redundant code is eliminated and the use of
existing class is extended. This saves time and cost of program.
In OOP, data can be made private to a class such that only member
functions of the class can access the data. This principle of data hiding
helps the programmer to build a secure program that can not be
invaded by code in other part of the program.
With the help of polymorphism, the same function or same operator
can be used for different purposes. This helps to manage software
complexity easily.
Large problems can be reduced to smaller and more manageable
problems. It is easy to partition the work in a project based on objects.
It is possible to have multiple instances of an object to co-exist without
any interference i.e. each object has its own separate member data and
function.
REFERENCES
Stackoverflow.com
Scribd.com
Wikipedia.org
Tutorialink.com
Admecindia.co.in

Вам также может понравиться