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

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