SlideShare a Scribd company logo
1 of 26
Final Requirement in Programming
Castro, Alyssa S.
FM09205




                http://eglobiotraining.com
Fundamentals In Programming




              http://eglobiotraining.com
   In programming, a switch, case, select or inspect statement 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 multi way branch (or "goto", one of several labels).
   The main reasons for using a switch statement in programming is to 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 cases.
   It is a substitute for long if statements that compare a variable to several "integral"
    values ("integral" values are simply values that can be expressed as an integer, such as
    the value of a char).
   In computer programming, the value of the variable given into switch is compared to
    the value following each of the cases, and when one value matches the value of the
    variable, the computer continues executing the program from that point.




                        http://eglobiotraining.com
   A loop (in programming) is a sequence of statements which is specified once but
    which may be carried out several times in succession. The code "inside" the loop
    (the body of the loop, shown below as xxx) is obeyed a specified number of
    times, or once for each of a collection of items, or until some condition is
    met, or indefinitely.

   In functional programming languages, such as Haskell and Scheme, loops can be
    expressed by using recursion or fixed point iteration rather than explicit looping
    constructs. Tail recursion is a special case of recursion which can be easily
    transformed to iteration.
   A loop is a fundamental programming idea that is commonly used in
    writing programs.
   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.

                      http://eglobiotraining.com
Source Code of Switch                                                   Screen Shot of Example 1
       Case Statement 1
                                                        http://eglobiotraining.com

#include <iostream>
using namespace std;
void playgame()
{
  cout << "Play game called";
}
void loadgame()
{
  cout << "Load game called";
}
void playmultiplayer()
{
  cout << "Play multiplayer game called";
}
int main()
{
  int input;
    cout<<"1. Play gamen";
    cout<<"2. Load gamen";
    cout<<"3. Play multiplayern";
    cout<<"4. Exitn";
    cout<<"Selection: ";
    cin>> input;
    switch ( input ) {
    case 1:      // Note the colon, not a semicolon
      playgame();
      break;
    case 2:      // Note the colon, not a semicolon
      loadgame();
      break;
    case 3:      // Note the colon, not a semicolon
      playmultiplayer();
      break;
    case 4:      // Note the colon, not a semicolon
      cout<<"Thank you for playing!n";
      break;
    default:       // Note the colon, not a semicolon
      cout<<"Error, bad input, quittingn";
      break;
    }
    cin.get();
}
   The first example of switch case statement in
    programming allows the user to input a number
    that states the functions in a game. If the user types
    the number before each chosen function [e.g 1 (play
    game)], the running program will show the words
    “thank you for playing”.




                http://eglobiotraining.com
Source Code of Switch
                                                                                                          Screen Shot of Example 2
        Case Statement 2
                                                                                 http://eglobiotraining.com

#include <iostream>
#include <stdlib.h>

using namespace std;
void welcome();
int getInteger();
void displayResponse(int choice);

int main(int argc, char *argv[])
{
  int choice; // declares the choice variable
  welcome(); // This calls the welcome function
  choice = getInteger(); // calls getInteger and receives the value for choice
  displayResponse(choice); // passes choice to displayResponse function

 system("PAUSE");
 return 0;
} // end main

