SlideShare ist ein Scribd-Unternehmen logo
1 von 21
Lab No. 3
saqib.rasheed@mail.au.edu.pk




  Air University
Write a program to check whether a triangle is
valid or not, when the three angles of the
triangle are entered through the keyboard. A
triangle is valid if the sum of all the three
Angles is equal to 180 degrees




                 Air University
switch statement
The control statement that allows
 us to make a decision from the
  number of choices is called a
              switch
switch ( variable name )
 {
     case „a‟ :
           statements;
     case „b‟ :
           statements;
     case „c‟ :
            statements;
     …
 }
switch statements
switch ( grade)
 {
     case „A‟ :
            cout << “ Excellent ” ;
     case „B‟ :
            cout << “ Very Good ” ;
     case „C‟ :
            …
     …
 }
switch statements
case „A‟ :
      cout << “ Excellent ” ;
      …
      …
switch ( grade)
{
       case „A‟ :
              cout <<   “ Excellent ” ;
       case „B‟ :
              cout <<   “ Very Good ” ;
       case „C‟ :
              cout <<   “Good ” ;
       case „D‟ :
              cout <<   “ Poor ” ;
       case „F‟ :
              cout <<   “ Fail ” ;
}
break;
switch ( grade )
{
        case „A‟ :
                cout << “ Excellent ” ;
                break ;
        case „B‟ :
                cout << “ Very Good ” ;
                 break ;
        case „C‟ :
                cout << “Good ” ;
                 break ;
        case „D‟ :
                cout << “ Poor ” ;
                 break ;
        case „F‟ :
                cout << “ Fail ” ;
                 break ;
}
default :
default :
 cout << “ Please Enter Grade from
 „A‟ to „D‟ or „F‟ “ ;
Flow Chart of switch statement

          switch (grade)

                    case ‘A’ :

                       Display
                     “Excellent”

                    case ‘B’ :


                       Display
                     “Very Good”
                    …



                    Default :


                      “……..”
int i = 2 ;
switch ( i )
{
   case 1 :
         cout<<"I am in case 1 n"; break;
   case 2 :
         cout<<"I am in case 2 n"; break;
   case 3 :
         cout<<"I am in case 3 n"; break;
   default :
         cout<<"I am in default n";
}



           Output
           I am in case 2
if (x == 1)
                              switch (x)
{
                              {
cout << "x is 1";
                               case 1:
}
                               cout << "x is 1";
else if (x == 2)
                               break;
{                              case 2:
 cout << "x is 2";             cout << "x is 2";
}                              break;
else                           default:
 {                             cout << "value of x unknown";
cout << "value of x unknown"; }
}
There are some things that you simply cannot
  do with a switch. These are:
 A float expression cannot be tested using a
  switch
 Cases can never have variable expressions
  (for example it is wrong to say case a +3 : )
 Multiple cases cannot use same expressions.
  Thus the following switch is illegal:
                 switch ( a )
                 {
                 case 3.2 :
                 ...
                 case 1 + 2 :
                 ...
                 }
int day;

   cout<<"Eneter Day Number";
   cin>>day;

switch (day)
  {
   case 1 : cout << "nSunday";
         break;
   case 2 : cout << "nMonday";
         break;
   case 3 : cout << "nTuesday";
         break;
   case 4 : cout << "nWednesday";
         break;
   case 5 : cout << "nThursday";
         break;
   case 6 : cout << "nFriday";
         break;
   case 7 : cout << "nSaturday";
         break;
  default : cout << "nNot an allowable day number";
         break;
}
switch (day)
 {
   case 1 :
   case 7 :
   cout << "This is a weekend day"; Break
                                         1
   break;
  case 2 :
  case 3 :
  case 4 :
  case 5 :
  case 6 : cout << "This is a weekday";
                                          Break
  break;                                    2
 default : cout << "Not a legal day"; break;
}
char ch ;
cout<< "Enter any of the alphabet a, b, or c ";
cin>>ch;
switch ( ch )
{
   case 'a' : case 'A' :
         cout<<"a is an apple" ; break ;
   case 'b' :
   case 'B' :
         cout<<"b as in brain";
   break ;
   case 'c' : case 'C' :
         cout<<"c as in cookie"; break ;
   default :
         cout<<"wish you knew what are alphabets" ;
}
 Yesand no. Yes, because it offers a better
 way of writing programs as compared to if,
 and no because in certain situations we are
 left with no choice but to use if. The
 disadvantage of switch is that one cannot
 have a case in a switch which looks like:

                case   i <= 20 :
 compiler   generates a jump table for a switch
  during compilation
 during execution it simply refers the jump
  table to decide which case should be
  executed .
 if-elses are slower because they are
  evaluated at execution time
