CPS 6, Ramm - Summer Semester I - 5/31/99 #8
- Announce
- Individual Meeting Today
- Coin Toss for Random Quiz #4
- Problems with Quiz #4 ?
- Test Wednesday, review tomorrow: bring questions
- See sample test on web
Chapt 5. Iteration with Programs and Classes
- Dice/While Example
roll300.cc
- Diamonds are for Fun
diamonds.cc
- More Looping: Math Tables
formerly got PhD for better tables
pow1.cc
pow2.cc
-
for Loop Syntax
- for(initialization; test expression; update)
- {
- statement list
- }
- Use where number of iterations is "known"
- Good for most examples shown previously
- Class: Modify
blastoff.cc
- Problem: Adder Program
- Add an unknown number of numbers
- When to quit
- Sentinel Value
-
while
or for ?
adder.cc
- Defining Constants
const type identifier = value;
all caps
- Pre-tested and Post-tested Loops
- Iteration (post-tested)
- initialization
- loop body
- update
- loop test
-
do-while Loop Syntax
- do
- {
- statement list
- } while ( test expression )
- Using the
do-while Loop
addwhile.cc
- Infinite Loops
-
break Statement
- Nested Loops
multable.cc
done previously by using function
e.g. roll300.cc
- Scope of Variables
- definition
- braces { }
- Private Variables
- Global Variables (XXX)
Chap 6. Sequential Access: Streams and Iterators
- Stream Iteration: Counting Words
- white space
- ' ', '\t', '\n'
- sentinel
- buffered input
-
cin.fail()
-
while (cin >> word)
wordcount.cc
- UNIX input redirection
program < filename
- Input File Streams
-
#include
-
ifstream streamname
-
streamname.open(filename)
-
streamname >> variable
wordcount2.cc