Introduction to Object
Oriented Programming
Language (OOPS) in C++
PROGRAMMING PARADIGM
Programming
Paradigms
Imperative
Programming
Procedural (C)
Object Oriented
Programming
(C++, Java)
Declarative
Programming
Functional
(Haskell)
Logic (Prolog)
STRUCTURED/ PROCEDURAL LANGUAGE
TOP- DOWN
APPROACH
PROGRAM
MODULE 1
MODULE 3 MODULE 4
MODULE 2
MODULE 5
EXAMPLES OF
STRUCTURED
LANGUAGE
FORTRAN
PASCAL
ALGOL
COBOL
BASIC
C
WHAT IS
OOP stands for Object-Oriented Programming
Features of OOPS
Encapsulation
Abstraction
Inheritance
Polymorphism
1. ENCAPSULATION
It is a process of wrapping of data and methods in a single unit
CLASS and OBJECT
CLASS OBJECT
Class is a container which collects
variables and methods
Object is an instance of a class
It is mere a blueprint to which no
memory is allocated at the time of
declaration
Sufficient memory space will be
allocated for the variables of class
at the time of declaration
One class definition should exist
only once in the program
For one class multiple objects can
be created.
SYNTAX:
CLASS OBJECT
class class_name
{
access specifier:
data members;
member funtions()
};
class_name object_reference;
<header files>
class addition
{ private:
int a, b, sum;
public:
void input()
{
cout<< “Enter two numbers”;
cin>>a>>b;
}
void add()
{
sum=a+b;
}
void output()
{
cout<< “Sum of two number is= “<<sum;
}
};
void main()
{
addition ob;
ob. input();
ob. add();
ob.output();
getch();
}
Enter two numbers
10
20
Sum of two number is= 30
OUTPUT
Data members
Input() add() output() are the
member functions
Object
initialization
Dot operator is
used for calling
<header files>
class addition
{
int a, b, sum;
public:
void add()
{
cout<< “Enter two numbers”;
cin>>a>>b;
sum=a+b;
cout<< “Sum of two number is= “<<sum;
}
};
void main()
{
clrscr();
addition ob;
ob. add();
getch();
}
Enter two numbers
10
20
Sum of two number is= 30
OUTPUT
2. Abstraction
Abstraction means displaying only essential information and
hiding the details
<header files>
class addition
{
int a, b, sum;
public:
void add()
{
cout<< “Enter two numbers”;
cin>>a>>b;
sum=a+b;
cout<< “Sum of two number is=
“<<sum;
}
};
void main()
{
addition ob;
ob. a= 10;
ob. b=20;
ob. add();
getch();
}
Using Access Specifier in
Class
Public:
Accessible
both inside
and outside
the class
Private:
Accessible
inside the
class but not
outside the
class
Protected:
accessible
inside the
class and
only in
inherited
classes
//Error; a and b not accessible
outside the class because they
are declared private
3. INHERITANCE
It is a mechanism in which one class acquires the property of another class.
Derived Class (child)
• The class that inherits
from another class
Base Class (Parent)
• The class being
inherited from
Syntax:
class base_class
{
//Body of base class
};
class derived_class : access_specifier base_class
{
//Body of derived class
};
Base Class
Derived Class
4. Polymorphism
Polymorphism means "one interface, multiple forms"
class Animal {
public:
void animalSound() {
cout << "The animal makes a sound n" ;
}
};
class Pig : public Animal {
public:
void animalSound() {
cout << "The pig says: wee wee n" ;
}
};
class Dog : public Animal {
public:
void animalSound() {
cout << "The dog says: bow wow n" ;
}
};
void main() {
Animal myAnimal;
Pig myPig;
Dog myDog;
myAnimal.animalSound();
myPig.animalSound();
myDog.animalSound();
}
OUTPUT
The animal makes a sound
The pig says: wee wee
The dog says: bow wow
Base Class (Animal)
Derived Class (Pig)
Derived Class (Dog)
class Animal {
public:
void animalSound() {
cout << "The animal makes a sound n" ;
}
};
class Pig : public Animal {
public:
void animalSound() {
cout << "The pig says: wee wee n" ;
}
};
class Dog : public Animal {
public:
void animalSound() {
cout << "The dog says: bow wow n" ;
}
};
void main() {
Animal myAnimal;
Pig myPig;
Dog myDog;
myAnimal.animalSound();
myPig.animalSound();
myDog.animalSound();
}
OUTPUT
The animal makes a sound
The pig says: wee wee
The dog says: bow wow
Base Class (Animal)
Derived Class (Pig)
Derived Class (Dog)
Conclusion
Structured Programming
..
.. ..
..
..

