Beruflich Dokumente
Kultur Dokumente
STRUCTURED
PROGRAMMING
Control Structures II (Switch)
First Semester / 2014-2015
Copyright © 2014 Applied Science University33. All Rights Reserved | Dr. Mahmood G. Al-Bashayreh
2
ORDER OF PRECEDENCE
• Relational and logical operators are evaluated from left to right.
• Parentheses can override precedence.
• ()
• ++Pre-increment, --pre-decrement, ! not (unary operators)
• *,/,%
• +,-
• <,<=,>=,>
• &&
• ||
• ==,!=
• Compound operators
• = assignment
• Post-increment++, post –decrement--
Copyright © 2014 Applied Science University33. All Rights Reserved | Dr. Mahmood G. Al-Bashayreh
3
SHORT-CIRCUIT EVALUATION
Copyright © 2014 Applied Science University33. All Rights Reserved | Dr. Mahmood G. Al-Bashayreh
4
EXAMPLE
Copyright © 2014 Applied Science University33. All Rights Reserved | Dr. Mahmood G. Al-Bashayreh
5
EXAMPLE (CONT’D.)
Copyright © 2014 Applied Science University33. All Rights Reserved | Dr. Mahmood G. Al-Bashayreh
6
EXAMPLE (CONT’D.)
Copyright © 2014 Applied Science University33. All Rights Reserved | Dr. Mahmood G. Al-Bashayreh
7
Copyright © 2014 Applied Science University33. All Rights Reserved | Dr. Mahmood G. Al-Bashayreh
8
SWITCH STRUCTURES
• Expression is sometimes
called the selector
Copyright © 2014 Applied Science University33. All Rights Reserved | Dr. Mahmood G. Al-Bashayreh
10
Copyright © 2014 Applied Science University33. All Rights Reserved | Dr. Mahmood G. Al-Bashayreh
11
Copyright © 2014 Applied Science University33. All Rights Reserved | Dr. Mahmood G. Al-Bashayreh
13
Copyright © 2014 Applied Science University33. All Rights Reserved | Dr. Mahmood G. Al-Bashayreh
15
EXAMPLE
#include <iostream>
#include <cassert>
using namespace std;
int main()
{
int x, y;
cin >> x >> y;
assert(y!=0);
cout << x/y << endl;
return 0;
}
Copyright © 2014 Applied Science University33. All Rights Reserved | Dr. Mahmood G. Al-Bashayreh