Make a calculator using switch statement
 It should take two numbers from user.
 Ask the user the function to perform
 Display the result




                 Air University
Que
Write a menu driven program program in C++
using switch statement that contain option as
under.( The Menu should )

Enetr 1--> To   Find   Largest Number Among Three Variables.
Enetr 2--> To   Find   ODD or EVEN
Enetr 3--> To   Find   Condition of Water
Enetr 4--> To   Find   Grade Of Student



                         Air University

Weitere ähnliche Inhalte

Was ist angesagt?

C++ Programming Club-Lecture 1
C++ Programming Club-Lecture 1C++ Programming Club-Lecture 1
C++ Programming Club-Lecture 1Ammara Javed
 
Elements of c program....by thanveer danish
Elements of c program....by thanveer danishElements of c program....by thanveer danish
Elements of c program....by thanveer danishMuhammed Thanveer M
 
C++ Programming Club-Lecture 2
C++ Programming Club-Lecture 2C++ Programming Club-Lecture 2
C++ Programming Club-Lecture 2Ammara Javed
 
Conditional statement
Conditional statementConditional statement
Conditional statementilakkiya
 
Decision making and branching in c programming
Decision making and branching in c programmingDecision making and branching in c programming
Decision making and branching in c programmingPriyansh Thakar
 
Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)heoff
 
C++ Programming Club-Lecture 3
C++ Programming Club-Lecture 3C++ Programming Club-Lecture 3
C++ Programming Club-Lecture 3Ammara Javed
 
Spf Chapter5 Conditional Logics
Spf Chapter5 Conditional LogicsSpf Chapter5 Conditional Logics
Spf Chapter5 Conditional LogicsHock Leng PUAH
 
C lecture 3 control statements slideshare
C lecture 3 control statements slideshareC lecture 3 control statements slideshare
C lecture 3 control statements slideshareGagan Deep
 
C++ decision making
C++ decision makingC++ decision making
C++ decision makingZohaib Ahmed
 
Programming in C++
Programming in C++Programming in C++
Programming in C++Pooya Merat
 
Lecture 2 php basics (1)
Lecture 2  php basics (1)Lecture 2  php basics (1)
Lecture 2 php basics (1)Core Lee
 

Was ist angesagt? (20)

Programming C Part 03
Programming C Part 03Programming C Part 03
Programming C Part 03
 
C++ Programming Club-Lecture 1
C++ Programming Club-Lecture 1C++ Programming Club-Lecture 1
C++ Programming Club-Lecture 1
 
Elements of c program....by thanveer danish
Elements of c program....by thanveer danishElements of c program....by thanveer danish
Elements of c program....by thanveer danish
 
Control statement
Control statementControl statement
Control statement
 
C++ Programming Club-Lecture 2
C++ Programming Club-Lecture 2C++ Programming Club-Lecture 2
C++ Programming Club-Lecture 2
 
Conditional statement
Conditional statementConditional statement
Conditional statement
 
C++ STATEMENTS
C++ STATEMENTS C++ STATEMENTS
C++ STATEMENTS
 
Decision making and branching in c programming
Decision making and branching in c programmingDecision making and branching in c programming
Decision making and branching in c programming
 
Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)
 
C++ Programming Club-Lecture 3
C++ Programming Club-Lecture 3C++ Programming Club-Lecture 3
C++ Programming Club-Lecture 3
 
Spf Chapter5 Conditional Logics
Spf Chapter5 Conditional LogicsSpf Chapter5 Conditional Logics
Spf Chapter5 Conditional Logics
 
if,loop,switch
if,loop,switchif,loop,switch
if,loop,switch
 
