l03_6up

# l03_6up - Expressions Recap CSci 1113 C/C for Scientists...

This preview shows pages 1–3. 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 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 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 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

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

View Full Document
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 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 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 ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern