• Save
Programming - Marla Fuentes
Upcoming SlideShare
Loading in...5
×
 

Programming - Marla Fuentes

on

  • 271 views

 

Statistics

Views

Total Views
271
Views on SlideShare
271
Embed Views
0

Actions

Likes
0
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Programming - Marla Fuentes Programming - Marla Fuentes Presentation Transcript

  • What is a Switch Case?0 Switch Case 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 multiway branch (or "goto", 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 case.
  • Examples:Example #1: break; case D :#include <iostream> cout << "You passed" << endl;using namespace std; break; case F :int main () cout << "Better try again" << endl;{ break; // local variable declaration: default : char grade = D; cout << "Invalid grade" << endl; } switch(grade) cout << "Your grade is " << grade << endl; { case A : System (“pause”); cout << "Excellent!" << endl; return 0; break; } case B : case C : cout << "Well done" << endl;
  • Example #2: }#include <iostream> cout << "Of course I had nothing to using namespace std; do with the grade."; cout << "nThe professor was really int main () off the wall.n"; { system ("pause"); char letGrad, ch; return 0; cout << "Please enter a character: "; cin >> letGrad; } switch (letGrad) { case A: cout << "The numericalgrade is between 90 and 100"; break; case B: cout << "The numericalgrade is between 80 and 89.9"; break; case C: cout << "The numericalgrade is between 70 and 79.9"; break; case D: cout << "How are you goingto explain this one?"; break;
  • Example #3: break;#include <iostream> case F:using namespace std; person = "female";int main ( ) break;{ string person ; case f:char gender ; person ="female";cout << "Please enter your gender !n"; break;cin >> gender; default:switch (gender) person = "unknown";{ case m: }person = "male" ; cout << person << endl;break; system ("pause");case M: return 0;person = "male"; }
  • Example #4: break; default: cout << "Too large!n";#include <iostream.h> break;int main() }{ cout << "nn"; unsigned short int number; cout << "Enter a number between 1 and 5: "; system("pause"); cin >> number; return 0; switch (number) { } case 0: cout << "Too small, sorry!"; break; case 5: cout << "Good job!n"; break; case 4: cout << "Nice Pick!n"; break; case 3: cout << "Excellent!n"; break; case 2: cout << "Masterful!n"; break; case 1: cout << "Incredible!n";
  • What are Loops?0 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 -- many programs or websites that produce extremely complex output (such as a message board) are really only executing a single task many times. (They may be executing a small number of tasks, but in principle, to produce a list of messages only requires repeating the operation of reading in some data and displaying it.) Now, think about what this means: a loop lets you write a very simple statement to produce a significantly greater result simply by repetition.
  • Examples:Example #1:#include <iostream>using namespace std;int main(){ int x; x = 0; do { cout<<"Hello, world!n"; } while ( x != 0 ); cin.get();}
  • Example #2:#include<iostream>#include<string>int main(){using namespace std;string password, happiness;happiness="happiness";cout<<"Enter the correct password..n"<<endl;do{cout<<"Enter the correct password to obtain surprise: ";cin>> password;}while (password!=happiness);cout<<"Youve got it!"<<endl;system("pause");return (0);}
  • Example #3: while ( time < 1 || time > 10) endl; { cout << "Must enter#include <iostream> between 1 and 10 seconds, }#include <cmath> please re-enter.n"; system ("pause");using namespace std; time = return 0; fallingdistance(); }int fallingdistance(); int fallingdistance () } {int main() int seconds; cout <<"nSeconds{ falling distancen"; cin >> seconds; int count = 1 ; cout <<"--------------------- return seconds; int time; ------------------n"; } double distance ; cout << "Please for ( count = 1; count <=entertime in 1 through 10 time; count++)seconds.nn"; { distance = .5 * 9.8 * time = fallingdistance(); pow(time, 2.0); cout << count << " " << distance <<" meters"<<
  • Submitted to:Mr. Edwin Globiohttp://eglobiotraining.com Thank you and God bless! http://www.slideshare.net/mfuentessss