SlideShare una empresa de Scribd logo
1 de 18
PROGRAMMING
Submitted by Jeronika Macaraeg




                                 http://eglobiotraining.com
TOPICS IN
PROGRAMMING:
SWITCH CASE
LOOPING

         http://eglobiotraining.com
LOOPING
 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
looping programming
has three types:
  FOR
  WHILE
  DO WHILE




              http://eglobiotraining.com
FOR
 The statements in the for loop repeat
  continuously for aspecific 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. Use
  a for loop when the number of repetition is
  know, or can be supplied by the user



                        http://eglobiotraining.com
WHILE
 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.




                        http://eglobiotraining.com
Do while
 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
 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.

                        http://eglobiotraining.com
SWITCH CASE
 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
 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
EXAMPLES OF SOURCE CODE IN C++
PROGRAMMING
#include <iostream>
#include <stdlib.h>
                                                                             // switch statement based on the choice variable
using namespace std;                                                          switch (choice) // notice no semicolon
void welcome();                                                               {
                                                                                case 'A': // choice was the letter A
char getChar();                                                                 case 'a': // choice was the letter a
void displayResponse(char choice);                                               cout << "your awesome dude.nn";
                                                                                 break; // this ends the statements for case A/a
int main(int argc, char *argv[])                                                case 'B': // choice was the letter b
                                                                                case 'b': // choice was the letter b
{
                                                                                 cout << "you will find your lovelife.nn";
    char choice; // declares the choice variable                                 break; // this ends the statements for case B/b
                                                                                case 'C': // choice was the letter C
    welcome(); // This calls the welcome function
                                                                                case 'c': // choice was the letter c
    choice = getChar(); // calls getChar and returns the value for choice        cout << "your will won the lottery.nn";
                                                                                 break; // this ends the statements for case C/c
    displayResponse(choice); // passes choice to displayResponse function
                                                                                  case 'D': // choice was the letter D
                                                                                case 'd': // choice was the letter d
                                                                                 cout << "your so ugly!!.nn";
    system("PAUSE");                                                             break; // this ends the statements for case D/d
    return 0;                                                                   default: // used when choice falls out of the cases covered above
                                                                                 cout << "You didn't pick a letter a, b or c.nn";
} // end main                                                                    again = getChar(); // gives the user another try
// welcome function displays an opening message to                               displayResponse(again); // recalls displayResponse with new
                                                                            character
// explain the program to the user                                               break;
                                                                              } // end of switch statement
