JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

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

Categories: c++ language in hindi

object array in c++ language in hindi , what is source code program for object array in c++

what is source code program for object array in c++ , object array in c++ language in hindi
इससे पहले के article मे , this pointer को discuss किया था जो की c++ class और object थ्योरी का एक महतवपूर्ण concept है अब इस article मे object की array को discuss करेगे |Array of Object
जब किसी class के एक या एक से अधिक object को declare किया जाता है तब object की array को declare किया जाता है | इस case मे , एक नए ही object syntax को declare किया जाता है | इस object variable को अलग variable की तरह से consider किया जाता है | object array का syntax नार्मल array की तरह होता है | इसका syntax निन्म होता है :-
class_name object_name[size];
यहा पर
class_name : ये class का नाम होता है जिसके लिए object को declare किया जाता है |
object_name : ये object का नाम होता है जिससे class के element को use किया जा सकता है |
प्रोग्राम हमेशा default class constructor को use किया जाता है लेकिन class object को create किया जाता है |जो की explicit initailized किया जाता है | declartion मे दो पॉइंट्स को include किया जाता है :-
1.class जो की default constructor को explicit call किया जाता है | इस case मे implicit defualt constructor को call नहीं किया जाता है |

और इस object class के लिए ओब्जेक्टे array के element को use करने के लिए निन्म syntax को use किया जाता है :-
object_name[index];

इस object को initail करने एक लिए निन्म default construtor को declare करते है |
class_name object_name [size] = {
class_name {class values },;
class_name {class value },
…………………….,
…………………….
};
इस syntax मे, object array की size और default constructor मे declare value की सख्या match होती है |

इसका उदाहरन निन्म है :
const stock & stock1 :: greator(const stock & stock2  )
{
if(total > stock2.total)
{
return total;
}
return *this  ;
}
class stock
{
char company [50];
int share ;
double sharevalue ;
double total ;
void set_total (){total = share value * share ;}
public :
stick ();
void buy();
void sell();
void show();
void update ();
const stock & stock :: greator(const stock & stock  )const ;
}
#include<iostream>
#include<conio.h>
stock :: stock (const char * compnany , int n =0 , double price = 0.0 )
{
std :: strcpy ( name ,company,50 );
company[50]=’\0′;
if(n<0)
{
std::cerr<<“share can not be negetive “;
<< we set share equal to ‘0’ “<<endl;
share = 0 ;
}
else
share = n ;
share_price = price ;
total ();
}
stock :: ~stock ()
{
std :: cout<<“Stock Management Syatem Close “<<Bye ;
}
stock :: buy()
{
if(n<0)
{
std::cerr<<“share purchase can not be negetive “;
<< Please enter share more than ‘0’ “<<endl;
share = 0 ;
}
else
share += n ;
share_price = price ;
total ();
}
stock :: sell()
{
if(n<0)
{
std::cerr<<“share sell can not be negetive “;
<< Please enter share more than ‘0’ “<<endl;
share = 0 ;
}
else
share -= n ;
share_price = price ;
total ();
}
stock :: show()
{
cout<<“company Name :<<company ;
cout<<“share value  :”<<total ;
cout<<“share number :”<<sharevalue
}
const stock & stock1 :: greator(const stock & stock2  )
{
if(total > stock2.total)
{
return total;
}
return *this  ;
}
main()
stock s[4]={
stock{“ABC”,12,200.0}
stock{“EFG”,11,100.0}
stock{“UJK”,10,500.0}
stock{“PQR”,12,1000.0}
};
इस उअदारण मे stock class के object array को discuss किया है | जिसकी size 4 है  | इसलिए जब default constructor मे 4 अलग अलग class value से initial किया जाता है |
अलग अलग object के लिए अलग अलाग class type को define किया जाता है :
stock s[4]={
stock(“ABC”,12,200.0),
stock(),
stock(“UJK”,10,500.0),
stock(“PQR”,12,1000.0)
};

Sbistudy

Recent Posts

मालकाना का युद्ध malkhana ka yudh kab hua tha in hindi

malkhana ka yudh kab hua tha in hindi मालकाना का युद्ध ? मालकाना के युद्ध…

4 weeks ago

कान्हड़देव तथा अलाउद्दीन खिलजी के संबंधों पर प्रकाश डालिए

राणा रतन सिंह चित्तौड़ ( 1302 ई. - 1303 ) राजस्थान के इतिहास में गुहिलवंशी…

4 weeks ago

हम्मीर देव चौहान का इतिहास क्या है ? hammir dev chauhan history in hindi explained

hammir dev chauhan history in hindi explained हम्मीर देव चौहान का इतिहास क्या है ?…

4 weeks ago

तराइन का प्रथम युद्ध कब और किसके बीच हुआ द्वितीय युद्ध Tarain battle in hindi first and second

Tarain battle in hindi first and second तराइन का प्रथम युद्ध कब और किसके बीच…

4 weeks ago

चौहानों की उत्पत्ति कैसे हुई थी ? chahamana dynasty ki utpatti kahan se hui in hindi

chahamana dynasty ki utpatti kahan se hui in hindi चौहानों की उत्पत्ति कैसे हुई थी…

1 month ago

भारत पर पहला तुर्क आक्रमण किसने किया कब हुआ first turk invaders who attacked india in hindi

first turk invaders who attacked india in hindi भारत पर पहला तुर्क आक्रमण किसने किया…

1 month 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