SlideShare a Scribd company logo
26-07-2018 08:24:48 PM
vishnuvishnushaji5@gmail.com [1/38]
OBJECT-ORIENTED PROGRAMMING WITH C++
OBJECT-ORIENTED
PROGRAMMING WITH C++
VISHNU P S
26-07-2018 08:24:49 PM
vishnuvishnushaji5@gmail.com [2/38]
OBJECT-ORIENTED PROGRAMMING WITH C++
Procedure Oriented Programming Object Oriented Programming
Divided Into In POP, program is divided into small parts
called functions.
In OOP, program is divided into parts called
objects.
Importance In POP, Importance is not given to data but
to functions as well as sequence of actions
to be done.
In OOP, Importance is given to the data
rather than procedures or functions because
it works as a real world.
Approach POP follows Top Down approach. OOP follows Bottom Up approach.
Access Specifiers POP does not have any access specifier. OOP has access specifiers named Public,
Private, Protected, etc.
Data Moving In POP, Data can move freely from
function to function in the system.
In OOP, objects can move and communicate
with each other through member functions.
Expansion To add new data and function in POP is
not so easy.
OOP provides an easy way to add new data
and function.
26-07-2018 08:24:49 PM
vishnuvishnushaji5@gmail.com [3/38]
OBJECT-ORIENTED PROGRAMMING WITH C++
Contd…
Overloading In POP, Overloading is not possible. In OOP, overloading is possible in the form of
Function Overloading and Operator
Overloading.
Examples Example of POP are : C, VB, FORTRAN,
Pascal.
Example of OOP are : C++, JAVA, VB.NET,
C#.NET
Data Access In POP, Most function uses Global data for
sharing that can be accessed freely from
function to function in the system.
In OOP, data can not move easily from
function to function,it can be kept public or
private so we can control the access of data.
Data Hiding POP does not have any proper way for
hiding data so it is less secure.
OOP provides Data Hiding so provides more
security.
26-07-2018 08:24:49 PM
vishnuvishnushaji5@gmail.com [4/38]
OBJECT-ORIENTED PROGRAMMING WITH C++
BASIC CONCEPTS OF OBJECT-ORIENTED PROGTAMMING
OBJECTS CLASSES
DATA
ABSTRACTION
DATA
ENCAPSULATION
INHERITANCE POLIYMORPHISM
DYNAMIC
BINDING
MESSAGE
PASSING
26-07-2018 08:24:49 PM
vishnuvishnushaji5@gmail.com [5/38]
OBJECT-ORIENTED PROGRAMMING WITH C++
#include<iostream.h>
main()
{
cout<<“Hello World!”;
return 0;
}
#include<stdio.h>
int main()
{
printf(“Hello World!”);
return 0;
}
26-07-2018 08:24:49 PM
vishnuvishnushaji5@gmail.com [6/38]
OBJECT-ORIENTED PROGRAMMING WITH C++
MEMMORY ALLOCATION
STATIC DYNAMIC
 is allocated at the start of your
program
 the global variables or global
available arrays
 is allocated at runtime
 malloc(), calloc(), new
26-07-2018 08:24:49 PM
vishnuvishnushaji5@gmail.com [7/38]
OBJECT-ORIENTED PROGRAMMING WITH C++
C
•malloc()
•calloc()
C++
•new
26-07-2018 08:24:49 PM
vishnuvishnushaji5@gmail.com [8/38]
OBJECT-ORIENTED PROGRAMMING WITH C++
new
 C++ uses new operator to allocate memory dynamically at run time.
Syntax
pointer_variable = new data_type;
Example
int *p;
p = new int;
int *q = new int;
26-07-2018 08:24:49 PM
vishnuvishnushaji5@gmail.com [9/38]
OBJECT-ORIENTED PROGRAMMING WITH C++
delete
 Destroyed by using delete.
Syntax
delete pointer_variable;
Example
delete p;
delete q;
26-07-2018 08:24:49 PM
vishnuvishnushaji5@gmail.com [11/38]
OBJECT-ORIENTED PROGRAMMING WITH C++
CLASSES AND OBJECTS
CLASS OBJECT
 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
 A class is like a blueprint for 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.
