CPS 1 - Spring, 1997 - Ramm 2/3/97 #8
- Announce
- Quiz on Wednesday: Check out Web
Chapter 2. Text Manipulation and Algorithm Design
- Copy (Substring) Function
- string := COPY(string, start, length);
- can get null string
- Length Function
- length := LENGTH(string);
- can get 0
- Position Function
- position := POS(substring, string);
- get 0 if not found
- first occurrence
- Example: Pig Latin
- He is a good cook => ehay siway away oodgay ookcay
- The teacher is coming => hetay eachertay siway omingcay
-
piglatin.pas
-
piglatin2.pas
- Loops!! ... and it all happened again ...
- The Infinite Loop
- WHILE true DO
- BEGIN
- statement;
- ...
- statement;
- END
loop1.pas
- Incorporate WHILE in previous programs
piglatin3.pas
- Character Translation
The "CryptoQuote" Problem
translate.pas
translate2.pas
- The Controlled WHILE Loop
- WHILE logical expression DO
- BEGIN
- statement;
- ...
- statement;
- END
- statements repeated as long as logical expression is true
- For proper loop: at least one of previous
statements must cause change in logical expression
- More Looping Examples
loop2.pas
loop3.pas