# Chap05 - Chapter 5 Conditions, Logical Expressions, and...

This preview shows pages 1–3. Sign up to view the full content.

57 Chapter 5 Conditions, Logical Expressions, and Selection Control Structures Chapter 5 CONDITIONS, LOGICAL EXPRESSIONS, AND  SELECTION CONTROL STRUCTURES CHAPTER GOALS To be able to construct a simple logical (Boolean) expression to evaluate a given condition. To be able to construct a complex logical expression to evaluate a given condition. To be able to construct an If-Then-Else statement to perform a specific task. To be able to construct an If-Then statement to perform a specific task. To be able to construct a set of nested If statements to perform a specific task. To be able to determine the precondition and postcondition for a module, and use them to perform an algorithm walk-through. To be able to trace the execution of a C++ program. To be able to test and debug a C++ program. CHAPTER OUTLINE I. Flow of Control A. Selection II. Conditions and Logical Expressions A. The bool Data Type Background Information : Before the bool Type B. Logical Expressions 1. Relational Operators 2. Comparing Strings 3. Logical Operators 4. Short-Circuit Evaluation May We Introduce : George Boole III. Precedence of Operators Software Engineering Tip : Changing English Statements into Logical Expressions A. Relational Operators with Floating Point Types IV. The If Statement A. The If-Then-Else Form B. Blocks (Compound Statements) Matters of Style : Braces and Blocks C. The If-Then Form D. A Common Mistake V. Nested If Statements A. The Dangling Else VI. Testing the State of an I/O Stream VII. Problem-Solving Case Study : Warning Notices IX VIII. Testing and Debugging A. Testing in the Problem-Solving Phase: The Algorithm Walk-Through X 1. Determining Preconditions and Postconditions XI 2. Performing the Algorithm Walk-Through B. The Implementation Phase

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

View Full Document
58 Chapter 5 Conditions, Logical Expressions, and Selection Control Structures 1. Code Walk-Through 2. Execution Trace XII 3. Testing Selection Control Structures C. The Test Plan D. Tests Performed Automatically During Compilation and Execution E. Testing and Debugging Hints IX. Summary GENERAL DISCUSSION There are three key concepts in this chapter: logical (Boolean) expressions, flow of control, and the testing process. Logical expressions are used to make assertions about the status of certain variables in a program; results of the evaluation of these expressions then are used to determine the flow of control. Students must understand the idea that an expression can result in a value of either true or false. The bool data type in C++ (introduced in the recent ANSI standard) provides a means for declaring logical variables. (If a pre-standard version of C+ + is being used, see section D.4 of Appendix D of the textbook.) Some students have trouble understanding the semantics of AND and OR. It usually takes only a few extra examples to make these operations clear. It is useful to relate the C++ operations to how we use AND and OR in English so that students see that the operations are not in any way new or exotic. (There is a subtle issue
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 06/13/2011 for the course CSC 140 taught by Professor Lebre during the Spring '04 term at Moraine Valley Community College.

### Page1 / 12

Chap05 - Chapter 5 Conditions, Logical Expressions, and...

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

View Full Document
Ask a homework question - tutors are online