Concept of OOPS with real life examples

  • 1.
    Introduction to Object OrientedProgramming Language (OOPS) in C++
  • 2.
    PROGRAMMING PARADIGM Programming Paradigms Imperative Programming Procedural (C) ObjectOriented Programming (C++, Java) Declarative Programming Functional (Haskell) Logic (Prolog)
  • 3.
    STRUCTURED/ PROCEDURAL LANGUAGE TOP-DOWN APPROACH PROGRAM MODULE 1 MODULE 3 MODULE 4 MODULE 2 MODULE 5
  • 4.
  • 5.
    WHAT IS OOP standsfor Object-Oriented Programming
  • 6.
  • 7.
    1. ENCAPSULATION It isa process of wrapping of data and methods in a single unit
  • 8.
    CLASS and OBJECT CLASSOBJECT Class is a container which collects variables and methods Object is an instance of a class It is mere a blueprint to which no memory is allocated at the time of declaration Sufficient memory space will be allocated for the variables of class at the time of declaration One class definition should exist only once in the program For one class multiple objects can be created.
  • 11.
    SYNTAX: CLASS OBJECT class class_name { accessspecifier: data members; member funtions() }; class_name object_reference;
  • 12.
    <header files> class addition {private: int a, b, sum; public: void input() { cout<< “Enter two numbers”; cin>>a>>b; } void add() { sum=a+b; } void output() { cout<< “Sum of two number is= “<<sum; } }; void main() { addition ob; ob. input(); ob. add(); ob.output(); getch(); } Enter two numbers 10 20 Sum of two number is= 30 OUTPUT Data members Input() add() output() are the member functions Object initialization Dot operator is used for calling
  • 13.
    <header files> class addition { inta, b, sum; public: void add() { cout<< “Enter two numbers”; cin>>a>>b; sum=a+b; cout<< “Sum of two number is= “<<sum; } }; void main() { clrscr(); addition ob; ob. add(); getch(); } Enter two numbers 10 20 Sum of two number is= 30 OUTPUT
  • 14.
    2. Abstraction Abstraction meansdisplaying only essential information and hiding the details
  • 15.
    <header files> class addition { inta, b, sum; public: void add() { cout<< “Enter two numbers”; cin>>a>>b; sum=a+b; cout<< “Sum of two number is= “<<sum; } }; void main() { addition ob; ob. a= 10; ob. b=20; ob. add(); getch(); } Using Access Specifier in Class Public: Accessible both inside and outside the class Private: Accessible inside the class but not outside the class Protected: accessible inside the class and only in inherited classes //Error; a and b not accessible outside the class because they are declared private
  • 16.
    3. INHERITANCE It isa mechanism in which one class acquires the property of another class. Derived Class (child) • The class that inherits from another class Base Class (Parent) • The class being inherited from
  • 18.
    Syntax: class base_class { //Body ofbase class }; class derived_class : access_specifier base_class { //Body of derived class }; Base Class Derived Class
  • 19.
    4. Polymorphism Polymorphism means"one interface, multiple forms"
  • 20.
    class Animal { public: voidanimalSound() { cout << "The animal makes a sound n" ; } }; class Pig : public Animal { public: void animalSound() { cout << "The pig says: wee wee n" ; } }; class Dog : public Animal { public: void animalSound() { cout << "The dog says: bow wow n" ; } }; void main() { Animal myAnimal; Pig myPig; Dog myDog; myAnimal.animalSound(); myPig.animalSound(); myDog.animalSound(); } OUTPUT The animal makes a sound The pig says: wee wee The dog says: bow wow Base Class (Animal) Derived Class (Pig) Derived Class (Dog)
  • 21.
    class Animal { public: voidanimalSound() { cout << "The animal makes a sound n" ; } }; class Pig : public Animal { public: void animalSound() { cout << "The pig says: wee wee n" ; } }; class Dog : public Animal { public: void animalSound() { cout << "The dog says: bow wow n" ; } }; void main() { Animal myAnimal; Pig myPig; Dog myDog; myAnimal.animalSound(); myPig.animalSound(); myDog.animalSound(); } OUTPUT The animal makes a sound The pig says: wee wee The dog says: bow wow Base Class (Animal) Derived Class (Pig) Derived Class (Dog)
  • 22.