x |
Build Dog Lot. ********|
Put fence next to wall. * |
Have one roll of fencing. * |
y * |
* |
* |
* |
********|
x |
Finding the Maximum
- trial value
- improve by finding better value
use loop
- e.g. who is tallest in the room?
- what trial value?
- use impossible or actual value
Automated Program
fence2.pas
Arrays, Motivation
- Aggregate Data Type
- Deal with items of same type
- Lists
- numbers
- words
- (any other type)
- Analogies
- mailboxes in PO
- CD rack with slots
- Simplifies Naming
- Allows use of Loops
- Required for:
- required for statistical problems
- required for dealing with lists
Have Multiple Elements or Cells
Use SUBSCRIPT or INDEX to Identify Element
- Subscripts are usually integers in brackets
- x[5] := 21;
- writeln( x[5] );
Use Arrays in a Loop
- k:= 0;
- while ( k < 10 ) do
- begin
- k := k + 1;
- writeln( name[i] );
- end;
Setting it all up...
Arrays Syntax: Define New Type
- TYPE
- arraytypename = ARRAY[1..n] OF type;
Arrays Syntax: Declare the Array
- VAR
- arrayname:arraytypename;
Subscript Range!!!
Simple Examples
Real Example
payout.pas