- Get link
- X
- Other Apps
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 a, b, c; // 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
Post a Comment