CPS 1 - Spring, 1997 - Ramm 2/10/97 #11
Chapter 2. Text Manipulation and Algorithm Design
- Loops: "Off by One"
- i := 0;
- while i < 10 do
- begin
- i := i + 1;
- writeln(i);
- end;
produces same output as:
- i := 1;
- while i <= 10 do
- begin
- writeln(i);
- i := i + 1;
- end;
- Loops: Other Ranges
- start := 10;
- stop := 20;
- i := start;
- while i < stop do
- begin
- i := i + 1;
- writeln(i);
- end;
Tracing
Loops: I/O Controlled
- readln(start);
- readln(stop);
- i := start;
- while i < stop do
- begin
- i := i + 1;
- writeln(i);
- end;
Chapter 3. Numerical Computation and a Study of Functions
- Data Types and Limitations
- String
- length limited to 255
- any valid character is ok
- Integer
- limited size: 32767 thru -32768
(details vary with machine & language)
- whole numbers only (no fractions)
- fixed granularity
New type: Real
- large range of numbers,
(details vary with machine & language)
- varying granularity
- handles fractions
(analogous to scientific notation)
- good for any everyday calculation;
- also called floating point
- (Note underneath is binary; therefore cannot represent all
fractions exactly; can get rather close).
Operations on Reals
- + , - , * , / (not div !)
- < , > , = , <>
- (watch out for what you mean by equal)
Programs using Reals
volsphere.pas
Write Fahrenheit to Celsius Conversion Program
- In Class
- Table
- Pretty I/O