Lecture15 - Engineering 101 Lecture 15 Selection Prof....

Info iconThis preview shows pages 1–18. Sign up to view the full content.

View Full Document Right Arrow Icon
Engineering 101 Engineering 101 Lecture 15 Lecture 15 Selection Selection Prof. Michael Falk University of Michigan, College of Engineering
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Announcements Announcements Project 4 due Friday 10/20 at 7pm Office Hours will be altered next week due to Fall Break No Wednesday lab 10/18 Exam 2: 10/25 Early administration 10/23, Contact me.
Background image of page 2
Selection Selection So far we have discussed sequence and iteration . Selection allows the execution of a portion of your code depending on some condition.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Selection Selection Allows the selective execution of a portion of your code depending on some condition. Syntax in C++: if (condition) statement_t else statement_f
Background image of page 4
Selection Selection Allows the selective execution of a portion of your code depending on some condition. Syntax in C++: if ( condition ) statement_t else statement_f The condition is similar to the while condition. It evaluates to true or false.
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Selection Selection Allows the selective execution of a portion of your code depending on some condition. Syntax in C++: if ( condition ) statement_t else statement_f If the condition evaluates to true then statement_t is executed.
Background image of page 6
Selection Selection Allows the selective execution of a portion of your code depending on some condition. Syntax in C++: if ( condition ) statement_t else statement_f If the condition evaluates to false then statement_f is executed.
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Selection Selection Allows the selective execution of a portion of your code depending on some condition. Syntax in C++: if ( condition ) statement_t else statement_f The statements can either be single line expressions or multiple expressions enclosed in braces.
Background image of page 8
Selection Selection Allows the selective execution of a portion of your code depending on some condition. Syntax in C++: if ( condition ) statement_t else statement_f The else can be entirely removed.
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Simple Example Simple Example int x; cin >> x; if (x % 2 == 0) cout << x << “is an even number” << endl; else cout << x << “is an odd number” << endl;
Background image of page 10
Simple Example Simple Example int x; cin >> x; if (x % 2 == 0) cout << x << “is an even number” << endl; else cout << x << “is an odd number” << endl; x 14
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Simple Example Simple Example int x; cin >> x; if ( 14 % 2 == 0 ) cout << x << “is an even number” << endl; else cout << x << “is an odd number” << endl; x 14
Background image of page 12
Simple Example Simple Example int x; cin >> x; if ( 0 == 0 ) cout << x << “is an even number” << endl; else cout << x << “is an odd number” << endl; x 14
Background image of page 13

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Simple Example Simple Example int x; cin >> x; if (x % 2 == 0) cout << x << “is an even number” << endl; else cout << x << “is an odd number” << endl; x 14 14 is an even number
Background image of page 14
Simple Example Simple Example int x; cin >> x; if (x % 2 == 0) cout << x << “is an even number” << endl; else cout << x << “is an odd number” << endl; x 27
Background image of page 15

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Simple Example Simple Example int x; cin >> x; if ( 27 % 2 == 0 ) cout << x << “is an even number” << endl; else cout << x << “is an odd number” << endl; x 27
Background image of page 16
Simple Example Simple Example int x; cin >> x; if ( 1 == 0 ) cout << x << “is an even number” << endl; else cout << x << “is an odd number” << endl; x 27
Background image of page 17

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 18
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/02/2008 for the course ENGR 101 taught by Professor Ringenberg during the Fall '07 term at University of Michigan.

Page1 / 53

Lecture15 - Engineering 101 Lecture 15 Selection Prof....

This preview shows document pages 1 - 18. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online