show_control_structs

show_control_structs - Lab 3 Lab 3 Beware Lab 3 is...

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

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

View Full Document

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

View Full Document

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

View Full Document

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Lab 3 Lab 3 Beware : Lab 3 is non-trivial. Prepare to spend between 2–3 × the effort of Labs 1 and 2. Begin as soon as you can. The lab consists of several independent parts, take advantage of this ! Control Structures in C++ CHAPTER 3 C++ Boolean Expressions and Selection Statements March 28, 2008 Control Structures in C++ C++ Code Path Control Programs that can “make decisions” are better than programs that cannot. 1. Decide whether user input is valid. 2. Decide if special calculations are necessary ( √- 4 = 2 i ). 3. Execute a sequence of instructions a specific number of times. All of these use Boolean expressions to as the fundamental building block of program logic. Boolean Expressions Relational Operators How do two number relate to each other == equality != non-equality < less than > greater than <= less than or equal >= greater than or equal 1 c o u t << ( 0 < 1 ) << e n d l ; 2 c o u t << ( 1 <= 0 ) << e n d l ; 3 c o u t << (- 1.2345 >=- 1.2345 ) << e n d l ; 4 c o u t << (- 1.2345 >- 1.2345 ) << e n d l ; 1 1 RUN EDIT relational_ops.cxx Boolean Expressions Logical Operators Combining True and False ! NOT && AND || OR 1 c o u t << ( 0 < 1 ) << e n d l ; 2 c o u t << ( 1 <= 0 ) << e n d l ; 3 c o u t << ( ( 0 < 1 ) | | ( 1 <= 0 ) ) << e n d l ; 4 c o u t << e n d l ; 5 c o u t << (- 1.2345 >=- 1.2345 ) << e n d l ; 6 c o u t << (- 1.2345 >- 1.2345 ) << e n d l ; 7 c o u t << ( (- 1.2345 >=- 1.2345 ) && \ 8 (- 1.2345 >- 1.2345 ) ) << e n d l ; 1 1 1 RUN EDIT logical_ops.cxx Boolean Expressions The (Growing) Precedence Table Precedence Operator(s) Associativity Notes First () innermost : Unary: ++ -- . ⇒ Postfix++ : Unary: ++ -- + - (cast) ⇐ ++Prefix : Binary: * / % ⇒ : Binary: + - ⇒ : Relational: < <= > >= ⇒ : Relational: == != ⇒ : Logical: && ⇒ : Logical: || ⇒ Last Assignment: = += -= *= /= %= ⇐ Boolean Expressions Boolean Expressions in Practice 1 c o u t << ((- 6 < 0 ) && ( 1 2 >= 1 0 . 0 ) ) << e n d l ; 1 RUN EDIT bool_expr_a.cxx 1 c o u t << ( ( 3 . 0 < 2 ) && ( 3 . 0 >= 4 . 0 ) ) << e n d l ; RUN EDIT bool_expr_c.cxx 1 / / Boolean e x p r e s s i o n s t y l e s 2 b o o l u s e _ p a r e n s ( ( 3 . 0 < 2 ) | | ( 3 . 0 >= 4 . 0 ) ) ; 3 b o o l u s e _ s p a c e ( 3.0 <2 | | 3 .0 >=4 .0 ) ; 4 b o o l u n h e l p f u l ( 3 . 0 < 2 | | 3 . 0 >= 4 . 0 ) ; 5 c o u t . s e t f ( i o s : : b o o l a l p h a ) ; 6 c o u t << u s e _ p a r e n s << ’ ’ 7 << ( i n t ) u s e _ s p a c e << ’ ’ 8 << u n h e l p f u l << e n d l ; Boolean Expressions Boolean Expressions in Practice 1 c o u t << ((- 6 < 0 ) && ( 1 2 >= 1 0 . 0 ) ) << e n d l ; 1 RUN EDIT bool_expr_a.cxx 1 c o u t << ( ( 3 . 0 < 2 ) && ( 3 . 0 >= 4 . 0 ) ) << e n d l ; RUN EDIT bool_expr_c.cxx 1 / / Boolean e x p r e s s i o n s t y l e s 2 b o o l u s e _ p a r e n s ( ( 3 . 0 < 2 ) | | ( 3 . 0 >= 4 . 0 ) ) ; 3 b o o l u s e _ s p a c e ( 3.0 <2 | | 3 .0 >=4 .0 ) ; 4 b o o l u n h e l p f u l ( 3 . 0 < 2 | | 3 . 0 >= 4 . 0 ) ; 5 c o u t . s e t f...
View Full Document

{[ snackBarMessage ]}

Page1 / 26

show_control_structs - Lab 3 Lab 3 Beware Lab 3 is...

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

View Full Document
Ask a homework question - tutors are online