{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# l03 - CSci 1113 C/C for Scientists and Engineers Section...

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

: CSci 1113 C/C++ for Scientists and Engineers Section 010 - evening class Boolean Expressions and Flow of Control Prof. Eric Van Wyk and Ted Kaminski Spring 2010 c Van Wyk and Kaminski CSci 1113: C/C++ for Scientists and Engineers, evening class Spring 2010 Page 1 / 35

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

View Full Document
Expressions: Recap : Exercise 3.1 Consider the following: double d; int m, n; d = m / n ; How many different ways can you modify the above code so that d gets the value of m divided by n using floating point division instead of integer division. c Van Wyk and Kaminski CSci 1113: C/C++ for Scientists and Engineers, evening class Spring 2010 Page 1 / 35
Expressions: Recap : Expressions: Recap static cast: there are others that we will come to later Additional modifiers: short , unsigned e.g. short int x; e.g. unsigned int y; c Van Wyk and Kaminski CSci 1113: C/C++ for Scientists and Engineers, evening class Spring 2010 Page 2 / 35

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

View Full Document
Expressions: Recap : Representing integers How should we represent negative integers? Consider Two’s complement: a single representation for 0 c Van Wyk and Kaminski CSci 1113: C/C++ for Scientists and Engineers, evening class Spring 2010 Page 3 / 35
Boolean Expressions : Consider the following problem: The City of Minneapolis needs to issue health warning if the air pollution rises to a dangerous level. Pollution measurements are taken in several locations and measured in “number of pollutant parts per million’. An average is computed and a health warning is raised if that average is over 50 parts per million. We know how to compute averages, but do not know how to make decisions based on such calculations. We need to compute “boolean values” - values of True or False. c Van Wyk and Kaminski CSci 1113: C/C++ for Scientists and Engineers, evening class Spring 2010 Page 4 / 35

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

View Full Document
Boolean Expressions : Boolean? Where does the work “boolean” come from? George Boole - an English mathematician who discovered a logic of true/false values. This logic is part of the foundation of computer science. c Van Wyk and Kaminski CSci 1113: C/C++ for Scientists and Engineers, evening class Spring 2010 Page 5 / 35
Boolean Expressions : From the perspective of type systems ... We need a type for the boolean values “true” and “false”. In C++ this type is written bool and the literals are written true and false . What operators should we have? c Van Wyk and Kaminski CSci 1113: C/C++ for Scientists and Engineers, evening class Spring 2010 Page 6 / 35

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

View Full Document
Boolean Expressions Boolean Operators: Operators Relational operators: < , , > , , =, = Logical operators: (“and”), (“or”), ¬ (“not”) In C++ these are: < , <= , > , >= , == , != . and && , || , ! c Van Wyk and Kaminski CSci 1113: C/C++ for Scientists and Engineers, evening class Spring 2010 Page 7 / 35
Boolean Expressions Boolean Operators: Some examples bool raiseWarning = partsPerMillion > 50 ; bool tooTall = ! ( height < 7 ) ; bool perfectScore = score == 100 ; bool passing = (score - 50) > 0 ; c Van Wyk and Kaminski CSci 1113: C/C++ for Scientists and Engineers, evening class Spring 2010 Page 8 / 35

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

View Full Document
Boolean Expressions Boolean Operators: Operator precedence We’ve understand this for arithmetic operators.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}