// welcome function displays an opening message to
// explain the program to the user
void welcome()
{
  cout << "This program displays different messages dependingn";
  cout << "on which number is entered by the user.n";
  cout << "Pick a number between 1 and 6 to see whatn";
  cout << "the program will say.nn";
} // end of welcome function
// getInteger asks the user for a number between 1 and 6.
// The integer is returned to where the function was called.
int getInteger()
{
  int response; // declares variable called response
  cout << "Please type a number between 1 and 6: "; // prompt for number
  cin >> response; // gets input from user and assigns it to response
  return response; // sends back the response value
} // end getInteger function
// displayResponse function takes the int variable and uses it
// to determine which set of tasks will be performed.
void displayResponse(int choice)
{
  int again;

  // switch statement based on the choice variable
  switch (choice) // notice no semicolon
 {
    case 1: // choice was the number 1
      cout << "One is a lonely number and very useful in math.nn";
      break; // this ends the statements for case 1
    case 2: // choice was the number 2
      cout << "Two is the only even prime number.nn";
      break; // this ends the statements for case 2
    case 3: // choice was the number 3
      cout << "Three is a crowd and also a prime number.nn";
      break; // this ends the statements for case 3
    case 4: // choice was the number 4
      cout << "Four square is a fun game to play, but four squared is ";
      cout << 4 * 4 << ".nn";
      break; // this ends the statements for case 4
    case 5: // choice was the number 5
      cout << "Counting by fives is fun. Five, Ten, Fifteen, Twenty...nn";
      break; // this ends the statements for case 5
    case 6: // choice was the number 6
      cout << "Six is divisible by two and three.nn";
      break; // this ends the statements for case 6
    default: // used when choice falls out of the cases covered above
      cout << "You didn't pick a number between 1 and 6.nn";
      again = getInteger(); // gives the user another try
      displayResponse(again); // recalls displayResponse with new number
      break;
  } // end of switch statement
} // end displayResponse function
   The second example of switch case
    statement in programming displays different
    messages depending on which number is
    entered by the user. Pick a number between 1
    and 6 and see what the program will say.




              http://eglobiotraining.com
Source Code of Switch
                                                                                                     Screen Shot of Example 3
         Case Statement 3
                                                                             http://eglobiotraining.com

#include <iostream>
#include <stdlib.h>
using namespace std;
void welcome();
char getChar();
void displayResponse(char choice);
int main(int argc, char *argv[])
 {
  char choice; // declares the choice variable
  welcome(); // This calls the welcome function
  choice = getChar(); // calls getChar and returns the value for choice
  displayResponse(choice); // passes choice to displayResponse function

  system("PAUSE");
  return 0;
} // end main
// welcome function displays an opening message to
// explain the program to the user
void welcome()
 {
  cout << "This program displays different messages dependingn";
  cout << "on which letter is entered by the user.n";
  cout << "Pick a letter a, b or c to see whatn";
  cout << "the program will say.nn";
} // end of welcome function
// getChar asks the user for a letter a, b or c.
// The character is returned to where the function was called.
char getChar()
 {
 char response; // declares variable called response
  cout << "Please type a letter a, b or c: "; // prompt for letter
  cin >> response; // gets input from user and assigns it to response
  return response; // sends back the response value
} // end getChar function
// displayResponse function takes the char variable and uses it
// to determine which set of tasks will be performed.
void displayResponse(char choice)
 {
  char again;

    // switch statement based on the choice variable
    switch (choice) // notice no semicolon
{
   case 'A': // choice was the letter A
   case 'a': // choice was the letter a
     cout << "A is for apple.nn";
     break; // this ends the statements for case A/a
   case 'B': // choice was the letter b
   case 'b': // choice was the letter b
     cout << "B is for baseball.nn";
     break; // this ends the statements for case B/b
   case 'C': // choice was the letter C
   case 'c': // choice was the letter c
     cout << "C is for cat.nn";
     break; // this ends the statements for case C/c
   default: // used when choice falls out of the cases covered above
     cout << "You didn't pick a letter a, b or c.nn";
     again = getChar(); // gives the user another try
     displayResponse(again); // recalls displayResponse with new character
     break;
 } // end of switch statement
} // end displayResponse function
   The third example of switch case statement
    in programming displays different messages
    depending on which letter is chosen by the
    user. Pick a, b or c and see what the program
    will say.




              http://eglobiotraining.com
Source Code of Switch                                                        Screen Shot of Example 4
Case Statement 4
                                                http://eglobiotraining.com


