CPS 1 - Spring, 1997 - Ramm 1/29/97 #6
- Announce
- Drop Add ending; If you haven't heard: NO
- Quiz today
- Go over last week's quiz (usually earlier)
Chapter 2. Text Manipulation and Algorithm Design
- Assignment Statement
x := y;
- contents of x destroyed;
- becomes identical to contents of y
- COPY, not a MOVE
- First Algorithm: Exchange Problem
- x contains 'milk'
- y contains 'juice'
- how do we interchange contents?
- use temp
-
- var
- x, y, temp:string;
- ...
- readln(x);
- readln(y);
- writeln(x, ' ', y);
- temp := x;
- x := y;
- y := temp;
- writeln(x, ' ', y);
- ...
- Note new form of writeln:
- writeln(a, b, c);
- writeln(a, ' and ', b, ' or ', c);
exc1.pas,
exc2.pas
- In Place Solution (optional: don't listen!)
- Numeric Example:
- x = 21, y = 37
- y = y - x = 16
- x = x + y = 21 + 16 = 37
- y = x - y = 37 - 16 = 21
- x = 37, y = 21
- lot of work
- What is 2 + 2 ?
- String Concatenation Operation: +
-
- var
- x, y, z:string;
- ...
- readln(x);
- readln(y);
- writeln(x, ' ', y);
- z := x + y;
- writeln(x, ' ', y, ' ', z));
- writeln(x, x, ' ', y+y, ' ', z+z));
- ...
additions.pas
- STRING and INTEGER Data Types
- var
- x, y: string;
- a, b: integer;
- Also have REAL; will use later
- Other Operators for INTEGERS
- Arithmetic:
- +, -
- *, div
- Comparison:
- <, >
- <> =