Presentation is loading. Please wait.

Presentation is loading. Please wait.

Refer to Ivor Horton’s Beginning ANSI C++ The Complete Language, 3rd Ed. APress Media, LLC. Choices and Decisions if statement if-else statement Relational.

Similar presentations


Presentation on theme: "Refer to Ivor Horton’s Beginning ANSI C++ The Complete Language, 3rd Ed. APress Media, LLC. Choices and Decisions if statement if-else statement Relational."— Presentation transcript:

1 Refer to Ivor Horton’s Beginning ANSI C++ The Complete Language, 3rd Ed. APress Media, LLC. Choices and Decisions if statement if-else statement Relational operators Logical operators and expressions switch statement – multiple choices

2 Refer to Ivor Horton’s Beginning ANSI C++ The Complete Language, 3rd Ed. APress Media, LLC. Relational Operators Operators –Less than  < –Less and equal than  <= –Greater than  > –Greater and equal than  >= –Equal to  == –Not equal to  != Program 4.1

3 Refer to Ivor Horton’s Beginning ANSI C++ The Complete Language, 3rd Ed. APress Media, LLC. Logical expressions Initializations Logical expressions

4 Refer to Ivor Horton’s Beginning ANSI C++ The Complete Language, 3rd Ed. APress Media, LLC. if Statements Program 4.2

5 Refer to Ivor Horton’s Beginning ANSI C++ The Complete Language, 3rd Ed. APress Media, LLC. Nested if Statements if (condition) { if (condition) { if (condition) { statements; } Program 4.3

6 Refer to Ivor Horton’s Beginning ANSI C++ The Complete Language, 3rd Ed. APress Media, LLC. Character Handling Character type header – or Functions for converting characters

7 Refer to Ivor Horton’s Beginning ANSI C++ The Complete Language, 3rd Ed. APress Media, LLC. Functions for Testing Characters

8 Refer to Ivor Horton’s Beginning ANSI C++ The Complete Language, 3rd Ed. APress Media, LLC. Logical Operators Boolean operators Boolean header file –bool.h Return integer –false (0), true (non-zero) Program 4.4

9 Refer to Ivor Horton’s Beginning ANSI C++ The Complete Language, 3rd Ed. APress Media, LLC. if-else statement char letter = 45; if (isalnum(letter)) cout << “It is a letter or a digit.” << endl; else cout << “it is neither a letter nor a digit.” << endl; Program 4.5

10 Refer to Ivor Horton’s Beginning ANSI C++ The Complete Language, 3rd Ed. APress Media, LLC. Nested if-else Statements

11 Refer to Ivor Horton’s Beginning ANSI C++ The Complete Language, 3rd Ed. APress Media, LLC. Nested if-else statement

12 Refer to Ivor Horton’s Beginning ANSI C++ The Complete Language, 3rd Ed. APress Media, LLC. More coffee and donuts

13 Refer to Ivor Horton’s Beginning ANSI C++ The Complete Language, 3rd Ed. APress Media, LLC. Clearer version

14 Refer to Ivor Horton’s Beginning ANSI C++ The Complete Language, 3rd Ed. APress Media, LLC. Logical (Boolean) operators Logical AND – && Logical OR – || Logical NOT – ! Program 4.6

15 Refer to Ivor Horton’s Beginning ANSI C++ The Complete Language, 3rd Ed. APress Media, LLC. Conditional Operator Ternary operator condition ? experssion1: expression2; E.g. –c = a > b ? a: b; –if (a>b) c = a; else c = b; –loan = (2*income<balance/2) ? (2*income): balance/2); –a < b ? ++i : --i; Program 4.7

16 Refer to Ivor Horton’s Beginning ANSI C++ The Complete Language, 3rd Ed. APress Media, LLC. switch Statement Multiple choices Keywords –switch –case –default –break Program 4.8, 4.9

17 Refer to Ivor Horton’s Beginning ANSI C++ The Complete Language, 3rd Ed. APress Media, LLC. Alternative Ways

18 Refer to Ivor Horton’s Beginning ANSI C++ The Complete Language, 3rd Ed. APress Media, LLC. Decision Statement Blocks and Variable Scope


Download ppt "Refer to Ivor Horton’s Beginning ANSI C++ The Complete Language, 3rd Ed. APress Media, LLC. Choices and Decisions if statement if-else statement Relational."

Similar presentations


Ads by Google