CPS 6.3,4 Ramm - Fall 2000 - 9/27/00 #14
- Announce
- Quiz Friday
- Exam next Wednesday
- In-class Review on Monday (Q&A)
- Old Exams On-Line
Chap 6. Classes, Iterators, & Patterns
- The Swap Problem and a Swap Function
- Swap x and y
- Want to use: tmp=x; x=y; y=tmp;
- How do we package this as a functions Swap(a, b)?
- Write Swap
- Reference Parameters
- Arguments NOT copied
- (Value parameters are copied)
- Side effects
- How Do We "return" More Than One Value?
- Sometimes "return" refers to return
- Sometimes "return" refers to getting information out
Possibly via the parameters
- Reference Parameters vs Value Parameters
- Time: value parameters slower for large arg copy
ref parameters faster
- Space: value parameters require space for arg copy
ref parameters don't require extra space
- Security: Value parameters guaranty no side effects
ref parameters allow changes to be made to outside
- Having Your Cake and Eating it Too
- Const Reference Parameters
- Save time and space
- Still protected
- Stream Iteration: Counting Words
wordcount.cpp
- Input File Streams
-
#include
-
ifstream streamname
-
streamname.open(filename)
-
streamname >> variable
wordcount2.cpp
- UNIX File Streams
stdin, stdout
- Redirection
-
program < infilename
-
program > outfilename
-
program < infilename > outfilename
- Pipes
-
program1 | program2
-
program1 | program2 | program3
- Filters
- Extrema, Statistics
- Type Casting (coercion)
- Change one type to another
- Only defined where it makes sense
- Several different forms exist
- E.g., changing int to double
- double(n)
- (double) n
- Using Reference Parameters
-
stats3.cpp
-
stats4.cpp