C++ Presentation 3
C++ Presentation 3
Institute of Technology
Department of Biomedical Engineering
6 Data Control the data and functions of data can move freely
an object act like a because each
single entity so function contains
accessibility is limited to different data.
the member functions of
the same class.
Cont.
NO. FEATURES OOP POP
7 Data hiding Is possible in OOP. No easy way for data
hiding.
8 Process follows a bottom-up It takes a top-down
approach for designing a approach to design a
program program
9 Program Is divided into objects Is divided into small
depending on the chunks based on the
problem. functions.
10 Examples Commonly used Commonly used
languages are C++, languages are Pascal
Java, VB.NET and Fortran.
Main Features of OOP
• The Objects Oriented programming
language supports all the features of
normal programming languages.
• In addition it supports some
important concepts and terminology
which has made it popular among
programming methodology.
Cont.
• Encapsulation:
• Incorporation into a class of data &
operations in one package
• Data can only be accessed through
that package
• “Information Hiding”
Cont.
• Inheritance
• Allows programmers to create new
classes based on an existing class
• Methods and attributes from the
parent class are inherited by the
newly-created class
• New methods and attributes can be
created in the new class, but don’t
affect the parent class’s definition
Cont.
• Data Abstraction
Data Abstraction helps to deal with
objects since their important features
and ignore all other details.
Cont.
• Polymorphism
• Creating methods which describe the
way to do some general function
(Example: The “drive” method in the
automobile class)
• Polymorphic methods can adapt to
specific types of objects.
Cont.
• Reusability
• This usage is achieved by the above
explained terminology called as
inheritance.
• Reusability is nothing but re- usage
of structure without changing the
existing one but adding new features
or characteristics to it.
Cont.
• Data Hiding
• The data is hidden inside the class by declaring it
as private inside the class.
• When data or functions are defined as private it
can be accessed only by the class in which it is
defined.
• Object Oriented programming gives importance
to protecting data which in any system.
• This is done by declaring data as private and
making it accessible only to the class in which it
is defined. This concept is called data hiding.
Overview of Object and Class
• Object – An object is basically a
self-contained entity that
accumulates both data and
procedures to manipulate the data.
Objects are merely instances of
classes.
Cont.
• Class – A class, in simple terms, is a
blueprint of an object which defines
all the common properties of one or
more objects that are associated
with it. A class can be used to define
multiple objects within a program.
Cont.
• An Object is an instance of a Class.
When a class is defined, no memory
is allocated but when it is
instantiated (i.e. an object is
created) memory is allocated. A
class is defined in C++ using
keyword class followed by the
name of class.
Cont.
• A class in C++ is the building block,
that leads to Object-Oriented
programming. It is a user-defined
data type, which holds its own data
members and member functions,
which can be accessed and used by
creating an instance of that class.
Cont.
• An object contains properties and
methods which are needed to make
a certain type of data useful. An
object’s properties are what it knows
and its methods are what it can do.
Cont.
• A class is a concept used in object
oriented programming languages
such as C++, PHP, and JAVA. It
provides values for state (member
variables) and implementations of
behavior (member functions,
methods) in programs.
Cont.
• A class is said to be a blueprint of an
object. It is an extensible guide used
for creating objects; it is a subroutine
that creates an object. A class does
not represent the object; it represents
all the information and methods an
object should have. One class can be
used to instantiate multiple objects. It
is considered to be an extended TYPE
declaration.
Cont.
Object Class
Definition An object is defined A class is used in OOP
as any entity that to describe one or
can be utilized by more objects.
using commands in
OOP.
Variables It is a variable. It is the type.
Concept It is an instantiation It is an expanded
of class. concept of data
structures.
Memory Memory is allocated. No memory is
allocated.
Cont.
Object Class
Identifier The ‘object_names’ The ‘class_name’ is a
is an optional list of valid identifier for the
names for objects of class.
this class.
Purpose Data abstraction and grouping of data
further inheritance
Example 1
Output
Example 2
Output
Example 3
Output
References
Object Oriented Programming in C++,
Robert Lafore
Absolute C++, 4th Ed, Walt Savitch, Addison
Wesley, 2009
Programming with Schaum Outlines 2nd
Edition
Thank You