26-07-2018 08:24:50 PM
vishnuvishnushaji5@gmail.com [12/38]
OBJECT-ORIENTED PROGRAMMING WITH C++
DEFINING CLASS
26-07-2018 08:24:50 PM
vishnuvishnushaji5@gmail.com [13/38]
OBJECT-ORIENTED PROGRAMMING WITH C++
DECLARING OBJECTS
When a class is defined, only the specification for the object is
defined; no memory or storage is allocated. To use the data and
access functions defined in the class, you need to create objects.
ClassName ObjectName;
26-07-2018 08:24:50 PM
vishnuvishnushaji5@gmail.com [14/38]
OBJECT-ORIENTED PROGRAMMING WITH C++
ACCESSING DATA MEMBERS AND MEMBER FUNCTIONS
ACCESSING DATA MEMBERS
The data members and member functions of class can be accessed using the dot(‘.’)
operator with the object. For example if the name of object is obj and you want to access
the member function with the name printName() then you will have to write
obj.printName() .
The public data members are also accessed in the same way given however the private data members
are not allowed to be accessed directly by the object. Accessing a data member depends solely on the
access control of that data member.
26-07-2018 08:24:50 PM
vishnuvishnushaji5@gmail.com [15/38]
OBJECT-ORIENTED PROGRAMMING WITH C++
// C++ program to demonstrate
// accessing of data members
#include <bits/stdc++.h>
using namespace std;
class Geeks
{
// Access specifier
public:
// Data Members
string name;
// Member Functions()
void printname()
{
cout << “Name is: " << name;
}
};
int main() {
// Declare an object of class
geeks
Geeks obj1;
// accessing data member
obj1.name = "Abhi";
// accessing member function
obj1.printname();
return 0;
}
26-07-2018 08:24:50 PM
vishnuvishnushaji5@gmail.com [17/38]
OBJECT-ORIENTED PROGRAMMING WITH C++
The capability of a class to derive properties
and characteristics from another class is
called Inheritance. Inheritance is one of the
most important feature of Object Oriented
Programming.
INHERITANCE IN C++
Sub Class :
The class that inherits properties from
another class is called Sub class or
Derived Class.
Super Class :
The class whose properties are inherited
by sub class is called Base Class or Super
class.
26-07-2018 08:24:52 PM
vishnuvishnushaji5@gmail.com [18/38]
OBJECT-ORIENTED PROGRAMMING WITH C++
Why and when to use inheritance?
26-07-2018 08:24:52 PM
vishnuvishnushaji5@gmail.com [19/38]
OBJECT-ORIENTED PROGRAMMING WITH C++
26-07-2018 08:24:52 PM
vishnuvishnushaji5@gmail.com [20/38]
OBJECT-ORIENTED PROGRAMMING WITH C++
Implementing inheritance in C++
For creating a sub-class which is inherited from the base class we have to follow the below
syntax.
class subclass_name : access_mode base_class_name
{
//body of subclass
};
subclass_name is the name of the sub class, access_mode is the mode in which you
want to inherit this sub class for example: public, private etc. and base_class_name is
the name of the base class from which you want to inherit the sub class.
26-07-2018 08:24:52 PM
vishnuvishnushaji5@gmail.com [21/38]
OBJECT-ORIENTED PROGRAMMING WITH C++
// C++ program to demonstrate
implementation
// of Inheritance
#include <iostream.h>
using namespace std;
//Base class
class Parent
{
public:
int id_p;
};
// Sub class inheriting from Base
Class(Parent)
class Child : public Parent
{
public:
int id_c;
};
//main function
int main()
{
Child obj1;
// An object of class child has
all data members
// and member functions of class
parent
obj1.id_c = 7;
obj1.id_p = 91;
cout << "Child id is "
<< obj1.id_c << endl;
cout << "Parent id is "
<< obj1.id_p << endl;
return 0;
}
26-07-2018 08:24:52 PM
vishnuvishnushaji5@gmail.com [22/38]
OBJECT-ORIENTED PROGRAMMING WITH C++
Modes of Inheritance
Public mode:
If we derive a sub class from a public
base class. Then the public member
of the base class will become public
in the derived class and protected
members of the base class will
become protected in derived class.
Private members of the base class
will never get inherited in sub class.
Protected mode:
If we derive a sub class from a
Protected base class. Then both
public member and protected
members of the base class will
become protected in derived class.
Private members of the base class
will never get inherited in sub class.
Private mode:
If we derive a sub class from a
Private base class. Then both public
member and protected members of
the base class will become Private in
derived class. Private members of
the base class will never get
inherited in sub class.
26-07-2018 08:24:52 PM
vishnuvishnushaji5@gmail.com [23/38]
OBJECT-ORIENTED PROGRAMMING WITH C++
The below table summarizes the above three modes and shows the access specifier of the members of base
class in the sub class when derived in public, protected and private modes:
26-07-2018 08:24:52 PM
vishnuvishnushaji5@gmail.com [24/38]
OBJECT-ORIENTED PROGRAMMING WITH C++
TYPES OF INHERITANCE IN C++
Single Inheritance Multiple Inheritance
Multilevel Inheritance Hierarchical Inheritance
Hybrid (Virtual) Inheritance
26-07-2018 08:24:52 PM
vishnuvishnushaji5@gmail.com [25/38]
OBJECT-ORIENTED PROGRAMMING WITH C++
Single Inheritance
In single inheritance, a class is allowed to inherit from only one class. i.e.
one sub class is inherited by one base class only.
26-07-2018 08:24:52 PM
vishnuvishnushaji5@gmail.com [26/38]
OBJECT-ORIENTED PROGRAMMING WITH C++
Multiple Inheritance
Multiple Inheritance is a feature of C++ where a class can inherit from more
than one classes. i.e one sub class is inherited from more than one base
classes.
26-07-2018 08:24:52 PM
vishnuvishnushaji5@gmail.com [27/38]
OBJECT-ORIENTED PROGRAMMING WITH C++
Multilevel Inheritance
In this type of inheritance, a derived class is created from another derived
class.
26-07-2018 08:24:52 PM
vishnuvishnushaji5@gmail.com [28/38]
OBJECT-ORIENTED PROGRAMMING WITH C++
Hierarchical Inheritance
In this type of inheritance, more than one sub class is inherited from a
single base class. i.e. more than one derived class is created from a single
base class.
26-07-2018 08:24:52 PM
vishnuvishnushaji5@gmail.com [29/38]
OBJECT-ORIENTED PROGRAMMING WITH C++
Hybrid (Virtual) Inheritance
Hybrid Inheritance is implemented by combining more than one type of
inheritance. For example: Combining Hierarchical inheritance and Multiple
Inheritance.
26-07-2018 08:24:53 PM
vishnuvishnushaji5@gmail.com [31/38]
OBJECT-ORIENTED PROGRAMMING WITH C++
DYNAMIC BINDING
• THE COMPILER MATCHES THE FUNCTION CALL WITH THE CORRECT
FUNCTION DEFINITION AT RUNTIME. IT IS ALSO KNOWN AS LATE BINDING
OR RUNTIME BINDING.
• IN LATE BINDING, THE COMPILER IDENTIFIES THE TYPE OF OBJECT AT
RUNTIME AND THEN MATCHES THE FUNCTION CALL WITH THE CORRECT
FUNCTION DEFINITION.
• THIS CAN BE ACHIEVED BY DECLARING A VIRTUAL FUNCTION.
26-07-2018 08:24:53 PM
vishnuvishnushaji5@gmail.com [32/38]
OBJECT-ORIENTED PROGRAMMING WITH C++
#include <iostream>
using namespace std;
class Animals
{
public:
void sound()
{
cout << "This is parent class" <<
endl;
}
};
class Dogs : public Animals
{
public:
void sound()
{
cout << "Dogs bark" << endl;
}
};
int main()
{
Animals *a;
Dogs d;
a= &d;
a -> sound(); // early binding
return 0;
}
26-07-2018 08:24:53 PM
vishnuvishnushaji5@gmail.com [33/38]
OBJECT-ORIENTED PROGRAMMING WITH C++
FRIEND CLASS
A friend class can access private and protected members of other class in which it is
declared as friend. It is sometimes useful to allow a particular class to access private
members of other class. For example a LinkedList class may be allowed to access private
members of Node.
FRIEND FUNCTION
Like friend class, a friend function can be given special grant to access private and
protected members. A friend function can be:
a) A method of another class
b) A global function
26-07-2018 08:24:53 PM
vishnuvishnushaji5@gmail.com [34/38]
OBJECT-ORIENTED PROGRAMMING WITH C++
class Node
{
private:
int key;
Node *next;
/* Other members of Node Class */
friend class LinkedList; // Now class
LinkedList can
// access
private members of Node
}
class Node
{
private:
int key;
Node *next;
/* Other members of Node Class */
friend int LinkedList::search(); // Only
search() of linkedList
// can
access internal members
};
FRIEND CLASS FRIEND FUNCTION
26-07-2018 08:24:53 PM
vishnuvishnushaji5@gmail.com [36/38]
OBJECT-ORIENTED PROGRAMMING WITH C++
ENCAPSULATION IN C++
Encapsulation is defined as wrapping up of data and information under a single unit
(Encapsulation is defined as binding together the data and the functions that manipulates
them.)
Consider a real life example of encapsulation, in a company there
are different sections like the accounts section, finance section,
sales section etc. The finance section handles all the financial
transactions and keep records of all the data related to finance.
Similarly the sales section handles all the sales related activities
and keep records of all the sales. Now there may arise a situation
when for some reason an official from finance section needs all the
data about sales in a particular month. In this case, he is not
allowed to directly access the data of sales section. He will first
have to contact some other officer in the sales section and then
request him to give the particular data. This is what encapsulation
is. Here the data of sales section and the employees that can
manipulate them are wrapped under a single name “sales section”.
26-07-2018 08:24:53 PM
vishnuvishnushaji5@gmail.com [37/38]
OBJECT-ORIENTED PROGRAMMING WITH C++
TEMPLATES IN C++
26-07-2018 08:24:53 PM
vishnuvishnushaji5@gmail.com [38/38]
OBJECT-ORIENTED PROGRAMMING WITH C++
TEMPLATES IN C++
 Template is simple and yet very powerful tool in C++.
 The simple idea is to pass data type as a parameter so that we don’t need to write same
