JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

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

Categories: c++ language in hindi

Write a program to print SD and Average using class , find maximum और minimum using class

अब इस article मे , class के उदाहरनो को discuss करेगे | इससे पहले के article मे class के उदाहरनो मे variable को private declare किया गया था और function को public mode मे declare किया गया था अब इस article मे class के अलग अलग access mode को use करते हुए variable और functions को discuss करेगे |उदहारण -1
Write a program to print SD and Average using class

Explanation
र्सबसे पहले class math को declare किया जाता है | इस class मे तीन variable avg, variance और  Standard_devation को calculate किया जाता है in सभी variable का access mode public है अतः इन variable को main() और class math मे use किया जा सकता है |
class math मे तीन function को देकाल्रे किया जाता है |
avg() : इसका access mode public है | अतः इसे main() के साथ class मे भी use किया जा सकता है |
variance() : इसका भी  access mode public है | अतः इसे main() के साथ class मे भी use किया जा सकता है |
SD(): इसका access mode private है अतः इसे केवल class मे ही use किया जा सकता है |

int avg() मे array और size को pass किया जा सकता है |
इस function मे , array के element को addition किया जाता है  | इसे sum variable मे assign किया जाता है |
इसके बाद avg= sum / size से average को calculate किया जाता है |
इस avg को print किया जाता है |

void variance () मे , int avg , array और size को pass किया जाता है | इसमें main() function से class math से variable avg को भी पास किया जाता है |
इसके बाद variance को calcualte किया जाता है |
और variance की value print किया जाता है |

void SD() मे , variance को पास किया जाता है |इस function को main() function मे call नही किया जाता है  |
जब variance को call किया जाता है तब  variance और  Standard_devation को calcualte किया जाता है |

#include<iostream.h>
#include<conio.h>
class math{
public :
int avg;
float variance , Standard_devation ;
public:
void avg(int a[],size)
{
for(i=1;i<size;i++)
{
int sum = sum + a[i];
}
avg= sum /size;
cout<<“Averge :”<<avg;
}
void variance ( int mean , int a[], int size )
{
int b[size];
for(i=1;i<size;i++)
{
b[i]=mean-a[i];
}
for(i=1;i<size;i++)
{
int sum = sum + b[i] * b[i];
}
variance = sum / size;
cout<<“Variance :”<<variance;
cout<<“Standard Deviation”<<SD(variance);
}
private :
int SD( float var)
{
Standard_devation = sqrt(var);
return Standard_devation;
}
};
void main()
{
math m;
int array[10];
cout<<“Array Element :”<<endl;
for(int i =0 ; i<10;i++)
{
cin>>array[i];
}
m.avg(array ,10 );
m.variance(m.avg , array , 10);
getch();
}

उदहारण -2
Write a program to find maximum और minimum using class

Explanation
र्सबसे पहले class math को declare किया जाता है | इस class मे maximum और minimum element को find किया जाता है | variable m का access mode public है अतः इन variable को main() और class math मे use किया जा सकता है |
class math मे  दो function को discuss किया जाता है |
minimum () : इसका access mode public है | अतः इसे main() के साथ class मे भी use किया जा सकता है |
maximum () : इसका भी  access mode public है | अतः इसे main() के साथ class मे भी use किया जा सकता है |
void  maximum () मे array और size को pass किया जा सकता है |
इस function मे , variable ‘m’ को array के first element से  initial किया जाता है |
उसके बाद loop चलाया जाता है |
loop की body मे m का comparsion array के element से करवाते है | अगर m की value array के element से छोटी होती है तब m और array के value मे swaping हो जाता है |
इस loop के end मे m की value array मे उपस्थित सभी elements मे सबसे बड़ी value को hold करता है |

void  minimum () मे array और size को pass किया जा सकता है |
इस function मे , variable ‘m’ को array के first element से  initial किया जाता है |
उसके बाद loop चलाया जाता है |
loop की body मे m का comparsion array के element से करवाते है | अगर m की value array के element से  बड़ी होती है तब m और array के value मे swaping हो जाता है |
इस loop के end मे m की value array मे उपस्थित सभी elements मे सबसे बड़ी value को hold करता है |

