CPS 6, Ramm - Spring 2000 - 1/31/00 #7
Chapter 2: C++ Programs: Form and Function
- 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