void welcome()
                                                                            } // end displayResponse function
{
    cout << "This program displays different messages dependingn";
    cout << "on which letter is entered by the user.n";
    cout << "Pick a letter a, b, c or d 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.                    http://eglobiotraining.com
EXAMPLES OF SOURCE CODE IN C++
 PROGRAMMING
#include <iostream.h>

int main(void) {
   int x = 0;
   int y = 0;
   bool validNumber = false;

  while (validNumber == false) {
    cout << "Please enter an integer between 1 and 10: ";
    cin >> x;
    cout << "You entered: " << x << endl << endl;

      if ((x < 1) || (x > 10)) {
           cout << "Your value for x is not between 1 and 10!"
           << endl;
           cout << "Please re-enter the number!" << endl << endl;
      }
      else
           validNumber = true;
  }

  cout << "Thank you for entering a valid number!" << endl;

  return 0;
       }




                                                                    http://eglobiotraining.com
EXAMPLES OF SOURCE CODE 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
EXAMPLES OF SOURCE CODE 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 * pow(time,
int main()                                             2.0);
{                                                                                   cout << count << "
             int count = 1 ;                           " << distance <<" meters"<< endl;
             int time;
             double distance ;                                       }
             cout << "Please enter time in 1 through     system ("pause");
                                                                     return 0;
10 seconds.nn";                                      }
                                                       // falling distance function for a return value in seconds
  time = fallingdistance();                            transfer to time
                                                       int fallingdistance ()
            while ( time < 1 || time > 10)             {
            { cout << "Must enter between 1 and 10                      int seconds;
                                                                        cin >> seconds;
seconds, please re-enter.n";                                           return seconds;
              time = fallingdistance();                }
                                                               http://eglobiotraining.com
RUNNING SOURCE FILE IN C++
PROGRAMMING




                http://eglobiotraining.com
RUNNING SOURCE FILE IN C++
PROGRAMMING




                http://eglobiotraining.com
RUNNING SOURCE FILE IN C++
PROGRAMMING




                http://eglobiotraining.com
RUNNING SOURCE FILE IN C++
PROGRAMMING




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


                  SUBMITTED TO:
                   EDWIN GLOBIO

                             http://eglobiotraining.com

Más contenido relacionado

La actualidad más candente

Final requirement in programming niperos
Final requirement in programming   niperosFinal requirement in programming   niperos
Final requirement in programming niperosmarkings17
 
Lecture 2 php basics (1)
Lecture 2  php basics (1)Lecture 2  php basics (1)
Lecture 2 php basics (1)Core Lee
 
Programming - Marla Fuentes
Programming - Marla FuentesProgramming - Marla Fuentes
Programming - Marla Fuentesmfuentessss
 
Advanced php
Advanced phpAdvanced php
Advanced phpAnne Lee
 
Computer programming
Computer programmingComputer programming
Computer programmingXhyna Delfin
 
Swift - One step forward from Obj-C
Swift -  One step forward from Obj-CSwift -  One step forward from Obj-C
Swift - One step forward from Obj-CNissan Tsafrir
 
A Spin-off: Firebird Checked by PVS-Studio
A Spin-off: Firebird Checked by PVS-StudioA Spin-off: Firebird Checked by PVS-Studio
A Spin-off: Firebird Checked by PVS-StudioAndrey Karpov
 
Fundamentals of programming angeli
Fundamentals of programming angeliFundamentals of programming angeli
Fundamentals of programming angelibergonio11339481
 
Hacking Parse.y with ujihisa
Hacking Parse.y with ujihisaHacking Parse.y with ujihisa
Hacking Parse.y with ujihisaujihisa
 
RailswayCon 2010 - Dynamic Language VMs
RailswayCon 2010 - Dynamic Language VMsRailswayCon 2010 - Dynamic Language VMs
RailswayCon 2010 - Dynamic Language VMsLourens Naudé
 

La actualidad más candente (20)

Final Exam in FNDPRG
Final Exam in FNDPRGFinal Exam in FNDPRG
Final Exam in FNDPRG
 
Final requirement in programming niperos
Final requirement in programming   niperosFinal requirement in programming   niperos
Final requirement in programming niperos
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
Cpp reference card
Cpp reference cardCpp reference card
Cpp reference card
 
Lecture 2 php basics (1)
Lecture 2  php basics (1)Lecture 2  php basics (1)
Lecture 2 php basics (1)
 
Linux shell
Linux shellLinux shell
Linux shell
 
Programming - Marla Fuentes
Programming - Marla FuentesProgramming - Marla Fuentes
Programming - Marla Fuentes
 
Chap03[1]
Chap03[1]Chap03[1]
Chap03[1]
 
Module Magic
Module MagicModule Magic
Module Magic
 
9-java language basics part3
9-java language basics part39-java language basics part3
9-java language basics part3
 
Advanced php
Advanced phpAdvanced php
Advanced php
 
C++ programming
C++ programmingC++ programming
C++ programming
 
C++ programming
C++ programmingC++ programming
C++ programming
 
Computer programming
Computer programmingComputer programming
Computer programming
 
Swift - One step forward from Obj-C
Swift -  One step forward from Obj-CSwift -  One step forward from Obj-C
Swift - One step forward from Obj-C
 
A Spin-off: Firebird Checked by PVS-Studio
A Spin-off: Firebird Checked by PVS-StudioA Spin-off: Firebird Checked by PVS-Studio
A Spin-off: Firebird Checked by PVS-Studio
 
Fundamentals of programming angeli
Fundamentals of programming angeliFundamentals of programming angeli
Fundamentals of programming angeli
 
Hacking Parse.y with ujihisa
Hacking Parse.y with ujihisaHacking Parse.y with ujihisa
Hacking Parse.y with ujihisa
 
Lazy Data Using Perl
Lazy Data Using PerlLazy Data Using Perl
Lazy Data Using Perl
 
RailswayCon 2010 - Dynamic Language VMs
RailswayCon 2010 - Dynamic Language VMsRailswayCon 2010 - Dynamic Language VMs
RailswayCon 2010 - Dynamic Language VMs
 

Destacado

Инновации в АПК
Инновации в АПКИнновации в АПК
Инновации в АПКOleg Evseenkov
 
выступление на конференции C news
выступление на конференции C newsвыступление на конференции C news
выступление на конференции C newsOleg Evseenkov
 
инновационная стратегия для промышленного региона
инновационная стратегия для промышленного регионаинновационная стратегия для промышленного региона
инновационная стратегия для промышленного регионаOleg Evseenkov
 
Audience research- Nicole Green
Audience research- Nicole GreenAudience research- Nicole Green
Audience research- Nicole Greennicole_green
 
Theories- Nicole Green.
Theories- Nicole Green.Theories- Nicole Green.
Theories- Nicole Green.nicole_green
 
Bebo Kobo
Bebo KoboBebo Kobo
Bebo KoboAaliyaM
 

Destacado (9)

Инновации в АПК
Инновации в АПКИнновации в АПК
Инновации в АПК
 
выступление на конференции C news
выступление на конференции C newsвыступление на конференции C news
выступление на конференции C news
 
инновационная стратегия для промышленного региона
инновационная стратегия для промышленного регионаинновационная стратегия для промышленного региона
инновационная стратегия для промышленного региона
 
Audience research- Nicole Green
Audience research- Nicole GreenAudience research- Nicole Green
Audience research- Nicole Green
 
Theories- Nicole Green.
Theories- Nicole Green.Theories- Nicole Green.
Theories- Nicole Green.
 
Nudge challenge
Nudge challengeNudge challenge
Nudge challenge
 
Bebo Kobo
Bebo KoboBebo Kobo
Bebo Kobo
 
Ghost dances
Ghost dancesGhost dances
Ghost dances
 
Dover beach
Dover beachDover beach
Dover beach
 

Similar a Macaraeg

My programming final proj. (1)
My programming final proj. (1)My programming final proj. (1)
My programming final proj. (1)aeden_brines
 
presentation_functions_1443207686_140676.ppt
presentation_functions_1443207686_140676.pptpresentation_functions_1443207686_140676.ppt
presentation_functions_1443207686_140676.pptSandipPradhan23
 
C++ Programming Club-Lecture 1
C++ Programming Club-Lecture 1C++ Programming Club-Lecture 1
C++ Programming Club-Lecture 1Ammara Javed
 
[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...Francesco Casalegno
 
Start with the inclusion of libraries#include iostream .docx
 Start with the inclusion of libraries#include iostream .docx Start with the inclusion of libraries#include iostream .docx
Start with the inclusion of libraries#include iostream .docxMARRY7
 
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
 
Lecture#4 Algorithm and computing
Lecture#4 Algorithm and computingLecture#4 Algorithm and computing
Lecture#4 Algorithm and computingNUST Stuff
 
c++basics.ppt
c++basics.pptc++basics.ppt
c++basics.pptEPORI
 

Similar a Macaraeg (20)

My programming final proj. (1)
My programming final proj. (1)My programming final proj. (1)
My programming final proj. (1)
 
presentation_functions_1443207686_140676.ppt
presentation_functions_1443207686_140676.pptpresentation_functions_1443207686_140676.ppt
presentation_functions_1443207686_140676.ppt
 
C++ Programming Club-Lecture 1
C++ Programming Club-Lecture 1C++ Programming Club-Lecture 1
C++ Programming Club-Lecture 1
 
Oop1
Oop1Oop1
Oop1
 
Project in programming
Project in programmingProject in programming
Project in programming
 
[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...
 
Start with the inclusion of libraries#include iostream .docx
 Start with the inclusion of libraries#include iostream .docx Start with the inclusion of libraries#include iostream .docx
Start with the inclusion of libraries#include iostream .docx
 
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
 
Lecture#4 Algorithm and computing
Lecture#4 Algorithm and computingLecture#4 Algorithm and computing
Lecture#4 Algorithm and computing
 
C++ theory
C++ theoryC++ theory
C++ theory
 
c++basics.ppt
c++basics.pptc++basics.ppt
c++basics.ppt
 
C++basics
C++basicsC++basics
C++basics
 
C++basics
C++basicsC++basics
C++basics
 
c++basiccs.ppt
c++basiccs.pptc++basiccs.ppt
c++basiccs.ppt
 
c++basics.ppt
c++basics.pptc++basics.ppt
c++basics.ppt
 
c++basics.ppt
c++basics.pptc++basics.ppt
c++basics.ppt
 
C++basics
C++basicsC++basics
C++basics
 
Oops presentation
Oops presentationOops presentation
Oops presentation
 
Presentation1
Presentation1Presentation1
Presentation1
 
Lab # 3
Lab # 3Lab # 3
Lab # 3
 

Macaraeg

  • 1. PROGRAMMING Submitted by Jeronika Macaraeg http://eglobiotraining.com
  • 3. LOOPING  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
  • 4. looping programming has three types:  FOR  WHILE  DO WHILE http://eglobiotraining.com
  • 5. FOR  The statements in the for loop repeat continuously for aspecific 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. Use a for loop when the number of repetition is know, or can be supplied by the user http://eglobiotraining.com
  • 6. WHILE  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. http://eglobiotraining.com
  • 7. Do while  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  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. http://eglobiotraining.com
  • 8. SWITCH CASE  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
  • 9. SWITCH CASE  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
  • 10. EXAMPLES OF SOURCE CODE IN C++ PROGRAMMING #include <iostream> #include <stdlib.h> // switch statement based on the choice variable using namespace std; switch (choice) // notice no semicolon void welcome(); { case 'A': // choice was the letter A char getChar(); case 'a': // choice was the letter a void displayResponse(char choice); cout << "your awesome dude.nn"; break; // this ends the statements for case A/a int main(int argc, char *argv[]) case 'B': // choice was the letter b case 'b': // choice was the letter b { cout << "you will find your lovelife.nn"; char choice; // declares the choice variable break; // this ends the statements for case B/b case 'C': // choice was the letter C welcome(); // This calls the welcome function case 'c': // choice was the letter c choice = getChar(); // calls getChar and returns the value for choice cout << "your will won the lottery.nn"; break; // this ends the statements for case C/c displayResponse(choice); // passes choice to displayResponse function case 'D': // choice was the letter D case 'd': // choice was the letter d cout << "your so ugly!!.nn"; system("PAUSE"); break; // this ends the statements for case D/d return 0; default: // used when choice falls out of the cases covered above cout << "You didn't pick a letter a, b or c.nn"; } // end main again = getChar(); // gives the user another try // welcome function displays an opening message to displayResponse(again); // recalls displayResponse with new character // explain the program to the user break; } // end of switch statement void welcome() } // end displayResponse function { cout << "This program displays different messages dependingn"; cout << "on which letter is entered by the user.n"; cout << "Pick a letter a, b, c or d 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. http://eglobiotraining.com
  • 11. EXAMPLES OF SOURCE CODE IN C++ PROGRAMMING #include <iostream.h> int main(void) { int x = 0; int y = 0; bool validNumber = false; while (validNumber == false) { cout << "Please enter an integer between 1 and 10: "; cin >> x; cout << "You entered: " << x << endl << endl; if ((x < 1) || (x > 10)) { cout << "Your value for x is not between 1 and 10!" << endl; cout << "Please re-enter the number!" << endl << endl; } else validNumber = true; } cout << "Thank you for entering a valid number!" << endl; return 0;  } http://eglobiotraining.com
  • 12. EXAMPLES OF SOURCE CODE 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
  • 13. EXAMPLES OF SOURCE CODE 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 * pow(time, int main() 2.0); { cout << count << " int count = 1 ; " << distance <<" meters"<< endl; int time; double distance ; } cout << "Please enter time in 1 through system ("pause"); return 0; 10 seconds.nn"; } // falling distance function for a return value in seconds time = fallingdistance(); transfer to time int fallingdistance () while ( time < 1 || time > 10) { { cout << "Must enter between 1 and 10 int seconds; cin >> seconds; seconds, please re-enter.n"; return seconds; time = fallingdistance(); } http://eglobiotraining.com
  • 14. RUNNING SOURCE FILE IN C++ PROGRAMMING http://eglobiotraining.com
  • 15. RUNNING SOURCE FILE IN C++ PROGRAMMING http://eglobiotraining.com
  • 16. RUNNING SOURCE FILE IN C++ PROGRAMMING http://eglobiotraining.com
  • 17. RUNNING SOURCE FILE IN C++ PROGRAMMING http://eglobiotraining.com
  • 18. http://eglobiotraining.com SUBMITTED TO: EDWIN GLOBIO http://eglobiotraining.com