//
 // Demonstrates switch statement
 #include <iostream.h>
  int main()
  {
    unsigned short int number;
    cout << "Enter a number between 1
and 5: ";
    cin >> number;
    switch (number)
    {
      case 0: cout << "Too small, sorry!";
           break;
      case 5: cout << "Good job!n"; // fall
through
      case 4: cout << "Nice Pick!n"; // fall
through
      case 3: cout << "Excellent!n"; // fall
through
      case 2: cout << "Masterful!n"; // fall
through
      case 1: cout << "Incredible!n";
          break;
      default: cout << "Too large!n";
          break;
    }
    cout << "nn";
     return 0;
 }
   This fourth example of switch case statement
    in programming asks the user to pick a
    number ranging from 1 to 5. Switch Case in
    programming is effective to any program
    especially in multiple choices.




              http://eglobiotraining.com
Source Code of Switch                                                                    Screen Shot of Example 5
         Case Statement 5
                                                                     http://eglobiotraining.com
#include <iostream>

using namespace std;

int main ()
{
    int score;


    cout << "What was your score?";
    cin >> score;


    if (score <= 25)
    {
        cout << "nOuch, less than 25...!";
    }
    else if (score <= 50)
    {
        cout << "nYou score aint great mate..";
    }
    else if (score <= 75)
    {
        cout << "nYour pretty good, wel done man!";
    }
    else if (score <= 100)
    {
        cout << "nYou got to the top!!!";
    }
    else
    {
        cout << "nYou cant score higher than 100!!! Cheater!!!!";
    }


    cin.ignore();
    cin.get();


    return 0;
}
   This fifth example of switch case statement in
    programming allows the user to input a score
    from 0 to 100. This programming sample is
    like having a feedback on the score you got
    (let’s say, from an exam).




              http://eglobiotraining.com
Source Code of                                                    Screen Shot of Example 1
Looping Statement 1
                                     http://eglobiotraining.com



#include <iostream>

using namespace std; // So the
program can see cout and endl

int main()
{
  // The loop goes while x <
10, and x increases by one
every loop
  for ( int x = 0; x < 10; x++ ) {
    // Keep in mind that the loop
condition checks
    // the conditional statement
before it loops again.
    // consequently, when x
equals 10 the loop breaks.
    // x is updated before the
condition is checked.
    cout<< x <<endl;
  }
  cin.get();
}
   This first example of looping in computer
    programming is an example of FOR loop.

   For loop is said to be the most useful type in
    programming.




              http://eglobiotraining.com
Source Code of                                                Screen Shot of Example 2
Looping Statement 2
                                     http://eglobiotraining.com



#include <iostream>

using namespace std; // So we
can see cout and endl

int main()
{
  int x = 0; // Don't forget to
declare variables

  while ( x < 10 ) { // While x is
less than 10
    cout<< x <<endl;
    x++;       // Update x so the
condition can be met
eventually
  }
  cin.get();
}
   This second example of looping in
    programming is just another simple loop
    program.

   A loop is a type in computer programming
    that is usually known through being a
    program that checks the whole process by
    reaching the end then jumping back again to
    the beginning.
              http://eglobiotraining.com
Source Code of                                                     Screen Shot of Example 3
Looping Statement 3
                                      http://eglobiotraining.com



#include <iostream>

using namespace std;

int main()
{
  int x;

  x = 0;
  do {
   // "Hello, world!" is printed at
least one time
   // even though the condition
is false
   cout<<"Hello, world!n";
  } while ( x != 0 );
  cin.get();
}
   This third example of looping in
    programming shows at least on print of
    “Hello World!” even if the condition is false.




               http://eglobiotraining.com
Source Code of                                                           Screen Shot of Example 4
Looping Statement 4
                                            http://eglobiotraining.com


