हिंदी माध्यम नोट्स
C++ : Switch (Advance ) in hindi , what is Switch at advanced level in c++ language with example program
#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 किया जाता है |
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…
Translation in english grammer in hindi examples Step of Translation (अनुवाद के चरण)
Translation 1. Step of Translation (अनुवाद के चरण) • मूल वाक्य का पता करना और उसकी…
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…
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…
विश्व के महाद्वीप की भौगोलिक विशेषताएँ continents of the world and their countries in hindi features
continents of the world and their countries in hindi features विश्व के महाद्वीप की भौगोलिक…
भारत के वन्य जीव राष्ट्रीय उद्यान list in hin hindi IAS UPSC
भारत के वन्य जीव भारत में जलवायु की दृष्टि से काफी विविधता पाई जाती है,…