हिंदी माध्यम नोट्स
object array in c++ language in hindi , what is source code program for object array in c++
जब किसी 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)
};
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…
Translation in english grammer in hindi examples Step of Translation (अनुवाद के चरण)
Translation 1. Step of Translation (अनुवाद के चरण) • मूल वाक्य का पता करना और उसकी…
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…
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…
विश्व के महाद्वीप की भौगोलिक विशेषताएँ continents of the world and their countries in hindi features
continents of the world and their countries in hindi features विश्व के महाद्वीप की भौगोलिक…
भारत के वन्य जीव राष्ट्रीय उद्यान list in hin hindi IAS UPSC
भारत के वन्य जीव भारत में जलवायु की दृष्टि से काफी विविधता पाई जाती है,…