L05if
L05ifL05if
L05if
 
C lecture 3 control statements slideshare
C lecture 3 control statements slideshareC lecture 3 control statements slideshare
C lecture 3 control statements slideshare
 
C++ decision making
C++ decision makingC++ decision making
C++ decision making
 
Switch statement mcq
Switch statement  mcqSwitch statement  mcq
Switch statement mcq
 
Control structures
Control structuresControl structures
Control structures
 
Control statements
Control statementsControl statements
Control statements
 
Programming in C++
Programming in C++Programming in C++
Programming in C++
 
Lecture 2 php basics (1)
Lecture 2  php basics (1)Lecture 2  php basics (1)
Lecture 2 php basics (1)
 

Andere mochten auch

Jindle for MTC Online
Jindle for MTC OnlineJindle for MTC Online
Jindle for MTC Onlinebytesli
 
Create an Assignment in MBC
Create an Assignment in MBCCreate an Assignment in MBC
Create an Assignment in MBCMaryAnn Medved
 
Lap trinh php va my sql
Lap trinh php va my sqlLap trinh php va my sql
Lap trinh php va my sqlhieusy
 
[Japanese]2011 dec ttc+arib
[Japanese]2011 dec ttc+arib[Japanese]2011 dec ttc+arib
[Japanese]2011 dec ttc+aribTsuguo Nobe
 
Ma oun special education presntation10
Ma oun special education presntation10Ma oun special education presntation10
Ma oun special education presntation10Maha Khan
 
Finding the meaning in meaningful use
Finding the meaning in meaningful useFinding the meaning in meaningful use
Finding the meaning in meaningful usegdabate
 
Russian Idiom Project
Russian Idiom ProjectRussian Idiom Project
Russian Idiom Projectmulhernb
 
Чудо-листовка
Чудо-листовкаЧудо-листовка
Чудо-листовкаprasu1995
 
Uml面向对象的分析与设计
Uml面向对象的分析与设计Uml面向对象的分析与设计
Uml面向对象的分析与设计xunhao
 
World war ii mz[1]
World war ii mz[1]World war ii mz[1]
World war ii mz[1]zapatam1990
 
Soal soal
Soal soalSoal soal
Soal soalhome
 
Target audience analyse
Target audience analyseTarget audience analyse
Target audience analysenctcmedia12
 
AT - How did you use media technologies?
AT - How did you use media technologies?AT - How did you use media technologies?
AT - How did you use media technologies?nctcmedia12
 
Digitisation: Costs and Sustainability
Digitisation: Costs and SustainabilityDigitisation: Costs and Sustainability
Digitisation: Costs and SustainabilityEd Fay
 

Andere mochten auch (20)

Jindle for MTC Online
Jindle for MTC OnlineJindle for MTC Online
Jindle for MTC Online
 
Create an Assignment in MBC
Create an Assignment in MBCCreate an Assignment in MBC
Create an Assignment in MBC
 
Lap trinh php va my sql
Lap trinh php va my sqlLap trinh php va my sql
Lap trinh php va my sql
 
[Japanese]2011 dec ttc+arib
[Japanese]2011 dec ttc+arib[Japanese]2011 dec ttc+arib
[Japanese]2011 dec ttc+arib
 
2003
20032003
2003
 
Ma oun special education presntation10
Ma oun special education presntation10Ma oun special education presntation10
Ma oun special education presntation10
 
Finding the meaning in meaningful use
Finding the meaning in meaningful useFinding the meaning in meaningful use
Finding the meaning in meaningful use
 
Russian Idiom Project
Russian Idiom ProjectRussian Idiom Project
Russian Idiom Project
 
Чудо-листовка
Чудо-листовкаЧудо-листовка
Чудо-листовка
 
สกกก
สกกกสกกก
สกกก
 
Uml面向对象的分析与设计
Uml面向对象的分析与设计Uml面向对象的分析与设计
Uml面向对象的分析与设计
 
What we need to know by Paul Sturges
What we need to know by Paul SturgesWhat we need to know by Paul Sturges
What we need to know by Paul Sturges
 
