CPS 6, Ramm - Summer Semester I - 6/1/00 #10
- Announce
- Test ...
- Quiz Monday
- Lab Today
Chapt 6. Classes, Iterators, and Patterns
- A Swap Routine
- 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?
- 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.cc
- Input File Streams
-
#include
-
ifstream streamname
-
streamname.open(filename)
-
streamname >> variable
wordcount2.cc
- UNIX File Streams
stdin, stdout
- Redirection
-
program < infilename
-
program > outfilename
-
program < infilename > outfilename
- Pipes
-
program1 | program2
-
program1 | program2 | program3
- Filters
- Extrema, Statistics
-
stats1.cc
-
stats2.cc
- Initialize with real data
- 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.cc
-
stats4.cc
- Text Processing Example
- Design Issues
- Moving Functionality to Functions
- Use of Reference Parameters
-
format.cpp
-
formatwatch.cpp
- More Reference Parameters (tricky)
-
ref.cpp