SlideShare a Scribd company logo
Programming - Marla Fuentes
What is a Switch Case?
0 Switch Case is a type of selection control mechanism that
 exists in most imperative programming languages such
 as Pascal, Ada, C/C++, C#, Java, and so on. It is also
 included in several other types of languages. Its purpose is
 to allow the value of a variable or expression to control
 the flow of program execution via a multiway branch (or
 "goto", one of several labels). The main reasons for using a
 switch include improving clarity, by reducing otherwise
 repetitive coding, and (if the heuristics permit) also
 offering the potential for faster execution through
 easier compiler optimization in many case.
Examples:
Example #1:                           break;
                                    case 'D' :
#include <iostream>                   cout << "You passed" << endl;
using namespace std;                  break;
                                    case 'F' :
int main ()                           cout << "Better try again" << endl;
{                                     break;
  // local variable declaration:    default :
  char grade = 'D';                   cout << "Invalid grade" << endl;
                                    }
 switch(grade)                      cout << "Your grade is " << grade << endl;
 {
 case 'A' :                        System (“pause”);
   cout << "Excellent!" << endl;    return 0;
   break;                          }
 case 'B' :
 case 'C' :
   cout << "Well done" << endl;
Example #2:                                                }

#include <iostream>                                         cout << "Of course I had nothing to
 using namespace std;                            do with the grade.";
                                                            cout << "nThe professor was really
  int main ()                                    off the wall.n";
  {
                                                 system ("pause");
           char letGrad, ch;                     return 0;
           cout << "Please enter a character: ";
           cin >> letGrad;                       }
           switch (letGrad)
            {
           case 'A': cout << "The numerical
grade is between 90 and 100"; break;
           case 'B': cout << "The numerical
grade is between 80 and 89.9"; break;
           case 'C': cout << "The numerical
grade is between 70 and 79.9"; break;
           case 'D': cout << "How are you going
to explain this one?"; break;
Example #3:                               break;

#include <iostream>                       case 'F':
using namespace std;                      person = "female";
int main ( )                              break;
{
  string person ;                         case 'f':
char gender ;                             person ="female";
cout << "Please enter your gender !n";   break;
cin >> gender;                            default:
switch (gender)                           person = "unknown";
{    case 'm':                            }
person = "male" ;                         cout << person << endl;
break;
                                          system ("pause");
case 'M':                                 return 0;
person = "male";                          }
Example #4:                                             break;
                                                           default: cout << "Too large!n";
#include <iostream.h>                                   break;
int main()                                          }
{                                                   cout << "nn";
      unsigned short int number;
      cout << "Enter a number between 1 and 5: ";   system("pause");
      cin >> number;                                 return 0;
      switch (number)
      {                                             }
      case 0: cout << "Too small, sorry!";

  break;
     case 5: cout << "Good job!n";
     break;
     case 4: cout << "Nice Pick!n";
     break;
     case 3: cout << "Excellent!n";
     break;
     case 2: cout << "Masterful!n";
     break;
     case 1: cout << "Incredible!n";
Programming - Marla Fuentes
What are Loops?
0 Loops are used to repeat a block of code. Being able to
 have your program repeatedly execute a block of code is
 one of the most basic but useful tasks in programming --
 many programs or websites that produce extremely
 complex output (such as a message board) are really only
 executing a single task many times. (They may be executing
 a small number of tasks, but in principle, to produce a list
 of messages only requires repeating the operation of
 reading in some data and displaying it.) Now, think about
 what this means: a loop lets you write a very simple
 statement to produce a significantly greater result simply
 by repetition.
Examples:
Example #1:
#include <iostream>

using namespace std;

int main()
{
  int x;

    x = 0;
    do {

     cout<<"Hello, world!n";
    } while ( x != 0 );
    cin.get();
}
Example #2:

#include<iostream>
#include<string>
int main()
{

using namespace std;
string password, happiness;
happiness="happiness";

cout<<"Enter the correct password..n"<<endl;
do{
cout<<"Enter the correct password to obtain surprise: ";
cin>> password;
}

while (password!=happiness);
cout<<"You've got it!"<<endl;

system("pause");
return (0);
}
Example #3:                   while ( time < 1 || time > 10) endl;
                                     { cout << "Must enter
#include <iostream>           between 1 and 10 seconds,                  }
#include <cmath>              please re-enter.n";                   system ("pause");
using namespace std;                   time =                            return 0;
                              fallingdistance();
                                                                   }
int fallingdistance();                                             int fallingdistance ()
                                     }
                                                                   {
int main()                                                               int seconds;
                                     cout <<"nSeconds
{                                           falling distancen";         cin >> seconds;
     int count = 1 ;                 cout <<"---------------------       return seconds;
     int time;                ------------------n";               }
     double distance ;
     cout << "Please                for ( count = 1; count <=
entertime in 1 through 10     time; count++)
seconds.nn";                      {
                                          distance = .5 * 9.8 *
  time = fallingdistance();   pow(time, 2.0);
                                          cout << count << "
                              " << distance <<" meters"<<
Programming - Marla Fuentes
Submitted to:

Mr. Edwin Globio
http://eglobiotraining.com




                  Thank you and God bless!
         http://www.slideshare.net/mfuentessss

More Related Content

PPTX
Project in programming
ODP
Rust言語紹介
PDF
Linux shell
PDF
Performance measurement and tuning
 
PPTX
Groovy closures
PPTX
Castro
PDF
Алексей Кутумов, Coroutines everywhere
Project in programming
Rust言語紹介
Linux shell
Performance measurement and tuning
 
Groovy closures
Castro
Алексей Кутумов, Coroutines everywhere

What's hot (20)

PDF
The Ring programming language version 1.10 book - Part 87 of 212
PPT
Introducere In Java Jx
PDF
Code Generation in PHP - PHPConf 2015
DOCX
Ns2programs
PDF
Rust Mozlando Tutorial
PDF
Email Using Plsql
PDF
Rust concurrency tutorial 2015 12-02
DOCX
Chatting dengan beberapa pc laptop
PDF
Swift - One step forward from Obj-C
PPT
Powerpoint loop examples a
PDF
C++ aptitude
PDF
C++ Programming - 12th Study
PDF
Bluespec Tutorial Helloworld
DOC
Study of aloha protocol using ns2 network java proram
PDF
C++ Programming - 9th Study
PDF
Getting Started with PL/Proxy
PDF
Aspect Mining for Large Systems
DOCX
Oops pramming with examples
PDF
4th_Ed_Ch03.pdf
The Ring programming language version 1.10 book - Part 87 of 212
Introducere In Java Jx
Code Generation in PHP - PHPConf 2015
Ns2programs
Rust Mozlando Tutorial
Email Using Plsql
Rust concurrency tutorial 2015 12-02
Chatting dengan beberapa pc laptop
Swift - One step forward from Obj-C
Powerpoint loop examples a
C++ aptitude
C++ Programming - 12th Study
Bluespec Tutorial Helloworld
Study of aloha protocol using ns2 network java proram
C++ Programming - 9th Study
Getting Started with PL/Proxy
Aspect Mining for Large Systems
Oops pramming with examples
4th_Ed_Ch03.pdf
Ad

Viewers also liked (9)

DOCX
Look book
PPT
orquestres, orquesta, cambra, banda, simfònica
DOC
Ct 2 evidens band 1&3 tahun 3
PPTX
Presentation1tmk modulgurumurid
DOCX
Kh pksr 1 2012
PPTX
Trial
PPT
repeticions
PPT
Kumpulan 4 sains
PPTX
Zvit presentation 01
Look book
orquestres, orquesta, cambra, banda, simfònica
Ct 2 evidens band 1&3 tahun 3
Presentation1tmk modulgurumurid
Kh pksr 1 2012
Trial
repeticions
Kumpulan 4 sains
Zvit presentation 01
Ad

Similar to Programming - Marla Fuentes (20)

PPTX
Final requirement (2)
PPTX
PPTX
Lab # 3
PPTX
Jangsehyun final requirement
PPTX
Final requirement in programming vinson
PPTX
Final requirement in programming niperos
PPSX
Ramirez slideshow
PDF
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
PPTX
Final requirement in programming
PPTX
Final exam
PPTX
Final exam
PPTX
C++ loop
DOCX
C++ Loops General Discussion of Loops A loop is a.docx
PPT
Lecture#4 Algorithm and computing
PPTX
Computer programming
PPTX
Intro to C++
PPTX
Final requirement
PPTX
C++ Programming Club-Lecture 3
PPTX
Final Exam in FNDPRG
PPTX
Overview of c++ language
Final requirement (2)
Lab # 3
Jangsehyun final requirement
Final requirement in programming vinson
Final requirement in programming niperos
Ramirez slideshow
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
Final requirement in programming
Final exam
Final exam
C++ loop
C++ Loops General Discussion of Loops A loop is a.docx
Lecture#4 Algorithm and computing
Computer programming
Intro to C++
Final requirement
C++ Programming Club-Lecture 3
Final Exam in FNDPRG
Overview of c++ language

Recently uploaded (20)

PDF
LDMMIA Reiki Yoga Finals Review Spring Summer
PDF
Practical Manual AGRO-233 Principles and Practices of Natural Farming
PDF
Complications of Minimal Access Surgery at WLH
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PPTX
UNIT III MENTAL HEALTH NURSING ASSESSMENT
PDF
Computing-Curriculum for Schools in Ghana
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
PDF
Weekly quiz Compilation Jan -July 25.pdf
PPTX
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
PPTX
Cell Types and Its function , kingdom of life
PDF
Indian roads congress 037 - 2012 Flexible pavement
PDF
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
PDF
advance database management system book.pdf
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PPTX
Introduction to Building Materials
PDF
Hazard Identification & Risk Assessment .pdf
LDMMIA Reiki Yoga Finals Review Spring Summer
Practical Manual AGRO-233 Principles and Practices of Natural Farming
Complications of Minimal Access Surgery at WLH
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Paper A Mock Exam 9_ Attempt review.pdf.
UNIT III MENTAL HEALTH NURSING ASSESSMENT
Computing-Curriculum for Schools in Ghana
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
Weekly quiz Compilation Jan -July 25.pdf
Radiologic_Anatomy_of_the_Brachial_plexus [final].pptx
Cell Types and Its function , kingdom of life
Indian roads congress 037 - 2012 Flexible pavement
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
advance database management system book.pdf
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
Introduction to Building Materials
Hazard Identification & Risk Assessment .pdf

Programming - Marla Fuentes

  • 2. What is a Switch Case? 0 Switch Case is a type of selection control mechanism that exists in most imperative programming languages such as Pascal, Ada, C/C++, C#, Java, and so on. It is also included in several other types of languages. Its purpose is to allow the value of a variable or expression to control the flow of program execution via a multiway branch (or "goto", one of several labels). The main reasons for using a switch include improving clarity, by reducing otherwise repetitive coding, and (if the heuristics permit) also offering the potential for faster execution through easier compiler optimization in many case.
  • 3. Examples: Example #1: break; case 'D' : #include <iostream> cout << "You passed" << endl; using namespace std; break; case 'F' : int main () cout << "Better try again" << endl; { break; // local variable declaration: default : char grade = 'D'; cout << "Invalid grade" << endl; } switch(grade) cout << "Your grade is " << grade << endl; { case 'A' : System (“pause”); cout << "Excellent!" << endl; return 0; break; } case 'B' : case 'C' : cout << "Well done" << endl;
  • 4. Example #2: } #include <iostream> cout << "Of course I had nothing to using namespace std; do with the grade."; cout << "nThe professor was really int main () off the wall.n"; { system ("pause"); char letGrad, ch; return 0; cout << "Please enter a character: "; cin >> letGrad; } switch (letGrad) { case 'A': cout << "The numerical grade is between 90 and 100"; break; case 'B': cout << "The numerical grade is between 80 and 89.9"; break; case 'C': cout << "The numerical grade is between 70 and 79.9"; break; case 'D': cout << "How are you going to explain this one?"; break;
  • 5. Example #3: break; #include <iostream> case 'F': using namespace std; person = "female"; int main ( ) break; { string person ; case 'f': char gender ; person ="female"; cout << "Please enter your gender !n"; break; cin >> gender; default: switch (gender) person = "unknown"; { case 'm': } person = "male" ; cout << person << endl; break; system ("pause"); case 'M': return 0; person = "male"; }
  • 6. Example #4: break; default: cout << "Too large!n"; #include <iostream.h> break; int main() } { cout << "nn"; unsigned short int number; cout << "Enter a number between 1 and 5: "; system("pause"); cin >> number; return 0; switch (number) { } case 0: cout << "Too small, sorry!"; break; case 5: cout << "Good job!n"; break; case 4: cout << "Nice Pick!n"; break; case 3: cout << "Excellent!n"; break; case 2: cout << "Masterful!n"; break; case 1: cout << "Incredible!n";
  • 8. What are Loops? 0 Loops are used to repeat a block of code. Being able to have your program repeatedly execute a block of code is one of the most basic but useful tasks in programming -- many programs or websites that produce extremely complex output (such as a message board) are really only executing a single task many times. (They may be executing a small number of tasks, but in principle, to produce a list of messages only requires repeating the operation of reading in some data and displaying it.) Now, think about what this means: a loop lets you write a very simple statement to produce a significantly greater result simply by repetition.
  • 9. Examples: Example #1: #include <iostream> using namespace std; int main() { int x; x = 0; do { cout<<"Hello, world!n"; } while ( x != 0 ); cin.get(); }
  • 10. Example #2: #include<iostream> #include<string> int main() { using namespace std; string password, happiness; happiness="happiness"; cout<<"Enter the correct password..n"<<endl; do{ cout<<"Enter the correct password to obtain surprise: "; cin>> password; } while (password!=happiness); cout<<"You've got it!"<<endl; system("pause"); return (0); }
  • 11. Example #3: while ( time < 1 || time > 10) endl; { cout << "Must enter #include <iostream> between 1 and 10 seconds, } #include <cmath> please re-enter.n"; system ("pause"); using namespace std; time = return 0; fallingdistance(); } int fallingdistance(); int fallingdistance () } { int main() int seconds; cout <<"nSeconds { falling distancen"; cin >> seconds; int count = 1 ; cout <<"--------------------- return seconds; int time; ------------------n"; } double distance ; cout << "Please for ( count = 1; count <= entertime in 1 through 10 time; count++) seconds.nn"; { distance = .5 * 9.8 * time = fallingdistance(); pow(time, 2.0); cout << count << " " << distance <<" meters"<<
  • 13. Submitted to: Mr. Edwin Globio http://eglobiotraining.com Thank you and God bless! http://www.slideshare.net/mfuentessss