CPS 6.3,4 Ramm - Fall 2000 - 9/18/00 #10
- Announce
- Quiz Solutions On-Line
- Sample questions next Friday's quiz
Chapt 5. Iteration with Programs and Classes
- Diamonds are for Fun
diamonds.cpp
Tracing a program
- More Looping: Math Tables
formerly got PhD for better tables
pow1.cpp
pow2.cpp
- The Fence Post Problem
-
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.cpp
- Problem: Adder Program
- Add an unknown number of numbers
- When to quit
- Sentinel Value
-
while
or for ?
adder.cpp
- 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.cpp
- Infinite Loops
-
break Statement
- Nested Loops
multable.cpp
nesting can be hidden by using function
- Scope of Variables
- definition
- braces { }
- Private Variables
- Global Variables (XXX)