#include<iostream.h>
#include<conio.h>
class math{
public :
int m ;
public:
void maximum(int a[],size)
{
m=a[1];
for(i=1;i<=size;i++)
{
if(m< a[i])
{
int temp;
temp = a[i];
a[i] = m;
m = temp ;
}
cout<<“Maximum Element :”<<m;
}
void minimum (int a[],size)
{
m=a[1];
for(i=1;i<=size;i++)
{
if(m > a[i])
{
int temp;
temp = a[i];
a[i] = m;
m = temp ;
}
cout<<“Minimum Element :”<<m ;
}
};
void main()
{
math c;
int array[10];
cout<<“Array Element :”<<endl;
for(int i =0 ; i<10;i++)
{
cin>>array[i];
}
c.minimum(array ,10 );
c.maximum(array , 10);
getch();
}

उदहारण -3
Write a program to find addition और subtraction of two matrix using class

Explanation
र्सबसे पहले class math को declare किया जाता है | इस class मे  addition और subtraction element को find किया जाता है |
class math मे  दो function को discuss किया जाता है |
addition () : इसका access mode public है | अतः इसे main() के साथ class मे भी use किया जा सकता है |
subtraction () : इसका भी  access mode public है | अतः इसे main() के साथ class मे भी use किया जा सकता है |
void  addition () मे  दोनों array और size को pass किया जा सकता है |
इस function मे , variable ‘c’ मे array के  elements को add किया जाता है |
void subtraction  () मे  दोनों array और size को pass किया जा सकता है |
इस function मे , variable ‘c’ मे array के  elements को subtract किया जाता है |

#include<iostream.h>
#include<conio.h>
class math{
public:
void addition (int a[],int b[] , int size )
{
int c[size][size];
for(i=1;i<=size;i++)
{
for(j=1;j<size;j++)
{
c[i][j] = a[i][j]+b[i][j];
}
}
for(i=1;i<=size;i++)
{
for(j=1;j<size;j++)
{
cout<<c[i][j];
}
cout<<endl;
}
}
void subtraction(int a[],int b[] ,int size )
{
int c[size][size];
for(i=1;i<=size;i++)
{
for(j=1;j<size;j++)
{
c[i][j] = a[i][j]-b[i][j];
}
}
for(i=1;i<=size;i++)
{
for(j=1;j<size;j++)
{
cout<<c[i][j];
}
cout<<endl;
}
}
};
void main()
{
math m;
int a[3][3],b[3][3];
cout<<“Enter elements of first array :”<<endl;
for(i=0;i<3;i++)
{
for(j=0;j=3;j++)
{
cin>>a[i][j];
}
}
cout<<“Enter elements of second array :”<<endl;
for(i=0;i<3;i++)
{
for(j=0;j=3;j++)
{
cin>>a[i][j];
}
}
m.addition(a,b);
m.subtraction(a,b);
getch();
}

Sbistudy

Recent Posts

सती रासो किसकी रचना है , sati raso ke rachnakar kaun hai in hindi , सती रासो के लेखक कौन है

सती रासो के लेखक कौन है सती रासो किसकी रचना है , sati raso ke…

13 hours ago

मारवाड़ रा परगना री विगत किसकी रचना है , marwar ra pargana ri vigat ke lekhak kaun the

marwar ra pargana ri vigat ke lekhak kaun the मारवाड़ रा परगना री विगत किसकी…

13 hours ago

राजस्थान के इतिहास के पुरातात्विक स्रोतों की विवेचना कीजिए sources of rajasthan history in hindi

sources of rajasthan history in hindi राजस्थान के इतिहास के पुरातात्विक स्रोतों की विवेचना कीजिए…

2 days ago

गुर्जरात्रा प्रदेश राजस्थान कौनसा है , किसे कहते है ? gurjaratra pradesh in rajasthan in hindi

gurjaratra pradesh in rajasthan in hindi गुर्जरात्रा प्रदेश राजस्थान कौनसा है , किसे कहते है…

2 days ago

Weston Standard Cell in hindi वेस्टन मानक सेल क्या है इससे सेल विभव (वि.वा.बल) का मापन

वेस्टन मानक सेल क्या है इससे सेल विभव (वि.वा.बल) का मापन Weston Standard Cell in…

3 months ago

polity notes pdf in hindi for upsc prelims and mains exam , SSC , RAS political science hindi medium handwritten

get all types and chapters polity notes pdf in hindi for upsc , SSC ,…

3 months 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