Final project powerpoint template (fndprg) (1)

Download Final project powerpoint template (fndprg) (1)

Post on 01-Dec-2014

361 views

Category:

Documents

3 download

DESCRIPTION

 

TRANSCRIPT

  • 1. FINAL REQUIREMENT Programming http://eglobiotraining.com
  • 2. Topics in Programming1. Looping2. Switch Case http://eglobiotraining.com
  • 3. 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 multiway branch (or "go to", 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 cases. http://eglobiotraining.com
  • 4. 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. The switch-case statement is a multi-way decision statement. Unlike the multiple decision statement that can be created using if- else, the switch statement evaluates the conditional expression and tests it against numerous constant values. The branch corresponding to the value that the expression matches is taken during execution. http://eglobiotraining.com
  • 5. 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. Switch will evaluate one of several statements, depending on the value of a given variable. If no given value matches the variable, the default statement is executed. The value of the expressions in a switch-case statement must be an ordinal type i.e. integer, char, short, long, etc. Float and double are not allowed. http://eglobiotraining.com
  • 6. Example of switch case IN C PROGRAMMING#include 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 uservoid welcome(){ cout