हिंदी माध्यम नोट्स
Encapsulation in c++ language in hindi , encapsulation meaning in hindi , example
इससे पहले के article मे , c++ language के namespace और class और object को discuss किया था अब इस article मे c++ language के एक और important concept Encapsulation को discuss करेगे |
सभी c++ प्रोग्राम दो elements को include किया जाता है :-
Program statements (code) − इस भाग मे c++ code मे perform किये जाने task के लिए code को define किया जाता है |इसमें मुख्य function s होते है |
Program data − इस भाग मे प्रोग्राम मे define किये गये function के लिए information और data को include किया जाता है |
Encapsulation का general मतलब होता है किसी एक भाग मे multiple चीजो को Encapsule करना है | ठीक उसी प्रकार किसी oops Object Oriented Programming मे Encapsulation का मतलब data और function को किसी data मे Encapsule करना जिसमे इसके information को सेफ किया जाता है | इस concept से फुन्सिओं और data के misuse को कम किया जाता है | Encapsulation से c++ language मे मुख्य concept data hiding को generate किया गया है |
data Encapsulation एक mechanism है जिसमे data और function को binding किया जाता है इस method मे सबसे पहले data को बनाया जाता है और in datas को use किये जाने वाले function को declare किया जाता है | data abstraction का मतलब interface को define करना और यूजर द्वारा दी गयी details के आधार task को perform करना |
c++ language मे , data Encapsulation और data hiding को यूजर define type को create करके किया जाता है इसे class भी कहते है | इससे ओपहले के article मे हम discuss कर चुके है class मे तीन प्रकार के access mode होते है
private : इसमें define data और function को केवल class मे use ककिया जा सकता है |
public : इसमें define data और function को class मे और class के बहार भी define किया जासकता है |
protected : इस mode मे define variable और function को protected किया जाता है|
उदाहरन के लिए :
class Box {
public:
double getVolume(void) {
return l * b * h;
}
private:
double l; // length of a box
double b; // breath of a box
double h; // heigth of a box
};
इस उदाहरन मे variable l, b, and h का mode private होता है | जिसे box class मे define member मे ही use किया जा सकता है | और किसी और प्रोग्राम के भाग मे use नहीं कर सकता है | लेकिन इसे variable को किसी दुसरे method मे use करने के लिए encapsulation को use किया जाता है |
जब किसी पार्ट को public घोषित करने के लिए | इस element को public keyword के बाद declare किया जाता है | सभी variable और फ़ुन्स्तिओन जिसे public keyword के बाद define किया जाता है use प्रोग्राम के किसी भी भाग मे use किया जासकता है |
Data Encapsulation Example
c++ प्रोग्राम मे , जहा पर class मे public और private member को define किया जाता है | इसका आईडिया से data encapsulation and data abstraction को expose किया जाता है | इसका उदाहरन निन्म है :
code :
#include <iostream>
#include<conio>
using namespace std;
class Add {
public:
// constructor
Add(int i = 0) {
square= i;
}
// interface to outside world
void addNumber(int number) {
square+= number;
}
// interface to outside world
int Total() {
return total;
};
private:
// hidden data from outside world
int total;
};
int main() {
Add a;
a.addNumber(10);
a.addNumber(20);
a.addNumber(30);
cout << “square” << a.Total() <<endl;
return 0;
}
जब इस code को execute किया जाता है तब इसका निन्म आउटपुट आता है :-
square60
इस code मे class मे number को add किया जाता है और public member addnumber और squareको code के बहार interface किया जाता है | अतः इस variable की value को क्लास के बहार pass किया जाता है | private member squareको डेफिन किया जाता है |
इस class मे , variable squareको private declare किया है लेकिन इस class मे एक और function total() को define किया गया है जिसमे squareकी value return किया जाता है इस तरह से squarevariable को class के बहार कभी कभी भी use नहीं किया जाता है | लेकिन function को call करके इसकी value को access किया जासकता है | इस method मे variable squareकी information को हाईड की गयी है |
उदाहरन 2 :
#include <iostream>
#include<conio>
using namespace std;
class sqaure {
public:
// constructor
sqaure (int a = 0 ) {
}
// interface to outside world
void sqaure(int a ) {
int square= a*a;
}
// interface to outside world
int getdataaftersqaure {
return square ;
};
private:
// hidden data from outside world
int sqaure;
};
int main() {
sqaure s;
s.sqaure(10);
cout<<“Sqaure of 10 “<<s.getdataaftersqaure ();
s.sqaure(20);
cout<<“Sqaure of 20 “<<s.getdataaftersqaure ();
return 0;
}
इस class मे , variable square को private declare किया है लेकिन इस class मे एक और function square () को define किया गया है जिसमे squareकी value return किया जाता है इस तरह से square variable को class के बहार कभी कभी भी use नहीं किया जाता है | लेकिन function को call करके इसकी value को access किया जासकता है | इस method मे variable square की information को हाईड की गयी है |
इस article मे data Encapsulation और data hiding को discuss किया है |
tags : encapsulation meaning in hindi , example , Encapsulation in c++ language in hindi ?
Recent Posts
सती रासो किसकी रचना है , sati raso ke rachnakar kaun hai in hindi , सती रासो के लेखक कौन है
सती रासो के लेखक कौन है सती रासो किसकी रचना है , sati raso ke…
मारवाड़ रा परगना री विगत किसकी रचना है , marwar ra pargana ri vigat ke lekhak kaun the
marwar ra pargana ri vigat ke lekhak kaun the मारवाड़ रा परगना री विगत किसकी…
राजस्थान के इतिहास के पुरातात्विक स्रोतों की विवेचना कीजिए sources of rajasthan history in hindi
sources of rajasthan history in hindi राजस्थान के इतिहास के पुरातात्विक स्रोतों की विवेचना कीजिए…
गुर्जरात्रा प्रदेश राजस्थान कौनसा है , किसे कहते है ? gurjaratra pradesh in rajasthan in hindi
gurjaratra pradesh in rajasthan in hindi गुर्जरात्रा प्रदेश राजस्थान कौनसा है , किसे कहते है…
Weston Standard Cell in hindi वेस्टन मानक सेल क्या है इससे सेल विभव (वि.वा.बल) का मापन
वेस्टन मानक सेल क्या है इससे सेल विभव (वि.वा.बल) का मापन Weston Standard Cell in…
polity notes pdf in hindi for upsc prelims and mains exam , SSC , RAS political science hindi medium handwritten
get all types and chapters polity notes pdf in hindi for upsc , SSC ,…