World war ii mz[1]
World war ii mz[1]World war ii mz[1]
World war ii mz[1]
 
Soal soal
Soal soalSoal soal
Soal soal
 
Diapason
DiapasonDiapason
Diapason
 
Amc Instruments
Amc InstrumentsAmc Instruments
Amc Instruments
 
Lesson2
Lesson2Lesson2
Lesson2
 
Target audience analyse
Target audience analyseTarget audience analyse
Target audience analyse
 
AT - How did you use media technologies?
AT - How did you use media technologies?AT - How did you use media technologies?
AT - How did you use media technologies?
 
Digitisation: Costs and Sustainability
Digitisation: Costs and SustainabilityDigitisation: Costs and Sustainability
Digitisation: Costs and Sustainability
 

Ähnlich wie Switch Statements Lab

FP 201 Unit 3
FP 201 Unit 3 FP 201 Unit 3
FP 201 Unit 3 rohassanie
 
Programming - Marla Fuentes
Programming - Marla FuentesProgramming - Marla Fuentes
Programming - Marla Fuentesmfuentessss
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAAiman Hud
 
Switch.pptx
Switch.pptxSwitch.pptx
Switch.pptxAliAbro7
 
Introduction to Selection control structures in C++
Introduction to Selection control structures in C++ Introduction to Selection control structures in C++
Introduction to Selection control structures in C++ Neeru Mittal
 
Cs1123 5 selection_if
Cs1123 5 selection_ifCs1123 5 selection_if
Cs1123 5 selection_ifTAlha MAlik
 
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyC++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyGrejoJoby1
 
Powerpoint loop examples a
Powerpoint loop examples aPowerpoint loop examples a
Powerpoint loop examples ajaypeebala
 
Control Statement.ppt
Control Statement.pptControl Statement.ppt
Control Statement.pptsanjay
 
ch4_additional.ppt
ch4_additional.pptch4_additional.ppt
ch4_additional.pptLokeshK66
 

Ähnlich wie Switch Statements Lab (20)

FP 201 Unit 3
FP 201 Unit 3 FP 201 Unit 3
FP 201 Unit 3
 
Programming - Marla Fuentes
Programming - Marla FuentesProgramming - Marla Fuentes
Programming - Marla Fuentes
 
Ramirez slideshow
Ramirez slideshowRamirez slideshow
Ramirez slideshow
 
Project in programming
Project in programmingProject in programming
Project in programming
 
C++ TUTORIAL 1
C++ TUTORIAL 1C++ TUTORIAL 1
C++ TUTORIAL 1
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
Macaraeg
MacaraegMacaraeg
Macaraeg
 
Castro
CastroCastro
Castro
 
Switch.pptx
Switch.pptxSwitch.pptx
Switch.pptx
 
lesson 2.pptx
lesson 2.pptxlesson 2.pptx
lesson 2.pptx
 
Introduction to Selection control structures in C++
Introduction to Selection control structures in C++ Introduction to Selection control structures in C++
Introduction to Selection control structures in C++
 
Cs1123 5 selection_if
Cs1123 5 selection_ifCs1123 5 selection_if
Cs1123 5 selection_if
 
Final Exam in FNDPRG
Final Exam in FNDPRGFinal Exam in FNDPRG
Final Exam in FNDPRG
 
DataTypes.ppt
DataTypes.pptDataTypes.ppt
DataTypes.ppt
 
Oop1
Oop1Oop1
Oop1
 
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyC++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
 
Powerpoint loop examples a
Powerpoint loop examples aPowerpoint loop examples a
Powerpoint loop examples a
 
Control Statement.ppt
Control Statement.pptControl Statement.ppt
Control Statement.ppt
 
Fekra c++ Course #2
Fekra c++ Course #2Fekra c++ Course #2
Fekra c++ Course #2
 
ch4_additional.ppt
ch4_additional.pptch4_additional.ppt
ch4_additional.ppt
 

Kürzlich hochgeladen

Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)cama23
 

Kürzlich hochgeladen (20)

FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)
 

