Skip to main content

How to start learning Web-development

Encapasulation , Abstration , Polymorphism , Inheritance in c++

 Encapasulation in c++ :-

It is defined as when you wrap and bind all related data together in a single form or in a single unit or you can defined as binding of data together and manipulating it are called encapasulation in C++ .

For Example :
If there is a three department in a company are Finance , sale , research department  finance department handle all finance related data and sales department handle sale related data if finance department needs information about any other section they need permission of head of the department to access it  this called encapasulation . this also lead data abstraction or data hiding


#include <iostream>
using namespace std;

class container
{
private:
    // data hidden from outside world
    int x;

public:
    void given(int a)
    {
        x = a;
    }

    int display()
    {
        return x;
    }
};

int main()
{
    container value;
    int a;
    cin >> a;

    value.given(a);
    cout<<"Output will be :"<<endl;
    cout << value.display();
    return 0;
}


output -
12 
Output will be :
12

 Abstraction in c++ :-

The meaning of data abstraction is it display only essential information and hiding all details . data abstraction refer to providing only essential information about an data to the outside world and hide all the background detail  that called Abstraction in c++.

For Example :
A man visit a website for fill form and they fill it and submit it but they don't know background work how they submit it or how it work.

#include <iostream>
using namespace std;
class container
{
private:
    int abc; // private variables
public:
    void sum()
    {
        cout << "Enter two values : ";
        cin >> a >> b;
        c = a * b;
        cout << "multiplication of two values is: " << c << endl;
    }
};
int main()
{
    container one;
    one.sum();
    return 0;
}

output -
Enter two values : 12
12
multiplication of two values is: 144

Polymorphism in c++ :-

Polymorphism means if we call a member function it will cause a different function to be executed . we can define it as the ability of a message to be displayed in more then one form.
it is called polymorphism in c++

For Example : 
a person the person will be father , son , brother at a same time but behave differently according to situation so its example of polymorphism in c++

this code is example 
#include <iostream>
using namespace std;
class base                                
  {  
       int a;  
       public:  
       void a()  
       {   
             cout<< "Class base ";  
        }  
  };  
class derived : public base                       
{  
    int b;  
    public:  
   void a()  
  {  
        cout<<"Class derived";  
  }  
};  
int main()
{
    ...
    return 0;
}

Inheritance in c++ :-

The capability of a class to derived property and character from other class are called inheritance in c++

For Example :
if we have two type of float variable and three type of float variable and we called both with different function for sum and there Parameters are different but working are same .


Program of function in c++ languages -

#include<iostream>
using namespace std;

// Defining the function here 
void function(int a , int b) 
{
    cout<<"First value of function is:"<<a<<endl;
    cout<<"Second value of function is:"<<b<<endl;
}
int main()
{
int A;
int B;
cout<<"Enter the value of a:"<<endl;
cin>>A;
cout<<"Enter the value of b:"<<endl;
cin>>B;
// calling the function here
function(A,B);
return 0;
}


Comments

Popular posts from this blog

Funcation in c++ programming example in detail

Friend Funcation- 1. Adding to complex number in friend function #include<iostream> using namespace std; class container { float a,b; public: void get() { cout<<endl<<"Enter value for A="; cin>>a; cout<<endl<<"Enter value for B="; cin>>b; } void disp() { cout<<endl<<a; cout<<endl<<b; } friend container addition(container,container); }; container addition(container X,container y) { container Z; Z.a=X.a+y.a; Z.b=X.b+y.b; return Z; } int main() { container P,Q,R; P.get(); P.disp(); Q.get(); Q.disp(); R=addition(P,Q); R.disp(); return 0; } Output - Enter value for A=12 Enter value for B=12 12 12 Enter value for A=1 Enter value for B=1 1 1 13 13 2.  If class one is friend function of two it not means that two is friend functio...

C++ programming tutorial 2

Control statement in C++ PROGRAMMING - 1. if-else statement :    there are types below of if else statement so they are -     1. if-statement      In this if statement a condition was entered if the condition was match or say what we write in condition on it was true then program was run if it was false then the program in if statement was not run . Syntax - if(Condition){ //code you want to run } PROGRAM - // if-else statement  #include <iostream> using   namespace  std; int   main () {      int   a  ;      cout << "If the entered integer in equal to the condition they it run " << endl ;      cin >>   a ;      if ( a <= 6 )     {          cout << "Program was running" ...

C++ programming tutorial 5

 Call by value or reference - There are two type in function call by value or call by reference in it we pass the value in call by value we pass value and in call by reference we pass the reference of the value . Call by value in C++ Programming language  :- In call by value we pass the variable or say argument and then it used by function which we made so see the code given below  Syntax - #include <iostream > using namespace std; // making function  void fun_name(int a, int b) { ... } int main() { //calling function  fun_name(int n,int n1); return 0; } Code -  // function call by value in C++ programming #include <iostream> using namespace std; // call by value in function declaration void container(int a, int b); int main() {   int x,y;   cout<<"Enter the value of x :"<<endl;   cin>>x;   cout<<"Enter the value of y :"<<endl;   cin>>y;   // here we passing the value as argume...