Class Crib Notes for CPSC 110 Brent Dingle
Friday, February 1, 2002
Reminders:
Lab Assignment 2 is due Feb 6 and 7
Review:
Robustness, Software Life Cycle
– 6 phases, Comparison Operators,
String variable type and char
variable type
Boolean Expressions, Conditional
Statements (if statements), While Loops
Side
note on char and string à chars are ONE symbol,
strings are zero to 255 chars.
You
may specify the max length of a string using square brackets, e.g.
VAR
test_str : string[30];
Would
limit test_str to being 0 to 30 characters long. IF you store something longer
than 30 chars in test_str, bad things (like memory corruption) happen.
Your Tasks for this weekend:
Find
out what the built in functions do: sqrt, abs, round, trunc, sqr, ln, exp. Review
MOD and DIV
Recall
Boolean Expressions were expressions that evaluate to TRUE or FALSE.
For
example: 5 = 5 is true.
‘a’ = ‘A’ is
false
‘Paul’ = ‘paul’
is false
5.30 = 5.3 is true (though doing equality compares on
reals can cause errors)
3 < 27 is
true, and so on.
The
simple if:
IF
(Boolean expression evaluates to true) THEN ß notice NO semi-colon
Begin
Do this stuff;
End;
The
simple while:
WHILE
(Boolean expression evaluates to true) DO
ß again NO semi-colon
Begin
Do this stuff;
End;
Aside:
IF you want ONLY ONE statement done if/while the Boolean expression is true
then the ‘begins’ and ‘ends’ are optional. For ‘good’ programming always use
them.
Loops
have EXIT conditions.
The
Exit condition of a WHILE loop occurs when its Boolean expression becomes
false.
Definition:
When you have begins and ends associated with ifs and loops the stuff starting
with the begin and ending with the end is referred to as a compound
statement. See the book for a more formal def.
FILE
Input/Output Commands (i.e. file I/O):
assign,
reset, rewrite, append, close
new
variable type à TEXT
Some
example posted on the web:
maketext.pas,
readtext.pas, read_in.txt,
askread.pas, loopread.pas, loop_in.txt, eofread.pas,
eof_in.txt.