JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

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

Categories: c++ language in hindi

C++ : Switch (Advance ) in hindi , what is Switch at advanced level in c++ language with example program

what is Switch at advanced level in c++ language with example program , C++ : Switch (Advance ) in hindi :-
इससे पहले के article मे , switch statement को discuss किया जाता है | जिसमे multiple conditions को check किया जाता है | जैसे switch statement मे case label को use किया जाता ही | case lable मे switch statement मो pass किया गया expression या condition से प्राप्त आउटपुट के आधार पर अलग अलग block को perform किया जाता है |}switch statement के लिए उदाहर निन्म है :
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
char choice ;
cout<<“Enter ‘m’ for morning  “;
cout<<“Enter ‘a’ for afternoon”;
cout<<“Enter ‘n’ for night “;
cout<<“Enter Choice  : “;
cin>>choice ;
switch(choice)
{
case ‘m’ :
cout<<“Good morning ! Have a nice day .”;
break;
case ‘a’ :
cout<<“Good afternoon ! Make sure half day of this day will be go fine.”;
break;
case ‘n’ :
cout<<“Good night ! Sweet Dreams.”;
break;
defalut :
cout<<“Invalid Choice “;
break;
}
cout<<“Output : “<<c;
getch();
}
getch();
}
इस उदाहरन मे , यूजर द्वारा choice को input किया जाता है | जिसे variable choice मे assign कर दिया जाता है | अगर यूजर द्वारा input किये गये input  निन्म होते है
अगर ‘m’ होती है तब morning message display होगा |
अगर ‘a’ होती है तब afternoon message display होगा |
अगर ‘n’ होती है तब night message display होगा |Enumeration as switch case lable
किसी enum variable के value को switch statement के case lable को declare किया जाता है | enum value एक constant की तरह करता है जिसकी कोई constant value होती है | उदाहरन के लिए :
enum{red,yellow,blue ,green};
इस enum variable मे चार values होती है | जिसमे red की value ‘0’ होती है | और yellow की value ‘1’ होती है | और blue की value ‘2’ होती है | और green की value ‘3’ होती है |
जब switch statement मे enum की value को pass किया जाता है तब इसके constant value के साथ डील किया जाता है |
उदाहरन के लिए :

#include<iostream.h>
#include<conio.h>
enum {parrot,peacock, dove, piegoen , crow , sparrow };
void main()
{
using namespace std;
int choice ;
cout<<“Enter Choice  (0-6) : “;
cin>>choice ;
while(choice >= parrot && choice <= sparrow)
{
switch(choice)
{
case sparrow  :
cout<<“Your Bird is sparrow.”;
break;
case peacock  :
cout<<“Your Bird is peacock.”;
break;
case dove  :
cout<<“Your Bird is dove.”;
break;
case piegoen  :
cout<<“Your Bird is piegoen.”;
break;
case crow  :
cout<<“Your Bird is crow.”;
break;
case parrot  :
cout<<“Your Bird is parrot.”;
break;
defalut :
cout<<“Sorry , We can not arrange your bird “;
break;
}
}
getch();
}
इस उदाहरन मे , enum बर्ड को use किया जाट अहै | जिसमे छ प्रकार के birds को use किया जाता है | यह पर parrot=0,peacock=1, dove=2, piegoen=3 , crow=4, sparrow=5 होती है | while loop मे , यूजर द्वारा input की गयी choice को enum value parrot और स्पैरो से check करते है | choice का data type integer है इसलिए यह पर choice की value ‘0’ से बड़ी और ‘5’ से कम होती है |
switch statement मे choice को pass किया जाता है |
अगर यूजर द्वारा input की गयी value ‘1’ होगी तब peacock को display किया जाता है |
अगर यूजर द्वारा input की गयी value ‘2’ होगी तब dove को display किया जाता है |
अगर यूजर द्वारा input की गयी value ‘3’ होगी तब piegoen को display किया जाता है |
अगर यूजर द्वारा input की गयी value ‘4’ होगी तब crow को display किया जाता है |
अगर यूजर द्वारा input की गयी value ‘5’ होगी तब sparrow को display किया जाता है |

break और continue statement
break और continue statement  का use प्रोग्राम के किसी block को स्किप करने के लिए किया जाता है | इसके अलावा break statement का use switch statement मे भी use किया जाता है | और loop मे भी किया जा सकता है |
अगर loop मे  break statement use किया जाता है तब  loop का control,loop से बहार हो जाता है |
ओए अगर switch मे break statement को use किया जाता है तब switch statement का control switch statement से बहार चला जाता है |
और break और continue statement  से loop के किसी भाग  को स्किप किया जा सकता है |
break statement ; इस statement से कंट्रो को स्किप किया जाता है | इसके बाद के सभी statement को exwcution को स्किप किया जा सकता है | जब  तक  continue statement नहीं आ जाता है |
continue statement ; इस statement का use break statement को terminate करने के लिए किया जाता है |
इसका उदाहरन निन्म है :

#include<iostream.h>
#include<conio.h>
void main()
{
using namespace std;
char name[50] ;
int place =0;
cout<<“line :”;
cin.get(name , 50);
cout<<“Full Name :”<<name;
cout<< ” Last Name : “;
for(int i =0 ; name [i]!=’\0′ ; i++)
{
cout<<name[i];
if(line[i]== “.”)
break;
if(name[i]!= ‘ ‘)
ccontiue;
place++;
}
coput<<“Place at :”<<place ;
getch();
}
इस उदाहरन  मे ,
सबसे पहले नाम को input किया जाता है | जिसमे first name और last name के बीच ‘.’ से separate किया जाता है |
इसके बाद फुल name को display किया जाता है | बाद last name को display किया जाता है |
last name को ‘.’ के बाद print करते है |

इस article मे , switch statement मे enum value को use को  और  break और continue statement  को discuss किया जाता है |

Sbistudy

Recent Posts

मालकाना का युद्ध malkhana ka yudh kab hua tha in hindi

malkhana ka yudh kab hua tha in hindi मालकाना का युद्ध ? मालकाना के युद्ध…

4 weeks ago

कान्हड़देव तथा अलाउद्दीन खिलजी के संबंधों पर प्रकाश डालिए

राणा रतन सिंह चित्तौड़ ( 1302 ई. - 1303 ) राजस्थान के इतिहास में गुहिलवंशी…

4 weeks ago

हम्मीर देव चौहान का इतिहास क्या है ? hammir dev chauhan history in hindi explained

hammir dev chauhan history in hindi explained हम्मीर देव चौहान का इतिहास क्या है ?…

4 weeks ago

तराइन का प्रथम युद्ध कब और किसके बीच हुआ द्वितीय युद्ध Tarain battle in hindi first and second

Tarain battle in hindi first and second तराइन का प्रथम युद्ध कब और किसके बीच…

4 weeks ago

चौहानों की उत्पत्ति कैसे हुई थी ? chahamana dynasty ki utpatti kahan se hui in hindi

chahamana dynasty ki utpatti kahan se hui in hindi चौहानों की उत्पत्ति कैसे हुई थी…

1 month ago

भारत पर पहला तुर्क आक्रमण किसने किया कब हुआ first turk invaders who attacked india in hindi

first turk invaders who attacked india in hindi भारत पर पहला तुर्क आक्रमण किसने किया…

1 month 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