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

Question Tag Definition in english with examples upsc ssc ias state pcs exames important topic

Question Tag Definition • A question tag is a small question at the end of a…

2 weeks ago

Translation in english grammer in hindi examples Step of Translation (अनुवाद के चरण)

Translation 1. Step of Translation (अनुवाद के चरण) • मूल वाक्य का पता करना और उसकी…

2 weeks ago

Report Writing examples in english grammer How to Write Reports explain Exercise

Report Writing • How to Write Reports • Just as no definite rules can be laid down…

2 weeks ago

Letter writing ,types and their examples in english grammer upsc state pcs class 12 10th

Letter writing • Introduction • Letter writing is an intricate task as it demands meticulous attention, still…

2 weeks ago

विश्व के महाद्वीप की भौगोलिक विशेषताएँ continents of the world and their countries in hindi features

continents of the world and their countries in hindi features विश्व के महाद्वीप की भौगोलिक…

2 weeks ago

भारत के वन्य जीव राष्ट्रीय उद्यान list in hin hindi IAS UPSC

भारत के वन्य जीव भारत में जलवायु की दृष्टि से काफी विविधता पाई जाती है,…

2 weeks 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