code for different data types.
 For example a software company may need sort() for different data types. Rather than
writing and maintaining the multiple codes, we can write one sort() and pass data type as a
parameter.
C++ adds two new keywords to support templates: ‘template’
CLASS TEMPLATES
FUNCTION TEMPLATES
26-07-2018 08:24:53 PM
vishnuvishnushaji5@gmail.com [39/38]
OBJECT-ORIENTED PROGRAMMING WITH C++
How templates work?
Templates are expended at compiler time.
This is like macros. The difference is, compiler
does type checking before template
expansion. The idea is simple, source code
contains only function/class, but compiled
code may contain multiple copies of same
function/class.
26-07-2018 08:24:54 PM
vishnuvishnushaji5@gmail.com [41/38]
OBJECT-ORIENTED PROGRAMMING WITH C++
C++ Exception Handling
 An exception is a problem that arises during the execution of a program.
 A C++ exception is a response to an exceptional circumstance that arises while a
program is running, such as an attempt to divide by zero.
 Exceptions provide a way to transfer control from one part of a program to another.
 C++ exception handling is built upon three keywords: try, catch, and throw.
26-07-2018 08:24:54 PM
vishnuvishnushaji5@gmail.com [42/38]
OBJECT-ORIENTED PROGRAMMING WITH C++
 throw − A program throws an exception when a problem shows up. This is done using
a throw keyword.
 catch − A program catches an exception with an exception handler at the place in a
program where you want to handle the problem. The catch keyword indicates the
catching of an exception.
 try − A try block identifies a block of code for which particular exceptions will be
activated. It's followed by one or more catch blocks.
26-07-2018 08:24:54 PM
vishnuvishnushaji5@gmail.com [43/38]
OBJECT-ORIENTED PROGRAMMING WITH C++
REFERENCE
https://www.tutorialspoint.com/
https://www.geeksforgeeks.org/
https://en.wikipedia.org/wiki/Main_Page

More Related Content

What's hot

C++ classes
C++ classesC++ classes
C++ classes
imhammadali
 
Object oriented concepts
Object oriented conceptsObject oriented concepts
Object oriented concepts
Pranali Chaudhari
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
Bhushan Nagaraj
 
Inheritance : Extending Classes
Inheritance : Extending ClassesInheritance : Extending Classes
Inheritance : Extending Classes
Nilesh Dalvi
 
C++ Object oriented concepts & programming
C++ Object oriented concepts & programmingC++ Object oriented concepts & programming
C++ Object oriented concepts & programming
nirajmandaliya
 
Support for Object-Oriented Programming (OOP) in C++
Support for Object-Oriented Programming (OOP) in C++Support for Object-Oriented Programming (OOP) in C++
Support for Object-Oriented Programming (OOP) in C++
Ameen Sha'arawi
 
Oop c++class(final).ppt
Oop c++class(final).pptOop c++class(final).ppt
Oop c++class(final).ppt
Alok Kumar
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
Nilesh Dalvi
 
Classes and data abstraction
Classes and data abstractionClasses and data abstraction
Classes and data abstraction
Hoang Nguyen
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
HalaiHansaika
 
Static Data Members and Member Functions
Static Data Members and Member FunctionsStatic Data Members and Member Functions
Static Data Members and Member Functions
MOHIT AGARWAL
 
Chapter 06 constructors and destructors
Chapter 06 constructors and destructorsChapter 06 constructors and destructors
Chapter 06 constructors and destructors
Praveen M Jigajinni
 
Data abstraction and object orientation
Data abstraction and object orientationData abstraction and object orientation
Data abstraction and object orientation
Hoang Nguyen
 
C++ oop
C++ oopC++ oop
C++ oop
Sunil OS
 
Object oriented programming using c++
Object oriented programming using c++Object oriented programming using c++
Object oriented programming using c++
Hoang Nguyen
 
Programming in c++
Programming in c++Programming in c++
Programming in c++
Baljit Saini
 
OOPS Basics With Example
OOPS Basics With ExampleOOPS Basics With Example
OOPS Basics With Example
Thooyavan Venkatachalam
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
FALLEE31188
 
