CPS 6.3,4 Ramm - Fall 2000 - 9/11/00 #7
- Announce
- Quiz Friday
- Answers to last quiz on Web
- Consultants on Web
- Peer Tutoring/Academic Skills
Chap 4: Control, Function, and Classes
- 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
- 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 )
- 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 Respone
- 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