Lecture3_4 - Lecture 3 - Making Decisions ECE 3090 Software...

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

View Full Document Right Arrow Icon
ECE 3090 Software for Engineering Systems Dr. Ayanna Howard School of Electrical and Computer Engineering Georgia Institute of Technology Lecture 3 - Making Decisions
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Adapted from “Brief Version of Starting Out with C++” Relational Operators Used to compare numbers to determine relative order Operators: Not equal to != Equal to ( Do not confuse with =) == Less than or equal to <= Greater than or equal to >= Less than < Greater than > Boolean expressions – true (1) or false (0) 12 > 5 is true 7 <= 5 is false if x is 10, then x == 10 is true , x != 8 is true , and x == 8 is false
Background image of page 2
3 Adapted from “Brief Version of Starting Out with C++” The if Statement Allows statements to be conditionally executed or skipped over Models the way we mentally evaluate situations: "If it is raining, take an umbrella." "If it is cold outside, wear a coat."
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 Adapted from “Brief Version of Starting Out with C++” The if Statement General Format: if ( expression ) statement ; To evaluate: if ( expression ) statement ; If the expression is true , then statement is executed. If the expression is false , then statement is skipped.
Background image of page 4
5 Adapted from “Brief Version of Starting Out with C++”
Background image of page 5

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

View Full DocumentRight Arrow Icon
6 Adapted from “Brief Version of Starting Out with C++” Expanding the if Statement To execute more than one statement as part of an if statement, enclose them in { } : if (score > 90) { grade = 'A'; cout << "Good Job!\n"; } { } creates a block of code
Background image of page 6
7 Adapted from “Brief Version of Starting Out with C++” The if/else Statement Provides two possible paths of execution Performs one statement or block if the expression is true, otherwise performs another statement or block. General Format: if ( expression ) statement1 ; // or block else statement2 ; // or block
Background image of page 7

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

View Full DocumentRight Arrow Icon
8 Adapted from “Brief Version of Starting Out with C++” if/else – what happens To evaluate: if ( expression ) statement1 ; else statement2 ; If expression is true , then statement1 executed If expression is false , then statement2 is executed.
Background image of page 8
9 Adapted from “Brief Version of Starting Out with C++”
Background image of page 9

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

View Full DocumentRight Arrow Icon
10 Adapted from “Brief Version of Starting Out with C++” The if/else if Statement Chain of if statements that test in order until one is found to be true Also models thought processes: “If it is raining, take an umbrella, else, if it is windy, take a hat, else, take sunglasses” if ( expression ) statement 1 ; // or block else if ( expression ) statement 2 ; // or block . . // other else ifs . else if ( expression ) statement n ; // or block
Background image of page 10
11 Adapted from “Brief Version of Starting Out with C++”
Background image of page 11

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

View Full DocumentRight Arrow Icon
12 Adapted from “Brief Version of Starting Out with C++” Using a Trailing else Used with if/else if statement when none of the expressions are true Provides default statement/action Used to catch invalid values, other exceptional situations
Background image of page 12
13 Adapted from “Brief Version of Starting Out with C++” Menus
Background image of page 13

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

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

This note was uploaded on 06/09/2009 for the course ECE 3090 taught by Professor Staff during the Fall '08 term at Georgia Institute of Technology.

Page1 / 60

Lecture3_4 - Lecture 3 - Making Decisions ECE 3090 Software...

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

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