Your SlideShare is downloading. ×
0
FINAL REQUIREMENThttp://eglobiotraining.com
SWITCH CASE STATEMENT    In programming,     a switch, case, select or inspect statement is a     type of selection contr...
SWITCH CASE STATEMENT   Switch case statements are a substitute for long if    statements that compare a variable to seve...
SWITCH CASE STATEMENT Switch is used to choose a fragment of template  depending on the value of an expression This has ...
EXAMPLE OF SWITCH CASE IN CPROGRAMMING                                                   cout << "This program displays di...
// switch statement based on the choice variable switch (choice) // notice no semicolon {    case A: // choice was the let...
LOOPINGThere may be a situation when you need to execute a blockof code several number of times.Programming languages prov...
FOR LOOP  A for loop is a repetition control structure that   allows you to efficiently write a loop that needs to   exec...
EXAMPLE OF FOR LOOPING  IN C PROGRAMMING#include <iostream>                                                       }#includ...
WHILE LOOP The while loop allows programs to repeat a  statement or series of statements, over and over,  as long as a ce...
EXAMPLE OF WHILE LOOP IN CPROGRAMMING#include <iostream.h>                               if ((x < 1) || (x > 10)) {       ...
DO WHILE LOOP In most computer programming languages, a do  while loop, sometimes just called a while loop, is  a control...
DO WHILE LOOP Unlike for and while loops, which test the loop  condition at the top of the loop, the do...while loop  che...
EXAMPLE OF A DO WHILELOOP IN C PROGRAMMING   #include <iostream>   using namespace std;   main()   { int num1, num2; ...
SUBMITTED TO:PROFESSOR ERWIN GLOBIO                                      http://eglobiotraining.com         http://eglobio...
Upcoming SlideShare
Loading in...5
×

Final requirement (2)

100

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
100
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Final requirement (2)"

  1. 1. FINAL REQUIREMENThttp://eglobiotraining.com
  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. 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. 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. 5. EXAMPLE OF SWITCH CASE IN CPROGRAMMING 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 functionvoid 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 tofor choice response displayResponse(choice); // passes choice to return response; // sends back the response valuedisplayResponse 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. 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 didnt pick a letter a, b or c.nn"; again = getChar(); // gives the user another try displayResponse(again); // recalls displayResponse with newcharacter break; } // end of switch statement} // end displayResponse function http://eglobiotraining.com
  7. 7. LOOPINGThere may be a situation when you need to execute a blockof code several number of times.Programming languages provide various control structuresthat allow for more complicated execution paths.A loop statement allows us to execute a statement or groupof statements multiple times and following is the general fromof a loop statement in most of the programming languages. http://eglobiotraining.com
  8. 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. 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. 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. 11. EXAMPLE OF WHILE LOOP IN CPROGRAMMING#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 1and 10: "; } cin >> x; cout << "Thank you for entering a valid cout << "You entered: " << x << endl << number!" << endl;endl; return 0; } http://eglobiotraining.com
  12. 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. 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. 14. EXAMPLE OF A DO WHILELOOP 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. 15. SUBMITTED TO:PROFESSOR ERWIN GLOBIO http://eglobiotraining.com http://eglobiotraining.com
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×