JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

हिंदी माध्यम नोट्स

Categories: c++ language in hindi

Declaring of C++ constructors , Use of constructors , exam program source code in hindi

इससे पहले के article मे , constructor को discuss किया जाता है | इससे पहले के article मे constructor के syntax और declare करने को discuss किया जाता है |
Declaring of C++ constructors
constructors को declare करने के लिए जिस functio age के लिए constructors को declare किया जता जाता है उसमे pass किये जाने वाले argument को constructors के लिए use किया जासकता है | उदहारण के लिए persoage constructorsमे pass किये गये argument की सख्या तीन होती है | क्योकि यूजर द्वारा केवल तीन value को लिए जाता है |  इसका syntax निन्म है :
persoage  (const char * name , int age  =0 , double salary  = 0.0 )
इस  constructors
पहला argument एक string का pointer है जिसमे persoage का name member से initial किया जाता है |
age : ये integer type variable है जिसमे persoage के age  को initail किया जाता है |
salary : ये double type variable है जिसमे persoage की salary को initail किया जाता है |
Use of constructors
c++ language मे , किसि object को initial करने क लिए दो method को use किया जाता है | दोनों ही method मे object को constructor से initial करने के लिए दो method को use किया जाता है |
सबसे पहले constructor को  explicit call किया जाता है |
persoage p = persoage  ( “parth” , 23 , 20,000 );
इस उदहारण से :
persoage object p के member variable name मे parth को initail किया जाता है |
persoage object p के member variable age  मे 23 को initail किया जाता है |
persoage object p के member variable salary मे 20,000 को initail किया जाता है |
दुसरे method मे constructor को implicit call किया जाता है | इसका syntax निन्म होता है :
persoage p( “meet” , 26 , 28,000 );
इस उदहारण से :
persoage object p के member variable name मे  meet को initial किया जाता है |
persoage object p के member variable age  मे 26 को initial किया जाता है |
persoage object p के member variable salary मे 23,000 को initial किया जाता है |
explicit constructor का format implicit constructor से complex होता है |
c++ language मे जब किसी c++ class को use किया जाता है तब c++ constructor को use किया जाता है |  जब किसी new operator का use किसी नए memory एलोकेशन को allocate करने के लिए use किया जाता है  तस्ब constructor को use किया जाता है |
persoage *p = new persoage  ( “parth” , 23 , 20,000 );
इस statement से persoage object को create किया जाता है जिसमे value को constructor के argument से initial किया जाता है | इस memory allocation से allocate memory space के address को pointer variable p मे assign किया जाता है | object का name नहीं होता है उसके pointer variable इस memory allocatioage को manage करने के लिए use किया जाता है |
constructor को किसी दुसरे class मे use करने के लिए दुसरे form को use किया जाता है |  कसी object को method को use करने के लिए use किया जासकता है | जैसे persoage मे show () एक functioage है तब इसे invoke करने के लिए किया जाता है:-
p.show();
Default Constructor
Default Constructor एक एस Constructor है जिसे किसी object को initial करने के लिए use किया जाता है | और इस Constructor को exciplit call नहीं किया जाता है | नीचे दिए उदाहरन मे  Constructor को use किया जाता है  जिसे class object को declare करने के लिए किया जाता है |
persoage p;
इस statement को use किया जाता है इसे Constructor को declare किये बिना object को use किया जाता है | c++ मे default Constructor को आटोमेटिक supllies किया जाता है |
जब किसि Constructor को explicit declare किया जाता है तब इस method को use नहीं किया जाता है | किसी persoage classमे , default Constructor को use किया जाता है :-
persoage :: person()
{
}
इस method के बाद persoage object को create किया जाता है लेकिन इस method मे member कोunintail किया जाता है | जिसे
int a;
किसी default Constructor को use करना complex होता है |किसी Constructor को define नहीं किया जाता है लेकिन जब किसी Constructor को declare किया जाता है तब default Constructor को use किया जाता है | जब किसी noage default Constructor को use किया जाता है तब  default constructor को use नहीं किया जाता है |persoage p; से error message आ जाता है |
Constructor का उदाहरन :
persoage :: persoage (const char * employee  , int age =0 , double salary  = 0.0 )
{
std :: strcpy ( name ,employee ,50 );
name [50]=’\0′;
if(n<0)
{
std::cerr<<” age इस not negative”;
       << we set share equal to ‘0’ “<<endl;
share = 0 ;
}
else
age = age ;
salary = salary ;
total ();
}
अगर इस उदाहरन को defualt Constructor को use किया जाता है तब इसका निन्म code होगा :-
persoage :: persoage ()
{
std :: strcpy ( name ,employee ,50 );
name [50]=’\0′;
if(n<0)
{
std::cerr<<” age is not negative”;
       << we set share equal to ‘0’ “<<endl;
share = 0 ;
}
else
age = age ;
salary = salary ;
total ();
}
Sbistudy

Recent Posts

सती रासो किसकी रचना है , sati raso ke rachnakar kaun hai in hindi , सती रासो के लेखक कौन है

सती रासो के लेखक कौन है सती रासो किसकी रचना है , sati raso ke…

21 hours ago

मारवाड़ रा परगना री विगत किसकी रचना है , marwar ra pargana ri vigat ke lekhak kaun the

marwar ra pargana ri vigat ke lekhak kaun the मारवाड़ रा परगना री विगत किसकी…

21 hours ago

राजस्थान के इतिहास के पुरातात्विक स्रोतों की विवेचना कीजिए sources of rajasthan history in hindi

sources of rajasthan history in hindi राजस्थान के इतिहास के पुरातात्विक स्रोतों की विवेचना कीजिए…

3 days ago

गुर्जरात्रा प्रदेश राजस्थान कौनसा है , किसे कहते है ? gurjaratra pradesh in rajasthan in hindi

gurjaratra pradesh in rajasthan in hindi गुर्जरात्रा प्रदेश राजस्थान कौनसा है , किसे कहते है…

3 days ago

Weston Standard Cell in hindi वेस्टन मानक सेल क्या है इससे सेल विभव (वि.वा.बल) का मापन

वेस्टन मानक सेल क्या है इससे सेल विभव (वि.वा.बल) का मापन Weston Standard Cell in…

3 months ago

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 ,…

3 months ago
All Rights ReservedView Non-AMP Version
X

Headline

You can control the ways in which we improve and personalize your experience. Please choose whether you wish to allow the following:

Privacy Settings
JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now