JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

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

Categories: c++ language in hindi

C++ : LOOPING WITH CLASS (PART 1) , Write a program to count the digit of the number using class .

इससे पहले के article मे conversion class को discuss किया था जिसमे number सिस्टम के चार प्रकार मे interchange करने केलिए प्रोग्राम को discuss किया था | अब इस article मे class को looping के साथ उदाहरनो को discuss करेगे |
उदाहरन 1 :
Write a program to count the digit of the number using class .
explanation
सबसे पहले class loop को declare करते है | जिसमे एक variabledigit को define करते है जिसका access mode private है | अतः इसे केवल class या class के function मे define किया जाता है |
इसके बाद public mode मे function count () को define किया जाता है |
count function मे ,
इस function मे  यूजर द्वारा input किये गये  number को पास किया जाता है |
number को 10 से divinde किया जाता है और इसके बाद इस division के last डिजिट को sum मे add कर दिया जाता है |
फिर number मे से last डिजिट को eliminate कर दिया जाता है | इसके लिए number को 10 से divind किया जाता है |
ये loop तब तक चलता है जब तक इसकी value ‘0’ नहीं हो जाती है |
main() मे ,
सबसे पहले class loop के object l को define किया जाता है |
यूजर द्वारा number को input करा दिया जाता है और इस number को class के object function मे pass कर दिया जाता है |
Source Code
#include<iostream.h>
#include<conio.h>
class loop{
private :
int digit ;
public :
function count (int number )
{
while(number != 0 )
{
digit = digit + ( number %10 );
number = number / 10 ;
}
cout<<“Sum of Digit : “<<digit;
}
void main ()
{
loop l;
int num;
cout<<“Enter Number : “<<endl;
cin>>num;
l.count(num);
}
इसका आउटपुट होगा :
Enter Number : 122334
Sum of Digit : 15
उदाहरन 2 :
Write a program to find first और last digit of the number using class .
explanation
सबसे पहले class find को declare करते है | जिसमे or variable first और last digi  को define करते है जिसका access mode private है | अतः इसे केवल class या class के function मे define किया जाता है |
इसके बाद public mode मे  दो function first() और last () को define किया जाता है |
first  function मे ,
इस function मे  यूजर द्वारा input किये गये  number मे से first digit को find किया जाता है  |
number को 10 से divinde किया जाता है और count को 10 से multiply किया जाता है |
फिर number मे से last डिजिट को eliminate कर दिया जाता है | इसके लिए number को 10 से divind किया जाता है |
ये loop तब तक चलता है जब तक इसकी value ‘0’ नहीं हो जाती है |
इसके बाद first मे number / count से number के first डिजिट को find किया जाता है |
last () मे
इसमें यूजर द्वारा input किये गये number मे से last डिजिट को find किया जाता है |
इसके लिए number को 10 से divid किया जाता है | इसके remainder को last digit मे assign किया जाता है |
main() मे ,
सबसे पहले class loop के object f को define किया जाता है |
यूजर द्वारा number को input करा दिया जाता है और इस number को class के object function मे pass कर दिया जाता है |
Source Code
#include<iostream.h>
#include<conio.h>
class find{
private :
int first , last , count  ;
public :
void first  (int number )
{
while(number != 0 )
{
count = count * 10 ;
number = number / 10 ;
}
first = number / count ;
cout<<“first digit : “<<first <<endl;
}
void last (int number )
{
last = number % 10 ;
cout<<“last number :”<<last ;
}
}
void main ()
{
find f;
int num;
cout<<“Enter Number : “<<endl;
cin>>num;
f.first(num);
f.last(num);
}
इसका आउटपुट होगा :
Enter Number : 122334
first digit : 1
last number : 4
उदाहरन 3 :
Write a program to print reverse of the number using class .
explanation
सबसे पहले class reverse को declare करते है | जिसमे एक variable reverse को define करते है जिसका access mode private है | अतः इसे केवल class मे ही use किया जाता है |
इसके बाद public mode मे function reverse() को define किया जाता है |
reverse function मे ,
इस function मे  यूजर द्वारा input किये गये  number को पास किया जाता है |
number को 10 से divinde किया जाता है और इसके बाद इस division के remainder को last डिजिट को find किया जाता है |
इसके बाद reverse को 10 से multiply करते है | reverse = reverse * 10 ;
इसके बाद reverse = reverse + last ; को calculate किया जाता है |
फिर number मे से last डिजिट को eliminate कर दिया जाता है | इसके लिए number को 10 से divind किया जाता है |
ये loop तब तक चलता है जब तक इसकी value ‘0’ नहीं हो जाती है |
main() मे ,
सबसे पहले class reverse के object r को define किया जाता है |
यूजर द्वारा number को input करा दिया जाता है और इस number को class के object function मे pass कर दिया जाता है |
Source Code
#include<iostream.h>
#include<conio.h>
class reverse {
private :
int reverse ;
public :
void reverse (int number )
{
while(number != 0 )
{
reverse = reverse *10 ;
reverse = reverse + ( number %10 );
number = number / 10 ;
}
cout<<” Reverse number : “<<reverse ;
}
void main ()
{
reverse r;
int num;
cout<<“Enter Number : “<<endl;
cin>>num;
r.reverse(num);
}
इसका आउटपुट होगा :
Enter Number : 122334
Reverse number : 433221
Sbistudy

Recent Posts

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

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

18 hours ago

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

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

18 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