Implementation of oop concept in c++
Implementation of oop concept in c++Implementation of oop concept in c++
Implementation of oop concept in c++
Swarup Kumar Boro
 
OOPS IN C++
OOPS IN C++OOPS IN C++
OOPS IN C++
Amritsinghmehra
 

What's hot (20)

C++ classes
C++ classesC++ classes
C++ classes
 
Object oriented concepts
Object oriented conceptsObject oriented concepts
Object oriented concepts
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
 
Inheritance : Extending Classes
Inheritance : Extending ClassesInheritance : Extending Classes
Inheritance : Extending Classes
 
C++ Object oriented concepts & programming
C++ Object oriented concepts & programmingC++ Object oriented concepts & programming
C++ Object oriented concepts & programming
 
Support for Object-Oriented Programming (OOP) in C++
Support for Object-Oriented Programming (OOP) in C++Support for Object-Oriented Programming (OOP) in C++
Support for Object-Oriented Programming (OOP) in C++
 
Oop c++class(final).ppt
Oop c++class(final).pptOop c++class(final).ppt
Oop c++class(final).ppt
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
Classes and data abstraction
Classes and data abstractionClasses and data abstraction
Classes and data abstraction
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
 
Static Data Members and Member Functions
Static Data Members and Member FunctionsStatic Data Members and Member Functions
Static Data Members and Member Functions
 
Chapter 06 constructors and destructors
Chapter 06 constructors and destructorsChapter 06 constructors and destructors
Chapter 06 constructors and destructors
 
Data abstraction and object orientation
Data abstraction and object orientationData abstraction and object orientation
Data abstraction and object orientation
 
C++ oop
C++ oopC++ oop
C++ oop
 
Object oriented programming using c++
Object oriented programming using c++Object oriented programming using c++
Object oriented programming using c++
 
Programming in c++
Programming in c++Programming in c++
Programming in c++
 
OOPS Basics With Example
OOPS Basics With ExampleOOPS Basics With Example
OOPS Basics With Example
 
C++ classes tutorials
C++ classes tutorialsC++ classes tutorials
C++ classes tutorials
 
Implementation of oop concept in c++
Implementation of oop concept in c++Implementation of oop concept in c++
Implementation of oop concept in c++
 
OOPS IN C++
OOPS IN C++OOPS IN C++
OOPS IN C++
 

Similar to Object Oriented Programming With C++

4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT
Ajay Chimmani
 
OBJECT ORIENTED PROGRAMING IN C++
OBJECT ORIENTED PROGRAMING IN C++ OBJECT ORIENTED PROGRAMING IN C++
OBJECT ORIENTED PROGRAMING IN C++
Dev Chauhan
 
C++ largest no between three nos
C++ largest no between three nosC++ largest no between three nos
C++ largest no between three nos
krismishra
 
Oop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer MelayiOop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer Melayi
Muhammed Thanveer M
 
I assignmnt(oops)
I assignmnt(oops)I assignmnt(oops)
I assignmnt(oops)
Jay Patel
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
Army Public School and College -Faisal
 
Creating sub zero dashboard plugin for apex with google
Creating sub zero dashboard plugin for apex with googleCreating sub zero dashboard plugin for apex with google
Creating sub zero dashboard plugin for apex with google
Roel Hartman
 
Java programming concept
Java programming conceptJava programming concept
Java programming concept
Sanjay Gunjal
 
Mca 2nd sem u-2 classes & objects
Mca 2nd  sem u-2 classes & objectsMca 2nd  sem u-2 classes & objects
Mca 2nd sem u-2 classes & objects
Rai University
 
Bca 2nd sem u-2 classes & objects
Bca 2nd sem u-2 classes & objectsBca 2nd sem u-2 classes & objects
Bca 2nd sem u-2 classes & objects
Rai University
 
Intake 38 4
Intake 38 4Intake 38 4
Intake 38 4
Mahmoud Ouf
 
Inheritance concepts Presentation (8).pptx
Inheritance concepts Presentation (8).pptxInheritance concepts Presentation (8).pptx
Inheritance concepts Presentation (8).pptx
ABHINAVARYANCSEA301
 
Oops concept on c#
Oops concept on c#Oops concept on c#
OOP in java
OOP in javaOOP in java
9781285852744 ppt ch11
9781285852744 ppt ch119781285852744 ppt ch11
9781285852744 ppt ch11
Terry Yoast
 
C++ [ principles of object oriented programming ]
C++ [ principles of object oriented programming ]C++ [ principles of object oriented programming ]
C++ [ principles of object oriented programming ]
Rome468
 
C++ Version 2
C++  Version 2C++  Version 2
C++ Version 2
JIGAR MAKHIJA
 
Opp concept in c++
Opp concept in c++Opp concept in c++
Opp concept in c++
SadiqullahGhani1
 
Lecture 2 (1)
Lecture 2 (1)Lecture 2 (1)
Lecture 2 (1)
zahid khan
 
Classes, Inheritance ,Packages & Interfaces.pptx
Classes, Inheritance ,Packages & Interfaces.pptxClasses, Inheritance ,Packages & Interfaces.pptx
Classes, Inheritance ,Packages & Interfaces.pptx
DivyaKS18
 

Similar to Object Oriented Programming With C++ (20)

4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT4 pillars of OOPS CONCEPT
4 pillars of OOPS CONCEPT
 
OBJECT ORIENTED PROGRAMING IN C++
OBJECT ORIENTED PROGRAMING IN C++ OBJECT ORIENTED PROGRAMING IN C++
OBJECT ORIENTED PROGRAMING IN C++
 
C++ largest no between three nos
C++ largest no between three nosC++ largest no between three nos
C++ largest no between three nos
 
Oop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer MelayiOop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer Melayi
 
I assignmnt(oops)
I assignmnt(oops)I assignmnt(oops)
I assignmnt(oops)
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
 
Creating sub zero dashboard plugin for apex with google
Creating sub zero dashboard plugin for apex with googleCreating sub zero dashboard plugin for apex with google
Creating sub zero dashboard plugin for apex with google
 
Java programming concept
Java programming conceptJava programming concept
Java programming concept
 
