हिंदी माध्यम नोट्स
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
मालकाना का युद्ध malkhana ka yudh kab hua tha in hindi
malkhana ka yudh kab hua tha in hindi मालकाना का युद्ध ? मालकाना के युद्ध…
1 month ago
कान्हड़देव तथा अलाउद्दीन खिलजी के संबंधों पर प्रकाश डालिए
राणा रतन सिंह चित्तौड़ ( 1302 ई. - 1303 ) राजस्थान के इतिहास में गुहिलवंशी…
1 month ago
हम्मीर देव चौहान का इतिहास क्या है ? hammir dev chauhan history in hindi explained
hammir dev chauhan history in hindi explained हम्मीर देव चौहान का इतिहास क्या है ?…
1 month ago
तराइन का प्रथम युद्ध कब और किसके बीच हुआ द्वितीय युद्ध Tarain battle in hindi first and second
Tarain battle in hindi first and second तराइन का प्रथम युद्ध कब और किसके बीच…
1 month ago
चौहानों की उत्पत्ति कैसे हुई थी ? chahamana dynasty ki utpatti kahan se hui in hindi
chahamana dynasty ki utpatti kahan se hui in hindi चौहानों की उत्पत्ति कैसे हुई थी…
2 months ago
भारत पर पहला तुर्क आक्रमण किसने किया कब हुआ first turk invaders who attacked india in hindi
first turk invaders who attacked india in hindi भारत पर पहला तुर्क आक्रमण किसने किया…
2 months ago