#include <iostream>
int main()
{
  using namespace std;
  // nSelection must be declared outside
do/while loop
  int nSelection;
  do
  {
     cout << "Please make a selection: "
<< endl;
     cout << "1) Addition" << endl;
     cout << "2) Subtraction" << endl;
     cout << "3) Multiplication" << endl;
     cout << "4) Division" << endl;
     cin >> nSelection;
  } while (nSelection != 1 && nSelection
!= 2 &&
       nSelection != 3 && nSelection !=
4);
    // do something with nSelection here
    // such as a switch statement
    return 0;
}
   This fourth example of looping in
    programming is a given sample of a DO
    WHILE loop.

   These type of loops are useful in computer
    programming.



              http://eglobiotraining.com
Source Code of                                         Screen Shot of Example 5
Looping Statement 5
                               http://eglobiotraining.com



#include <iostream>
using namespace std;
int main ()
{
int x;
cout << "Input the number:";
cin >> x;
while (x>0)
{
cout << x << "; ";
--x;
}
cout << "EXFORSYS";
}
   This fifth example of looping in programming
    tells the user to input a number. And once the
    user clicked enter, the word “exforsys”
    appears.




              http://eglobiotraining.com
http://eglobiotraining.com
Submitted to:




                http://eglobiotraining.com

More Related Content

What's hot

Macasu, gerrell c.
Macasu, gerrell c.Macasu, gerrell c.
Macasu, gerrell c.gerrell
 
Switch case and looping kim
Switch case and looping kimSwitch case and looping kim
Switch case and looping kimkimberly_Bm10203
 
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
 
Switch case and looping
Switch case and loopingSwitch case and looping
Switch case and loopingChaAstillas
 
1584503386 1st chap
1584503386 1st chap1584503386 1st chap
1584503386 1st chapthuhiendtk4
 
Computer programming
Computer programmingComputer programming
Computer programmingXhyna Delfin
 
Lecture 2 php basics (1)
Lecture 2  php basics (1)Lecture 2  php basics (1)
Lecture 2 php basics (1)Core Lee
 
JavaScript Control Statements I
JavaScript Control Statements IJavaScript Control Statements I
JavaScript Control Statements IReem Alattas
 
Spf Chapter4 Variables
Spf Chapter4 VariablesSpf Chapter4 Variables
Spf Chapter4 VariablesHock Leng PUAH
 
C decision making and looping.
C decision making and looping.C decision making and looping.
C decision making and looping.Haard Shah
 
Decision making statements in C programming
Decision making statements in C programmingDecision making statements in C programming
Decision making statements in C programmingRabin BK
 
Programming fundamental 02
Programming fundamental 02Programming fundamental 02
Programming fundamental 02Suhail Akraam
 

What's hot (19)

Macasu, gerrell c.
Macasu, gerrell c.Macasu, gerrell c.
Macasu, gerrell c.
 
Switch case and looping kim
Switch case and looping kimSwitch case and looping kim
Switch case and looping kim
 
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 Tutorials
C TutorialsC Tutorials
C Tutorials
 
3. control statement
3. control statement3. control statement
3. control statement
 
Learn Java Part 2
Learn Java Part 2Learn Java Part 2
Learn Java Part 2
 
C++ programming
C++ programmingC++ programming
C++ programming
 
Switch case and looping jam
Switch case and looping jamSwitch case and looping jam
Switch case and looping jam
 
Lec 10
Lec 10Lec 10
Lec 10
 
Switch case and looping
Switch case and loopingSwitch case and looping
Switch case and looping
 
1584503386 1st chap
1584503386 1st chap1584503386 1st chap
1584503386 1st chap
 
Computer programming
Computer programmingComputer programming
Computer programming
 
C operators
C operatorsC operators
C operators
 
Lecture 2 php basics (1)
Lecture 2  php basics (1)Lecture 2  php basics (1)
Lecture 2 php basics (1)
 
JavaScript Control Statements I
JavaScript Control Statements IJavaScript Control Statements I
JavaScript Control Statements I
 
Spf Chapter4 Variables
Spf Chapter4 VariablesSpf Chapter4 Variables
Spf Chapter4 Variables
 
