Class Crib Notes for CPSC 110 Brent Dingle
Monday, February 4, 2002
Reminders:
Lab Assignment 2 is due Feb 6 and 7
Review:
Read
up on the built in functions do: sqrt, abs, round, trunc, sqr, ln, exp.
Understand MOD and DIV
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.
More
I/O stuff
EOF = End Of File
Example:
while
(NOT (eof(infile)) ) DO
BEGIN
readln(infile, cur_str);
writeln(cur_str);
END;
EOLN = End Of LiNe ~~= Carriage Return Line Feed = CRLF
Boolean
Tables for NOT, OR and AND (try
combining them like NOT (a OR b) )
Short
Circuit evaluation – Pascal’s default behavior
Consider if a = 12 and b = 0 what happens when we do
IF
(a < 10) AND (a / b = 4) THEN
whatever
What would happen if Short Circuit Evaluation was
NOT used (hint runtime error divide by zero)
Comparison
Operators ( <, <=, =, >, >=, <>) and new one IN
Example:
IF
(ch IN [‘a’, ‘e’, ‘i’, ‘o’, ‘u’, ‘A’, ‘E’, ‘I’, ‘O’, ‘U’] THEN
Begin
Writeln(‘ch is a vowel);
End
ELSE ß sneaky introduction of ELSE
Begin
Writeln(ch is a consonant’);
End;
Next
time more on If-Else and nested ifs and CASE statements