CPS 6 Ramm - Spring 2001 - 2/16/01 #15
Chap 6. Classes, Iterators, & Patterns
- 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
- Text Processing Example
- Design Issues
- Moving Functionality to Functions
- Use of Reference Parameters
-
format.cpp
-
formatwatch.cpp
- More Reference Parameters (tricky)
-
ref.cpp
Chap 7. Class Interfaces, Design, and Implementation
- Switch Statement
- switch ( expression )
- {
- case constant1:
- statement list;
- break;
- case constant2:
- statement list;
- break;
- ...
- default:
- statement list;
- }
- Example Using the Switch Statement