C decision making and looping.
C decision making and looping.C decision making and looping.
C decision making and looping.
 
Decision making statements in C programming
Decision making statements in C programmingDecision making statements in C programming
Decision making statements in C programming
 
Programming fundamental 02
Programming fundamental 02Programming fundamental 02
Programming fundamental 02
 

Similar to Powerpoint presentation final requirement in fnd prg

Final requirement (2)
Final requirement (2)Final requirement (2)
Final requirement (2)Anjie Sengoku
 
Fundamentals of programming angeli
Fundamentals of programming angeliFundamentals of programming angeli
Fundamentals of programming angelibergonio11339481
 
2.overview of c++ ________lecture2
2.overview of c++  ________lecture22.overview of c++  ________lecture2
2.overview of c++ ________lecture2Warui Maina
 
Clean & Typechecked JS
Clean & Typechecked JSClean & Typechecked JS
Clean & Typechecked JSArthur Puthin
 
Switch case and looping
Switch case and loopingSwitch case and looping
Switch case and loopingaprilyyy
 
Yeahhhh the final requirement!!!
Yeahhhh the final requirement!!!Yeahhhh the final requirement!!!
Yeahhhh the final requirement!!!olracoatalub
 
week3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docx
week3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docxweek3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docx
week3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docxalanfhall8953
 
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
 
Gift-VT Tools Development Overview
Gift-VT Tools Development OverviewGift-VT Tools Development Overview
Gift-VT Tools Development Overviewstn_tkiller
 
OOPS USING C++(UNIT 2)
OOPS USING C++(UNIT 2)OOPS USING C++(UNIT 2)
OOPS USING C++(UNIT 2)SURBHI SAROHA
 
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docxPROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docxamrit47
 
Fpga 06-data-types-system-tasks-compiler-directives
Fpga 06-data-types-system-tasks-compiler-directivesFpga 06-data-types-system-tasks-compiler-directives
Fpga 06-data-types-system-tasks-compiler-directivesMalik Tauqir Hasan
 

Similar to Powerpoint presentation final requirement in fnd prg (20)

Macaraeg
MacaraegMacaraeg
Macaraeg
 
Final requirement (2)
Final requirement (2)Final requirement (2)
Final requirement (2)
 
Castro
CastroCastro
Castro
 
Fundamentals of programming angeli
Fundamentals of programming angeliFundamentals of programming angeli
Fundamentals of programming angeli
 
2.overview of c++ ________lecture2
2.overview of c++  ________lecture22.overview of c++  ________lecture2
2.overview of c++ ________lecture2
 
My final requirement
My final requirementMy final requirement
My final requirement
 
Clean & Typechecked JS
Clean & Typechecked JSClean & Typechecked JS
Clean & Typechecked JS
 
Switch case and looping
Switch case and loopingSwitch case and looping
Switch case and looping
 
C++ programming
C++ programmingC++ programming
C++ programming
 
Yeahhhh the final requirement!!!
Yeahhhh the final requirement!!!Yeahhhh the final requirement!!!
Yeahhhh the final requirement!!!
 
week3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docx
week3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docxweek3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docx
week3_srcDoWhileLoopFactorial.javaweek3_srcDoWhileLoopFactoria.docx
 
Project in programming
Project in programmingProject in programming
Project in programming
 
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
 
Gift-VT Tools Development Overview
Gift-VT Tools Development OverviewGift-VT Tools Development Overview
Gift-VT Tools Development Overview
 
Elements of programming
Elements of programmingElements of programming
Elements of programming
 
OOPS USING C++(UNIT 2)
OOPS USING C++(UNIT 2)OOPS USING C++(UNIT 2)
OOPS USING C++(UNIT 2)
 
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docxPROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
PROVIDE COMMENTS TO FELLOW STUDENTS ANSWERS AND PLEASE DON’T SAY G.docx
 
