TAILIEUCHUNG - Lecture Programming in C++ - Chapter 5: Decision making

On completion of this chapter students will learned how to: Create simple if and if-else statements, create relational expressions, utilize logical operators, interpret the order of precedence for all operators (arithmetic, relational, and logical), create multiple decision statements (if-else-if or switch statements), utilize bool data type. | Chapter 5 – Decision Making Simple if Statement Capable of making decisions Relational expression evaluated Evaluated as true or false Lesson if (relational expression) { statement(s); } Block of statements done if results true, skipped if results false! Relational Expressions Type of logical expression Produces result of true or false Compares values of two arithmetic expressions Lesson left_operand relational_operator right_operand Relational Operators greater than >= greater than or equal to != not equal Lesson Simple If/Else Statement Provides block of statements to be executed for either true OR false Braces optional if only one statement in block Lesson if (expression) { statement1a; statement1b; } else { statement1a; statement1b; } if TRUE if FALSE if Examples x = 3; if (x greater than >= greater than or equal to != not equal Lesson Simple If/Else Statement Provides block of statements to be executed for either true OR false Braces optional if only one statement in block Lesson if (expression) { statement1a; statement1b; } else { statement1a; statement1b; } if TRUE if FALSE if Examples x = 3; if (x b) { ans = 10;} else { ans = 25;} a > b ? (ans = 10) : (ans = 25) ; conditional expression if true, execute this statement if false, execute this statement ans = (a > b) ? 10 : 25 ; Lesson Nested if-else Statements Lesson if (outer) { if (inner) { } else { } } else { } If outer is true, this block executed. If outer is false, this block executed. Executed if inner is true. Executed if inner is false. Three Logical Operators Exclamation mark ! NOT (negation) unary Two ampersands && AND (conjunction) binary Two vertical pipes

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.