हिंदी माध्यम नोट्स
Categories: c++ language in hindi
Write a program to check a number Armstrong , palindrome condition by using class , even – odd
इससे पहले के article मे , class के उदाहरनो को discuss किया तह | लेकिन अब इस article मे कुछ advance उदाहरानो को discuss करेगे जिसे आप सभी को पहले खुद try करना चाहिए | जिससे आप सभी के c++ language के सबसे महतवपूर्ण concept class + object को मजबूत हो सके |
उदहारण -1
Write a program to check a number Armstrong , palindrome condition by using class .
Explanation
सबसे पहले class check को declare किया जाता है | इस class मे एक variable number को calculate किया जाता है इन सभी variable का access mode public है अतः इन variable को main() और class check मे use किया जा सकता है |
class check मे दो functions को declare किया जाता है |
Armstrong() : इसका access mode public है | इसमें Armstrong number की condition को check किया जाता है | इसे main() के साथ class check मे भी use किया जा सकता है |
parlidlom () : इसका भी access mode public है | इसमें palindrome number की condition को check किया जाता है | इसे main() के साथ check class मे भी use किया जा सकता है |
parlidlom() mai
सबसे पहले function मे यूजर द्वारा input की गयी number को pass किया जाता है | Armstrong number को check करने के लिए loop को चलाया जाता है |
loop मे control variable को number से initial किया जाता है | ये loop तब तक चलाया जाता अहि जब तक control variable की value ‘0’ नहीं होती है |
loop की body मे , remainder = i % 10 ; से remainder को calculate किया जाता है | इसके बाद check variable मे check + remainder *10 को assign किया जाता है |
इसके बाद control variable को number /10 से update किया जाता है |
इसके बाद number और check की value को check किया जाता है |
अगर दोनों की value सामान होती है तब number is parlidlom का message print हो जाता है | अन्यथा number is not parlidlom. display होगा |
Armstrong() मे ,
सबसे पहले function मे यूजर द्वारा input की गयी number को pass किया जाता है | armstorng number को check करने के लिए loop को चलाया जाता है |
loop मे control variable को number से initial किया जाता है | ये loop तब तक चलाया जाता अहि जब तक control variable की value ‘0’ नहीं होती है |
loop की body मे , remainder = number % 10 ; से remainder को calculate किया जाता है | इसके बाद check variable मे remainder*remainder*remainder को add किया जाता है |
इसके बाद control variable को number /10 से update किया जाता है |
इसके बाद number और check की value को check किया जाता है |
अगर दोनों की value सामान होती है तब number is Armstrong का message print हो जाता है | अन्यथा number is not Armstrong. display होगा |
palindrome () मे ,
इस function मे यूजर द्वारा input किये गये number को pass करते है |
#include<iostream.h>
#include<conio.h>
class check {
public :
int remainder , check ;
public:
void armstorng(int number )
{
int i =0;
i=number ;
while(i != 0 )
{
remainder = i % 10 ;
check += remainder*remainder*remainder’
i = i /10;
}
if(check == number )
{
cout<<“number is armstorng” ;
}
else
{
cout<<“number is not armstorng “;
}
void parlidlom(int number )
{
int i =0;
i=number ;
while(i != 0 )
{
remainder = i % 10 ;
check = check + remainder *10;
i = i /10;
}
if(check == number )
{
cout<<“number is parlidlom.” ;
}
else
{
cout<<“number is not parlidlom.”;
}
}
};
void main()
{
check.c;
int num;
cout<<“Enter Number :”<<endl;
cin>>num;
c.armstorng(num);
c.parlidlom(num);
getch();
}
उदहारण -2
Write a program to find even – odd using class within range.
Explanation
र्सबसे पहले class condition को declare किया जाता है | इस class मे किसी range मे उपस्थित even or odd element को find किया जाता है |
class math मे दो function को discuss किया जाता है |
even () : इसका access mode public है | अतः इसे main() के साथ class condition मे भी use किया जा सकता है | इसमें first और last element को pass किया जाता है |
odd () : इसका भी access mode public है | अतः इसे main() के साथ class condition मे भी use किया जा सकता है |
void even () मे first और last को pass किया जा सकता है |
उसके बाद loop चलाया जाता है |
loop मे control variable को first element से initial किया जाता है | ये loop तब तक चलता है जब तक इसकी value last से कम या सामान होती है |
loop की body मे control variable पर even की condition को check किया जाता है | अगर condition true है तब number print हो जाता है |
इस loop के body को एक बार excute होने के बाद control variable को ‘1’ से update करता है |
void odd() मे first और last को pass किया जा सकता है |
odd condition की check करने के लिए loop चलाया जाता है |
loop मे control variable को first element से initial किया जाता है | ये loop तब तक चलता है जब तक इसकी value last element से कम या सामान होती है |
loop की body मे control variable पर odd की condition को check किया जाता है | अगर condition true है तब number print हो जाता है |
इस loop के body को एक बार excute होने के बाद control variable को ‘1’ से update करता है |
#include<iostream.h>
#include<conio.h>
class condition {
public:
void even (int first ,int second )
{
cout<<“Even Number in Range “;
for ( int i = first ; i < = last ; i++)
{
if((i%2)==0)
cout<<i;
}
}
void odd (int first ,int second )
{
cout<<“Odd Number in Range “;
for ( int i = first ; i < = last ; i++)
{
if((i%2)!=0)
cout<<i;
}
}
};
void main()
{
condition c;
int a,b ;
cout<<“Enter first element : “;
cin>>a;
cout<<“Enter last element : “;
cin>>b;
c.even (a,b);
c.odd(a,b);
getch();
}
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