SlideShare une entreprise Scribd logo
1  sur  15
FINAL REQUIREMENT


http://eglobiotraining.com
SWITCH CASE STATEMENT

    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
     Programming languages. Its purpose is to allow the
     value of a variable or expression to control the flow
     of program execution via a multway branch (or "go
     to", one of several labels).


            http://eglobiotraining.com
SWITCH CASE STATEMENT
   Switch case statements are 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). The basic format for using
    the switch case in the programming is outlined
    below. 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
SWITCH CASE STATEMENT
 Switch is used to choose a fragment of template
  depending on the value of an expression
 This has a similar function as the If condition - but it
  is more useful in situations when there is many
  possible values for the variable.




          http://eglobiotraining.com
EXAMPLE OF SWITCH CASE IN C
PROGRAMMING                                                   cout << "This program displays different messages
                                                              dependingn";
                                                                  cout << "on which letter is entered by the user.n";
#include <iostream>
                                                                  cout << "Pick a letter a, b, c or d to see whatn";
#include <stdlib.h>
                                                                  cout << "the program will say.nn";
using namespace std;
                                                              } // end of welcome function
void welcome();
                                                              // getChar asks the user for a letter a, b or c.
char getChar();
                                                              // The character is returned to where the function was called.
void displayResponse(char choice);
                                                              char getChar()