Switch Statements Lab

  • 2. Write a program to check whether a triangle is valid or not, when the three angles of the triangle are entered through the keyboard. A triangle is valid if the sum of all the three Angles is equal to 180 degrees Air University
  • 3. switch statement The control statement that allows us to make a decision from the number of choices is called a switch
  • 4. switch ( variable name ) { case „a‟ : statements; case „b‟ : statements; case „c‟ : statements; … }
  • 5. switch statements switch ( grade) { case „A‟ : cout << “ Excellent ” ; case „B‟ : cout << “ Very Good ” ; case „C‟ : … … }
  • 6. switch statements case „A‟ : cout << “ Excellent ” ; … …
  • 7. switch ( grade) { case „A‟ : cout << “ Excellent ” ; case „B‟ : cout << “ Very Good ” ; case „C‟ : cout << “Good ” ; case „D‟ : cout << “ Poor ” ; case „F‟ : cout << “ Fail ” ; }
  • 9. switch ( grade ) { case „A‟ : cout << “ Excellent ” ; break ; case „B‟ : cout << “ Very Good ” ; break ; case „C‟ : cout << “Good ” ; break ; case „D‟ : cout << “ Poor ” ; break ; case „F‟ : cout << “ Fail ” ; break ; }
  • 10. default : default : cout << “ Please Enter Grade from „A‟ to „D‟ or „F‟ “ ;
  • 11. Flow Chart of switch statement switch (grade) case ‘A’ : Display “Excellent” case ‘B’ : Display “Very Good” … Default : “……..”
  • 12. int i = 2 ; switch ( i ) { case 1 : cout<<"I am in case 1 n"; break; case 2 : cout<<"I am in case 2 n"; break; case 3 : cout<<"I am in case 3 n"; break; default : cout<<"I am in default n"; } Output I am in case 2
  • 13. if (x == 1) switch (x) { { cout << "x is 1"; case 1: } cout << "x is 1"; else if (x == 2) break; { case 2: cout << "x is 2"; cout << "x is 2"; } break; else default: { cout << "value of x unknown"; cout << "value of x unknown"; } }
  • 14. There are some things that you simply cannot do with a switch. These are:  A float expression cannot be tested using a switch  Cases can never have variable expressions (for example it is wrong to say case a +3 : )  Multiple cases cannot use same expressions. Thus the following switch is illegal: switch ( a ) { case 3.2 : ... case 1 + 2 : ... }
  • 15. int day; cout<<"Eneter Day Number"; cin>>day; switch (day) { case 1 : cout << "nSunday"; break; case 2 : cout << "nMonday"; break; case 3 : cout << "nTuesday"; break; case 4 : cout << "nWednesday"; break; case 5 : cout << "nThursday"; break; case 6 : cout << "nFriday"; break; case 7 : cout << "nSaturday"; break; default : cout << "nNot an allowable day number"; break; }
  • 16. switch (day) { case 1 : case 7 : cout << "This is a weekend day"; Break 1 break; case 2 : case 3 : case 4 : case 5 : case 6 : cout << "This is a weekday"; Break break; 2 default : cout << "Not a legal day"; break; }
  • 17. char ch ; cout<< "Enter any of the alphabet a, b, or c "; cin>>ch; switch ( ch ) { case 'a' : case 'A' : cout<<"a is an apple" ; break ; case 'b' : case 'B' : cout<<"b as in brain"; break ; case 'c' : case 'C' : cout<<"c as in cookie"; break ; default : cout<<"wish you knew what are alphabets" ; }
  • 18.  Yesand no. Yes, because it offers a better way of writing programs as compared to if, and no because in certain situations we are left with no choice but to use if. The disadvantage of switch is that one cannot have a case in a switch which looks like:  case i <= 20 :
  • 19.  compiler generates a jump table for a switch during compilation  during execution it simply refers the jump table to decide which case should be executed .  if-elses are slower because they are evaluated at execution time
  • 20. Make a calculator using switch statement  It should take two numbers from user.  Ask the user the function to perform  Display the result Air University
  • 21. Que Write a menu driven program program in C++ using switch statement that contain option as under.( The Menu should ) Enetr 1--> To Find Largest Number Among Three Variables. Enetr 2--> To Find ODD or EVEN Enetr 3--> To Find Condition of Water Enetr 4--> To Find Grade Of Student Air University