Switch case looping
Switch case loopingSwitch case looping
Switch case looping
 
Fpga 06-data-types-system-tasks-compiler-directives
Fpga 06-data-types-system-tasks-compiler-directivesFpga 06-data-types-system-tasks-compiler-directives
Fpga 06-data-types-system-tasks-compiler-directives
 
Survelaine murillo ppt
Survelaine murillo pptSurvelaine murillo ppt
Survelaine murillo ppt
 

Powerpoint presentation final requirement in fnd prg

  • 1. Final Requirement in Programming Castro, Alyssa S. FM09205 http://eglobiotraining.com
  • 2. Fundamentals In Programming http://eglobiotraining.com
  • 3. In programming, a switch, case, select or inspect statement 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 multi way branch (or "goto", one of several labels).  The main reasons for using a switch statement in programming is to 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 cases.  It is a substitute for long if statements that compare a variable to several "integral" values ("integral" values are simply values that can be expressed as an integer, such as the value of a char).  In computer programming, the value of the variable given into switch is compared to the value following each of the cases, and when one value matches the value of the variable, the computer continues executing the program from that point. http://eglobiotraining.com
  • 4. A loop (in programming) is a sequence of statements which is specified once but which may be carried out several times in succession. The code "inside" the loop (the body of the loop, shown below as xxx) is obeyed a specified number of times, or once for each of a collection of items, or until some condition is met, or indefinitely.  In functional programming languages, such as Haskell and Scheme, loops can be expressed by using recursion or fixed point iteration rather than explicit looping constructs. Tail recursion is a special case of recursion which can be easily transformed to iteration.  A loop is a fundamental programming idea that is commonly used in writing programs.  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. http://eglobiotraining.com
  • 5. Source Code of Switch Screen Shot of Example 1 Case Statement 1 http://eglobiotraining.com #include <iostream> using namespace std; void playgame() { cout << "Play game called"; } void loadgame() { cout << "Load game called"; } void playmultiplayer() { cout << "Play multiplayer game called"; } int main() { int input; cout<<"1. Play gamen"; cout<<"2. Load gamen"; cout<<"3. Play multiplayern"; cout<<"4. Exitn"; cout<<"Selection: "; cin>> input; switch ( input ) { case 1: // Note the colon, not a semicolon playgame(); break; case 2: // Note the colon, not a semicolon loadgame(); break; case 3: // Note the colon, not a semicolon playmultiplayer(); break; case 4: // Note the colon, not a semicolon cout<<"Thank you for playing!n"; break; default: // Note the colon, not a semicolon cout<<"Error, bad input, quittingn"; break; } cin.get(); }
  • 6. The first example of switch case statement in programming allows the user to input a number that states the functions in a game. If the user types the number before each chosen function [e.g 1 (play game)], the running program will show the words “thank you for playing”. http://eglobiotraining.com
  • 7. Source Code of Switch Screen Shot of Example 2 Case Statement 2 http://eglobiotraining.com #include <iostream> #include <stdlib.h> using namespace std; void welcome(); int getInteger(); void displayResponse(int choice); int main(int argc, char *argv[]) { int choice; // declares the choice variable welcome(); // This calls the welcome function choice = getInteger(); // calls getInteger and receives the value for choice displayResponse(choice); // passes choice to displayResponse function system("PAUSE"); return 0; } // end main // welcome function displays an opening message to // explain the program to the user void welcome() { cout << "This program displays different messages dependingn"; cout << "on which number is entered by the user.n"; cout << "Pick a number between 1 and 6 to see whatn"; cout << "the program will say.nn"; } // end of welcome function // getInteger asks the user for a number between 1 and 6. // The integer is returned to where the function was called. int getInteger() { int response; // declares variable called response cout << "Please type a number between 1 and 6: "; // prompt for number cin >> response; // gets input from user and assigns it to response return response; // sends back the response value } // end getInteger function // displayResponse function takes the int variable and uses it // to determine which set of tasks will be performed. void displayResponse(int choice) { int again; // switch statement based on the choice variable switch (choice) // notice no semicolon { case 1: // choice was the number 1 cout << "One is a lonely number and very useful in math.nn"; break; // this ends the statements for case 1 case 2: // choice was the number 2 cout << "Two is the only even prime number.nn"; break; // this ends the statements for case 2 case 3: // choice was the number 3 cout << "Three is a crowd and also a prime number.nn"; break; // this ends the statements for case 3 case 4: // choice was the number 4 cout << "Four square is a fun game to play, but four squared is "; cout << 4 * 4 << ".nn"; break; // this ends the statements for case 4 case 5: // choice was the number 5 cout << "Counting by fives is fun. Five, Ten, Fifteen, Twenty...nn"; break; // this ends the statements for case 5 case 6: // choice was the number 6 cout << "Six is divisible by two and three.nn"; break; // this ends the statements for case 6 default: // used when choice falls out of the cases covered above cout << "You didn't pick a number between 1 and 6.nn"; again = getInteger(); // gives the user another try displayResponse(again); // recalls displayResponse with new number break; } // end of switch statement } // end displayResponse function
  • 8. The second example of switch case statement in programming displays different messages depending on which number is entered by the user. Pick a number between 1 and 6 and see what the program will say. http://eglobiotraining.com
  • 9. Source Code of Switch Screen Shot of Example 3 Case Statement 3 http://eglobiotraining.com #include <iostream> #include <stdlib.h> using namespace std; void welcome(); char getChar(); void displayResponse(char choice); int main(int argc, char *argv[]) { char choice; // declares the choice variable welcome(); // This calls the welcome function choice = getChar(); // calls getChar and returns the value for choice displayResponse(choice); // passes choice to displayResponse function system("PAUSE"); return 0; } // end main // welcome function displays an opening message to // explain the program to the user void welcome() { cout << "This program displays different messages dependingn"; cout << "on which letter is entered by the user.n"; cout << "Pick a letter a, b or c to see whatn"; cout << "the program will say.nn"; } // end of welcome function // getChar asks the user for a letter a, b or c. // The character is returned to where the function was called. char getChar() { char response; // declares variable called response cout << "Please type a letter a, b or c: "; // prompt for letter cin >> response; // gets input from user and assigns it to response return response; // sends back the response value } // end getChar function // displayResponse function takes the char variable and uses it // to determine which set of tasks will be performed. void displayResponse(char choice) { char again; // switch statement based on the choice variable switch (choice) // notice no semicolon { case 'A': // choice was the letter A case 'a': // choice was the letter a cout << "A is for apple.nn"; break; // this ends the statements for case A/a case 'B': // choice was the letter b case 'b': // choice was the letter b cout << "B is for baseball.nn"; break; // this ends the statements for case B/b case 'C': // choice was the letter C case 'c': // choice was the letter c cout << "C is for cat.nn"; break; // this ends the statements for case C/c default: // used when choice falls out of the cases covered above cout << "You didn't pick a letter a, b or c.nn"; again = getChar(); // gives the user another try displayResponse(again); // recalls displayResponse with new character break; } // end of switch statement } // end displayResponse function
  • 10. The third example of switch case statement in programming displays different messages depending on which letter is chosen by the user. Pick a, b or c and see what the program will say. http://eglobiotraining.com
  • 11. Source Code of Switch Screen Shot of Example 4 Case Statement 4 http://eglobiotraining.com // // Demonstrates switch statement #include <iostream.h> int main() { unsigned short int number; cout << "Enter a number between 1 and 5: "; cin >> number; switch (number) { case 0: cout << "Too small, sorry!"; break; case 5: cout << "Good job!n"; // fall through case 4: cout << "Nice Pick!n"; // fall through case 3: cout << "Excellent!n"; // fall through case 2: cout << "Masterful!n"; // fall through case 1: cout << "Incredible!n"; break; default: cout << "Too large!n"; break; } cout << "nn"; return 0; }
  • 12. This fourth example of switch case statement in programming asks the user to pick a number ranging from 1 to 5. Switch Case in programming is effective to any program especially in multiple choices. http://eglobiotraining.com
  • 13. Source Code of Switch Screen Shot of Example 5 Case Statement 5 http://eglobiotraining.com #include <iostream> using namespace std; int main () { int score; cout << "What was your score?"; cin >> score; if (score <= 25) { cout << "nOuch, less than 25...!"; } else if (score <= 50) { cout << "nYou score aint great mate.."; } else if (score <= 75) { cout << "nYour pretty good, wel done man!"; } else if (score <= 100) { cout << "nYou got to the top!!!"; } else { cout << "nYou cant score higher than 100!!! Cheater!!!!"; } cin.ignore(); cin.get(); return 0; }
  • 14. This fifth example of switch case statement in programming allows the user to input a score from 0 to 100. This programming sample is like having a feedback on the score you got (let’s say, from an exam). http://eglobiotraining.com
  • 15. Source Code of Screen Shot of Example 1 Looping Statement 1 http://eglobiotraining.com #include <iostream> using namespace std; // So the program can see cout and endl int main() { // The loop goes while x < 10, and x increases by one every loop for ( int x = 0; x < 10; x++ ) { // Keep in mind that the loop condition checks // the conditional statement before it loops again. // consequently, when x equals 10 the loop breaks. // x is updated before the condition is checked. cout<< x <<endl; } cin.get(); }
  • 16. This first example of looping in computer programming is an example of FOR loop.  For loop is said to be the most useful type in programming. http://eglobiotraining.com
  • 17. Source Code of Screen Shot of Example 2 Looping Statement 2 http://eglobiotraining.com #include <iostream> using namespace std; // So we can see cout and endl int main() { int x = 0; // Don't forget to declare variables while ( x < 10 ) { // While x is less than 10 cout<< x <<endl; x++; // Update x so the condition can be met eventually } cin.get(); }
  • 18. This second example of looping in programming is just another simple loop program.  A loop is a type in computer programming that is usually known through being a program that checks the whole process by reaching the end then jumping back again to the beginning. http://eglobiotraining.com
  • 19. Source Code of Screen Shot of Example 3 Looping Statement 3 http://eglobiotraining.com #include <iostream> using namespace std; int main() { int x; x = 0; do { // "Hello, world!" is printed at least one time // even though the condition is false cout<<"Hello, world!n"; } while ( x != 0 ); cin.get(); }
  • 20. This third example of looping in programming shows at least on print of “Hello World!” even if the condition is false. http://eglobiotraining.com
  • 21. Source Code of Screen Shot of Example 4 Looping Statement 4 http://eglobiotraining.com #include <iostream> int main() { using namespace std; // nSelection must be declared outside do/while loop int nSelection; do { cout << "Please make a selection: " << endl; cout << "1) Addition" << endl; cout << "2) Subtraction" << endl; cout << "3) Multiplication" << endl; cout << "4) Division" << endl; cin >> nSelection; } while (nSelection != 1 && nSelection != 2 && nSelection != 3 && nSelection != 4); // do something with nSelection here // such as a switch statement return 0; }
  • 22. This fourth example of looping in programming is a given sample of a DO WHILE loop.  These type of loops are useful in computer programming. http://eglobiotraining.com
  • 23. Source Code of Screen Shot of Example 5 Looping Statement 5 http://eglobiotraining.com #include <iostream> using namespace std; int main () { int x; cout << "Input the number:"; cin >> x; while (x>0) { cout << x << "; "; --x; } cout << "EXFORSYS"; }
  • 24. This fifth example of looping in programming tells the user to input a number. And once the user clicked enter, the word “exforsys” appears. http://eglobiotraining.com
  • 26. Submitted to: http://eglobiotraining.com