CPS 6, Ramm - Spring 2000 - 1/24/00 #5
Chapter 2: C++ Programs: Form and Function
- Go Over Friday's Quiz
- Processing Numbers
Example: Collision at -40
tempscale.cpp
- Type:
int Numbers
- max, min
- micros, workstations
- Type:
double Numbers
- Arithmetic Operators/Operands
- + addition
- - subtraction
- * multiplication
- / division
- % modulus/remainder
- Operator Precedence
- ( )
- *, /, %
- +, -
- left to right
- Automatic
int to double conversion
- Classes and Types
- Objects and Variables
-
if Statement
if ( test expression )
{
statement list;
}
-
if/else Statement
if ( test expression )
{
statement list;
}
else
{
statement list;
}
-
if/else Examples:
- Relational Operators
| == | equal to
|
| > | greater than
|
| < | less than
|
| != | not equal to
|
| >= | greater than or equal to
|
| <= | less than or equal to
|
- Assignment Statement: ... = ...
- Snuck it into the last program
- Pronounce gets rather than equals
- Value of Relational Operations
true = 1
false = 0
- Logical Operators
- Short Circuit Evaluation
exhaust4.cpp
- C++ Operator Precedence
| ! | NOT
|
| *, /, % | mult, div, mod
|
| +, - | add, subt
|
| <<, >> | insert, extract
|
| <, <=, >, >= | LT, LE, GT, GE
|
| ==, != | EQ, NE
|
| && | AND
|
| || | OR
|
| =, +=, -=, *=, /=, %= | assignment
|
When in doubt, parenthesize