Name:- Yashraj Chanchad

Class:-   BCA CTIS

URN:-   2020-B-09052001A

Sub:-     OOPs with C++

Topic:-  Basic Concepts of Object Oriented Programming.


What is Object oriented programming in C++?

Object oriented programming may be a sort of programming which uses objects and classes its functioning. the thing-oriented programming is predicated on entities like inheritance, polymorphism, data hiding, etc. It aims at binding together data and performance work on these data sets into one entity to limit their usage.

The basic concepts of OOPs in C++ are as follows:

  • CLASS
  • OBJECTS
  • ENCAPSULATION
  • POLYMORPHISM
  • INHERITANCE
  • ABSTRACTION

 

➥ Class:

-----------------------------------------------------------------------------------------

    A category may be a data-type that has its own members i.e. data members and member functions. it's the blueprint for an object in object oriented programing language . it's the essential building block of object oriented programming in C++. The members of a category are accessed in programing language by creating an instance of the category.

⚪ Some important properties of are

       1.  Class may be a user-defined data-type

                         2.  Data members and member functions are present in class itself.

             3.  Data members are variables of the category .

             4.  Member functions are the methods that are wont to manipulate data                                                       members.

              5.  Data members define the properties of the category whereas the member                                               functions define the behavior of the category .

  

 Syntax:-

class class_name 

   {

       data_type data_name;

       return_type method_name(parameters);

   }

 

➥ Object:

-----------------------------------------------------------------------------------------

        It's an entity with characteristics and behavior that are utilized in the thing oriented programming. An object is that the entity that's created to allocate memory. a category when defined doesn't have memory chunk itself which can be allocated as soon as objects are created.


Syntax :

class_name object_name;

 

Example:

#include<iostream>

using namespace std;

class calculator {

   int number1;

   int number2;

   char symbol;

   public :

   void add() {

      std::cout<<"The sum is "<<number1 + number2 ;

   }

   void subtract() {

      std::cout<<"The subtraction is "<<number1 - number2 ;

   }

   void multiply() {

      std::cout<<"The multiplication is "<<number1 * number2 ;

   }

   void divide() {

      std::cout<<"The division is "<<number1 / number2 ;

   }

   calculator (int a , int b , char sym) {

      number1 = a;

      number2 = b;

      symbol = sym;

      switch(symbol){

         case '+' : add();

            break;

         case '-' : add();

            break;

         case '*' : add();

            break;

         case '/' : add();

            break;

         default : std::cout<<"Wrong operator";

      }

   }

};

int main() {

   calculator c1(12 , 34 , '+');

}




 















➥ Encapsulation:

-----------------------------------------------------------------------------------------

            In object oriented programming, encapsulation is that the concept of wrapping together of knowledge and knowledge during a single unit. A formal definition of encapsulation would be: encapsulation is binding together the info and related function which will manipulate the info .

Let’s understand the subject with a simple real world example,

            In our colleges, we've departments for every course like computing , information tech. , electronics, etc. each of those departments have their own students and subjects that are kept track of and being taught. let's consider each department as a category that encapsulates the info about students of that department and therefore the subjects that are to be taught. Also a department has some fixed rules and guidelines that are to be followed by the scholars that course like timings, methods used while learning, etc. this is often encapsulation in real world , there are data and there are ways to control data.

            Due to the concept of encapsulation in object oriented programming another vital concept is feasible , it's data abstraction or Data Hiding. it's possible as encapsulating hides the info at show only the knowledge that's required to be displayed.

 Syntax:

class Rectangle

{

       public:

       int length;

       int breadth;

       int getArea()

             {

                 return length * breadth;

             }

};


➥ Polymorphism:
-----------------------------------------------------------------------------------------

        The name defines polymorphism is multiple forms. which suggests polymorphism is that the ability of object oriented programming to try to to some work using multiple forms. The behavior of the tactic depends on the sort or things during which the tactic is named .

 

        Let’s take a true life example, an individual can have quite one behavior depending upon things . sort of a woman a mother, manager and a daughter And this define her behavior. this is often from where the concept of polymorphism came from.

 ➡   In C++ programing language , polymorphism is achieved using two ways. they're operator overloading and performance overloading.

       ➡   Operator overloading In operator overloading and operator can have multiple behavior in several instances of usage.

               ➡   Function overloading Functions with an equivalent name which will do multiple types supported some condition.


 Syntax:

// Base class

class Animal

{

public:

void animalSound()

   {

     cout << "The animal makes a sound \n" ;
   }
};


// Derived class
class Pig : public Animal

{
    public:
    void animalSound()

    {
    cout << "The pig says: wee wee \n" ;
    }
};

// Derived class
class Dog : public Animal

  {
    public:
    void animalSound() {
    cout << "The dog says: bow wow \n" ;
  }
};


➥ Inheritance:

-----------------------------------------------------------------------------------------

            Inheritance it's the potential of a category to inherit or derive properties or characteristics other class. it's vital and object oriented program because it allows reusability i.e. employing a method defined in another class by using inheritance. the category that derives properties from other class is understood as child class or subclass and therefore the class from which the properties are inherited is base class or parent class.

 

C++ programming language supports the following types of inheritance:

              Single inheritance.

              Multiple inheritance.

              Multi-level inheritance.

              Hierarchical inheritance.

              Hybrid inheritance.

 Syntax:

// Base class
class Vehicle

   {
     public:
     string brand = "Ford";

     void honk()

     {
        cout << "Tuut, tuut! \n" ;
      }
};


// Derived class
class Car: public Vehicle 

{
public:
    string model = "Mustang";
};

int main()

{
Car myCar;
myCar.honk();

cout << myCar.brand + " " + myCar.model;
  return 0;

}


➥ Abstraction:

-----------------------------------------------------------------------------------------

        Data abstraction or Data Hiding is that the concept of hiding data and showing only relevant data to the ultimate user. it's also a crucial part object oriented programming.

        Let's take real world example to know concept better, once we ride a motorcycle, we only know that pressing the brake will stop the bike and rotating the throttle will accelerate but you do not skills it works and it's also not think we should always know that's why this is often done from an equivalent as an idea data abstraction.


Syntax:

// Base class

#include <iostream>

using namespace std;

int main()

{

    cout << "Hello World" << endl;

}

********************************THANK YOU********************************


Comments