CPS 6, Ramm - Summer Semester I - 5/23/01 #5
- Announce
- Lab #3 Tomorrow
- Quiz Today
Chapter 4: Control, Functions, and Classes
- Relational Operators
| == | equal to
|
| > | greater than
|
| < | less than
|
| != | not equal to
|
| >= | greater than or equal to
|
| <= | less than or equal to
|
- 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
- Writing Functions
Design Different "Curving" Functions
- Converting Digits to Words
numtoeng.cpp
- 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 )
- Examples Using String Functions (class)
- Member Function vs Free Function
-
int length() is member function of string class
-
int sqrt(int) is not part of any class
- String Example: Yes of No Response
- What can go wrong when expecting a yes/no response?
- Look at
yesOrNo.cpp
- What is not tested by this example main()?
- What is a more practical way to use this function?
- Preconditions and Postconditions for Functions