Mca 2nd sem u-2 classes & objects
Mca 2nd  sem u-2 classes & objectsMca 2nd  sem u-2 classes & objects
Mca 2nd sem u-2 classes & objects
 
Bca 2nd sem u-2 classes & objects
Bca 2nd sem u-2 classes & objectsBca 2nd sem u-2 classes & objects
Bca 2nd sem u-2 classes & objects
 
Intake 38 4
Intake 38 4Intake 38 4
Intake 38 4
 
Inheritance concepts Presentation (8).pptx
Inheritance concepts Presentation (8).pptxInheritance concepts Presentation (8).pptx
Inheritance concepts Presentation (8).pptx
 
Oops concept on c#
Oops concept on c#Oops concept on c#
Oops concept on c#
 
OOP in java
OOP in javaOOP in java
OOP in java
 
9781285852744 ppt ch11
9781285852744 ppt ch119781285852744 ppt ch11
9781285852744 ppt ch11
 
C++ [ principles of object oriented programming ]
C++ [ principles of object oriented programming ]C++ [ principles of object oriented programming ]
C++ [ principles of object oriented programming ]
 
C++ Version 2
C++  Version 2C++  Version 2
C++ Version 2
 
Opp concept in c++
Opp concept in c++Opp concept in c++
Opp concept in c++
 
Lecture 2 (1)
Lecture 2 (1)Lecture 2 (1)
Lecture 2 (1)
 
Classes, Inheritance ,Packages & Interfaces.pptx
Classes, Inheritance ,Packages & Interfaces.pptxClasses, Inheritance ,Packages & Interfaces.pptx
Classes, Inheritance ,Packages & Interfaces.pptx
 

Recently uploaded

CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...
CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...
CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...
Nguyen Thanh Tu Collection
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
Nguyen Thanh Tu Collection
 
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdfمصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
سمير بسيوني
 
220711130083 SUBHASHREE RAKSHIT Internet resources for social science
220711130083 SUBHASHREE RAKSHIT  Internet resources for social science220711130083 SUBHASHREE RAKSHIT  Internet resources for social science
220711130083 SUBHASHREE RAKSHIT Internet resources for social science
Kalna College
 
The basics of sentences session 7pptx.pptx
The basics of sentences session 7pptx.pptxThe basics of sentences session 7pptx.pptx
The basics of sentences session 7pptx.pptx
heathfieldcps1
 
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptxCapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapitolTechU
 
KHUSWANT SINGH.pptx ALL YOU NEED TO KNOW ABOUT KHUSHWANT SINGH
KHUSWANT SINGH.pptx ALL YOU NEED TO KNOW ABOUT KHUSHWANT SINGHKHUSWANT SINGH.pptx ALL YOU NEED TO KNOW ABOUT KHUSHWANT SINGH
KHUSWANT SINGH.pptx ALL YOU NEED TO KNOW ABOUT KHUSHWANT SINGH
shreyassri1208
 
HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.
deepaannamalai16
 
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...
EduSkills OECD
 
Oliver Asks for More by Charles Dickens (9)
Oliver Asks for More by Charles Dickens (9)Oliver Asks for More by Charles Dickens (9)
Oliver Asks for More by Charles Dickens (9)
nitinpv4ai
 
Standardized tool for Intelligence test.
Standardized tool for Intelligence test.Standardized tool for Intelligence test.
Standardized tool for Intelligence test.
deepaannamalai16
 
A Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two HeartsA Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two Hearts
Steve Thomason
 
NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...
NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...
NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...
Payaamvohra1
 
Educational Technology in the Health Sciences
Educational Technology in the Health SciencesEducational Technology in the Health Sciences
Educational Technology in the Health Sciences
Iris Thiele Isip-Tan
 
Creative Restart 2024: Mike Martin - Finding a way around “no”
Creative Restart 2024: Mike Martin - Finding a way around “no”Creative Restart 2024: Mike Martin - Finding a way around “no”
Creative Restart 2024: Mike Martin - Finding a way around “no”
Taste
 
Information and Communication Technology in Education
Information and Communication Technology in EducationInformation and Communication Technology in Education
Information and Communication Technology in Education
MJDuyan
 
How to Manage Reception Report in Odoo 17
How to Manage Reception Report in Odoo 17How to Manage Reception Report in Odoo 17
How to Manage Reception Report in Odoo 17
Celine George
 
skeleton System.pdf (skeleton system wow)
skeleton System.pdf (skeleton system wow)skeleton System.pdf (skeleton system wow)
skeleton System.pdf (skeleton system wow)
Mohammad Al-Dhahabi
 
Skimbleshanks-The-Railway-Cat by T S Eliot
Skimbleshanks-The-Railway-Cat by T S EliotSkimbleshanks-The-Railway-Cat by T S Eliot
Skimbleshanks-The-Railway-Cat by T S Eliot
nitinpv4ai
 
Diversity Quiz Prelims by Quiz Club, IIT Kanpur
Diversity Quiz Prelims by Quiz Club, IIT KanpurDiversity Quiz Prelims by Quiz Club, IIT Kanpur
Diversity Quiz Prelims by Quiz Club, IIT Kanpur
Quiz Club IIT Kanpur
 

Recently uploaded (20)

CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...
CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...
CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...
 
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
BÀI TẬP BỔ TRỢ TIẾNG ANH LỚP 8 - CẢ NĂM - FRIENDS PLUS - NĂM HỌC 2023-2024 (B...
 
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdfمصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
 
220711130083 SUBHASHREE RAKSHIT Internet resources for social science
220711130083 SUBHASHREE RAKSHIT  Internet resources for social science220711130083 SUBHASHREE RAKSHIT  Internet resources for social science
220711130083 SUBHASHREE RAKSHIT Internet resources for social science
 
The basics of sentences session 7pptx.pptx
The basics of sentences session 7pptx.pptxThe basics of sentences session 7pptx.pptx
The basics of sentences session 7pptx.pptx
 
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptxCapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
 
KHUSWANT SINGH.pptx ALL YOU NEED TO KNOW ABOUT KHUSHWANT SINGH
KHUSWANT SINGH.pptx ALL YOU NEED TO KNOW ABOUT KHUSHWANT SINGHKHUSWANT SINGH.pptx ALL YOU NEED TO KNOW ABOUT KHUSHWANT SINGH
KHUSWANT SINGH.pptx ALL YOU NEED TO KNOW ABOUT KHUSHWANT SINGH
 
HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.HYPERTENSION - SLIDE SHARE PRESENTATION.
HYPERTENSION - SLIDE SHARE PRESENTATION.
 
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...
 
Oliver Asks for More by Charles Dickens (9)
Oliver Asks for More by Charles Dickens (9)Oliver Asks for More by Charles Dickens (9)
Oliver Asks for More by Charles Dickens (9)
 
Standardized tool for Intelligence test.
Standardized tool for Intelligence test.Standardized tool for Intelligence test.
Standardized tool for Intelligence test.
 
A Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two HeartsA Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two Hearts
 
NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...
NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...
NIPER 2024 MEMORY BASED QUESTIONS.ANSWERS TO NIPER 2024 QUESTIONS.NIPER JEE 2...
 
Educational Technology in the Health Sciences
Educational Technology in the Health SciencesEducational Technology in the Health Sciences
Educational Technology in the Health Sciences
 
Creative Restart 2024: Mike Martin - Finding a way around “no”
Creative Restart 2024: Mike Martin - Finding a way around “no”Creative Restart 2024: Mike Martin - Finding a way around “no”
Creative Restart 2024: Mike Martin - Finding a way around “no”
 
Information and Communication Technology in Education
Information and Communication Technology in EducationInformation and Communication Technology in Education
Information and Communication Technology in Education
 
How to Manage Reception Report in Odoo 17
How to Manage Reception Report in Odoo 17How to Manage Reception Report in Odoo 17
How to Manage Reception Report in Odoo 17
 
skeleton System.pdf (skeleton system wow)
skeleton System.pdf (skeleton system wow)skeleton System.pdf (skeleton system wow)
skeleton System.pdf (skeleton system wow)
 
Skimbleshanks-The-Railway-Cat by T S Eliot
Skimbleshanks-The-Railway-Cat by T S EliotSkimbleshanks-The-Railway-Cat by T S Eliot
Skimbleshanks-The-Railway-Cat by T S Eliot
 
Diversity Quiz Prelims by Quiz Club, IIT Kanpur
Diversity Quiz Prelims by Quiz Club, IIT KanpurDiversity Quiz Prelims by Quiz Club, IIT Kanpur
Diversity Quiz Prelims by Quiz Club, IIT Kanpur
 

Object Oriented Programming With C++

  • 1. 26-07-2018 08:24:48 PM vishnuvishnushaji5@gmail.com [1/38] OBJECT-ORIENTED PROGRAMMING WITH C++ OBJECT-ORIENTED PROGRAMMING WITH C++ VISHNU P S
  • 2. 26-07-2018 08:24:49 PM vishnuvishnushaji5@gmail.com [2/38] OBJECT-ORIENTED PROGRAMMING WITH C++ Procedure Oriented Programming Object Oriented Programming Divided Into In POP, program is divided into small parts called functions. In OOP, program is divided into parts called objects. Importance In POP, Importance is not given to data but to functions as well as sequence of actions to be done. In OOP, Importance is given to the data rather than procedures or functions because it works as a real world. Approach POP follows Top Down approach. OOP follows Bottom Up approach. Access Specifiers POP does not have any access specifier. OOP has access specifiers named Public, Private, Protected, etc. Data Moving In POP, Data can move freely from function to function in the system. In OOP, objects can move and communicate with each other through member functions. Expansion To add new data and function in POP is not so easy. OOP provides an easy way to add new data and function.
  • 3. 26-07-2018 08:24:49 PM vishnuvishnushaji5@gmail.com [3/38] OBJECT-ORIENTED PROGRAMMING WITH C++ Contd… Overloading In POP, Overloading is not possible. In OOP, overloading is possible in the form of Function Overloading and Operator Overloading. Examples Example of POP are : C, VB, FORTRAN, Pascal. Example of OOP are : C++, JAVA, VB.NET, C#.NET Data Access In POP, Most function uses Global data for sharing that can be accessed freely from function to function in the system. In OOP, data can not move easily from function to function,it can be kept public or private so we can control the access of data. Data Hiding POP does not have any proper way for hiding data so it is less secure. OOP provides Data Hiding so provides more security.
  • 4. 26-07-2018 08:24:49 PM vishnuvishnushaji5@gmail.com [4/38] OBJECT-ORIENTED PROGRAMMING WITH C++ BASIC CONCEPTS OF OBJECT-ORIENTED PROGTAMMING OBJECTS CLASSES DATA ABSTRACTION DATA ENCAPSULATION INHERITANCE POLIYMORPHISM DYNAMIC BINDING MESSAGE PASSING
  • 5. 26-07-2018 08:24:49 PM vishnuvishnushaji5@gmail.com [5/38] OBJECT-ORIENTED PROGRAMMING WITH C++ #include<iostream.h> main() { cout<<“Hello World!”; return 0; } #include<stdio.h> int main() { printf(“Hello World!”); return 0; }
  • 6. 26-07-2018 08:24:49 PM vishnuvishnushaji5@gmail.com [6/38] OBJECT-ORIENTED PROGRAMMING WITH C++ MEMMORY ALLOCATION STATIC DYNAMIC  is allocated at the start of your program  the global variables or global available arrays  is allocated at runtime  malloc(), calloc(), new
  • 7. 26-07-2018 08:24:49 PM vishnuvishnushaji5@gmail.com [7/38] OBJECT-ORIENTED PROGRAMMING WITH C++ C •malloc() •calloc() C++ •new
  • 8. 26-07-2018 08:24:49 PM vishnuvishnushaji5@gmail.com [8/38] OBJECT-ORIENTED PROGRAMMING WITH C++ new  C++ uses new operator to allocate memory dynamically at run time. Syntax pointer_variable = new data_type; Example int *p; p = new int; int *q = new int;
  • 9. 26-07-2018 08:24:49 PM vishnuvishnushaji5@gmail.com [9/38] OBJECT-ORIENTED PROGRAMMING WITH C++ delete  Destroyed by using delete. Syntax delete pointer_variable; Example delete p; delete q;
  • 10. 26-07-2018 08:24:49 PM vishnuvishnushaji5@gmail.com [11/38] OBJECT-ORIENTED PROGRAMMING WITH C++ CLASSES AND OBJECTS CLASS OBJECT  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  A class is like a blueprint for 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.
  • 11. 26-07-2018 08:24:50 PM vishnuvishnushaji5@gmail.com [12/38] OBJECT-ORIENTED PROGRAMMING WITH C++ DEFINING CLASS
  • 12. 26-07-2018 08:24:50 PM vishnuvishnushaji5@gmail.com [13/38] OBJECT-ORIENTED PROGRAMMING WITH C++ DECLARING OBJECTS When a class is defined, only the specification for the object is defined; no memory or storage is allocated. To use the data and access functions defined in the class, you need to create objects. ClassName ObjectName;
  • 13. 26-07-2018 08:24:50 PM vishnuvishnushaji5@gmail.com [14/38] OBJECT-ORIENTED PROGRAMMING WITH C++ ACCESSING DATA MEMBERS AND MEMBER FUNCTIONS ACCESSING DATA MEMBERS The data members and member functions of class can be accessed using the dot(‘.’) operator with the object. For example if the name of object is obj and you want to access the member function with the name printName() then you will have to write obj.printName() . The public data members are also accessed in the same way given however the private data members are not allowed to be accessed directly by the object. Accessing a data member depends solely on the access control of that data member.
  • 14. 26-07-2018 08:24:50 PM vishnuvishnushaji5@gmail.com [15/38] OBJECT-ORIENTED PROGRAMMING WITH C++ // C++ program to demonstrate // accessing of data members #include <bits/stdc++.h> using namespace std; class Geeks { // Access specifier public: // Data Members string name; // Member Functions() void printname() { cout << “Name is: " << name; } }; int main() { // Declare an object of class geeks Geeks obj1; // accessing data member obj1.name = "Abhi"; // accessing member function obj1.printname(); return 0; }
  • 15. 26-07-2018 08:24:50 PM vishnuvishnushaji5@gmail.com [17/38] OBJECT-ORIENTED PROGRAMMING WITH C++ The capability of a class to derive properties and characteristics from another class is called Inheritance. Inheritance is one of the most important feature of Object Oriented Programming. INHERITANCE IN C++ Sub Class : The class that inherits properties from another class is called Sub class or Derived Class. Super Class : The class whose properties are inherited by sub class is called Base Class or Super class.
  • 16. 26-07-2018 08:24:52 PM vishnuvishnushaji5@gmail.com [18/38] OBJECT-ORIENTED PROGRAMMING WITH C++ Why and when to use inheritance?
  • 17. 26-07-2018 08:24:52 PM vishnuvishnushaji5@gmail.com [19/38] OBJECT-ORIENTED PROGRAMMING WITH C++
  • 18. 26-07-2018 08:24:52 PM vishnuvishnushaji5@gmail.com [20/38] OBJECT-ORIENTED PROGRAMMING WITH C++ Implementing inheritance in C++ For creating a sub-class which is inherited from the base class we have to follow the below syntax. class subclass_name : access_mode base_class_name { //body of subclass }; subclass_name is the name of the sub class, access_mode is the mode in which you want to inherit this sub class for example: public, private etc. and base_class_name is the name of the base class from which you want to inherit the sub class.
  • 19. 26-07-2018 08:24:52 PM vishnuvishnushaji5@gmail.com [21/38] OBJECT-ORIENTED PROGRAMMING WITH C++ // C++ program to demonstrate implementation // of Inheritance #include <iostream.h> using namespace std; //Base class class Parent { public: int id_p; }; // Sub class inheriting from Base Class(Parent) class Child : public Parent { public: int id_c; }; //main function int main() { Child obj1; // An object of class child has all data members // and member functions of class parent obj1.id_c = 7; obj1.id_p = 91; cout << "Child id is " << obj1.id_c << endl; cout << "Parent id is " << obj1.id_p << endl; return 0; }
  • 20. 26-07-2018 08:24:52 PM vishnuvishnushaji5@gmail.com [22/38] OBJECT-ORIENTED PROGRAMMING WITH C++ Modes of Inheritance Public mode: If we derive a sub class from a public base class. Then the public member of the base class will become public in the derived class and protected members of the base class will become protected in derived class. Private members of the base class will never get inherited in sub class. Protected mode: If we derive a sub class from a Protected base class. Then both public member and protected members of the base class will become protected in derived class. Private members of the base class will never get inherited in sub class. Private mode: If we derive a sub class from a Private base class. Then both public member and protected members of the base class will become Private in derived class. Private members of the base class will never get inherited in sub class.
  • 21. 26-07-2018 08:24:52 PM vishnuvishnushaji5@gmail.com [23/38] OBJECT-ORIENTED PROGRAMMING WITH C++ The below table summarizes the above three modes and shows the access specifier of the members of base class in the sub class when derived in public, protected and private modes:
  • 22. 26-07-2018 08:24:52 PM vishnuvishnushaji5@gmail.com [24/38] OBJECT-ORIENTED PROGRAMMING WITH C++ TYPES OF INHERITANCE IN C++ Single Inheritance Multiple Inheritance Multilevel Inheritance Hierarchical Inheritance Hybrid (Virtual) Inheritance
  • 23. 26-07-2018 08:24:52 PM vishnuvishnushaji5@gmail.com [25/38] OBJECT-ORIENTED PROGRAMMING WITH C++ Single Inheritance In single inheritance, a class is allowed to inherit from only one class. i.e. one sub class is inherited by one base class only.
  • 24. 26-07-2018 08:24:52 PM vishnuvishnushaji5@gmail.com [26/38] OBJECT-ORIENTED PROGRAMMING WITH C++ Multiple Inheritance Multiple Inheritance is a feature of C++ where a class can inherit from more than one classes. i.e one sub class is inherited from more than one base classes.
  • 25. 26-07-2018 08:24:52 PM vishnuvishnushaji5@gmail.com [27/38] OBJECT-ORIENTED PROGRAMMING WITH C++ Multilevel Inheritance In this type of inheritance, a derived class is created from another derived class.
  • 26. 26-07-2018 08:24:52 PM vishnuvishnushaji5@gmail.com [28/38] OBJECT-ORIENTED PROGRAMMING WITH C++ Hierarchical Inheritance In this type of inheritance, more than one sub class is inherited from a single base class. i.e. more than one derived class is created from a single base class.
  • 27. 26-07-2018 08:24:52 PM vishnuvishnushaji5@gmail.com [29/38] OBJECT-ORIENTED PROGRAMMING WITH C++ Hybrid (Virtual) Inheritance Hybrid Inheritance is implemented by combining more than one type of inheritance. For example: Combining Hierarchical inheritance and Multiple Inheritance.
  • 28. 26-07-2018 08:24:53 PM vishnuvishnushaji5@gmail.com [31/38] OBJECT-ORIENTED PROGRAMMING WITH C++ DYNAMIC BINDING • THE COMPILER MATCHES THE FUNCTION CALL WITH THE CORRECT FUNCTION DEFINITION AT RUNTIME. IT IS ALSO KNOWN AS LATE BINDING OR RUNTIME BINDING. • IN LATE BINDING, THE COMPILER IDENTIFIES THE TYPE OF OBJECT AT RUNTIME AND THEN MATCHES THE FUNCTION CALL WITH THE CORRECT FUNCTION DEFINITION. • THIS CAN BE ACHIEVED BY DECLARING A VIRTUAL FUNCTION.
  • 29. 26-07-2018 08:24:53 PM vishnuvishnushaji5@gmail.com [32/38] OBJECT-ORIENTED PROGRAMMING WITH C++ #include <iostream> using namespace std; class Animals { public: void sound() { cout << "This is parent class" << endl; } }; class Dogs : public Animals { public: void sound() { cout << "Dogs bark" << endl; } }; int main() { Animals *a; Dogs d; a= &d; a -> sound(); // early binding return 0; }
  • 30. 26-07-2018 08:24:53 PM vishnuvishnushaji5@gmail.com [33/38] OBJECT-ORIENTED PROGRAMMING WITH C++ FRIEND CLASS A friend class can access private and protected members of other class in which it is declared as friend. It is sometimes useful to allow a particular class to access private members of other class. For example a LinkedList class may be allowed to access private members of Node. FRIEND FUNCTION Like friend class, a friend function can be given special grant to access private and protected members. A friend function can be: a) A method of another class b) A global function
  • 31. 26-07-2018 08:24:53 PM vishnuvishnushaji5@gmail.com [34/38] OBJECT-ORIENTED PROGRAMMING WITH C++ class Node { private: int key; Node *next; /* Other members of Node Class */ friend class LinkedList; // Now class LinkedList can // access private members of Node } class Node { private: int key; Node *next; /* Other members of Node Class */ friend int LinkedList::search(); // Only search() of linkedList // can access internal members }; FRIEND CLASS FRIEND FUNCTION
  • 32. 26-07-2018 08:24:53 PM vishnuvishnushaji5@gmail.com [36/38] OBJECT-ORIENTED PROGRAMMING WITH C++ ENCAPSULATION IN C++ Encapsulation is defined as wrapping up of data and information under a single unit (Encapsulation is defined as binding together the data and the functions that manipulates them.) Consider a real life example of encapsulation, in a company there are different sections like the accounts section, finance section, sales section etc. The finance section handles all the financial transactions and keep records of all the data related to finance. Similarly the sales section handles all the sales related activities and keep records of all the sales. Now there may arise a situation when for some reason an official from finance section needs all the data about sales in a particular month. In this case, he is not allowed to directly access the data of sales section. He will first have to contact some other officer in the sales section and then request him to give the particular data. This is what encapsulation is. Here the data of sales section and the employees that can manipulate them are wrapped under a single name “sales section”.
  • 33. 26-07-2018 08:24:53 PM vishnuvishnushaji5@gmail.com [37/38] OBJECT-ORIENTED PROGRAMMING WITH C++ TEMPLATES IN C++
  • 34. 26-07-2018 08:24:53 PM vishnuvishnushaji5@gmail.com [38/38] OBJECT-ORIENTED PROGRAMMING WITH C++ TEMPLATES IN C++  Template is simple and yet very powerful tool in C++.  The simple idea is to pass data type as a parameter so that we don’t need to write same code for different data types.  For example a software company may need sort() for different data types. Rather than writing and maintaining the multiple codes, we can write one sort() and pass data type as a parameter. C++ adds two new keywords to support templates: ‘template’ CLASS TEMPLATES FUNCTION TEMPLATES
  • 35. 26-07-2018 08:24:53 PM vishnuvishnushaji5@gmail.com [39/38] OBJECT-ORIENTED PROGRAMMING WITH C++ How templates work? Templates are expended at compiler time. This is like macros. The difference is, compiler does type checking before template expansion. The idea is simple, source code contains only function/class, but compiled code may contain multiple copies of same function/class.
  • 36. 26-07-2018 08:24:54 PM vishnuvishnushaji5@gmail.com [41/38] OBJECT-ORIENTED PROGRAMMING WITH C++ C++ Exception Handling  An exception is a problem that arises during the execution of a program.  A C++ exception is a response to an exceptional circumstance that arises while a program is running, such as an attempt to divide by zero.  Exceptions provide a way to transfer control from one part of a program to another.  C++ exception handling is built upon three keywords: try, catch, and throw.
  • 37. 26-07-2018 08:24:54 PM vishnuvishnushaji5@gmail.com [42/38] OBJECT-ORIENTED PROGRAMMING WITH C++  throw − A program throws an exception when a problem shows up. This is done using a throw keyword.  catch − A program catches an exception with an exception handler at the place in a program where you want to handle the problem. The catch keyword indicates the catching of an exception.  try − A try block identifies a block of code for which particular exceptions will be activated. It's followed by one or more catch blocks.
  • 38. 26-07-2018 08:24:54 PM vishnuvishnushaji5@gmail.com [43/38] OBJECT-ORIENTED PROGRAMMING WITH C++ REFERENCE https://www.tutorialspoint.com/ https://www.geeksforgeeks.org/ https://en.wikipedia.org/wiki/Main_Page