CPS 6, Ramm - Summer Semester I - 5/23/00 #4
- Announce
- Lab #2 Today
- Quiz Tomorrow
- Assignment #2
Chapter 4: Control, Functions, and Classes
- 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
- Functions that Return Values
math.cpp
- Writing
Double Functions
tfuncts.cpp
- Use Functions Like Variables
- Writing
string Functions
getgrade.cpp
getgradealt.cpp
- Design Different "Curving" Functions
- Writing Functions
Design Different "Curving" Functions
- Look at
numtoeng.cpp in Book
- The
string Member Functions
string demo = "Monday morning";
- Length:
int length()
demo.length() == 14
- Substring:
string substr(int pos, int len)
demo.substr(7,4) == "morn"
- Find:
int find(string s)
demo.find("y m") == 5
(not found: string::npos )