JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

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

Class 6

Hindi social science science maths English

Class 7

Hindi social science science maths English

Class 8

Hindi social science science maths English

Class 9

Hindi social science science Maths English

Class 10

Hindi Social science science Maths English

Class 11

Hindi sociology physics physical education maths english economics geography History

chemistry business studies biology accountancy political science

Class 12

Hindi physics physical education maths english economics

chemistry business studies biology accountancy Political science History sociology

Home science Geography

English medium Notes

Class 6

Hindi social science science maths English

Class 7

Hindi social science science maths English

Class 8

Hindi social science science maths English

Class 9

Hindi social science science Maths English

Class 10

Hindi Social science science Maths English

Class 11

Hindi physics physical education maths entrepreneurship english economics

chemistry business studies biology accountancy

Class 12

Hindi physics physical education maths entrepreneurship english economics

chemistry business studies biology accountancy

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

four potential in hindi 4-potential electrodynamics चतुर्विम विभव किसे कहते हैं

चतुर्विम विभव (Four-Potential) हम जानते हैं कि एक निर्देश तंत्र में विद्युत क्षेत्र इसके सापेक्ष…

2 days ago

Relativistic Electrodynamics in hindi आपेक्षिकीय विद्युतगतिकी नोट्स क्या है परिभाषा

आपेक्षिकीय विद्युतगतिकी नोट्स क्या है परिभाषा Relativistic Electrodynamics in hindi ? अध्याय : आपेक्षिकीय विद्युतगतिकी…

4 days ago

pair production in hindi formula definition युग्म उत्पादन किसे कहते हैं परिभाषा सूत्र क्या है लिखिए

युग्म उत्पादन किसे कहते हैं परिभाषा सूत्र क्या है लिखिए pair production in hindi formula…

6 days ago

THRESHOLD REACTION ENERGY in hindi देहली अभिक्रिया ऊर्जा किसे कहते हैं सूत्र क्या है परिभाषा

देहली अभिक्रिया ऊर्जा किसे कहते हैं सूत्र क्या है परिभाषा THRESHOLD REACTION ENERGY in hindi…

6 days ago

elastic collision of two particles in hindi definition formula दो कणों की अप्रत्यास्थ टक्कर क्या है

दो कणों की अप्रत्यास्थ टक्कर क्या है elastic collision of two particles in hindi definition…

6 days 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