SlideShare a Scribd company logo
ECAP444 - OBJECT ORIENTED
PROGRAMMING USING C++
Dr. V. DEVENDRAN
Professor
UNIT - 1
Object Oriented Programming in C++
• Object oriented programming is a type of
programming which uses objects and classes its
functioning.
• The object-oriented programming is based on real
world entities like inheritance, polymorphism, data
hiding, etc.
Object Oriented Programming in C++
OOPS
Encapsulation
Inheritance
Abstraction
Polymorphism
Class
• Class is basic structure block on object oriented
programming.
• A class is a data-type that has its own members i.e.
data members and member functions.
• Members of class can accessed by making
instance of class
Properties of class
• Class is a user-defined data-type.
• Data members are variables of the class.
• Member functions are the methods that are used to
manipulate data members.
Data members define the properties of the class where
as member function defines the behaviour on class.
Syntax of class
class class_name
{
data_type data_name;
return_type method_name(parameters);
}
Object
• An object is instance of class.
• An object is entity that is created to allocate
memory.
• An object is entity access data member and
member functions of class in object oriented
programming.
Syntax
class_name object_name;
Example
#include<iostream>
using namespace std;
class demo
{
public:
int f_num, s_num;
sum ( int a, int b ) {
cout << a+b; }
};
Int main()
{
demo d1;
d1.sum(d1.f_num=10,d1.s_num=39);
return 0;
}
Encapsulation
• Encapsulation is binding together the data and
related function that can manipulate the data.
• Encapsulation is the concept of wrapping together
of data and information in a single unit.
Polymorphism
The name defines polymorphism is multiple forms.
which means polymorphism is the ability of object
oriented programming to do some work using
multiple forms.
Inheritance
• The capability of a class to derive properties and
characteristics from another class is
called Inheritance.
• The class that derives properties from other class is
known as child class or subclass and the class
from which the properties are inherited is base
class or parent class.
Inheritance
Child Class or Sub Class: The class that inherits
properties from another class is called Sub class or
Derived Class.
Parent Class or Super Class: The class whose
properties are inherited by sub class is called Base
Class or Super class.
Types of Inheritance
• Single inheritance
• Multiple inheritance
• Multi level inheritance
• Hierarchical inheritance
• Hybrid inheritance
ABSTRACTION
• Abstraction is concept of hiding data and showing
only relevant data to the final user.
• There are two ways which can accomplish data
abstraction
• Using classes
• Using header file
Object Oriented Programming Languages
• Java
• JavaScript
• Python
• C++
• Visual Basic .NET
• Ruby
• Scala
• PHP
Benefits of OOP's
• Modular approach
• Reusability of code
• Flexibility
• It is very easy to partition the work in a project
based on objects.
• It is possible to map the objects in problem domain
to those in the program.
Benefits of OOP's
• Object oriented systems can be easily upgraded
from small to large systems.
• Software complexity can be easily managed.
• OOP provides a good framework for code libraries
where supplied software components can be easily
adapted and modified by the programmer. This is
particularly useful for developing graphical user
interfaces.
Benefits of OOP's
• OOP makes it easy to maintain and modify existing
code as new objects can be created with small
differences to existing ones.
C++ Class
• A class is a blueprint for the object.
• Keyword class is used to create class.
• The class body, enclosed by a pair of curly braces.
Syntax
class className {
access specifier;
//data members;
//member functions;
};
C++ Access Specifier
• C++ access specifiers are used for determining or
setting the boundary for the availability of class
members (data members and member functions)
beyond that class.
• The class members are grouped into sections,
private protected and public. These keywords are
called access specifiers
Types of C++ Access Modifiers
• public
• private
• Protected
By default the class members are private.
public access specifier
• The public keyword is used to create public
members (data and functions).
• The public members are accessible from any part
of the program.
Example : C++ public access specifier
#include<iostream>
using namespace std;
class abc{
public:
int number;
void display(){ cout<<"Number ="<<number; } };
main() {
abc obj1;
cout<<"Enter number";
cin>>obj1.number;
obj1.display(); }
private access specifier
• The private keyword is used to create private
members (data and functions).
• The private members can only be accessed from
within the class.
• But, friend classes and friend functions can access
private members.
Example : C++ private access specifier
#include<iostream> using namespace std;
class abc {
private: int number;
public:
void display(int n) {
number=n; cout<<"Number ="<<number; } };
main() {
int input_number; abc obj1; cout<<"Enter number”; cin>>input_number;
obj1.display(input_number); }
protected access specifier
• The protected keyword is used to create protected
members (data and function).
• The protected members can be accessed within the
class and from the derived class.
Protected access specifier accessed using
inheritance in C++.
C++ Class Member Function
• Member function of a class is a function that has its
definition or its prototype within the class definition like any
other variable.
• It operates on any object of the class.
• A member function is defined outside the class using the ::
(double colon symbol) scope resolution operator. This is
useful when we did not want to define the function within
the main program, which makes the program more
understandable and easy to maintain.
Syntax
return_type class_name :: member_function
Program
#include<iostream>
using namespace std;
class find_sum{
public:
int x,y; int sum();
};
int find_sum ::sum(){
return x+y; }
int main(){
find_sum sum1;
sum1.x=100;
sum1.y=200;
cout<<"Sum of x and y
is"<<sum1.sum();
return 0;
}
Nested member function
• A member function may call another member function within
itself. This is called nesting of member functions.
• A member function can access not only the public functions
but also the private functions of the class it belongs to.
• Calling a member function with in another member
function.
• Scope resolution operators ( : : ) used to defining a function
outside a class.
Program
#include<iostream>
using namespace std;
class area {
private:
int l,w;
public:
void getdata();
void display_area(); };
void area::getdata() {
cout<<"Enter length and width";
cin>>l>>w; }
void area::display_area() {
getdata();
cout<<"area is"<<l*w; }
int main(){
area a1;
a1.display_area(); }
Private Member Function
• A function declared inside the class's private
section is known as "private member function". A
private member function is accessible through the
only public member function.
• A private member variable or function cannot be
accessed, or even viewed from outside the class.
Only the class and friend functions can access
private members.
Array
An array is a collection of elements of the same type
placed in contiguous memory .
Syntax
type arrayName [ arraySize ];
Program
#include<iostream>
using namespace std;
int main(){
int arr[5];
cout<<"Enter Array Elements";
for(int i=0;i<=4;i++) {
cin>>arr[i];
}
}
cout << "Entered array elements are” <<
endl;
for(int i=0;i<=4;i++) {
cout<<arr[i]<<endl;
}
return 0;
}
Array within a class
• Arrays can be declared as the members of a class.
The arrays can be declared as private, public or
protected members of the class.
Program
#include<iostream>
using namespace std;
class student {
int marks[5];
public:
void getdata ();
void showdata();
};
void student::getdata() {
for(int i=0;i<=4;i++) {
cin>>marks[i]; } }
void student::showdata() {
for(int i=0;i<=4;i++) {
cout<<marks[i]<<endl; } }
int main() {
student stu; stu.getdata();
stu.showdata(); }

