JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

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

Categories: c++ language in hindi

CLASS IMPLEMENTATION in c++ language in hindi , Class implementation file

इससे पहले के article मे , class ऑफ़ object को discuss किया था अब इस article मे object के array को implement को discuss करेगे |जब किसी character की array को declare किया जाता है तब इस array मे केवेल length – 1 ही charecter store होते है | उदहार के लिए निम् उदाहरन को discuss करेगे :-
array name [30];
इस उदाहरन मे declare name मे 30 element की जगह 29 element ही store होते है | ठीक उसी प्रकार object की array के साथ भी होता है | उदाहरन के लिए
stock firm_detail{“ABC,POR,CDA”,30,353};
इस उदाहरन मे अगर firm_detial की size 10 है तब इसमें ABC,POR,CD store होगा | A truncating हो जाता है |

इस तरह के size restriction की प्रॉब्लम के solution को इस article मे discuss करेगे | length restriction को class implement से solve किया जा सकता है | इस प्रॉब्लम को solve करने के लिए निन्म methods को use किक्या जाता है :-
1.पहले method मे array की size को बढाया जाता है | जो की मेमोरी wasted की प्रॉब्लम को generate करता है |
2.दुसरे method मे array के स्थान पर string को use किया जाना चाहिए | और string की size automatic होनी चाहिए | इस method को implement करने के लिए class मे तीन मुख्य changes करने होते है |
change1 : string class को add  किया जाता है | string class को अड़ करने एक लिए header position पर string.h header file को इन्क्लुए किया जाता है |
change2 : दुसरे changes मे , class के private सेक्शन को change किया जाता है | private सेक्शन मे company का नाम के लिए array को define किया गया था लेकिन अब string को define करेगे |
change 3 : तीरसे change मे constructor को change किया गया था | जिसमे कंपनी name को कंपनी array मे copy किया गया था और इस array के last block मे null pointer को assign किया गया था | लेकिन string के साथ केवल string को एक वर्तिअब्ले मे से दुसरे variable मे assign किया जाता जाता है |

इन तीनो changes से  क्लास के implement मे किया जाता है  | class के private method मे ही change करना है | उसके public method मे कोई change नहीं होगा |
कई बार प्रोग्रामर class implement मे कोई भी change नहीं कर सकता है | लेकिन इसके जगा एक नए constructor’
को add कर सकते है | जिसमे इस कंपनी name को assign किया जा सकता है |

नार्मल code :
class stock
{
private :
char company [50];
int share ;
double sharevalue ;
double total ;
double total ;
public :
void total (){ return total = share value * share;}
stick ();
void buy();
void sell();
void show();
void update ();
};
इस code मे आप देख सकते है की कम्पनी के नाम को store करने के लिए company [] array को use किया गया है जिसकी size 50 है इसमें 50 charecter store हो सकते है | इस array की size काफी बड़ी है | इसलिए इसमें सभी कंपनी के नाम store हो सकता है | लेकिन कभी कभी कंपनी का नाम बहुत छोटा होता है तब memory wasteage बहुत ज्यादा होता है | इस memory wastage को कम करने के लिए string को use किया जाता है |

Modified code 2 :

class stock
{
private :
string company [50];
int share ;
double sharevalue ;
double total ;
double total ;
public :
void total (){ return total = share value * share;}
stick ();
void buy();
void sell();
void show();
void update ();
};

इस code मे array की जगह string class के string data type को use किया गया है | string data type को use करने एक लिए header section मे string class को include किया जाता है | जिसका स्यन्त्याक्स निन्म होता है :
#include<string>
या
#include<string.h>
इस दोनों syntax से string class को code मे include किया जा सकता है  |

Constructer code :
stock :: stock (const char * compnany , int n =0 , double price = 0.0 )
{
std :: strcpy ( name ,company,50 );
name[50]=’\0′;
}
इस code मे constructor को define किया गया है जो की array के साथ use किया जाता है | इसमें company variable के data को  name array मे assign किया जाता है | और array के last block मे null pointer को assign किया जाता है |

Modified code :
stock :: stock (const char * compnany , int n =0 , double price = 0.0 )
{
name = company ;
}
इस code मे केवल , string variable name मे compnany के data को assign किया जाता है | जिसके लिए simple string assignment operator को use किया जाता है |

और अगर यूजर द्वारा class के code को modify नहीं किया जा सकता है तब class constructor को modify किया जाता है | इसका code निन्म होता है :-
string (const :: string & company , int n , int price);

इस constructor को use करने पर interface भी change हो जाता है | इसके लिए main() code मे निन्म तरह से object को initial किया जाता है |
इस constructor style से private सेक्शन मे कोई भी change नहीं होता है बल्कि public सेक्शन मे change होता है |
इसके लिए main() function मे निन्म code होता है :
string name ;
getline (cout  , name );
stock min (name , 12 , 200);

इस तरह से class को modify करके memory और time complxity को कम किया जा सकता है |

Sbistudy

Recent Posts

Question Tag Definition in english with examples upsc ssc ias state pcs exames important topic

Question Tag Definition • A question tag is a small question at the end of a…

2 weeks ago

Translation in english grammer in hindi examples Step of Translation (अनुवाद के चरण)

Translation 1. Step of Translation (अनुवाद के चरण) • मूल वाक्य का पता करना और उसकी…

2 weeks ago

Report Writing examples in english grammer How to Write Reports explain Exercise

Report Writing • How to Write Reports • Just as no definite rules can be laid down…

2 weeks ago

Letter writing ,types and their examples in english grammer upsc state pcs class 12 10th

Letter writing • Introduction • Letter writing is an intricate task as it demands meticulous attention, still…

2 weeks ago

विश्व के महाद्वीप की भौगोलिक विशेषताएँ continents of the world and their countries in hindi features

continents of the world and their countries in hindi features विश्व के महाद्वीप की भौगोलिक…

2 weeks ago

भारत के वन्य जीव राष्ट्रीय उद्यान list in hin hindi IAS UPSC

भारत के वन्य जीव भारत में जलवायु की दृष्टि से काफी विविधता पाई जाती है,…

2 weeks 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