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

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 argument   // and also calling the function  

Code of HTML and CSS how we take color , border , etc

  code of HTML and CSS - 1. How we take change color in css (color and border both property) 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>color in css</title> <style> .color1{ background-color: green; } .color2{ color: yellow; } .color3{ border: 2px solid red; } </style> </head> <body> <!-- lets take paragarph --> <p class="color1"> In display property if we apply inline-block property on it we can be set their width and height and element was set next to a element in line it not take extra space so in easy word it is work as both block element who's width and height can be changed </p> <p class="color2"> In display property if we apply inline-blo

Class and Object , function overloading Explanation in c++ language

 Classes in C language - It is a user defined data type data type which hold its own data members and member function which can be accessed and user by creating an instance of that class and we say that class is building block that leads to Object Oriented programming  Data member -  It is the data variable of the function  Member function - It are the function use to manipulate these function variable  For Example -  A car is an object the car has attribute such as weight , color and methods such as drive and brake Attribute and method are basically variable and function that belong to class syntax - class   class{        // The class    public :              // Access specifier      int   Num;         // Attribute (int variable)     string word;   // Attribute (string variable) }; Program - // class explaination #include <iostream> using   namespace  std; class   classname {      public:      string   mystring ;      void   printfun ()     {          cout   <<   "Gee