More Related Content

PPTX
c++.pptxwjwjsijsnsksomammaoansnksooskskk
PPTX
Unit - I Intro. to OOP Concepts and Control Structure -OOP and CG (2024 Patte...
PPTX
OOP CHAPTER object oreinted programming using c++
PPTX
object oriented programming-classes and objects.pptx
PPTX
PPTX
c++.pptxwjwjsijsnsksomammaoansnksooskskk
Unit - I Intro. to OOP Concepts and Control Structure -OOP and CG (2024 Patte...
OOP CHAPTER object oreinted programming using c++
object oriented programming-classes and objects.pptx

Similar to ECAP444 - OBJECT ORIENTED PROGRAMMING USING C++.pptx (20)

PPTX
C++ & Data Structure - Unit - first.pptx
PPTX
Php oop (1)
PPTX
Summer Training Project On C++
PPTX
oop lecture 3
PPT
Overview of Object Oriented Programming using C++
PPTX
Object Oriented Programming
PPTX
PPTX
asic computer is an electronic device that can receive, store, process, and o...
PPTX
Classes and objects
PPTX
PPT_Object Oriented Programming .pptx
PPTX
PPT_Object Oriented Programming (2).pptx
PPTX
Lecture-10_PHP-OOP.pptx
PPTX
Object oriented programming in C++
PPTX
Oop ppt
PPT
Share Unit 1- Basic concept of object-oriented-programming.ppt
PDF
Object Oriented Programming Constructors & Destructors
PPT
Oop(object oriented programming)
PPTX
Inheritance
PPTX
Object oriented programming introduction .pptx
PPTX
Classes and objects
C++ & Data Structure - Unit - first.pptx
Php oop (1)
Summer Training Project On C++
oop lecture 3
Overview of Object Oriented Programming using C++
Object Oriented Programming
asic computer is an electronic device that can receive, store, process, and o...
Classes and objects
PPT_Object Oriented Programming .pptx
PPT_Object Oriented Programming (2).pptx
Lecture-10_PHP-OOP.pptx
Object oriented programming in C++
Oop ppt
Share Unit 1- Basic concept of object-oriented-programming.ppt
Object Oriented Programming Constructors & Destructors
Oop(object oriented programming)
Inheritance
Object oriented programming introduction .pptx
Classes and objects
Ad

Recently uploaded (20)

PPTX
Geodesy 1.pptx...............................................
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPT
Mechanical Engineering MATERIALS Selection
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PPTX
Strings in CPP - Strings in C++ are sequences of characters used to store and...
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPTX
Lesson 3_Tessellation.pptx finite Mathematics
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPTX
additive manufacturing of ss316l using mig welding
PPTX
web development for engineering and engineering
PPTX
Sustainable Sites - Green Building Construction
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PPT
Project quality management in manufacturing
Geodesy 1.pptx...............................................
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Mechanical Engineering MATERIALS Selection
Embodied AI: Ushering in the Next Era of Intelligent Systems
Operating System & Kernel Study Guide-1 - converted.pdf
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
Strings in CPP - Strings in C++ are sequences of characters used to store and...
UNIT-1 - COAL BASED THERMAL POWER PLANTS
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Lesson 3_Tessellation.pptx finite Mathematics
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
additive manufacturing of ss316l using mig welding
web development for engineering and engineering
Sustainable Sites - Green Building Construction
Foundation to blockchain - A guide to Blockchain Tech
Project quality management in manufacturing
Ad

ECAP444 - OBJECT ORIENTED PROGRAMMING USING C++.pptx

  • 1. ECAP444 - OBJECT ORIENTED PROGRAMMING USING C++ Dr. V. DEVENDRAN Professor UNIT - 1
  • 2. Object Oriented Programming in C++ • Object oriented programming is a type of programming which uses objects and classes its functioning. • The object-oriented programming is based on real world entities like inheritance, polymorphism, data hiding, etc.
  • 3. Object Oriented Programming in C++ OOPS Encapsulation Inheritance Abstraction Polymorphism
  • 4. Class • Class is basic structure block on object oriented programming. • A class is a data-type that has its own members i.e. data members and member functions. • Members of class can accessed by making instance of class
  • 5. Properties of class • Class is a user-defined data-type. • Data members are variables of the class. • Member functions are the methods that are used to manipulate data members. Data members define the properties of the class where as member function defines the behaviour on class.
  • 6. Syntax of class class class_name { data_type data_name; return_type method_name(parameters); }
  • 7. Object • An object is instance of class. • An object is entity that is created to allocate memory. • An object is entity access data member and member functions of class in object oriented programming.
  • 9. Example #include<iostream> using namespace std; class demo { public: int f_num, s_num; sum ( int a, int b ) { cout << a+b; } }; Int main() { demo d1; d1.sum(d1.f_num=10,d1.s_num=39); return 0; }
  • 10. Encapsulation • Encapsulation is binding together the data and related function that can manipulate the data. • Encapsulation is the concept of wrapping together of data and information in a single unit.
  • 11. Polymorphism The name defines polymorphism is multiple forms. which means polymorphism is the ability of object oriented programming to do some work using multiple forms.
  • 12. Inheritance • The capability of a class to derive properties and characteristics from another class is called Inheritance. • The class that derives properties from other class is known as child class or subclass and the class from which the properties are inherited is base class or parent class.
  • 13. Inheritance Child Class or Sub Class: The class that inherits properties from another class is called Sub class or Derived Class. Parent Class or Super Class: The class whose properties are inherited by sub class is called Base Class or Super class.
  • 14. Types of Inheritance • Single inheritance • Multiple inheritance • Multi level inheritance • Hierarchical inheritance • Hybrid inheritance
  • 15. ABSTRACTION • Abstraction is concept of hiding data and showing only relevant data to the final user. • There are two ways which can accomplish data abstraction • Using classes • Using header file
  • 16. Object Oriented Programming Languages • Java • JavaScript • Python • C++ • Visual Basic .NET • Ruby • Scala • PHP
  • 17. Benefits of OOP's • Modular approach • Reusability of code • Flexibility • It is very easy to partition the work in a project based on objects. • It is possible to map the objects in problem domain to those in the program.
  • 18. Benefits of OOP's • Object oriented systems can be easily upgraded from small to large systems. • Software complexity can be easily managed. • OOP provides a good framework for code libraries where supplied software components can be easily adapted and modified by the programmer. This is particularly useful for developing graphical user interfaces.
  • 19. Benefits of OOP's • OOP makes it easy to maintain and modify existing code as new objects can be created with small differences to existing ones.
  • 20. C++ Class • A class is a blueprint for the object. • Keyword class is used to create class. • The class body, enclosed by a pair of curly braces.
  • 21. Syntax class className { access specifier; //data members; //member functions; };
  • 22. C++ Access Specifier • C++ access specifiers are used for determining or setting the boundary for the availability of class members (data members and member functions) beyond that class. • The class members are grouped into sections, private protected and public. These keywords are called access specifiers
  • 23. Types of C++ Access Modifiers • public • private • Protected By default the class members are private.
  • 24. public access specifier • The public keyword is used to create public members (data and functions). • The public members are accessible from any part of the program.
  • 25. Example : C++ public access specifier #include<iostream> using namespace std; class abc{ public: int number; void display(){ cout<<"Number ="<<number; } }; main() { abc obj1; cout<<"Enter number"; cin>>obj1.number; obj1.display(); }
  • 26. private access specifier • The private keyword is used to create private members (data and functions). • The private members can only be accessed from within the class. • But, friend classes and friend functions can access private members.
  • 27. Example : C++ private access specifier #include<iostream> using namespace std; class abc { private: int number; public: void display(int n) { number=n; cout<<"Number ="<<number; } }; main() { int input_number; abc obj1; cout<<"Enter number”; cin>>input_number; obj1.display(input_number); }
  • 28. protected access specifier • The protected keyword is used to create protected members (data and function). • The protected members can be accessed within the class and from the derived class. Protected access specifier accessed using inheritance in C++.
  • 29. C++ Class Member Function • Member function of a class is a function that has its definition or its prototype within the class definition like any other variable. • It operates on any object of the class. • A member function is defined outside the class using the :: (double colon symbol) scope resolution operator. This is useful when we did not want to define the function within the main program, which makes the program more understandable and easy to maintain.
  • 31. Program #include<iostream> using namespace std; class find_sum{ public: int x,y; int sum(); }; int find_sum ::sum(){ return x+y; } int main(){ find_sum sum1; sum1.x=100; sum1.y=200; cout<<"Sum of x and y is"<<sum1.sum(); return 0; }
  • 32. Nested member function • A member function may call another member function within itself. This is called nesting of member functions. • A member function can access not only the public functions but also the private functions of the class it belongs to. • Calling a member function with in another member function. • Scope resolution operators ( : : ) used to defining a function outside a class.
  • 33. Program #include<iostream> using namespace std; class area { private: int l,w; public: void getdata(); void display_area(); }; void area::getdata() { cout<<"Enter length and width"; cin>>l>>w; } void area::display_area() { getdata(); cout<<"area is"<<l*w; } int main(){ area a1; a1.display_area(); }
  • 34. Private Member Function • A function declared inside the class's private section is known as "private member function". A private member function is accessible through the only public member function. • A private member variable or function cannot be accessed, or even viewed from outside the class. Only the class and friend functions can access private members.
  • 35. Array An array is a collection of elements of the same type placed in contiguous memory . Syntax type arrayName [ arraySize ];
  • 36. Program #include<iostream> using namespace std; int main(){ int arr[5]; cout<<"Enter Array Elements"; for(int i=0;i<=4;i++) { cin>>arr[i]; } } cout << "Entered array elements are” << endl; for(int i=0;i<=4;i++) { cout<<arr[i]<<endl; } return 0; }
  • 37. Array within a class • Arrays can be declared as the members of a class. The arrays can be declared as private, public or protected members of the class.
  • 38. Program #include<iostream> using namespace std; class student { int marks[5]; public: void getdata (); void showdata(); }; void student::getdata() { for(int i=0;i<=4;i++) { cin>>marks[i]; } } void student::showdata() { for(int i=0;i<=4;i++) { cout<<marks[i]<<endl; } } int main() { student stu; stu.getdata(); stu.showdata(); }