JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

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

Class 6

Hindi social science science maths English

Class 7

Hindi social science science maths English

Class 8

Hindi social science science maths English

Class 9

Hindi social science science Maths English

Class 10

Hindi Social science science Maths English

Class 11

Hindi sociology physics physical education maths english economics geography History

chemistry business studies biology accountancy political science

Class 12

Hindi physics physical education maths english economics

chemistry business studies biology accountancy Political science History sociology

Home science Geography

English medium Notes

Class 6

Hindi social science science maths English

Class 7

Hindi social science science maths English

Class 8

Hindi social science science maths English

Class 9

Hindi social science science Maths English

Class 10

Hindi Social science science Maths English

Class 11

Hindi physics physical education maths entrepreneurship english economics

chemistry business studies biology accountancy

Class 12

Hindi physics physical education maths entrepreneurship english economics

chemistry business studies biology accountancy

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

four potential in hindi 4-potential electrodynamics चतुर्विम विभव किसे कहते हैं

चतुर्विम विभव (Four-Potential) हम जानते हैं कि एक निर्देश तंत्र में विद्युत क्षेत्र इसके सापेक्ष…

3 days ago

Relativistic Electrodynamics in hindi आपेक्षिकीय विद्युतगतिकी नोट्स क्या है परिभाषा

आपेक्षिकीय विद्युतगतिकी नोट्स क्या है परिभाषा Relativistic Electrodynamics in hindi ? अध्याय : आपेक्षिकीय विद्युतगतिकी…

5 days ago

pair production in hindi formula definition युग्म उत्पादन किसे कहते हैं परिभाषा सूत्र क्या है लिखिए

युग्म उत्पादन किसे कहते हैं परिभाषा सूत्र क्या है लिखिए pair production in hindi formula…

7 days ago

THRESHOLD REACTION ENERGY in hindi देहली अभिक्रिया ऊर्जा किसे कहते हैं सूत्र क्या है परिभाषा

देहली अभिक्रिया ऊर्जा किसे कहते हैं सूत्र क्या है परिभाषा THRESHOLD REACTION ENERGY in hindi…

7 days ago

elastic collision of two particles in hindi definition formula दो कणों की अप्रत्यास्थ टक्कर क्या है

दो कणों की अप्रत्यास्थ टक्कर क्या है elastic collision of two particles in hindi definition…

7 days 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