int main(int argc, char *argv[])
                                                              {
{
                                                                    char response; // declares variable called response
    char choice; // declares the choice variable
                                                                cout << "Please type a letter a, b, c and d: "; // prompt for
    welcome(); // This calls the welcome function             letter
 choice = getChar(); // calls getChar and returns the value    cin >> response; // gets input from user and assigns it to
for choice                                                    response
 displayResponse(choice); // passes choice to                     return response; // sends back the response value
displayResponse function
                                                              } // end getChar function
                                                              // displayResponse function takes the char variable and uses
    system("PAUSE");                                          it
    return 0;                                                 // to determine which set of tasks will be performed.
} // end main                                                 void displayResponse(char choice)
// welcome function displays an opening message to            {
// explain the program to the user                                char again;
void welcome()
{
                           http://eglobiotraining.com
// 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 << "your awesome dude.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 << "you will find your lovelife.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 << "your will won the lottery.nn";
     break; // this ends the statements for case C/c
      case 'D': // choice was the letter D
    case 'd': // choice was the letter d
     cout << "your so ugly!!.nn";
     break; // this ends the statements for case D/d
    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                       http://eglobiotraining.com
LOOPING
There may be a situation when you need to execute a block
of code several number of times.

Programming languages provide various control structures
that allow for more complicated execution paths.
A loop statement allows us to execute a statement or group
of statements multiple times and following is the general from
of a loop statement in most of the programming languages.




          http://eglobiotraining.com
FOR LOOP
  A for loop is a repetition control structure that
   allows you to efficiently write a loop that needs to
   execute a specific number of times.
  The statements in the for loop repeat continuously
   for a specific number of times. The while and do-
   while loops repeat until a certain condition is
   met. The for loop repeats until a specific count is
   met.




                 http://eglobiotraining.com
EXAMPLE OF FOR LOOPING
  IN C PROGRAMMING
#include <iostream>                                                       }
#include <cmath>
using namespace std;                                                      cout <<"nSeconds
                                                                          falling distancen";
//prototype                                                               cout <<"---------------------------------------n";
int fallingdistance();
                                                                          for ( count = 1; count <= time; count++)
                                                                          {
//main function                                                                           distance = .5 * 9.8 *
int main()                                                 pow(time, 2.0);
{                                                                                         cout << count << "
              int count = 1 ;                              " << distance <<" meters"<< endl;
              int time;
              double distance ;                                         }
              cout << "Please enter time in 1 through 10     system ("pause");
seconds.nn";                                                          return 0;
                                                           }
  time = fallingdistance();                                // falling distance function for a return value in seconds
                                                           transfer to time
                                                           int fallingdistance ()
             while ( time < 1 || time > 10)                {
             { cout << "Must enter between 1 and 10                         int seconds;
seconds, please re-enter.n";                                               cin >> seconds;
               time = fallingdistance();                                    return seconds;
                                                           }



                              http://eglobiotraining.com
WHILE LOOP
 The while loop allows programs to repeat a
  statement or series of statements, over and over,
  as long as a certain test condition is true.
 The while loop can be used if you don’t know how
  many times a loop must run.




                 http://eglobiotraining.com
EXAMPLE OF WHILE LOOP IN C
PROGRAMMING
#include <iostream.h>                               if ((x < 1) || (x > 10)) {
                                                                 cout << "Your value for x is not between
                                                    1 and 10!"
int main(void) {
    int x = 0;                                                      << endl;
                                                               cout << "Please re-enter the number!"
    int y = 0;
                                                    << endl << endl;
    bool validNumber = false;
                                                             }
                                                             else
    while (validNumber == false) {
                                                                 validNumber = true;
       cout << "Please enter an integer between 1
and 10: ";                                              }

        cin >> x;
                                                       cout << "Thank you for entering a valid
        cout << "You entered: " << x << endl <<
                                                    number!" << endl;
endl;

                                                        return 0;
                                                    }




                        http://eglobiotraining.com
DO WHILE LOOP
 In most computer programming languages, a do
  while loop, sometimes just called a while loop, is
  a control flow statement that allows code to be
  executed once based on a
  given Boolean condition.
 The do while construct consists of a process
  symbol and a condition. First, the code within the
  block is executed, and then the condition is
  evaluated.



           http://eglobiotraining.com
DO WHILE LOOP
 Unlike for and while loops, which test the loop
  condition at the top of the loop, the do...while loop
  checks its condition at the bottom of the loop.
 A do...while loop is similar to a while loop, except
  that a do...while loop is guaranteed to execute at
  least one time.




           http://eglobiotraining.com
EXAMPLE OF A DO WHILE
LOOP IN C PROGRAMMING
   #include <iostream>
   using namespace std;
   main()
   { int num1, num2;
   char again = 'y';

   while (again == 'y' || again == 'Y') {
   cout << "Enter a number: ";
   cin >> num1;
   cout << "Enter another number: ";
   cin >> num2;
   cout << "Their sum is " << (num1 + num2) << endl;
   cout << "Do you want to do this again? ";
   cin >> again; }
   return 0;
   }
                           http://eglobiotraining.com
SUBMITTED TO:
PROFESSOR ERWIN GLOBIO




                                      http://eglobiotraining.com
         http://eglobiotraining.com

Contenu connexe

Tendances

[C++][a] tutorial 2
[C++][a] tutorial 2[C++][a] tutorial 2
[C++][a] tutorial 2
yasir_cesc
 
Router Queue Simulation in C++ in MMNN and MM1 conditions
Router Queue Simulation in C++ in MMNN and MM1 conditionsRouter Queue Simulation in C++ in MMNN and MM1 conditions
Router Queue Simulation in C++ in MMNN and MM1 conditions
Morteza Mahdilar
 
Ti1220 Lecture 2: Names, Bindings, and Scopes
Ti1220 Lecture 2: Names, Bindings, and ScopesTi1220 Lecture 2: Names, Bindings, and Scopes
Ti1220 Lecture 2: Names, Bindings, and Scopes
Eelco Visser
 
Switch case and looping kim
Switch case and looping kimSwitch case and looping kim
Switch case and looping kim
kimberly_Bm10203
 
Continuations
ContinuationsContinuations
Continuations
openbala
 

Tendances (20)

Patterns for JVM languages JokerConf
Patterns for JVM languages JokerConfPatterns for JVM languages JokerConf
Patterns for JVM languages JokerConf
 
[C++][a] tutorial 2
[C++][a] tutorial 2[C++][a] tutorial 2
[C++][a] tutorial 2
 
C++ programming
C++ programmingC++ programming
C++ programming
 
Router Queue Simulation in C++ in MMNN and MM1 conditions
Router Queue Simulation in C++ in MMNN and MM1 conditionsRouter Queue Simulation in C++ in MMNN and MM1 conditions
Router Queue Simulation in C++ in MMNN and MM1 conditions
 
Le langage rust
Le langage rustLe langage rust
Le langage rust
 
Variables: names, bindings, type, scope
Variables: names, bindings, type, scopeVariables: names, bindings, type, scope
Variables: names, bindings, type, scope
 
C++ aptitude
C++ aptitudeC++ aptitude
C++ aptitude
 
Ti1220 Lecture 2: Names, Bindings, and Scopes
Ti1220 Lecture 2: Names, Bindings, and ScopesTi1220 Lecture 2: Names, Bindings, and Scopes
Ti1220 Lecture 2: Names, Bindings, and Scopes
 
C++ programming
C++ programmingC++ programming
C++ programming
 
Programming Fundamentals
Programming FundamentalsProgramming Fundamentals
Programming Fundamentals
 
4th_Ed_Ch03.pdf
4th_Ed_Ch03.pdf4th_Ed_Ch03.pdf
4th_Ed_Ch03.pdf
 
Switch case and looping kim
Switch case and looping kimSwitch case and looping kim
Switch case and looping kim
 
Functions
FunctionsFunctions
Functions
 
Session 3
Session 3Session 3
Session 3
 
Switch case and looping new
Switch case and looping newSwitch case and looping new
Switch case and looping new
 
Php Debugger
Php DebuggerPhp Debugger
Php Debugger
 
C++ Presentation
C++ PresentationC++ Presentation
C++ Presentation
 
Continuations
ContinuationsContinuations
Continuations
 
C++loop statements
C++loop statementsC++loop statements
C++loop statements
 
Elements of programming
Elements of programmingElements of programming
Elements of programming
 

En vedette

3 Compromises at the Constitutional Convention
3 Compromises at the Constitutional Convention3 Compromises at the Constitutional Convention
3 Compromises at the Constitutional Convention
John
 

En vedette (7)

3 Compromises at the Constitutional Convention
3 Compromises at the Constitutional Convention3 Compromises at the Constitutional Convention
3 Compromises at the Constitutional Convention
 
Activism x Technology
Activism x TechnologyActivism x Technology
Activism x Technology
 
The Near Future of CSS
The Near Future of CSSThe Near Future of CSS
The Near Future of CSS
 
How to Battle Bad Reviews
How to Battle Bad ReviewsHow to Battle Bad Reviews
How to Battle Bad Reviews
 
Classroom Management Tips for Kids and Adolescents
Classroom Management Tips for Kids and AdolescentsClassroom Management Tips for Kids and Adolescents
Classroom Management Tips for Kids and Adolescents
 
The Buyer's Journey - by Chris Lema
The Buyer's Journey - by Chris LemaThe Buyer's Journey - by Chris Lema
The Buyer's Journey - by Chris Lema
 
The Presentation Come-Back Kid
The Presentation Come-Back KidThe Presentation Come-Back Kid
The Presentation Come-Back Kid
 

Similaire à Final requirement (2)

Powerpoint presentation final requirement in fnd prg
Powerpoint presentation final requirement in fnd prgPowerpoint presentation final requirement in fnd prg
Powerpoint presentation final requirement in fnd prg
alyssa-castro2326
 
Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)Final project powerpoint template (fndprg) (1)
Final project powerpoint template (fndprg) (1)
jewelyngrace
 
My programming final proj. (1)
My programming final proj. (1)My programming final proj. (1)
My programming final proj. (1)
aeden_brines
 
Programming - Marla Fuentes
Programming - Marla FuentesProgramming - Marla Fuentes
Programming - Marla Fuentes
mfuentessss
 
Classes function overloading
Classes function overloadingClasses function overloading
Classes function overloading
ankush_kumar
 
presentation_functions_1443207686_140676.ppt
presentation_functions_1443207686_140676.pptpresentation_functions_1443207686_140676.ppt
presentation_functions_1443207686_140676.ppt
SandipPradhan23
 
2.overview of c++ ________lecture2
2.overview of c++  ________lecture22.overview of c++  ________lecture2
2.overview of c++ ________lecture2
Warui Maina
 
Php Reusing Code And Writing Functions
Php Reusing Code And Writing FunctionsPhp Reusing Code And Writing Functions
Php Reusing Code And Writing Functions
mussawir20
 
Switch case and looping
Switch case and loopingSwitch case and looping
Switch case and looping
ChaAstillas
 
FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2
rohassanie
 

Similaire à Final requirement (2) (20)

Final requirement
Final requirementFinal requirement
Final requirement
 
Powerpoint presentation final requirement in fnd prg
Powerpoint presentation final requirement in fnd prgPowerpoint presentation final requirement in fnd prg
Powerpoint presentation final requirement in fnd prg
 
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++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...
[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...
[C++] The Curiously Recurring Template Pattern: Static Polymorphsim and Expre...
 
My programming final proj. (1)
My programming final proj. (1)My programming final proj. (1)
My programming final proj. (1)
 
Object oriented programming system with C++
Object oriented programming system with C++Object oriented programming system with C++
Object oriented programming system with C++
 
Programming - Marla Fuentes
Programming - Marla FuentesProgramming - Marla Fuentes
Programming - Marla Fuentes
 
Function C++
Function C++ Function C++
Function C++
 
Classes function overloading
Classes function overloadingClasses function overloading
Classes function overloading
 
presentation_functions_1443207686_140676.ppt
presentation_functions_1443207686_140676.pptpresentation_functions_1443207686_140676.ppt
presentation_functions_1443207686_140676.ppt
 
Better Open Source Enterprise C++ Web Services
Better Open Source Enterprise C++ Web ServicesBetter Open Source Enterprise C++ Web Services
Better Open Source Enterprise C++ Web Services
 
Project in programming
Project in programmingProject in programming
Project in programming
 
Templates
TemplatesTemplates
Templates
 
2.overview of c++ ________lecture2
2.overview of c++  ________lecture22.overview of c++  ________lecture2
2.overview of c++ ________lecture2
 
Php Reusing Code And Writing Functions
Php Reusing Code And Writing FunctionsPhp Reusing Code And Writing Functions
Php Reusing Code And Writing Functions
 
Fp201 unit5 1
Fp201 unit5 1Fp201 unit5 1
Fp201 unit5 1
 
C++aptitude questions and answers
C++aptitude questions and answersC++aptitude questions and answers
C++aptitude questions and answers
 
Switch case and looping
Switch case and loopingSwitch case and looping
Switch case and looping
 
Ppt on java basics
Ppt on java basicsPpt on java basics
Ppt on java basics
 
FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2
 

Final requirement (2)

  • 2. SWITCH CASE STATEMENT  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 Programming languages. Its purpose is to allow the value of a variable or expression to control the flow of program execution via a multway branch (or "go to", one of several labels). http://eglobiotraining.com
  • 3. SWITCH CASE STATEMENT  Switch case statements are 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). The basic format for using the switch case in the programming is outlined below. 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. SWITCH CASE STATEMENT  Switch is used to choose a fragment of template depending on the value of an expression  This has a similar function as the If condition - but it is more useful in situations when there is many possible values for the variable. http://eglobiotraining.com
  • 5. EXAMPLE OF SWITCH CASE IN C PROGRAMMING cout << "This program displays different messages dependingn"; cout << "on which letter is entered by the user.n"; #include <iostream> cout << "Pick a letter a, b, c or d to see whatn"; #include <stdlib.h> cout << "the program will say.nn"; using namespace std; } // end of welcome function void welcome(); // getChar asks the user for a letter a, b or c. char getChar(); // The character is returned to where the function was called. void displayResponse(char choice); char getChar() int main(int argc, char *argv[]) { { char response; // declares variable called response char choice; // declares the choice variable cout << "Please type a letter a, b, c and d: "; // prompt for welcome(); // This calls the welcome function letter choice = getChar(); // calls getChar and returns the value cin >> response; // gets input from user and assigns it to for choice response displayResponse(choice); // passes choice to return response; // sends back the response value displayResponse function } // end getChar function // displayResponse function takes the char variable and uses system("PAUSE"); it return 0; // to determine which set of tasks will be performed. } // end main void displayResponse(char choice) // welcome function displays an opening message to { // explain the program to the user char again; void welcome() { http://eglobiotraining.com
  • 6. // 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 << "your awesome dude.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 << "you will find your lovelife.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 << "your will won the lottery.nn"; break; // this ends the statements for case C/c case 'D': // choice was the letter D case 'd': // choice was the letter d cout << "your so ugly!!.nn"; break; // this ends the statements for case D/d 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 http://eglobiotraining.com
  • 7. LOOPING There may be a situation when you need to execute a block of code several number of times. Programming languages provide various control structures that allow for more complicated execution paths. A loop statement allows us to execute a statement or group of statements multiple times and following is the general from of a loop statement in most of the programming languages. http://eglobiotraining.com
  • 8. FOR LOOP  A for loop is a repetition control structure that allows you to efficiently write a loop that needs to execute a specific number of times.  The statements in the for loop repeat continuously for a specific number of times. The while and do- while loops repeat until a certain condition is met. The for loop repeats until a specific count is met. http://eglobiotraining.com
  • 9. EXAMPLE OF FOR LOOPING IN C PROGRAMMING #include <iostream> } #include <cmath> using namespace std; cout <<"nSeconds falling distancen"; //prototype cout <<"---------------------------------------n"; int fallingdistance(); for ( count = 1; count <= time; count++) { //main function distance = .5 * 9.8 * int main() pow(time, 2.0); { cout << count << " int count = 1 ; " << distance <<" meters"<< endl; int time; double distance ; } cout << "Please enter time in 1 through 10 system ("pause"); seconds.nn"; return 0; } time = fallingdistance(); // falling distance function for a return value in seconds transfer to time int fallingdistance () while ( time < 1 || time > 10) { { cout << "Must enter between 1 and 10 int seconds; seconds, please re-enter.n"; cin >> seconds; time = fallingdistance(); return seconds; } http://eglobiotraining.com
  • 10. WHILE LOOP  The while loop allows programs to repeat a statement or series of statements, over and over, as long as a certain test condition is true.  The while loop can be used if you don’t know how many times a loop must run. http://eglobiotraining.com
  • 11. EXAMPLE OF WHILE LOOP IN C PROGRAMMING #include <iostream.h> if ((x < 1) || (x > 10)) { cout << "Your value for x is not between 1 and 10!" int main(void) { int x = 0; << endl; cout << "Please re-enter the number!" int y = 0; << endl << endl; bool validNumber = false; } else while (validNumber == false) { validNumber = true; cout << "Please enter an integer between 1 and 10: "; } cin >> x; cout << "Thank you for entering a valid cout << "You entered: " << x << endl << number!" << endl; endl; return 0; } http://eglobiotraining.com
  • 12. DO WHILE LOOP  In most computer programming languages, a do while loop, sometimes just called a while loop, is a control flow statement that allows code to be executed once based on a given Boolean condition.  The do while construct consists of a process symbol and a condition. First, the code within the block is executed, and then the condition is evaluated. http://eglobiotraining.com
  • 13. DO WHILE LOOP  Unlike for and while loops, which test the loop condition at the top of the loop, the do...while loop checks its condition at the bottom of the loop.  A do...while loop is similar to a while loop, except that a do...while loop is guaranteed to execute at least one time. http://eglobiotraining.com
  • 14. EXAMPLE OF A DO WHILE LOOP IN C PROGRAMMING  #include <iostream>  using namespace std;  main()  { int num1, num2;  char again = 'y';  while (again == 'y' || again == 'Y') {  cout << "Enter a number: ";  cin >> num1;  cout << "Enter another number: ";  cin >> num2;  cout << "Their sum is " << (num1 + num2) << endl;  cout << "Do you want to do this again? ";  cin >> again; }  return 0;  } http://eglobiotraining.com
  • 15. SUBMITTED TO: PROFESSOR ERWIN GLOBIO http://eglobiotraining.com http://eglobiotraining.com