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...

Tutorial 13 Visibility property

 Properties of css - 1. Visibility property in css -     In this property element will can visible or hidden by using this property so let say we take a paragarph tag and write some content on it if we use visibility property so we can hide the element but the space of element in web page are left there and no other element take that space so this is it  syntax -   visibility :  visible ;     visibility :hidden ; Code - <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Visiblity in css </title> <style> /* visibility property */ .visible{ visibility: visible; } .hidden{ visibility: hidden; } </style> </head> <body> <h1...

C++ programming tutorial 3

 Control statement in c++ programming - 1. For loop statement in c++ programming -  In this loops we run a single part of code many times this used for simple our programming and in less code , time work done is same . Syntax - for(int i =0; i< x ; i++){ ..... } Code -  // For loop in c++ language  #include <iostream> using   namespace  std; int   main () {      int   i  ,  a ;      cout << "Loop was start Below " << endl ;      cout << "Enter the value of a:" << endl ;      cin >> a ;      for ( i = 0 ; i <= a ; i ++ )     {          cout <<   "this is a number count :" <<   i << endl ;     }  ...